Example #1
0
        public void SpeedTest()
        {
            const int RandSeed = 24;
            const int BoardCount = 100;
            const int BoardSize = 12;

            Random rands = new Random(RandSeed);
            HexBoard[] boards = new HexBoard[BoardCount];

            // make some boards
            for (int loopIndex = 0; loopIndex < BoardCount; loopIndex++)
            {
                boards[loopIndex] = RandomBoard(BoardSize, 10 + loopIndex, rands);
            }

            // time it the old way
            DateTime oldStart = DateTime.Now;

            foreach (HexBoard board in boards)
            {
                PathLengthLoop oldPath = new PathLengthLoop(board);
                oldPath.PlayerScore(true);
                oldPath.PlayerScore(false);
            }

            DateTime oldEnd = DateTime.Now;

            // and the new way
            DateTime newStart = DateTime.Now;

            foreach (HexBoard board in boards)
            {
                PathLengthAStar newPath = new PathLengthAStar(board);
                newPath.PlayerScore(true);
                newPath.PlayerScore(false);
            }

            DateTime newEnd = DateTime.Now;

            TimeSpan oldDuration = oldEnd - oldStart;
            TimeSpan newDuration = newEnd - newStart;

            double ratio = newDuration.Milliseconds / (double)oldDuration.Milliseconds;

            Assert.IsTrue(ratio < 1.0);
        }
Example #2
0
        private static double GetRatio(int cellFilledCount)
        {
            const int RandSeed = 24;
            const int BoardCount = 50;
            const int BoardSize = 12;

            Random rands = new Random(RandSeed + cellFilledCount);
            HexBoard[] boards = new HexBoard[BoardCount];

            // make some boards
            for (int loopIndex = 0; loopIndex < BoardCount; loopIndex++)
            {
                boards[loopIndex] = RandomBoard(BoardSize, cellFilledCount, rands);
            }

            // time it the old way
            DateTime oldStart = DateTime.Now;

            foreach (HexBoard board in boards)
            {
                PathLengthLoop oldPath = new PathLengthLoop(board);
                oldPath.PlayerScore(true);
                oldPath.PlayerScore(false);
            }

            DateTime oldEnd = DateTime.Now;

            // and the new way
            DateTime newStart = DateTime.Now;

            foreach (HexBoard board in boards)
            {
                PathLengthAStar newPath = new PathLengthAStar(board);
                newPath.PlayerScore(true);
                newPath.PlayerScore(false);
            }

            DateTime newEnd = DateTime.Now;

            TimeSpan oldDuration = oldEnd - oldStart;
            TimeSpan newDuration = newEnd - newStart;

            double ratio = newDuration.Milliseconds / (double)oldDuration.Milliseconds;

            return ratio;
        }
Example #3
0
        private static void CheckPathLength(HexBoard board, int boardIndex)
        {
            // first do it with the old path length
            PathLengthLoop oldPath = new PathLengthLoop(board);
            int oldX = oldPath.PlayerScore(true);
            int oldY = oldPath.PlayerScore(false);

            // now the new
            PathLengthAStar newPath = new PathLengthAStar(board)
                {
                    UseNeighbours2 = false
                };

            int newX = newPath.PlayerScore(true);
            int newY = newPath.PlayerScore(false);

            Assert.AreEqual(oldX, newX, "X not equal at board index" + boardIndex);
            Assert.AreEqual(oldY, newY, "Y not equal at board index" + boardIndex);
        }