Starlight-30036225 / ChessTCP

FILLMELATER
0 stars 0 forks source link

Moving pieces #20

Closed Starlight-30036225 closed 7 months ago

Starlight-30036225 commented 7 months ago

Now that the client can request for pieces to be moved, I need to allow them to actually be moved. This should be very simple but lets see.

Starlight-30036225 commented 7 months ago

public boolean move(Piece[][] board,String NewLocation) { if (GetPossibleMoves(board).contains(NewLocation)){ int oldx = x; int oldy = y; x = Character.getNumericValue(NewLocation.charAt(0)); y = Character.getNumericValue(NewLocation.charAt(1)); board[x][y] = this; board[oldx][oldy] = null; return true; } return false; }

This is a function inside the base piece class, it checks if a move is valid, then if it is executes it. Updating both its internal location value and its position on the board. Making its previous location null.

This function will need to be overriden by pawns and kings for their special rules (En-passant and castling respectively).

But first lets see if this works.

Starlight-30036225 commented 7 months ago

image image

image

image

image

Works as expected