public void AreCoordinatesOverBoard2IntsNo() { GameObject obj = new GameObject(); obj.AddComponent <ChessBoard>(); ChessBoard board = obj.GetComponent <ChessBoard>(); Assert.That(!board.AreCoordinatesOverBoard(-1, 4) && !board.AreCoordinatesOverBoard(8, 4)); }
public void AreCoordinatesOverBoardVectorNo() { GameObject obj = new GameObject(); obj.AddComponent <ChessBoard>(); ChessBoard board = obj.GetComponent <ChessBoard>(); IntVector2 v1 = new IntVector2(-1, 4); IntVector2 v2 = new IntVector2(8, 4); Assert.That(!board.AreCoordinatesOverBoard(v1) && !board.AreCoordinatesOverBoard(v2)); }
public override Bitboard GetBasicMoves(ChessBoard chessBoard) { Bitboard moves = new Bitboard(); IntVector2 currentTile = chessBoard.GetTileCoordinates(this); IntVector2[] deltas = { IntVector2.right + 2 * IntVector2.up, 2 * IntVector2.right + IntVector2.up, 2 * IntVector2.right - IntVector2.up, IntVector2.right - 2 * IntVector2.up, -IntVector2.right + 2 * IntVector2.up, -2 * IntVector2.right + IntVector2.up, -2 * IntVector2.right - IntVector2.up, -IntVector2.right - 2 * IntVector2.up }; for (int i = 0; i < deltas.Length; i++) { IntVector2 check = currentTile + deltas[i]; if (!chessBoard.AreCoordinatesOverBoard(check)) { continue; } ChessPiece pieceAt = chessBoard.GetChessPieceAt(check); if (pieceAt == null) { moves[check.x, check.y] = true; } else if (pieceAt.pieceColor != pieceColor) { moves[check.x, check.y] = true; } } return(moves); }
public override Bitboard GetBasicMoves(ChessBoard chessBoard) { Bitboard moves = new Bitboard(); IntVector2 currentTile = chessBoard.GetTileCoordinates(this); IntVector2[] deltas = { IntVector2.one, -IntVector2.one, IntVector2.up - IntVector2.right, IntVector2.right - IntVector2.up }; for (int i = 0; i < deltas.Length; i++) { for (IntVector2 check = currentTile + deltas[i]; chessBoard.AreCoordinatesOverBoard(check); check += deltas[i]) { ChessPiece pieceAt = chessBoard.GetChessPieceAt(check); if (pieceAt == null) { moves[check.x, check.y] = true; } else if (pieceAt.pieceColor != pieceColor) { moves[check.x, check.y] = true; break; } else { break; } } } return(moves); }
public override Bitboard GetBasicMoves(ChessBoard chessBoard) { Bitboard moves = new Bitboard(); IntVector2 currentTile = chessBoard.GetTileCoordinates(this); if (currentTile.x < 0) { Debug.LogError("King is not on the specified chess board"); return(null); } IntVector2[] deltas = { IntVector2.one, IntVector2.right - IntVector2.up, -IntVector2.one, -IntVector2.right + IntVector2.up, IntVector2.right, -IntVector2.up, -IntVector2.right, IntVector2.up }; for (int i = 0; i < deltas.Length; i++) { IntVector2 check = currentTile + deltas[i]; if (chessBoard.AreCoordinatesOverBoard(check)) { ChessPiece atCheck = chessBoard.GetChessPieceAt(check); moves[check.x, check.y] = atCheck == null || atCheck.pieceColor != pieceColor; } } return(moves); }
public void AreCoordinatesOverBoardVectorYes() { GameObject obj = new GameObject(); obj.AddComponent <ChessBoard>(); ChessBoard board = obj.GetComponent <ChessBoard>(); IntVector2 valid = new IntVector2(3, 4); Assert.That(board.AreCoordinatesOverBoard(valid)); }
public override Bitboard GetBasicMoves(ChessBoard chessBoard) { Bitboard moves = new Bitboard(); IntVector2 currentTile = chessBoard.GetTileCoordinates(this); if (currentTile.x < 0) { Debug.LogError("Pawn is not on the specified chess board"); return(null); } IntVector2 forwardDelta = IntVector2.up; if (pieceColor == PieceColor.BLACK) { forwardDelta = -IntVector2.up; } IntVector2 check = currentTile + forwardDelta; if (chessBoard.AreCoordinatesOverBoard(check)) { moves[check.x, check.y] = chessBoard.GetChessPieceAt(check) == null; check += forwardDelta; if (movementsMade == 0 && chessBoard.AreCoordinatesOverBoard(check) && chessBoard.GetChessPieceAt(check) == null) { moves[check.x, check.y] = true; } check = currentTile + forwardDelta + IntVector2.right; if (chessBoard.AreCoordinatesOverBoard(check) && chessBoard.GetChessPieceAt(check) != null && chessBoard.GetChessPieceAt(check).pieceColor != pieceColor) { moves[check.x, check.y] = true; } check = currentTile + forwardDelta - IntVector2.right; if (chessBoard.AreCoordinatesOverBoard(check) && chessBoard.GetChessPieceAt(check) != null && chessBoard.GetChessPieceAt(check).pieceColor != pieceColor) { moves[check.x, check.y] = true; } } return(moves); }
/** Check if a piece can legally be moved to the specified tile on the board, excluding rules involving * check, checkmate, and stalemate. */ public static bool CanMovePieceNoEndConditions(ChessPiece piece, IntVector2 tileCoordinates, ChessBoard board) { // UNITTEST contingent on CanMovePiece(ChessPiece, IntVector2) and IsPathClear(...) // FEATURE add a method that returns the reason for false IntVector2 startCoords = board.GetTileCoordinates(piece); if (!board.AreCoordinatesOverBoard(tileCoordinates)) { return(false); } IntVector2 deltaTiles = tileCoordinates - startCoords; // Check if the piece could legally move there based only on its normal movement pattern if (!CanMovePiece(piece, deltaTiles)) { // Check for pawn diagonal movement if (piece.pieceType == ChessPiece.PieceType.PAWN) { if (deltaTiles.IsDiagonal() && deltaTiles.IsInUnitForm() && IsMovingForward(piece, deltaTiles)) { ChessPiece atLoc = board.GetChessPieceAt(tileCoordinates); return(atLoc != null && atLoc.pieceColor != piece.pieceColor); } else { return(false); } } else { return(false); } } if (!IsPathClear(piece, tileCoordinates, board)) { return(false); } return(true); }