public void CheckDefaultPositions()
        {
            Board board = BoardFactory.CreateBoard();

            for (int x = 0; x < Board.BOARD_DIMENSIONS; x++)
            {
                for (int y = 0; y < Board.BOARD_DIMENSIONS; y++)
                {
                    BoardPiece currentPiece = board.BoardPieces[x, y];
                    if (y == 0) // Bottom row - P1
                    {
                        Assert.IsTrue(PieceTypePositionCheck(x, Player.PlayerOne, currentPiece));
                    }
                    else if (y == 1) // Pawn row - P1
                    {
                        Assert.IsTrue(currentPiece.PieceType == PieceType.Pawn && currentPiece.PieceOwner == Player.PlayerOne);
                    }
                    else if (y == 6) // Pawn row - P2
                    {
                        Assert.IsTrue(currentPiece.PieceType == PieceType.Pawn && currentPiece.PieceOwner == Player.PlayerTwo);
                    }
                    else if (y == 7) // Top row - P2
                    {
                        Assert.IsTrue(PieceTypePositionCheck(x, Player.PlayerTwo, currentPiece));
                    }
                    else // Empty squares
                    {
                        Assert.IsTrue(currentPiece.PieceType == PieceType.None && currentPiece.PieceOwner == Player.None);
                    }
                }
            }
        }
        public void PawnInvalidMovePieceTest()
        {
            Board       board   = BoardFactory.CreateBoard();
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            Vector2I pawnPos = new Vector2I(3, 1);

            Assert.IsTrue(board.BoardPieces[pawnPos.X, pawnPos.Y].PieceType == PieceType.Pawn);

            Vector2I pawnDest = new Vector2I(3, 4);

            Assert.IsTrue(board.BoardPieces[pawnDest.X, pawnDest.Y].PieceType == PieceType.None);

            BoardPieceMove move = new BoardPieceMove(pawnPos, pawnDest);

            Assert.IsFalse(player1.ApplyMove(move));

            Assert.IsTrue(board.BoardPieces[pawnPos.X, pawnPos.Y].PieceType == PieceType.Pawn);
            Assert.IsTrue(board.BoardPieces[pawnDest.X, pawnDest.Y].PieceType == PieceType.None);
        }
        public void InvalidMove()
        {
            char[,] boardLayout =
            {
                {'C', 'N', 'B', 'Q', 'K', 'B', 'N', 'C'},
                {'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'},
                {'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e'},
                {'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e'}, 
                {'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e'}, 
                {'c', 'e', 'e', 'e', 'e', 'e', 'e', 'e'},
                {'e', 'p', 'p', 'p', 'p', 'p', 'p', 'p'},
                {'e', 'n', 'b', 'q', 'k', 'b', 'n', 'c'}
            };
            boardLayout = boardLayout.RotateArray();
            
            Board board = BoardFactory.CreateBoard(boardLayout);
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);
            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);
            board.AddPlayer(player2);
            
            Vector2I castlePos = new Vector2I(0, 2);
            Assert.IsTrue(board.BoardPieces[castlePos.X, castlePos.Y].PieceType == PieceType.Castle);
            
            Vector2I castleDest = new Vector2I(2, 4);
            Assert.IsTrue(board.BoardPieces[castleDest.X, castleDest.Y].PieceType == PieceType.None);
            
            BoardPieceMove move = new BoardPieceMove(castlePos, castleDest);
            Assert.IsFalse(player1.ApplyMove(move));

            Assert.IsTrue(board.BoardPieces[castlePos.X, castlePos.Y].PieceType == PieceType.Castle);
            Assert.IsTrue(board.BoardPieces[castleDest.X, castleDest.Y].PieceType == PieceType.None);
        }
示例#4
0
        public void SetUpBoardBeginner()
        {
            var board = BoardFactory.CreateBoard(height: 9, width: 9, mines: 10);

            Assert.Equal(9, board.Height);
            Assert.Equal(9, board.Width);
            Assert.Equal(10, board.Mines.Count());
        }
