Compare commits

..

No commits in common. "ad8ddd6418e4c5d88eae497a744625a569e7c16a" and "02e83697f544c0afdaf54a68824e39c7a7cb5cd5" have entirely different histories.

3 changed files with 16 additions and 77 deletions

View File

@ -1,39 +1,17 @@
package backend;
import java.util.ArrayList;
import java.util.Random;
public class AutoPlayer {
private Random rand = new Random();
public Move computeBestMove(Board board) {
ArrayList<Move> possibleMoves = new ArrayList<>();
boolean whiteTurn = board.isTurnWhite();
for (Piece p : board.getPieces()) {
if (p.isWhite() == whiteTurn) {
ArrayList<int[]> moves = Move.getPossibleMoves(board, p);
for (int[] pos : moves) {
int toX = pos[0];
int toY = pos[1];
Piece captured = board.getPieceAt(toX, toY);
Move move = new Move(p, p.getX(), p.getY(), toX, toY, captured);
possibleMoves.add(move);
}
}
}
// Si aucune possibilité => null
if (possibleMoves.isEmpty()) return null;
// Cherche un coup qui capture une pièce
for (Move m : possibleMoves) {
if (m.getCapturedPiece() != null) {
return m;
}
}
// Sinon, retourne un coup aléatoire
return possibleMoves.get(rand.nextInt(possibleMoves.size()));
}
/**
* returns the best Move to try on provided board for active player
* @param board
* @return
*/
public Move computeBestMove(Board board) {
return null;
}
}

View File

@ -257,39 +257,6 @@ public class Board {
public void playMove(Move move) {
if (move == null) return;
<<<<<<< HEAD
Piece pieceToMove = getPieceAt(move.getFromX(), move.getFromY());
if (pieceToMove == null) return;
// Supprimer la pièce d'origine
pieces.remove(pieceToMove);
// Supprimer la pièce capturée (si elle existe)
Piece captured = getPieceAt(move.getToX(), move.getToY());
if (captured != null) {
pieces.remove(captured);
}
// Ajouter la nouvelle position
Piece newPiece = new Piece(
pieceToMove.getType(),
pieceToMove.isWhite(),
move.getToX(),
move.getToY()
);
pieces.add(newPiece);
// Enregistrer dans l'historique pour undo
moveHistory.add(move);
// Fin de tour
turnNumber++;
// Désélection et surlignage off
selectedX = -1;
selectedY = -1;
highlightedSquares.clear();
=======
// Remove the moved piece from its old position
Piece from = move.getMovedPiece();
pieces.removeIf(p -> p.getX() == from.getX() && p.getY() == from.getY());
@ -305,13 +272,8 @@ public class Board {
moveHistory.add(move);
turnNumber++;
>>>>>>> branch 'master' of https://gitarero.ecam.fr/g.vancompernolle/OOP_2B3_Project.git
}
<<<<<<< HEAD
=======
>>>>>>> branch 'master' of https://gitarero.ecam.fr/g.vancompernolle/OOP_2B3_Project.git
public Piece getPieceAt(int x, int y) {
for (Piece p : pieces) {
if (p.getX() == x && p.getY() == y) {

View File

@ -48,10 +48,9 @@ public class Game extends Thread {
}
private void aiPlayerTurn() {
if(isAITurn()) {
Move m = aiPlayer.computeBestMove(board);
board.playMove(m);
}
if(isAITurn()) {
board.playMove(aiPlayer.computeBestMove(new Board(board)));
}
}
public void clickCoords(int x, int y) {