Exemplo n.º 1
0
        public void CloneTest_WhenCloning_ThenReturnsCopyButDifferentInstance()
        {
            BoardState target = new BoardState(null);
            target.SetPiece(0, 0, Piece.X);
            var copiedBoard = target.Clone();
            Assert.AreEqual(copiedBoard.GetPiece(0, 0), Piece.X);

            target.SetPiece(0, 1, Piece.X);
            Assert.AreEqual(target.GetPiece(0, 1), Piece.X);
            Assert.AreEqual(copiedBoard.GetPiece(0, 1), Piece.Empty);
        }
Exemplo n.º 2
0
        public void GetPieceTest_WhenFieldIsX_ThenGetPieceReturnsX()
        {
            BoardState target = new BoardState(null);
            var board = new Piece[3, 3];
            board[0, 0] = Piece.Empty; board[1, 0] = Piece.X;     board[2, 0] = Piece.Empty;
            board[0, 1] = Piece.Empty; board[1, 1] = Piece.Empty; board[2, 1] = Piece.Empty;
            board[0, 2] = Piece.Empty; board[1, 2] = Piece.Empty; board[2, 2] = Piece.Empty;
            target.Board = board;

            Piece actualPiece = target.GetPiece(1, 0);
            Assert.AreEqual(Piece.X, actualPiece);
        }
Exemplo n.º 3
0
        public List<Position> GetEmptyFields(BoardState board)
        {
            var emptyPositions = new List<Position>();
            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    if (board.GetPiece(x, y) == Piece.Empty)
                    {
                        emptyPositions.Add(new Position { X = x, Y = y });
                    }
                }
            }

            return emptyPositions;
        }
Exemplo n.º 4
0
        public void DoMoveTest_WhenAnIllegalMoveIsEntered_ThenUserMustEnterALegalMove()
        {
            var reader = new InputReaderFake();
            reader.SetUserInput("a2");
            reader.SetUserInput("a2");
            reader.SetUserInput("a1");
            var target = new HumanPlayer(reader);
            var boardState = new BoardState(null);
            var board = new Piece[3, 3];
            board[0, 0] = Piece.Empty; board[1, 0] = Piece.X; board[2, 0] = Piece.Empty;
            board[0, 1] = Piece.Empty; board[1, 1] = Piece.Empty; board[2, 1] = Piece.Empty;
            board[0, 2] = Piece.Empty; board[1, 2] = Piece.Empty; board[2, 2] = Piece.Empty;
            boardState.Board = board;

            int retValue = target.DoMove(Piece.O, boardState);
            Assert.AreEqual(0, retValue);
            Assert.AreEqual(Piece.O, boardState.GetPiece(0, 0));
        }
Exemplo n.º 5
0
        public List <Position> GetEmptyFields(BoardState board)
        {
            var emptyPositions = new List <Position>();

            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    if (board.GetPiece(x, y) == Piece.Empty)
                    {
                        emptyPositions.Add(new Position {
                            X = x, Y = y
                        });
                    }
                }
            }

            return(emptyPositions);
        }
Exemplo n.º 6
0
        public int DoMove(Piece piece, BoardState boardState)
        {
            GetUserInput();
            do
            {
                if (IsFinished())
                {
                    return(-100);
                }

                if (IsInputValid() && boardState.GetPiece(MoveCoordinatesX, MoveCoordinatesY) == Piece.Empty)
                {
                    boardState.SetPiece(MoveCoordinatesX, MoveCoordinatesY, piece);
                    return(0);
                }

                GetUserInput();
            }while (true);
        }
Exemplo n.º 7
0
        public int DoMove(Piece piece, BoardState boardState)
        {
            GetUserInput();
            do
            {
                if (IsFinished())
                {
                    return -100;
                }

                if (IsInputValid() && boardState.GetPiece(MoveCoordinatesX, MoveCoordinatesY) == Piece.Empty)
                {
                    boardState.SetPiece(MoveCoordinatesX, MoveCoordinatesY, piece);
                    return 0;
                }

                GetUserInput();
            }
            while (true);
        }
Exemplo n.º 8
0
 public void WhenResettingTheBoard_ThenTheFieldsAreEmpty()
 {
     BoardState target = new BoardState(null);
     target.Board[1, 2] = Piece.X;
     target.Reset();
     Assert.AreEqual(Piece.Empty, target.GetPiece(1, 2));
 }