示例#5
0
 public PongGame(RenderWindow rw)
 {
     this._score          = new Text("Score: 0 - 0", new Font(@"..\..\..\resources\Fonts\CaviarDreams.ttf"), 20);
     this._score.Position = new Vector2f(rw.GetView().Size.X / 2, rw.GetView().Size.Y / 10);
     this._player         = new Player(rw);
     this._enemy          = new Enemy(rw);
     this._ball           = BallFactory.CreateBall(rw, BallTypes.Normal);
     this._board          = BoardFactory.CreateBoard(rw, BoardTypes.Normal);
 }
示例#6
0
        public void NewGame()
        {
            var board = BoardFactory.CreateBoard(height: 3, width: 3, mines: 1);

            var game = new Game(board, new GameDateProvider(new DateTime(2000, 1, 1, 13, 00, 00)));

            Assert.Equal(0, game.Score);
            Assert.True(game.IsRunning);
        }
示例#7
0
        public void CountBombsInNeighbarhood()
        {
            var board = BoardFactory.CreateBoard(height: 3, width: 3, mines: 9);

            Assert.Equal(4 * 3 + 4 * 5 + 1 * 8,
                         board.AllFields
                         .Select(point => board.CountBombs(point))
                         .Sum());
        }
        public void InvalidCastlingTest()
        {
            char[,] boardLayout =
            {
                { 'C', 'N', 'B', 'Q', 'K', 'B', 'N', 'C' },
                { 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'p', 'p', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'n', 'e', 'b' },
                { 'p', 'p', 'p', 'p', 'p', 'e', 'e', 'c' },
                { 'c', 'n', 'b', 'q', 'k', 'e', 'e', 'e' }
            };
            boardLayout = boardLayout.RotateArray();

            Board       board   = BoardFactory.CreateBoard(boardLayout);
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            // Castle moves, can no longer perform castling
            Vector2I castlePos = new Vector2I(7, 1);

            Assert.IsTrue(board.BoardPieces[castlePos.X, castlePos.Y].PieceType == PieceType.Castle);

            Vector2I castleDest = new Vector2I(7, 0);

            Assert.IsTrue(board.BoardPieces[castleDest.X, castleDest.Y].PieceType == PieceType.None);

            BoardPieceMove move = new BoardPieceMove(castlePos, castleDest);

            player1.ApplyMove(move);

            Assert.IsTrue(board.BoardPieces[castlePos.X, castlePos.Y].PieceType == PieceType.None);
            Assert.IsTrue(board.BoardPieces[castleDest.X, castleDest.Y].PieceType == PieceType.Castle);

            board.PlayerTurn = Player.PlayerOne;

            Vector2I kingPos = new Vector2I(4, 0);

            Assert.IsTrue(board.BoardPieces[kingPos.X, kingPos.Y].PieceType == PieceType.King);

            Vector2I kingDest = new Vector2I(6, 0);

            Assert.IsTrue(board.BoardPieces[kingDest.X, kingDest.Y].PieceType == PieceType.None);

            move = new BoardPieceMove(kingPos, kingDest);
            Assert.IsFalse(player1.ApplyMove(move));

            Assert.IsTrue(board.BoardPieces[kingPos.X, kingPos.Y].PieceType == PieceType.King);
            Assert.IsTrue(board.BoardPieces[kingDest.X, kingDest.Y].PieceType == PieceType.None);
            Assert.IsTrue(board.BoardPieces[7, 0].PieceType == PieceType.Castle);
        }
示例#9
0
        public void GetBoardReturnsBoard()
        {
            //Arrange
            BoardFactory boardFactory = new BoardFactory();
            //Act
            Board board = boardFactory.CreateBoard();

            //Assert
            Assert.That(board, Is.TypeOf(typeof(Board)));
        }
