Ejemplo n.º 1
0
        public void TestLegalJumpsWontJumpOverOwnPiece()
        {
            var board = new CheckerBoard();

            board.AddPiece(PieceColor.White, CheckerBoard.SIZE - 1, 0);
            board.AddPiece(PieceColor.White, CheckerBoard.SIZE - 2, 1); // One below and to the right
            var whiteMoves = board.GetLegalMoves(PieceColor.White);

            Assert.AreEqual(2, whiteMoves.Count);
            var moveForwardLeft  = new Move(new CheckerPiece(board.GetPiece(CheckerBoard.SIZE - 2, 1)), MoveDirection.ForwardLeft);
            var moveForwardRight = new Move(new CheckerPiece(board.GetPiece(CheckerBoard.SIZE - 2, 1)), MoveDirection.ForwardRight);

            Assert.IsTrue(whiteMoves.Contains(moveForwardLeft));
            Assert.IsTrue(whiteMoves.Contains(moveForwardRight));
        }
Ejemplo n.º 2
0
        public void TestKingJump()
        {
            var board = new CheckerBoard();

            board.AddPiece(PieceColor.Black, CheckerBoard.SIZE - 1, 0);
            board.GetPiece(CheckerBoard.SIZE - 1, 0).IsKing = true;
            board.AddPiece(PieceColor.White, CheckerBoard.SIZE - 2, 1);
            //board.PlacePiece(PieceColor.White, Board.BOARD_SIZE - 4, 3);
            var blackMoves = board.GetLegalMoves(PieceColor.Black);

            Assert.AreEqual(1, blackMoves.Count);
            var blackMove = new Move(board.GetPiece(CheckerBoard.SIZE - 1, 0), new List <MoveDirection> {
                MoveDirection.BackwardRight
            });

            Assert.AreEqual(blackMove, blackMoves[0]);
        }
Ejemplo n.º 3
0
        public void TestMultipleJumps()
        {
            var board = new CheckerBoard();

            board.AddPiece(PieceColor.White, CheckerBoard.SIZE - 1, 0);
            board.AddPiece(PieceColor.Black, CheckerBoard.SIZE - 2, 1);
            board.AddPiece(PieceColor.Black, CheckerBoard.SIZE - 4, 3);
            var whiteMoves = board.GetLegalMoves(PieceColor.White);

            Assert.AreEqual(1, whiteMoves.Count);
            var whiteMove = new Move(board.GetPiece(CheckerBoard.SIZE - 1, 0), new List <MoveDirection>
            {
                MoveDirection.ForwardRight,
                MoveDirection.ForwardRight
            });

            Assert.AreEqual(whiteMove, whiteMoves[0]);
        }
Ejemplo n.º 4
0
        private static CheckerBoard CreateBoardWithPieces(IEnumerable <CheckerPiece> pieces)
        {
            var board = new CheckerBoard();

            foreach (var piece in pieces)
            {
                board.AddPiece(piece);
            }
            return(board);
        }
Ejemplo n.º 5
0
        public void TestLegalJumps()
        {
            var board = new CheckerBoard();

            board.AddPiece(PieceColor.White, CheckerBoard.SIZE - 1, 0);
            board.AddPiece(PieceColor.Black, CheckerBoard.SIZE - 2, 1); // One below and to the right
            var whiteMoves = board.GetLegalMoves(PieceColor.White);
            var blackMoves = board.GetLegalMoves(PieceColor.Black);

            Assert.AreEqual(1, whiteMoves.Count);
            Assert.AreEqual(1, blackMoves.Count);
            var whiteMove = new Move(board.GetPiece(CheckerBoard.SIZE - 1, 0), new List <MoveDirection>  {
                MoveDirection.ForwardRight
            });
            var blackMove = new Move(board.GetPiece(CheckerBoard.SIZE - 2, 1), new List <MoveDirection> {
                MoveDirection.ForwardRight
            });

            Assert.AreEqual(whiteMove, whiteMoves[0]);
            Assert.AreEqual(blackMove, blackMoves[0]);
        }
        public void TestDisplayIndividualPieces()
        {
            var board = new CheckerBoard();

            board.AddPiece(PieceColor.White, 0, 0);
            board.AddPiece(PieceColor.Black, 1, 1);

            string result = $"W  -  -  -  -  -  -  -  {Environment.NewLine}";

            result += $"-  B  -  -  -  -  -  -  {Environment.NewLine}";
            for (int row = 2; row < CheckerBoard.SIZE; ++row)
            {
                result += EMPTY_ROW;
            }

            var display   = new Mocks.MockTextDisplay();
            var uiDisplay = new BoardPlainTextUIDisplay(display);

            uiDisplay.UpdateDisplay(board);

            Assert.AreEqual(result, display.Text);
        }
        public void TestDisplayKingsOnRightSide()
        {
            var board     = new CheckerBoard();
            var whiteKing = CheckerPiece.AsKing(0, CheckerBoard.SIZE - 1, PieceColor.White);
            var blackKing = CheckerPiece.AsKing(1, CheckerBoard.SIZE - 1, PieceColor.Black);

            board.AddPiece(whiteKing);
            board.AddPiece(blackKing);

            string result = $"-  -  -  -  -  -  -  W* {Environment.NewLine}";

            result += $"-  -  -  -  -  -  -  B* {Environment.NewLine}";
            for (int row = 2; row < CheckerBoard.SIZE; ++row)
            {
                result += EMPTY_ROW;
            }

            var display   = new Mocks.MockTextDisplay();
            var uiDisplay = new BoardPlainTextUIDisplay(display);

            uiDisplay.UpdateDisplay(board);

            Assert.AreEqual(result, display.Text);
        }
Ejemplo n.º 8
0
 public void AddPiece_WhiteNonKingPiece_AddsWithCorrectValues()
 {
     _board.AddPiece(_piece);
     Assert.AreEqual(_piece, _board.GetPiece(_piece.Row, _piece.Col));
 }