Skip to content

Commit

Permalink
add getPiecesWithColor() function - Board class
Browse files Browse the repository at this point in the history
  • Loading branch information
OsamaX01 committed Aug 25, 2022
1 parent e5b6dea commit 218443b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/board/Board.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package board;

import general.Color;
import general.Square;
import general.Player;
import pieces.Piece;

import java.util.ArrayList;
import java.util.Arrays;

abstract public class Board {
Expand Down Expand Up @@ -56,6 +58,18 @@ public Piece getPieceAt(Square square) {
return pieces[square.getRow()][square.getColumn()];
}

public ArrayList<Piece> getPiecesWithColor(Player player) {
ArrayList<Piece> result = new ArrayList<>();
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (pieces[i][j] != null && player.equals(pieces[i][j].getOwner())) {
result.add(pieces[i][j]);
}
}
}
return result;
}

public abstract void initializeBoardWithPieces(Player white, Player black);

@Override
Expand Down
2 changes: 0 additions & 2 deletions src/general/GameState.java

This file was deleted.

23 changes: 23 additions & 0 deletions src/general/GameStatesChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package general;

import board.StandardChessBoard;
import pieces.Piece;

public class GameState {
public boolean isStillInCheck(StandardChessBoard board, Square from, Square to) {
board.removePiece(board.getPieceAt(to));
Piece currentPiece = board.getPieceAt(from);
board.removePiece(currentPiece);
currentPiece.setLocation(to);
board.addPiece(currentPiece);
return isCheck(board);
}

public boolean isCheck(StandardChessBoard board) {
return true;
}

public boolean isCheckMate() {
return true;
}
}

0 comments on commit 218443b

Please sign in to comment.