So, I am making a chess engine in Java. Given the current configuration of the board, the AI should find out every possible move that it can make, add it to the linked list of all possible moves and return this list. I am currently testing the following board configuration:
“bR” means the black rook, “bN” means the black knight, etc. "Nu" means "zero" or "no." In this configuration, I moved the lower left rook to the middle of the board.
The next method possibleMoves()in my class Mobilityis what should generate and return a linked list of all possible board configurations. Each index icorresponds to parts on the board starting from the left. In this case, AI is white, so 0 is the leftmost white pawn, 7 is the rightmost white pawn, 8 is the white rook now in the center of the board, 9 is the other white rook, etc. Right now I'm just checking the rooks, so the other conventions are empty. nonPawnBoardGen()returns a list of possible board configurations.
public LL possibleMoves(){
LL children = new LL();
for(int i = 0; i < 16; i++){
if(i < 8){
}
else if(i < 10){
children.joinWith(nonPawnBoardGen(i, 0, -1));
children.joinWith(nonPawnBoardGen(i, 0, 1));
children.joinWith(nonPawnBoardGen(i, -1, 0));
children.joinWith(nonPawnBoardGen(i, 1, 0));
}
else if(i < 12){
}
else if(i < 14){
}
else{
}
}
return children;
}
joinWith(), in my LL class, joins a subscription with a general list of related children.
public void joinWith(LL newList){
if(newList.isEmpty())
return;
if(this.isEmpty()){
first = newList.getFirst();
last = newList.getLast();
}
else{
last.next = newList.getFirst();
last = newList.getLast();
}
}
nonPawnBoardGen() - , index . , , nonPawnBoardGen(8, 0, -1), - 8, . , , , .
private LL nonPawnBoardGen(int index, int vecR, int vecC){
LL boardSubLst = new LL();
int sR, sC;
if(turn == true){
if(coords[index + 16] == null){
return null;
}
sR = coords[index + 16].getRow();
sC = coords[index + 16].getCol();
}
else{
if(coords[index] == null){
return null;
}
sR = coords[index].getRow();
sC = coords[index].getCol();
}
int curR = sR;
int curC = sC;
curR+=vecR;
curC+=vecC;
while(curR > -1 && curR < 8 && curC > -1 && curC < 8){
if(turn == true){
if(board[curR][curC].charAt(0) != 'w'){
coords[index + 16].setRow(curR);
coords[index + 16].setCol(curC);
if(board[curR][curC].charAt(0) == 'b'){
int r, c;
for(int j = 0; j < 16; j++){
r = coords[j].getRow();
c = coords[j].getCol();
if(curR == r && curC == c){
coords[j] = null;
boardSubLst.insert(coords);
break;
}
}
break;
}
else{
boardSubLst.insert(coords);
}
}
else{
break;
}
}
else{
if(board[curR][curC].charAt(0) != 'b'){
coords[index].setRow(curR);
coords[index].setCol(curC);
if(board[curR][curC].charAt(0) == 'w'){
int r, c;
for(int j = 0; j < 16; j++){
r = coords[j + 16].getRow();
c = coords[j + 16].getCol();
if(curR == r && curC == c){
coords[j + 16] = null;
boardSubLst.insert(coords);
break;
}
}
break;
}
else{
boardSubLst.insert(coords);
}
}
else{
break;
}
}
curR+=vecR;
curC+=vecC;
}
return boardSubLst;
}
, nonPawnBoardGen(), , , ( ):
coords[index + 16].setRow(curR);
coords[index + 16].setCol(curC);
:
boardSubLst.insert(coords);
, coords, boardSubList coords. ?
EDIT:
, , nonPawnBoardGen() . , . possibleMoves(). , ...