示例#10
0
        public void EmptyBoard()
        {
            var board = BoardFactory.CreateBoard(height: 3, width: 3, mines: 0);

            var allFields = board.AllFields;

            Assert.Equal(9, allFields.Count());
            Assert.Equal(0, board.Mines.Count());
            Assert.True(allFields.All(point => !board.HasBomb(point)));
        }
        public void CheckMateRegisteredTest()
        {
            char[,] boardLayout =
            {
                { 'e', 'e', 'e', 'e', 'K', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'c' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'k', 'e', 'c', 'e' }
            };
            boardLayout = boardLayout.RotateArray();

            Board       board   = BoardFactory.CreateBoard(boardLayout);
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            bool   checkMate     = false;
            Player winningPlayer = Player.None;

            board.OnGameStateChanged += delegate(GameState state)
            {
                if (state != GameState.WonByCheckmate)
                {
                    return;
                }

                checkMate     = true;
                winningPlayer = board.PlayerTurn;
            };

            Vector2I castlePos = new Vector2I(6, 0);

            Assert.IsTrue(board.BoardPieces[castlePos.X, castlePos.Y].PieceType == PieceType.Castle);

            Vector2I castleDest = new Vector2I(6, 7);

            Assert.IsTrue(board.BoardPieces[castleDest.X, castleDest.Y].PieceType == PieceType.None);

            BoardPieceMove move = new BoardPieceMove(castlePos, castleDest);

            player1.ApplyMove(move);

            Assert.IsTrue(checkMate);
            Assert.AreEqual(GameState.WonByCheckmate, board.GameState);
            Assert.AreEqual(winningPlayer, Player.PlayerOne);
        }
示例#12
0
        public void Basic2()
        {
            // X X O R
            // O X R R
            // R R X O
            // R O X X

            const uint BlackColor = 1;
            const uint RedColor   = 2;

            Constraint blackConstr  = new Constraint(BlackColor, 1);
            Constraint blackConstr2 = new Constraint(BlackColor, 2);
            Constraint redConstr    = new Constraint(RedColor, 1);
            Constraint redConstr2   = new Constraint(RedColor, 2);

            var row0 = BoardFactory.CreateConstraintSet(new[] { blackConstr2, redConstr });
            var row1 = BoardFactory.CreateConstraintSet(new[] { blackConstr, redConstr2 });
            var row2 = BoardFactory.CreateConstraintSet(new[] { redConstr2, blackConstr });
            var row3 = BoardFactory.CreateConstraintSet(new[] { redConstr, blackConstr2 });

            var col0 = BoardFactory.CreateConstraintSet(new[] { blackConstr, redConstr2 });
            var col1 = BoardFactory.CreateConstraintSet(new[] { blackConstr2, redConstr });
            var col2 = BoardFactory.CreateConstraintSet(new[] { redConstr, blackConstr2 });
            var col3 = BoardFactory.CreateConstraintSet(new[] { redConstr2, blackConstr });

            var rowConstraints = new[] { row0, row1, row2, row3 };
            var colConstraints = new[] { col0, col1, col2, col3 };

            IBoard board = BoardFactory.CreateBoard(rowConstraints, colConstraints, RedColor);

            ISolvedBoard solvedBoard = board.Solve();

            Assert.True(solvedBoard[0, 0] == BlackColor);
            Assert.True(solvedBoard[0, 1] == BlackColor);
            Assert.True(solvedBoard[0, 2] == 0);
            Assert.True(solvedBoard[0, 3] == RedColor);

            Assert.True(solvedBoard[1, 0] == 0);
            Assert.True(solvedBoard[1, 1] == BlackColor);
            Assert.True(solvedBoard[1, 2] == RedColor);
            Assert.True(solvedBoard[1, 3] == RedColor);

            Assert.True(solvedBoard[2, 0] == RedColor);
            Assert.True(solvedBoard[2, 1] == RedColor);
            Assert.True(solvedBoard[2, 2] == BlackColor);
            Assert.True(solvedBoard[2, 3] == 0);

            Assert.True(solvedBoard[3, 0] == RedColor);
            Assert.True(solvedBoard[3, 1] == 0);
            Assert.True(solvedBoard[3, 2] == BlackColor);
            Assert.True(solvedBoard[3, 3] == BlackColor);
        }
