Module app

Class Utils

java.lang.Object
app.chess.utils.Utils

public final class Utils extends Object
  • Method Details

    • roadNotObstructed

      public static boolean roadNotObstructed(Field currentPosition, Field newPosition, ChessPiece[][] board)
    • getRookPositionBasedOnCastling

      public static Field getRookPositionBasedOnCastling(Castle move)
      Returns:
      Assuming that castling is possible, returns the position on which the rook should be located. Makes ABSOLUTELY NO GUARANTEE that castling is legal.

      TODO: Placement of this function is bad. Find a class where it makes more sense.

    • fieldIsValid

      public static boolean fieldIsValid(Field toValidate)
    • getPieceByField

      public static ChessPiece getPieceByField(Field field, ChessPiece[][] board)
    • putPieceOnBoard

      public static ChessPiece putPieceOnBoard(ChessPiece who, Field field, ChessPiece[][] board)
      Puts the piece on a given piece on board, WITHOUT changing any data about piece location (inside the piece). Should be used with caution.
      Returns:
      Piece that was already on a given field
    • getMatchingPieces

      public static List<ChessPiece> getMatchingPieces(boolean checkPlayer, int player, ChessPiece[][] board)
      Parameters:
      checkPlayer - Whether to return pieces of only one player
      player - Player whose pieces should be returned
      Returns:
      All pieces on board that satisfact the given criteria
    • fieldIsUnderAttack

      public static boolean fieldIsUnderAttack(int byWho, Field field, ChessPiece[][] board)
    • getKingsPosition

      public static Field getKingsPosition(int player, ChessPiece[][] board)
    • kingIsSafe

      public static boolean kingIsSafe(int whose, ChessPiece[][] board)
    • findPawnThatCanBePromoted

      public static ChessPiece findPawnThatCanBePromoted(int player, ChessPiece[][] board)
    • inferNewRookPositionAfterCastling

      public static Field inferNewRookPositionAfterCastling(Castle move)