public void testValidDestiny(Position origin, Position destiny) { if (!GameBoard.piece(origin).canMoveTo(destiny)) { throw new BoardException("Invalid destiny position!"); } }
public void MakePlay(Position origin, Position destiny) { Piece piece = ExecuteMove(origin, destiny); if (KingInCheck(CurrentPlayer)) { UndoMove(origin, destiny, piece); throw new BoardException("You can't put yourself in check!"); } Piece p = GameBoard.piece(destiny); // #specialmove Promote pawn if (p is Pawn) { if ((p.color == Color.White && destiny.Line == 0) || (p.color == Color.Black && destiny.Line == 7)) { p = GameBoard.removePiece(destiny); gamePieces.Remove(p); Piece queen = new Queen(GameBoard, p.color); GameBoard.placePiece(queen, destiny); gamePieces.Add(queen); } } if (KingInCheck(rival(CurrentPlayer))) { Check = true; } else { Check = false; } if (testCheckMate(rival(CurrentPlayer))) { Finished = true; } else { Turn++; changePlayer(); } // #specialmove En Passant if (p is Pawn && (destiny.Line == origin.Line + 2 || destiny.Line == origin.Line - 2)) { enPassantDanger = p; } else { enPassantDanger = null; } }
public void testValidOrigin(Position pos) { if (GameBoard.piece(pos) == null) { throw new BoardException("There are no piece in that position."); } if (CurrentPlayer != GameBoard.piece(pos).color) { throw new BoardException("That piece is not yours."); } if (!GameBoard.piece(pos).testPossibleMoves()) { throw new BoardException("There are no possible moves for the chosen piece."); } }