示例#13
0
        public void LostGameWithoutPoints()
        {
            var board = BoardFactory.CreateBoard(height: 3, width: 3, mines: 1);

            var game = new Game(board, new GameDateProvider(new DateTime(2000, 1, 1, 13, 00, 00)));

            Assert.Equal(0, game.Score);
            Assert.True(game.IsRunning);

            game.Play(board.Mines.Single());
            Assert.False(game.IsRunning);
            Assert.Equal(0, game.Score);
        }
        public void ResetBoardTest()
        {
            char[,] boardLayout =
            {
                { 'e', 'e', 'e', 'e', 'K', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'c' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'k', 'e', 'c', 'e' }
            };
            boardLayout = boardLayout.RotateArray();

            Board board = BoardFactory.CreateBoard(boardLayout);

            board.PlayerTurn = Player.PlayerTwo;

            BoardFactory.ResetBoard(board);
            Assert.AreEqual(Player.PlayerOne, board.PlayerTurn);

            for (int x = 0; x < Board.BOARD_DIMENSIONS; x++)
            {
                for (int y = 0; y < Board.BOARD_DIMENSIONS; y++)
                {
                    BoardPiece currentPiece = board.BoardPieces[x, y];
                    if (y == 0) // Bottom row - P1
                    {
                        Assert.IsTrue(PieceTypePositionCheck(x, Player.PlayerOne, currentPiece));
                    }
                    else if (y == 1) // Pawn row - P1
                    {
                        Assert.IsTrue(currentPiece.PieceType == PieceType.Pawn && currentPiece.PieceOwner == Player.PlayerOne);
                    }
                    else if (y == 6) // Pawn row - P2
                    {
                        Assert.IsTrue(currentPiece.PieceType == PieceType.Pawn && currentPiece.PieceOwner == Player.PlayerTwo);
                    }
                    else if (y == 7) // Top row - P2
                    {
                        Assert.IsTrue(PieceTypePositionCheck(x, Player.PlayerTwo, currentPiece));
                    }
                    else // Empty squares
                    {
                        Assert.IsTrue(currentPiece.PieceType == PieceType.None && currentPiece.PieceOwner == Player.None);
                    }
                }
            }
        }
示例#15
0
        public void WinGameWithOneGuess()
        {
            var board = BoardFactory.CreateBoard(height: 3, width: 3, mines: 0);

            var game = new Game(board, new GameDateProvider(new DateTime(2000, 1, 1, 13, 00, 00)));

            Assert.Equal(0, game.Score);
            Assert.True(game.IsRunning);

            game.Play(new Point(1, 1));

            Assert.False(game.IsRunning);
            Assert.True(game.Score > 0);
        }
示例#16
0
        public void WinGameWithPoints()
        {
            var board = BoardFactory.CreateBoard(height: 3, width: 3, mines: 1);

            var game = new Game(board, new GameDateProvider(new DateTime(2000, 1, 1, 13, 00, 00)));

            Assert.Equal(0, game.Score);
            Assert.True(game.IsRunning);

            foreach (var point in board.AllFields.Except(board.Mines))
            {
                game.Play(point);
            }
            Assert.False(game.IsRunning);
            Assert.True(game.Score > 0);
        }
示例#17
0
        public Level ParseMap(char[,] map)
        {
            int width  = map.GetLength(0);
            int height = map.GetLength(1);

            Square[,] grid = new Square[width, height];

            IList <NPC>    ghosts         = new List <NPC>();
            IList <Square> startPositions = new List <Square>();

            MakeGrid(map, width, height, grid, ghosts, startPositions);

            Board board = boardCreator.CreateBoard(grid);

            return(levelCreator.CreateLevel(board, ghosts, startPositions));
        }
        public void CheckRegisteredTest()
        {
            char[,] boardLayout =
            {
                { 'C', 'N', 'B', 'Q', 'K', 'B', 'N', 'C' },
                { 'P', 'P', 'P', 'P', 'P', 'e', 'P', 'P' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'P', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'b', 'p', 'e', 'e', 'e' },
                { 'p', 'p', 'p', 'p', 'e', 'p', 'p', 'p' },
                { 'c', 'n', 'b', 'q', 'k', 'e', 'n', 'c' }
            };
            boardLayout = boardLayout.RotateArray();

            Board       board   = BoardFactory.CreateBoard(boardLayout);
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            bool   inCheck       = false;
            Player playerInCheck = Player.None;

            board.OnPlayerInCheck += delegate(Player player)
            {
                inCheck       = true;
                playerInCheck = player;
            };

            Vector2I queenPos = new Vector2I(3, 0);

            Assert.IsTrue(board.BoardPieces[queenPos.X, queenPos.Y].PieceType == PieceType.Queen);

            Vector2I queenDest = new Vector2I(7, 4);

            Assert.IsTrue(board.BoardPieces[queenDest.X, queenDest.Y].PieceType == PieceType.None);

            BoardPieceMove move = new BoardPieceMove(queenPos, queenDest);

            player1.ApplyMove(move);

            Assert.IsTrue(inCheck);
            Assert.AreEqual(playerInCheck, Player.PlayerTwo);
        }
