This commit is contained in:
Utilisateur 2025-05-03 19:55:29 +02:00
parent 96593f2352
commit 820183e90b
3 changed files with 1015 additions and 287 deletions

View File

@ -1,8 +1,12 @@
package backend;
import java.util.ArrayList;
import java.util.Random;
public class AutoPlayer {
/**
* returns the best Move to try on provided board for active player
* @param board

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,96 @@
package backend;
public class Move {
private int fromX, fromY, toX, toY;
private Piece movingPiece;
private Piece capturedPiece;
private boolean isEnPassantCapture;
private boolean isCastling;
public Move(int fromX, int fromY, int toX, int toY, Piece movingPiece,
Piece capturedPiece, boolean isEnPassantCapture, boolean isCastling) {
this.fromX = fromX;
this.fromY = fromY;
this.toX = toX;
this.toY = toY;
this.movingPiece = movingPiece;
this.capturedPiece = capturedPiece;
this.isEnPassantCapture = isEnPassantCapture;
this.isCastling = isCastling;
}
public int getFromX() {
return fromX;
}
public int getFromY() {
return fromY;
}
public int getToX() {
return toX;
}
public int getToY() {
return toY;
}
public Piece getMovingPiece() {
return movingPiece;
}
public Piece getCapturedPiece() {
return capturedPiece;
}
public boolean isEnPassantCapture() {
return isEnPassantCapture;
}
public boolean isCastling() {
return isCastling;
}
@Override
public String toString() {
char fromFile = (char)('a' + fromX);
int fromRank = 8 - fromY;
char toFile = (char)('a' + toX);
int toRank = 8 - toY;
String result = fromFile + "" + fromRank + " to " + toFile + "" + toRank;
if (capturedPiece != null) {
result += " (captures " + capturedPiece.getType() + ")";
} else if (isEnPassantCapture) {
result += " (en passant)";
} else if (isCastling) {
result += " (castling)";
}
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Move other = (Move) obj;
return fromX == other.fromX &&
fromY == other.fromY &&
toX == other.toX &&
toY == other.toY;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + fromX;
result = prime * result + fromY;
result = prime * result + toX;
result = prime * result + toY;
return result;
}
}