trying to implement undolastmove with hashmaps, they work like

dictionnaries in python, the key will be turnNb and the associated value
will be the arraylist associated
This commit is contained in:
hugomanipoud2 2025-05-23 10:50:59 +02:00
parent f4cf1e6904
commit 7fe7f6c17e
1 changed files with 3 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package backend; package backend;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; // for unddolastmove
public class Board { public class Board {
private int column; // constructors for column and line private int column; // constructors for column and line
@ -11,7 +12,7 @@ public class Board {
private int selectX = -1; private int selectX = -1;
private int selectY = -1; private int selectY = -1;
private Move move; private Move move;
private int zero = -1; private HashMap<Integer, ArrayList<Piece>> boardHistory; // hashmap for undolastmove
//initiation of the board, creating an 8 * 8 grid //initiation of the board, creating an 8 * 8 grid
public Board(int colNum, int lineNum) { public Board(int colNum, int lineNum) {
@ -19,6 +20,7 @@ public class Board {
this.line = lineNum; this.line = lineNum;
this.pieces = new ArrayList<>(); this.pieces = new ArrayList<>();
this.move = new Move(pieces, this); //adding an acces to Move methods and linkking the arraylist to the class methods this.move = new Move(pieces, this); //adding an acces to Move methods and linkking the arraylist to the class methods
this.boardHistory = new HashMap<>(); //for history of the board an make undolastmove possible, acts like a dictionnary in python
} }
@ -37,10 +39,6 @@ public class Board {
public void setTurnNb(int turnNb) { public void setTurnNb(int turnNb) {
this.turnNb = turnNb; this.turnNb = turnNb;
} }
public int getZero() {
return this.zero;
}
public boolean isTurnWhite() { public boolean isTurnWhite() {
if (turnNb % 2 == 0){ if (turnNb % 2 == 0){