示例#19
0
        public void Create()
        {
            var numberOfPieces = _userInterface.GetNumberOfPieces(2, 4);
            var board          = _boardFactory.CreateBoard();
            var pieces         = new List <Piece>();

            for (var i = 0; i < numberOfPieces; i++)
            {
                pieces.Add(new Piece(0, board.Count - 1));
            }

            var gamePlay = new GamePlay(board, pieces, _dice);

            Start(numberOfPieces);
            GameLoop(gamePlay, pieces);
            End(pieces);
        }
示例#20
0
        public IHttpActionResult Solve(BoardProperties boardProperties)
        {
            if (boardProperties == null)
            {
                return(BadRequest("Invalid Request Object"));
            }

            if (boardProperties.Letters.Length != (int)boardProperties.Style)
            {
                return(BadRequest("Invalid Letter Count " + boardProperties.Letters.Length + ". Must use " + (int)boardProperties.Style + " letters. "));
            }

            var board = BoardFactory.CreateBoard(boardProperties.Style, boardProperties.Dictionary, boardProperties.Board, boardProperties.Letters);
            var json  = JToken.FromObject(board.Solve());

            return(Ok(json));
        }
        public void TurnSwapTest()
        {
            Board       board   = BoardFactory.CreateBoard();
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            Assert.IsTrue(board.PlayerTurn == Player.PlayerOne);
            player1.ApplyMove(3, 1, 3, 2);

            Assert.IsTrue(board.PlayerTurn == Player.PlayerTwo);
            player2.ApplyMove(3, 6, 3, 5);

            Assert.IsTrue(board.PlayerTurn == Player.PlayerOne);
        }
        public void ActionsRecordedTest()
        {
            Board       board   = BoardFactory.CreateBoard();
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            List <BoardChange> recordedActions = new List <BoardChange>();

            board.OnBoardChanged += delegate(List <BoardChange> actions)
            {
                for (int i = 0; i < actions.Count; i++)
                {
                    recordedActions.Add(actions[i]);
                }
            };
            player1.ApplyMove(3, 1, 3, 2);
            player2.ApplyMove(3, 6, 3, 5);

            Assert.AreEqual(2, recordedActions.Count);

            // First action
            Assert.AreEqual(Player.PlayerOne, recordedActions[0].Player);
            Assert.AreEqual(BoardChangeType.MovePiece, recordedActions[0].Type);
            var action = (MovePieceChange)recordedActions[0];

            Assert.AreEqual(PieceType.Pawn, action.MovedPieceType);
            Assert.AreEqual(new Vector2I(3, 1), action.Move.From);
            Assert.AreEqual(new Vector2I(3, 2), action.Move.To);

            // Second action
            Assert.AreEqual(Player.PlayerTwo, recordedActions[1].Player);
            Assert.AreEqual(BoardChangeType.MovePiece, recordedActions[1].Type);
            action = (MovePieceChange)recordedActions[1];
            Assert.AreEqual(PieceType.Pawn, action.MovedPieceType);
            Assert.AreEqual(new Vector2I(3, 6), action.Move.From);
            Assert.AreEqual(new Vector2I(3, 5), action.Move.To);
        }
        public void CastlingTest()
        {
            char[,] boardLayout =
            {
                { 'C', 'N', 'B', 'Q', 'K', 'B', 'N', 'C' },
                { 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'p', 'p', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'n', 'e', 'b' },
                { 'p', 'p', 'p', 'p', 'p', 'e', 'e', 'p' },
                { 'c', 'n', 'b', 'q', 'k', 'e', 'e', 'c' }
            };
            boardLayout = boardLayout.RotateArray();

            Board       board   = BoardFactory.CreateBoard(boardLayout);
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            // Move right twice
            Vector2I kingPos = new Vector2I(4, 0);

            Assert.IsTrue(board.BoardPieces[kingPos.X, kingPos.Y].PieceType == PieceType.King);

            Vector2I kingDest = new Vector2I(6, 0);

            Assert.IsTrue(board.BoardPieces[kingDest.X, kingDest.Y].PieceType == PieceType.None);

            BoardPieceMove move = new BoardPieceMove(kingPos, kingDest);

            player1.ApplyMove(move);

            Assert.IsTrue(board.BoardPieces[kingPos.X, kingPos.Y].PieceType == PieceType.None);
            Assert.IsTrue(board.BoardPieces[kingDest.X, kingDest.Y].PieceType == PieceType.King);
            Assert.IsTrue(board.BoardPieces[kingDest.X - 1, kingDest.Y].PieceType == PieceType.Castle);
        }
        public void PieceTakenEnPassantTest()
        {
            char[,] boardLayout =
            {
                { 'C', 'N', 'B', 'Q', 'K', 'B', 'N', 'C' },
                { 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'p', 'e', 'e', 'e', 'e' }, // Pawn take pawn
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'p', 'p', 'p', 'e', 'p', 'p', 'p', 'p' },
                { 'c', 'n', 'b', 'q', 'k', 'b', 'n', 'c' }
            };
            boardLayout = boardLayout.RotateArray();

            Board       board   = BoardFactory.CreateBoard(boardLayout);
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            board.PlayerTurn = Player.PlayerTwo;

            var pawnPos  = new Vector2I(4, 6); // Move enemy pawn
            var pawnDest = new Vector2I(4, 4);
            var move     = new BoardPieceMove(pawnPos, pawnDest);

            player2.ApplyMove(move);

            pawnPos  = new Vector2I(3, 4); // En passant take
            pawnDest = new Vector2I(4, 5);
            move     = new BoardPieceMove(pawnPos, pawnDest);
            player1.ApplyMove(move);

            Assert.IsTrue(board.BoardPieces[pawnPos.X, pawnPos.Y].PieceType == PieceType.None);
            Assert.IsTrue(board.BoardPieces[pawnDest.X, pawnDest.Y].PieceType == PieceType.Pawn && board.BoardPieces[pawnDest.X, pawnDest.Y].PieceOwner == Player.PlayerOne);
            Assert.IsTrue(board.BoardPieces[4, 4].PieceType == PieceType.None);
        }
        public void ValidMovementLeftDiagonalBackwards()
        {
            char[,] boardLayout =
            {
                { 'C', 'N', 'B', 'Q', 'K', 'B', 'N', 'C' },
                { 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'b', 'p', 'e', 'e', 'e' },
                { 'p', 'p', 'p', 'p', 'e', 'p', 'p', 'p' },
                { 'c', 'n', 'b', 'q', 'k', 'e', 'n', 'c' } // Bishop movement
            };
            boardLayout = boardLayout.RotateArray();

            Board       board   = BoardFactory.CreateBoard(boardLayout);
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            Vector2I bishopPos = new Vector2I(3, 2);

            Assert.IsTrue(board.BoardPieces[bishopPos.X, bishopPos.Y].PieceType == PieceType.Bishop);

            Vector2I bishopDest = new Vector2I(5, 0);

            Assert.IsTrue(board.BoardPieces[bishopDest.X, bishopDest.Y].PieceType == PieceType.None);

            BoardPieceMove move = new BoardPieceMove(bishopPos, bishopDest);

            player1.ApplyMove(move);

            Assert.IsTrue(board.BoardPieces[bishopPos.X, bishopPos.Y].PieceType == PieceType.None);
            Assert.IsTrue(board.BoardPieces[bishopDest.X, bishopDest.Y].PieceType == PieceType.Bishop);
        }
        public void PawnInvalidMovePieceTest3()
        {
            char[,] boardLayout =
            {
                { 'C', 'N', 'B', 'Q', 'K', 'B', 'N', 'C' },
                { 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'p', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' }, // Pawn has already moved
                { 'p', 'p', 'p', 'e', 'p', 'p', 'p', 'p' },
                { 'c', 'n', 'b', 'q', 'k', 'b', 'n', 'c' }
            };
            boardLayout = boardLayout.RotateArray();

            Board       board   = BoardFactory.CreateBoard(boardLayout);
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            var pawnPos = new Vector2I(3, 4);

            Assert.IsTrue(board.BoardPieces[pawnPos.X, pawnPos.Y].PieceType == PieceType.Pawn);

            var pawnDest = new Vector2I(3, 3);

            Assert.IsTrue(board.BoardPieces[pawnDest.X, pawnDest.Y].PieceType == PieceType.None);

            var move = new BoardPieceMove(pawnPos, pawnDest);

            Assert.IsFalse(player1.ApplyMove(move));

            Assert.IsTrue(board.BoardPieces[pawnPos.X, pawnPos.Y].PieceType == PieceType.Pawn);
            Assert.IsTrue(board.BoardPieces[pawnDest.X, pawnDest.Y].PieceType == PieceType.None);
        }
        public void ValidMoveVertical()
        {
            char[,] boardLayout =
            {
                { 'C', 'N', 'B', 'Q', 'K', 'B', 'N', 'C' },
                { 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e' },
                { 'p', 'p', 'p', 'e', 'p', 'p', 'p', 'p' },
                { 'c', 'n', 'b', 'q', 'k', 'b', 'n', 'c' }
            };
            boardLayout = boardLayout.RotateArray();

            Board       board   = BoardFactory.CreateBoard(boardLayout);
            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            Vector2I queenPos = new Vector2I(3, 0);

            Assert.IsTrue(board.BoardPieces[queenPos.X, queenPos.Y].PieceType == PieceType.Queen);

            Vector2I queenDest = new Vector2I(3, 5);

            Assert.IsTrue(board.BoardPieces[queenDest.X, queenDest.Y].PieceType == PieceType.None);

            BoardPieceMove move = new BoardPieceMove(queenPos, queenDest);

            player1.ApplyMove(move);

            Assert.IsTrue(board.BoardPieces[queenPos.X, queenPos.Y].PieceType == PieceType.None);
            Assert.IsTrue(board.BoardPieces[queenDest.X, queenDest.Y].PieceType == PieceType.Queen);
        }
示例#28
0
        public Cell[,,,] ObservableGridToBoard(ObservableCollection <ObservableCollection <ObservableCollection <ObservableCollection <ObservableCell> > > > observableGrid)
        {
            Cell[,,,] board = BoardFactory.CreateBoard(observableGrid.Count, observableGrid[0].Count, observableGrid[0][0].Count, observableGrid[0][0][0].Count);

            for (int subgridX = 0; subgridX < board.GetLength(0); subgridX++)
            {
                for (int subgridY = 0; subgridY < board.GetLength(1); subgridY++)
                {
                    for (int X = 0; X < board.GetLength(2); X++)
                    {
                        for (int Y = 0; Y < board.GetLength(3); Y++)
                        {
                            if (observableGrid[subgridX][subgridY][X][Y].Number.HasValue)
                            {
                                CellHelper.SetPossibility(board[subgridX, subgridY, X, Y], observableGrid[subgridX][subgridY][X][Y].Number.GetValueOrDefault());
                            }
                        }
                    }
                }
            }

            return(board);
        }
示例#29
0
        private void ButtonNewGameAction()
        {
            BoardFactory boardFactory = new BoardFactory();

            CurrentBoard                = boardFactory.CreateBoard();
            _canSaveAction              = true;
            ButtonSaveGameClickCommand  = null;
            _canHelpAction              = true;
            ButtonHelpClickCommand      = null;
            _canSolveAction             = true;
            AmountOfHelp                = 3;
            ButtonSolveGameClickCommand = null;
            _canPrintAction             = true;
            ButtonPrintGameClickCommand = null;
            foreach (Field field in CurrentBoard.Fields)
            {
                field.AllFieldAreCreated = true;
                field.AddedValueField   += OnAddedField;
            }
            int howManyFieldsToDoEmptyYet = 0;

            switch (SelectedLevel)
            {
            case 1:
                howManyFieldsToDoEmptyYet = 30;
                break;

            case 2:
                howManyFieldsToDoEmptyYet = 45;
                break;

            case 3:
                howManyFieldsToDoEmptyYet = 60;
                break;
            }
            List <int> listOfRandomEmpltyFieldIndex = new List <int>();
            Random     random = new Random();

            listOfRandomEmpltyFieldIndex.Add(random.Next(0, 80));
            while (listOfRandomEmpltyFieldIndex.Count < howManyFieldsToDoEmptyYet)
            {
                int        poczatek = 0;
                int        koniec   = 80;
                List <int> _listOfRandomEmpltyFieldIndex = new List <int>();
                foreach (int randomNumber in listOfRandomEmpltyFieldIndex)
                {
                    if (listOfRandomEmpltyFieldIndex.Count + _listOfRandomEmpltyFieldIndex.Count < howManyFieldsToDoEmptyYet)
                    {
                        if (poczatek < randomNumber - 1)
                        {
                            _listOfRandomEmpltyFieldIndex.Add(random.Next(poczatek + 1, randomNumber - 1));
                        }
                        poczatek = randomNumber;
                    }
                    else
                    {
                        break;
                    }
                }
                if (listOfRandomEmpltyFieldIndex.Count + _listOfRandomEmpltyFieldIndex.Count < howManyFieldsToDoEmptyYet)
                {
                    if (poczatek < koniec)
                    {
                        _listOfRandomEmpltyFieldIndex.Add(random.Next(poczatek + 1, koniec));
                    }
                }
                foreach (int randomNumber in _listOfRandomEmpltyFieldIndex)
                {
                    listOfRandomEmpltyFieldIndex.Add(randomNumber);
                }
                listOfRandomEmpltyFieldIndex.Sort();
            }
            foreach (int randomNumber in listOfRandomEmpltyFieldIndex)
            {
                CurrentBoard.Fields[randomNumber].ValueField = "";
            }
            if (threadHelp.ThreadState == ThreadState.Suspended)
            {
                threadHelp.Resume();
                threadHelp.Abort();
            }
        }
        public static void Main(string[] args)
        {
            // Create the board
            var board = BoardFactory.CreateBoard();

            BasicPlayer player1 = new BasicPlayer(board, Player.PlayerOne);

            board.AddPlayer(player1);
            BasicPlayer player2 = new BasicPlayer(board, Player.PlayerTwo);

            board.AddPlayer(player2);

            // Loop until the game is over
            while (board.GameState != GameState.Ended)
            {
                // Render the board in the console
                PrintBoardToConsole(board);

                // Fetch the current players turn
                Console.Write(board.PlayerTurn.ToFriendlyString() + " enter your move: ");
                var moveString = Console.ReadLine();

                // Ensure the input is in the correct format (xFrom,yFrom,xTo,yTo) - no commas and must be in the correct chess notation e.g. a1a3
                if (!BoardHelpers.ValidMoveRepresentation(moveString))
                {
                    Console.WriteLine("Invalid string, please enter it again.");
                    continue;
                }

                // Fetch the available moves for the player
                var validMoves = new HashSet <BoardPieceMove>();
                ValidMovesCalc.GetValidMovesForPlayer(board, board.PlayerTurn, validMoves);

                // Create an instance of the move
                var from = BoardHelpers.ConvertStringRepIntoPos(moveString.Substring(0, 2));
                var to   = BoardHelpers.ConvertStringRepIntoPos(moveString.Substring(2, 2));
                var move = new BoardPieceMove(from, to);

                // Make sure the move is legal
                if (!validMoves.Contains(move))
                {
                    Console.WriteLine("Invalid move, please enter it again.");
                    continue;
                }

                // Apply the move
                if (board.PlayerTurn == Player.PlayerOne)
                {
                    player1.ApplyMove(move);
                }
                else
                {
                    player2.ApplyMove(move);
                }
            }

            PrintBoardToConsole(board);
            Console.WriteLine(board.PlayerTurn.ToFriendlyString() + " wins!");

            Console.ReadLine();
        }