Exemplo n.º 1
0
        public void TestPathLength2()
        {
            HexGame hexGame = new HexGame(7);

            /* player1 has played at 3, 3
             * thier shortest path has narrowed to ones passing through this */
            hexGame.Play(3, 3);

            /* These points are on player X's shortest path */
            Location[] xPath = new Location[19];

            xPath[0]  = new Location(0, 6);
            xPath[1]  = new Location(1, 5);
            xPath[2]  = new Location(1, 6);
            xPath[3]  = new Location(2, 4);
            xPath[4]  = new Location(2, 5);
            xPath[5]  = new Location(2, 6);
            xPath[6]  = new Location(3, 0);
            xPath[7]  = new Location(3, 1);
            xPath[8]  = new Location(3, 2);
            xPath[9]  = new Location(3, 3);
            xPath[10] = new Location(3, 4);
            xPath[11] = new Location(3, 5);
            xPath[12] = new Location(3, 6);
            xPath[13] = new Location(4, 0);
            xPath[14] = new Location(4, 1);
            xPath[15] = new Location(4, 2);
            xPath[16] = new Location(5, 0);
            xPath[17] = new Location(5, 1);
            xPath[18] = new Location(6, 0);

            Assert.IsTrue(hexGame.HasWon() == Occupied.Empty);

            int xPathLength = hexGame.PlayerScore(true);
            int yPathLength = hexGame.PlayerScore(false);

            // clean the path, get cells on the path
            List <Location> xPathActual = hexGame.GetCleanPath(true);

            Assert.IsTrue(xPathLength < yPathLength);

            for (int x = 0; x < hexGame.Board.Size; x++)
            {
                for (int y = 0; y < hexGame.Board.Size; y++)
                {
                    Cell cell = hexGame.Board.GetCellAt(x, y);

                    bool xOnPath       = cell.Location.IsInList(xPath);
                    bool xOnPathActual = xPathActual.Contains(cell.Location);

                    Assert.AreEqual(xOnPath, xOnPathActual, "X Path at " + cell.Location);
                }
            }
        }
Exemplo n.º 2
0
        public void TestPathLength2()
        {
            HexGame hexGame = new HexGame(7);
            /* player1 has played at 3, 3
               thier shortest path has narrowed to ones passing through this */
            hexGame.Play(3, 3);

            /* These points are on player X's shortest path */
            Location[] xPath = new Location[19];

            xPath[0] = new Location(0, 6);
            xPath[1] = new Location(1, 5);
            xPath[2] = new Location(1, 6);
            xPath[3] = new Location(2, 4);
            xPath[4] = new Location(2, 5);
            xPath[5] = new Location(2, 6);
            xPath[6] = new Location(3, 0);
            xPath[7] = new Location(3, 1);
            xPath[8] = new Location(3, 2);
            xPath[9] = new Location(3, 3);
            xPath[10] = new Location(3, 4);
            xPath[11] = new Location(3, 5);
            xPath[12] = new Location(3, 6);
            xPath[13] = new Location(4, 0);
            xPath[14] = new Location(4, 1);
            xPath[15] = new Location(4, 2);
            xPath[16] = new Location(5, 0);
            xPath[17] = new Location(5, 1);
            xPath[18] = new Location(6, 0);

            Assert.IsTrue(hexGame.HasWon() == Occupied.Empty);

            int xPathLength = hexGame.PlayerScore(true);
            int yPathLength = hexGame.PlayerScore(false);

            // clean the path, get cells on the path
            List<Location> xPathActual = hexGame.GetCleanPath(true);

            Assert.IsTrue(xPathLength < yPathLength);

            for (int x = 0; x < hexGame.Board.Size; x++)
            {
                for (int y = 0; y < hexGame.Board.Size; y++)
                {
                    Cell cell = hexGame.Board.GetCellAt(x, y);

                    bool xOnPath = cell.Location.IsInList(xPath);
                    bool xOnPathActual = xPathActual.Contains(cell.Location);

                    Assert.AreEqual(xOnPath, xOnPathActual, "X Path at " + cell.Location);
                }
            }
        }
Exemplo n.º 3
0
        public void TestPlay()
        {
            HexGame   hexGame = new HexGame(7);
            const int X       = 3;
            const int Y       = 3;

            Assert.IsTrue(hexGame.Board.GetCellOccupiedAt(X, Y) == Occupied.Empty);

            hexGame.Play(X, Y);
            Assert.IsTrue(hexGame.Board.GetCellOccupiedAt(X, Y) == Occupied.PlayerX);

            hexGame.Clear();
            Assert.IsTrue(hexGame.Board.GetCellOccupiedAt(X, Y) == Occupied.Empty);
        }
Exemplo n.º 4
0
 private static void SetupGame(HexGame game)
 {
     // red starts
     game.Play(0, 5); // red
     game.Play(4, 1);
     game.Play(1, 3); // red
     game.Play(2, 1);
     game.Play(3, 1); // red
     game.Play(2, 2);
     game.Play(3, 2); // red
     game.Play(1, 4);
     game.Play(2, 3); // red
     game.Play(0, 4);
     game.Play(2, 4); // red
     game.Play(1, 5);
 }
Exemplo n.º 5
0
 private static void SetupGame(HexGame game)
 {
     // red starts
     game.Play(0, 5); // red
     game.Play(4, 1);
     game.Play(1, 3); // red
     game.Play(2, 1);
     game.Play(3, 1); // red
     game.Play(2, 2);
     game.Play(3, 2); // red
     game.Play(1, 4);
     game.Play(2, 3); // red
     game.Play(0, 4);
     game.Play(2, 4); // red
     game.Play(1, 5);
 }
Exemplo n.º 6
0
        public void TestPlay()
        {
            HexGame hexGame = new HexGame(7);
            const int X = 3;
            const int Y = 3;

            Assert.IsTrue(hexGame.Board.GetCellOccupiedAt(X, Y) == Occupied.Empty);

            hexGame.Play(X, Y);
            Assert.IsTrue(hexGame.Board.GetCellOccupiedAt(X, Y) == Occupied.PlayerX);

            hexGame.Clear();
            Assert.IsTrue(hexGame.Board.GetCellOccupiedAt(X, Y) == Occupied.Empty);
        }