public void Move() { var board = new Board(); var pawn = board.CellAt("c2").Piece; var cell = board.CellAt("e4"); var move = MoveNotationConverter.ParseMoveNotation("a4", PieceColor.White); move.MovePiece(pawn, cell); Assert.Equal(pawn, cell.Piece); Assert.Null(board.CellAt("c2").Piece); }
public void WhitePawnPutsKingInCheck() { var board = new Board(false); board.AddPiece("e6", new Pawn(PieceColor.White)); board.AddPiece("d7", new Pawn(PieceColor.Black)); board.AddPiece("e8", new King(PieceColor.Black)); board.PlayMove("exd7+", PieceColor.White); var move = MoveNotationConverter.ParseMoveNotation("exd7+", PieceColor.White); Assert.True(move.IsCheck); }
public void Test() { var board = new Board(false); board.AddPiece("c3", new Knight(PieceColor.Black)); board.AddPiece("c2", new Pawn(PieceColor.White)); var moveAN = "c3"; var move = MoveNotationConverter.ParseMoveNotation(moveAN, PieceColor.White); Action exception = () => board.FindPieceWhoNeedsToBeMoved(move); Assert.Throws <InvalidOperationException>(exception); }
public void FindPieceWhoNeedsToBeMovedShouldThrowAnException() { var board = new Board(); var pawn = board.CellAt("e2").Piece; var cell = board.CellAt("e3"); var move = MoveNotationConverter.ParseMoveNotation("a4", PieceColor.White); move.MovePiece(pawn, cell); Action exception = () => board.FindPieceWhoNeedsToBeMoved("e5", PieceColor.White); Assert.Throws <InvalidOperationException>(exception); }
public void IsOnInitialPositionShouldReturnTRue() { var board = new Board(); var pawn = board.CellAt("a2").Piece; Assert.True(pawn.IsOnInitialPosition()); //to do move var cell = board.CellAt("a4"); var move = MoveNotationConverter.ParseMoveNotation("a4", PieceColor.White); move.MovePiece(pawn, cell); Assert.False(pawn.IsOnInitialPosition()); }
public void Play(List <string> listOfMoves) { //initialize board board = new Board(); foreach (var moveAN in listOfMoves) { var move = MoveNotationConverter.ParseMoveNotation(moveAN, currentPlayer); Console.WriteLine(currentPlayer + " player " + move.Name + " moves to " + move.Coordinates); NextTurn(currentPlayer, moveAN); IsGameOver = board.GetWin; MovesCounter++; if (IsGameOver) { Console.WriteLine("game over"); break; } } }
private void NextTurn(PieceColor player, string moveAN) { var move = MoveNotationConverter.ParseMoveNotation(moveAN, player); if (move.IsKingCastling || move.IsQueenCastling) { Console.WriteLine("Performing castling."); return; } var piece = board.PlayMove(moveAN, player); if (move.IsCheck) { //verify if king is actually in check Console.WriteLine(currentPlayer + " puts opponent king in check!"); } if (move.IsCheckMate) { Winner = move.PieceColor; Console.WriteLine(Winner + " won!"); } currentPlayer = currentPlayer == PieceColor.White ? PieceColor.Black : PieceColor.White; }