Part3.3
This commit is contained in:
parent
96593f2352
commit
820183e90b
|
|
@ -1,8 +1,12 @@
|
||||||
package backend;
|
package backend;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class AutoPlayer {
|
public class AutoPlayer {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the best Move to try on provided board for active player
|
* returns the best Move to try on provided board for active player
|
||||||
* @param board
|
* @param board
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,5 +1,96 @@
|
||||||
package backend;
|
package backend;
|
||||||
|
|
||||||
public class Move {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue