Ejemplo n.º 1
0
        public void GetAgainDoesNotIncreaseCount()
        {
            BoardCache boardCache = new BoardCache(10);

            const int TestSize = 10;
            HexBoard[] usedBoards = new HexBoard[TestSize];

            // add some boards
            for (int i = 0; i < TestSize; i++)
            {
                usedBoards[i] = boardCache.GetBoard();
            }

            // remove them
            for (int i = 0; i < TestSize; i++)
            {
                boardCache.Release(usedBoards[i]);
            }

            // get again, count should not change since there are now boards ready to use
            for (int i = 0; i < TestSize; i++)
            {
                usedBoards[i] = boardCache.GetBoard();
                Assert.IsNotNull(usedBoards[i]);
                Assert.AreEqual(TestSize, boardCache.BoardCount);
            }
        }
Ejemplo n.º 2
0
        public void CreateIsEmptyCache()
        {
            BoardCache boardCache = new BoardCache(10);

            // empty cache
            Assert.IsNotNull(boardCache);
            Assert.AreEqual(0, boardCache.BoardCount);
        }
Ejemplo n.º 3
0
        public Minimax(HexBoard board, GoodMoves goodMoves, ICandidateMoves candidateMovesFinder)
        {
            this.actualBoard = board;
            this.goodMoves = goodMoves;
            this.candidateMovesFinder = candidateMovesFinder;

            this.boardCache = new BoardCache(board.Size);
            this.pathLengthFactory = new PathLengthAStarFactory();
        }
Ejemplo n.º 4
0
        public void AddBoardIncreasesCount()
        {
            BoardCache boardCache = new BoardCache(10);

            const int TestSize = 10;
            HexBoard[] usedBoards = new HexBoard[TestSize];

            // add some boards
            for (int i = 0; i < TestSize; i++)
            {
                usedBoards[i] = boardCache.GetBoard();
                Assert.IsNotNull(usedBoards[i]);
                Assert.AreEqual(i + 1, boardCache.BoardCount);
            }
        }
Ejemplo n.º 5
0
        public void ReleaseBoardIncreasesCount()
        {
            BoardCache boardCache = new BoardCache(10);

            const int TestSize = 10;
            HexBoard[] usedBoards = new HexBoard[TestSize];

            // add some boards
            for (int i = 0; i < TestSize; i++)
            {
                usedBoards[i] = boardCache.GetBoard();
            }

            // remove them
            for (int i = 0; i < TestSize; i++)
            {
                boardCache.Release(usedBoards[i]);

                // count doesn't go down
                Assert.AreEqual(TestSize, boardCache.BoardCount);
                Assert.AreEqual(i + 1, boardCache.AvailableCount);
            }
        }