william #1

Merged
william merged 6 commits from william into master 2023-03-21 18:08:15 -04:00
2 changed files with 60 additions and 1 deletions
Showing only changes of commit faecae0822 - Show all commits

View File

@ -15,9 +15,13 @@ public class GameTree {
static class Node { static class Node {
private final Collection<Node> childs; private final Collection<Node> childs;
private final Pawn pawn;
private final Pawn.PawnMovement movement;
Node(Collection<Node> childs) { Node(Collection<Node> childs, Pawn pawn, Pawn.PawnMovement movement) {
this.childs = childs; this.childs = childs;
this.pawn = pawn;
this.movement = movement;
} }
public Collection<Node> getChilds() { public Collection<Node> getChilds() {

View File

@ -68,4 +68,59 @@ public class MiniMax {
return score; return score;
} }
private static int didWin(Pawn pawn) {
int goal = pawn.getPlayer() == Player.RED ? 7 : 0;
if (pawn.getRow() == goal) {
return Integer.MAX_VALUE;
}
return 0;
}
private static int didCapture(Pawn pawn, PusherBoard board) {
Pawn capturedPawn = board.getBoard()[pawn.getRow()][pawn.getCol()];
if (capturedPawn != null) {
if (capturedPawn.getPlayer() != pawn.getPlayer()) {
return 50;
}
}
return 0;
}
static class MiniMaxResult {
private final int score;
private final Pawn pawn;
private final Pawn.PawnMovement movement;
public MiniMaxResult(int score, Pawn pawn, Pawn.PawnMovement movement) {
this.score = score;
this.pawn = pawn;
this.movement = movement;
}
public int getScore() {
return score;
}
public Pawn getPawn() {
return pawn;
}
public Pawn.PawnMovement getMovement() {
return movement;
}
@Override
public String toString() {
return "MiniMaxResult{" +
"score=" + score +
", pawn=" + pawn +
", movement=" + movement +
'}';
}
}
} }