Fixes?
This commit is contained in:
parent
02b49c9437
commit
dbc494042b
|
@ -6,9 +6,7 @@
|
|||
<component name="ChangeListManager">
|
||||
<list default="true" id="41395b4b-3252-492c-a869-5f4dab107186" name="Changes" comment="Fixes?">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/Client.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Client.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/MiniMax.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/MiniMax.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/MovingBoard.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/MovingBoard.java" afterDir="false" />
|
||||
</list>
|
||||
<list id="98b8a79f-2f53-42bf-96da-7af322697a0d" name="Changes by acastonguay" comment="" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
@ -134,7 +132,8 @@
|
|||
<workItem from="1679424430928" duration="11764000" />
|
||||
<workItem from="1679593788411" duration="10753000" />
|
||||
<workItem from="1679672719638" duration="8340000" />
|
||||
<workItem from="1679779362814" duration="5861000" />
|
||||
<workItem from="1679779362814" duration="5912000" />
|
||||
<workItem from="1679787823160" duration="2189000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="MiniMax">
|
||||
<created>1679263366439</created>
|
||||
|
@ -164,7 +163,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1679682974611</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="5" />
|
||||
<task id="LOCAL-00005" summary="Fixes?">
|
||||
<created>1679786894920</created>
|
||||
<option name="number" value="00005" />
|
||||
<option name="presentableId" value="LOCAL-00005" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1679786894920</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="6" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
|
|
|
@ -40,7 +40,6 @@ public class Client {
|
|||
|
||||
if (cmd == '5') {
|
||||
stopGame();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -109,19 +109,89 @@ public class MiniMax {
|
|||
int score = pawns.size() * 5;
|
||||
|
||||
for (MovingPawn pawn : pawns) {
|
||||
int row = pawn.getRow();
|
||||
int goal = pawn.getPlayer().getGoal();
|
||||
|
||||
if (row == goal) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
score += Math.abs(goal - row);
|
||||
score += evaluate(board, pawn);
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
private static int evaluate(MovingBoard game, MovingPawn pawn) {
|
||||
if (pawn.getRow() == pawn.getPlayer().getGoal()) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
// Favorise les pièces qui peuvent gagner au prochain tour
|
||||
if (pawn.getRow() + pawn.getDirection() == pawn.getPlayer().getGoal()) {
|
||||
return Integer.MAX_VALUE / 2;
|
||||
}
|
||||
|
||||
int score = 0;
|
||||
score += attackScore(game, pawn);
|
||||
|
||||
// Favorise les attaques de notre côté
|
||||
if ((pawn.getPlayer().getGoal() - pawn.getRow()) / 2f < 4) {
|
||||
score *= 2;
|
||||
}
|
||||
|
||||
score += getValidMoveCount(game, pawn) * 50;
|
||||
|
||||
// Favorise les pushed
|
||||
if (!pawn.isPusher()) {
|
||||
score += 50;
|
||||
}
|
||||
|
||||
// Favorise les pièces qui n'ont pas encore bougées
|
||||
if (pawn.getRow() == (pawn.getPlayer() == Player.RED ? 0 : 7)) {
|
||||
score += 50;
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
private static int attackScore(MovingBoard game, MovingPawn pawn) {
|
||||
int score = 0;
|
||||
if (nextToOtherPlayer(game, pawn, -1)) {
|
||||
score += 100;
|
||||
}
|
||||
if (nextToOtherPlayer(game, pawn, 1)) {
|
||||
score += 100;
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
private static boolean nextToOtherPlayer(MovingBoard game, MovingPawn pawn, int colOffset) {
|
||||
int row = pawn.getRow() + pawn.getDirection();
|
||||
int col = pawn.getCol() + colOffset;
|
||||
|
||||
if (col < 0 || col > 7) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MovingPawn dest = game.getBoard()[row][col];
|
||||
return dest != null && dest.getPlayer() != pawn.getPlayer();
|
||||
}
|
||||
|
||||
private static int getValidMoveCount(MovingBoard game, MovingPawn pawn) {
|
||||
int moveCount = 0;
|
||||
|
||||
// Diagonale gauche
|
||||
if (pawn.getCol() > 0) {
|
||||
moveCount++;
|
||||
}
|
||||
|
||||
// Il n'y a pas de pièce adverse devant
|
||||
if (!nextToOtherPlayer(game, pawn, 0)) {
|
||||
moveCount++;
|
||||
}
|
||||
|
||||
// Diagonale droite
|
||||
if (pawn.getCol() < 7) {
|
||||
moveCount++;
|
||||
}
|
||||
|
||||
return moveCount;
|
||||
}
|
||||
|
||||
static class Action {
|
||||
private final MovingPawn pawn;
|
||||
private final Pawn.PawnMovement movement;
|
||||
|
|
Loading…
Reference in New Issue