Ejemplo n.º 1
0
        public static void TestMoves()
        {
            // Arrange
            var grid = new LogarithmicGrid(new[, ]
            {
                { 2, 2, 4, 4 },
                { 0, 2, 2, 0 },
                { 0, 2, 2, 2 },
                { 2, 0, 0, 2 }
            });

            var expectedLeft = new LogarithmicGrid(new[, ]
            {
                { 4, 8, 0, 0 },
                { 4, 0, 0, 0 },
                { 4, 2, 0, 0 },
                { 4, 0, 0, 0 }
            });

            var expectedRight = new LogarithmicGrid(new[, ]
            {
                { 0, 0, 4, 8 },
                { 0, 0, 0, 4 },
                { 0, 0, 2, 4 },
                { 0, 0, 0, 4 }
            });

            var expectedUp = new LogarithmicGrid(new[, ]
            {
                { 4, 4, 4, 4 },
                { 0, 2, 4, 4 },
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 }
            });

            var expectedDown = new LogarithmicGrid(new[, ]
            {
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 },
                { 0, 2, 4, 4 },
                { 4, 4, 4, 4 }
            });

            // Act
            var left  = grid.MakeMove(Move.Left);
            var right = grid.MakeMove(Move.Right);
            var up    = grid.MakeMove(Move.Up);
            var down  = grid.MakeMove(Move.Down);

            // Assert
            Assert.StrictEqual(left, expectedLeft);
            Assert.StrictEqual(right, expectedRight);
            Assert.StrictEqual(up, expectedUp);
            Assert.StrictEqual(down, expectedDown);
        }
Ejemplo n.º 2
0
        public static void TestMoves()
        {
            // Arrange
            var grid = new LogarithmicGrid(new[,]
            {
                { 2, 2, 4, 4 },
                { 0, 2, 2, 0 },
                { 0, 2, 2, 2 },
                { 2, 0, 0, 2 }
            });

            var expectedLeft = new LogarithmicGrid(new[,]
            {
                { 4, 8, 0, 0 },
                { 4, 0, 0, 0 },
                { 4, 2, 0, 0 },
                { 4, 0, 0, 0 }
            });

            var expectedRight = new LogarithmicGrid(new[,]
            {
                { 0, 0, 4, 8 },
                { 0, 0, 0, 4 },
                { 0, 0, 2, 4 },
                { 0, 0, 0, 4 }
            });

            var expectedUp = new LogarithmicGrid(new[,]
            {
                { 4, 4, 4, 4 },
                { 0, 2, 4, 4 },
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 }
            });

            var expectedDown = new LogarithmicGrid(new[,]
            {
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 },
                { 0, 2, 4, 4 },
                { 4, 4, 4, 4 }
            });

            // Act
            var left = grid.MakeMove(Move.Left);
            var right = grid.MakeMove(Move.Right);
            var up = grid.MakeMove(Move.Up);
            var down = grid.MakeMove(Move.Down);

            // Assert
            Assert.StrictEqual(left, expectedLeft);
            Assert.StrictEqual(right, expectedRight);
            Assert.StrictEqual(up, expectedUp);
            Assert.StrictEqual(down, expectedDown);
        }
Ejemplo n.º 3
0
        private static LogarithmicGrid RunGameInConsole()
        {
            var logGrid = new LogarithmicGrid(new byte[4, 4]).AddRandomTile().AddRandomTile();

            var agent = new Agent(logGrid, new ProbabilityLimitedExpectiMaxerFactory(), new OvolveHeuristic());

            try
            {
                int counter = 0;

                while (true)
                {
                    counter++;

                    var startTime = SystemClock.Instance.Now;

                    Console.WriteLine("Start next move calculation...");

                    var result = agent.MakeDecision();

                    var elapsed = SystemClock.Instance.Now - startTime;

                    Console.Clear();

                    Console.WriteLine("End move calcualtion, time taken: {0}", elapsed.ToString("ss.fff", CultureInfo.InvariantCulture));
                    Console.WriteLine();

                    Console.WriteLine(result);

                    PrintTimings(agent);

                    logGrid = logGrid.MakeMove(result.BestMove).AddRandomTile();
                    agent.UpdateGrid(logGrid);
                }
            }
            catch (GameOverException)
            {
                Console.WriteLine("GAME OVER!");
            }

            return(logGrid);
        }
Ejemplo n.º 4
0
        private static LogarithmicGrid RunGameInConsole()
        {
            var logGrid = new LogarithmicGrid(new byte[4, 4]).AddRandomTile().AddRandomTile();

            var agent = new Agent(logGrid, new ProbabilityLimitedExpectiMaxerFactory(), new OvolveHeuristic());
            try
            {
                int counter = 0;

                while (true)
                {
                    counter++;

                    var startTime = SystemClock.Instance.Now;

                    Console.WriteLine("Start next move calculation...");

                    var result = agent.MakeDecision();

                    var elapsed = SystemClock.Instance.Now - startTime;

                    Console.Clear();

                    Console.WriteLine("End move calcualtion, time taken: {0}", elapsed.ToString("ss.fff", CultureInfo.InvariantCulture));
                    Console.WriteLine();

                    Console.WriteLine(result);

                    PrintTimings(agent);

                    logGrid = logGrid.MakeMove(result.BestMove).AddRandomTile();
                    agent.UpdateGrid(logGrid);
                }
            }
            catch (GameOverException)
            {
                Console.WriteLine("GAME OVER!");
            }

            return logGrid;
        }