diff --git a/src/fr/insalyon/chess/ChessGame.java b/src/fr/insalyon/chess/ChessGame.java index dde9968..7441514 100644 --- a/src/fr/insalyon/chess/ChessGame.java +++ b/src/fr/insalyon/chess/ChessGame.java @@ -8,4 +8,4 @@ public class ChessGame { public static void main(String ... args) { Application.launch(GameApplication.class); } -} +} \ No newline at end of file diff --git a/src/fr/insalyon/chess/Game.java b/src/fr/insalyon/chess/Game.java index 8f1dc49..71ae3fd 100644 --- a/src/fr/insalyon/chess/Game.java +++ b/src/fr/insalyon/chess/Game.java @@ -13,7 +13,7 @@ import fr.insalyon.chess.core.pawns.Queen; import fr.insalyon.chess.core.pawns.Rook; -public class Game implements Cloneable { +public class Game { private AbstractPawn[][] board; private int currentPlayer = 0; @@ -85,11 +85,16 @@ public void display() { System.out.println(Arrays.deepToString(board)); } - //The game is over + /** + * Game ending state for a team + * @param team + * @return + */ public End gameOver(Team team) { Location[] escapeMoves = new Location[0]; + //Possible escape moves for the king for(int i = 0; i < 8; i++) { for(int j = 0; j < 8; j++) { AbstractPawn pawn = board[i][j]; @@ -108,8 +113,11 @@ public End gameOver(Team team) { } return End.NONE; } - - //The king is in threat + /** + * The king is in threat ? + * @param team + * @return + */ public boolean check(Team team) { King king = getKing(team); @@ -137,14 +145,4 @@ public King getKing(Team team) { } return king; } - - public Object clone() { - Object clonedGame = null; - try { - clonedGame = super.clone(); - } catch(CloneNotSupportedException exception) { - exception.printStackTrace(); - } - return clonedGame; - } } diff --git a/src/fr/insalyon/chess/ai/ChessAI.java b/src/fr/insalyon/chess/ai/ChessAI.java index 562f30b..2387eaa 100644 --- a/src/fr/insalyon/chess/ai/ChessAI.java +++ b/src/fr/insalyon/chess/ai/ChessAI.java @@ -7,7 +7,14 @@ import fr.insalyon.chess.core.pawns.King; public class ChessAI { + + /* + * ATTENTION + * + * Ancienne version : regarder ChessAI3 + * + */ //Avoid suicide variables private Location[] allTargetedLocations = new Location[0]; diff --git a/src/fr/insalyon/chess/ai/ChessAI2.java b/src/fr/insalyon/chess/ai/ChessAI2.java index 24ea0d2..04ecebc 100644 --- a/src/fr/insalyon/chess/ai/ChessAI2.java +++ b/src/fr/insalyon/chess/ai/ChessAI2.java @@ -11,6 +11,12 @@ public class ChessAI2 { private int pieces = 0; private int enemyPieces = 0; + /* + * ATTENTION + * + * Ancienne version : regarder ChessAI3 + * + */ private void setupVariables(Game game, Team team) { pieces = 0; @@ -54,7 +60,6 @@ public int evalState(AbstractPawn[][] board, Team team) { //Min max tree implementation public void play(Game game, Team team) { - game = (Game) game.clone(); AbstractPawn[][] board = game.getBoard(); int initialValue = evalState(board, Team.BLACK); diff --git a/src/fr/insalyon/chess/ai/ChessAI3.java b/src/fr/insalyon/chess/ai/ChessAI3.java index 04dfc42..5813dc2 100644 --- a/src/fr/insalyon/chess/ai/ChessAI3.java +++ b/src/fr/insalyon/chess/ai/ChessAI3.java @@ -6,25 +6,6 @@ import fr.insalyon.chess.core.Team; public class ChessAI3 { - - private Location[] allTargetedLocations = new Location[0]; - private int enemyPieces = 0; - - - private void setupVariables(Game game, Team team) { - enemyPieces = 0; - for(int i = 0; i < 8; i++) { - for(int j = 0; j < 8; j++) { - AbstractPawn pawn = game.getBoard()[i][j]; - if(pawn == null) continue; - if(pawn.getTeam() != team) { - Location[] targets = pawn.getMovement(game, pawn.getLocation(), true); - allTargetedLocations = Location.concat(allTargetedLocations, targets); - enemyPieces++; - } - } - } - } /* * Return an integer giving a perspective of the current board for a given team @@ -59,7 +40,6 @@ public void play(Game game, Team team) { long firstTime = System.currentTimeMillis(); - game = (Game) game.clone(); AbstractPawn[][] board = game.getBoard(); int initialValue = evalState(game, Team.BLACK); @@ -67,14 +47,9 @@ public void play(Game game, Team team) { Location bestTo = null; AbstractPawn bestPawn = null; - int depth = 4; - - setupVariables(game, team); - if(enemyPieces == 1) { - depth = 5; - } + int depth = 3; - System.out.println("INITIAL STATE " + initialValue); + System.out.println("INITIAL SCORE " + initialValue); int a = 0; for(int i = 0; i < 8; i++) { @@ -94,10 +69,8 @@ public void play(Game game, Team team) { game.movePawn(from, targetedLoc); game.rotatePlayer(); -// System.out.println("Start min max for " + pawn.getName() + " to " + targetedLoc); //Recursive tree int value = miniMax(game, game.getCurrentPlayer(), depth, Integer.MIN_VALUE, Integer.MAX_VALUE, false); -// System.out.println("MIN VALUE FOR STRIKE " + (a++) + " is " + value); //Is it the best one ? if(value >= bestValue) { @@ -119,7 +92,7 @@ public void play(Game game, Team team) { game.movePawn(bestPawn.getLocation(), bestTo); System.out.println("Alpha beta triggered " + b); long timeDif = System.currentTimeMillis() - firstTime; - System.out.println("Time taken = " + timeDif); + System.out.println("Time taken = " + timeDif + "ms"); System.out.println("__________________________"); } } diff --git a/src/fr/insalyon/chess/core/MovementBuilder.java b/src/fr/insalyon/chess/core/MovementBuilder.java index d146e9b..74f2f8e 100644 --- a/src/fr/insalyon/chess/core/MovementBuilder.java +++ b/src/fr/insalyon/chess/core/MovementBuilder.java @@ -55,6 +55,7 @@ public void add(MovementType movementType, Location from, Location to) { row += rowInc; col += colInc; Location newLocation = new Location(row, col); + //Check collision and if allowed or not ? (for little pawn purpose) if(collide) { noCollision = Game.isEmpty(board, newLocation); } diff --git a/src/fr/insalyon/chess/gui/GameApplication.java b/src/fr/insalyon/chess/gui/GameApplication.java index 009e3e1..5a12af4 100644 --- a/src/fr/insalyon/chess/gui/GameApplication.java +++ b/src/fr/insalyon/chess/gui/GameApplication.java @@ -32,10 +32,11 @@ public class GameApplication extends Application { public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Jeu d'échecs"); - // Chess board + // Generate the game object this.game = new Game(); game.init(); + // Draw the chess board this.boardGrid = new GridPane(); this.boardScene = new Scene(boardGrid, WIDTH, HEIGHT); @@ -91,7 +92,7 @@ public void drawPieces() { private ImageView createPawnNode(AbstractPawn pawn) { // Retrieve the proper pawn image - Image image = new Image(pawn.getTeam().getName() + "_" + pawn.getName() + ".png"); + Image image = new Image("resources/" + pawn.getTeam().getName() + "_" + pawn.getName() + ".png"); ImageView pieceImage = new ImageView(image); // Define drag and drop event diff --git a/src/fr/insalyon/chess/gui/Menu.java b/src/fr/insalyon/chess/gui/Menu.java deleted file mode 100644 index f38459e..0000000 --- a/src/fr/insalyon/chess/gui/Menu.java +++ /dev/null @@ -1,14 +0,0 @@ -package fr.insalyon.chess.gui; - -import javafx.scene.Parent; -import javafx.scene.Scene; - -public class Menu extends Scene { - - public Menu(Parent root) { - super(root); - } - - - -} diff --git a/src/fr/insalyon/chess/gui/TakePlaceHandler.java b/src/fr/insalyon/chess/gui/TakePlaceHandler.java index 872a4dc..2604b9e 100644 --- a/src/fr/insalyon/chess/gui/TakePlaceHandler.java +++ b/src/fr/insalyon/chess/gui/TakePlaceHandler.java @@ -38,6 +38,7 @@ public void handle(DragEvent event) { gameApplication.refresh(); event.setDropCompleted(true); if(!checkOver()) { + //Launch the AI turn in async gameApplication.setComputerTurn(true); AsyncComputerPlay asyncComputerPlay = new AsyncComputerPlay(gameApplication); asyncComputerPlay.setOnSucceeded(new EventHandler() {