示例#1
0
        static void Main(string[] args)
        {
            if (args.Length == 1 && args[0] == "g")
            {
                Board.GenerateDuplets();
                Board.GenerateTriplets();
                return;
            }

            DateTime start = DateTime.Now;

            Board gameBoard = new Board();
            bool drawnGame = false;
            bool wonGame = false;
            char winner = 'c';
            while (true)
            {
                MakeAMove(Side1, gameBoard);
                CheckWinLoseDraw(gameBoard, ref drawnGame, ref wonGame, ref winner);
                if (wonGame || drawnGame)
                {
                    break;
                }

                MakeAMove(Side2, gameBoard);
                CheckWinLoseDraw(gameBoard, ref drawnGame, ref wonGame, ref winner);
                if (wonGame || drawnGame)
                {
                    break;
                }
            }

            Console.WriteLine("Run time: " + (DateTime.Now - start));

            if (drawnGame)
            {
                Console.WriteLine("Drawn game!");
                Console.WriteLine(gameBoard.ToString());
                Console.ReadLine();
                return;
            }

            if (wonGame)
            {
                Console.WriteLine(winner + " has won!");
                Console.WriteLine(gameBoard.ToString());
                Console.ReadLine();
                return;
            }
            Console.WriteLine("Impossible");
        }
示例#2
0
        public void DropTest()
        {
            {
                Board target = new Board(); // TODO: Initialize to an appropriate value
                target.board = new char[,]
                    {   { 'a', 'a', '.' },
                        { 'a', 'a', '.' },
                        { '.', '.', '.' },
                        { 'a', '.', '.' } };
                int col = 0; // TODO: Initialize to an appropriate value
                char side = 'a'; // TODO: Initialize to an appropriate value
                bool expected = false; // TODO: Initialize to an appropriate value
                bool actual;
                actual = target.Drop(col, side);
                Assert.AreEqual(expected, actual);
                //Assert.Inconclusive("Verify the correctness of this test method.");
            }

            {
                Board target = new Board(); // TODO: Initialize to an appropriate value
                target.board = new char[,]
                    {   { 'a', 'a', '.' },
                        { 'a', 'a', '.' },
                        { '.', '.', '.' },
                        { 'a', 'a', 'a' } };
                int col = 0; // TODO: Initialize to an appropriate value
                char side = 'a'; // TODO: Initialize to an appropriate value
                bool expected = false; // TODO: Initialize to an appropriate value
                bool actual;
                actual = target.Drop(col, side);
                Assert.AreEqual(expected, actual);
                //Assert.Inconclusive("Verify the correctness of this test method.");
            }

            {
                Board target = new Board(); // TODO: Initialize to an appropriate value
                target.board = new char[,]
                    {   { 'a', 'a', '.' },
                        { 'a', 'a', '.' },
                        { '.', '.', '.' },
                        { 'a', '.', '.' } };
                int col = 1; // TODO: Initialize to an appropriate value
                char side = 'a'; // TODO: Initialize to an appropriate value
                bool expected = true; // TODO: Initialize to an appropriate value
                bool actual;
                actual = target.Drop(col, side);
                Assert.AreEqual(expected, actual);
                Assert.AreEqual('a', target.board[2, 1]);
                //Assert.Inconclusive("Verify the correctness of this test method.");
            }
        }
示例#3
0
 private static void CheckWinLoseDraw(Board gameBoard, ref bool drawnGame, ref bool wonGame, ref char winner)
 {
     if (gameBoard.IsFull())
     {
         drawnGame = true;
     }
     switch (gameBoard.Score(Side1, false))
     {
         case Board.Win:
             wonGame = true;
             winner = Side1;
             break;
         case Board.Lose:
             wonGame = true;
             winner = Side2;
             break;
     }
 }
示例#4
0
 private static void MakeAMove(char side, Board gameBoard)
 {
     int col = MakeAMoveHelper(side, side, gameBoard);
     //while (gameBoard.IsFull(col))
     //{
     //    ++col;
     //}
     gameBoard.Drop(col, side);
     Console.WriteLine("{0} made a move at {1}. Current board size is {2}.", side, col, gameBoard.cnt);
     //System.Diagnostics.Debug.WriteLine(gameBoard.ToString());
 }
示例#5
0
        private static int MakeAMoveHelper(char side, char playAs, Board gameBoard)
        {
            int score = gameBoard.Score(side, false);
            if (score != 0)
            {
                return score;
            }

            if (gameBoard.IsFull())
            {
                return 0;
            }

            List<int> scores = new List<int>(3);
            for (int i = 0; i < 3; ++i)
            {
                scores.Add(Board.Lose);
            }
            for (int i = 0; i < 3; ++i)
            {
                if (!gameBoard.IsFull(i))
                {
                    gameBoard.Drop(i, side);
                    scores[i] = (-(MakeAMoveHelper(side, side == Side1 ? Side2 : Side1, gameBoard)));
                    gameBoard.Pop(i);
                }
            }
            return scores.IndexOf(scores.Max());
        }
示例#6
0
 public void ToStringTest()
 {
     Board target = new Board(); // TODO: Initialize to an appropriate value
     string expected = @". . .
     . . .
     . . .
     . . .
     "; // TODO: Initialize to an appropriate value
     string actual;
     actual = target.ToString();
     Assert.IsTrue(expected == actual);
     //Assert.Inconclusive("Verify the correctness of this test method.");
 }
示例#7
0
        public void ScoreTest()
        {
            {
                Board target = new Board(); // TODO: Initialize to an appropriate value
                target.board = new char[,]
                    {   { 'a', 'a', 'a' },
                        { '.', '.', '.' },
                        { '.', '.', '.' },
                        { '.', '.', '.' } };
                char side = 'a'; // TODO: Initialize to an appropriate value
                int expected = Board.Win; // TODO: Initialize to an appropriate value
                int actual;
                actual = target.Score(side, false);
                Assert.AreEqual(expected, actual);
                //Assert.Inconclusive("Verify the correctness of this test method.");
            }

            {
                Board target = new Board(); // TODO: Initialize to an appropriate value
                target.board = new char[,]
                    {   { 'a', '.', '.' },
                        { '.', 'a', '.' },
                        { '.', '.', 'a' },
                        { '.', '.', '.' } };
                char side = 'b'; // TODO: Initialize to an appropriate value
                int expected = Board.Lose; // TODO: Initialize to an appropriate value
                int actual;
                actual = target.Score(side, false);
                Assert.AreEqual(expected, actual);
                //Assert.Inconclusive("Verify the correctness of this test method.");
            }

            {
                Board target = new Board(); // TODO: Initialize to an appropriate value
                target.board = new char[,]
                    {   { 'a', '.', '.' },
                        { 'a', '.', '.' },
                        { 'a', '.', '.' },
                        { '.', '.', '.' } };
                char side = 'a'; // TODO: Initialize to an appropriate value
                int expected = Board.Win; // TODO: Initialize to an appropriate value
                int actual;
                actual = target.Score(side, false);
                Assert.AreEqual(expected, actual);
                //Assert.Inconclusive("Verify the correctness of this test method.");
            }

            {
                Board target = new Board(); // TODO: Initialize to an appropriate value
                target.board = new char[,]
                    {   { '.', '.', 'a' },
                        { '.', 'a', '.' },
                        { 'a', '.', '.' },
                        { '.', '.', '.' } };
                char side = 'b'; // TODO: Initialize to an appropriate value
                int expected = Board.Lose; // TODO: Initialize to an appropriate value
                int actual;
                actual = target.Score(side, false);
                Assert.AreEqual(expected, actual);
                //Assert.Inconclusive("Verify the correctness of this test method.");
            }

            {
                Board target = new Board(); // TODO: Initialize to an appropriate value
                target.board = new char[,]
                    {   { 'a', 'a', '.' },
                        { 'a', 'a', '.' },
                        { '.', '.', '.' },
                        { '.', '.', '.' } };
                char side = 'a'; // TODO: Initialize to an appropriate value
                int expected = 5; // TODO: Initialize to an appropriate value
                int actual;
                actual = target.Score(side, true);
                Assert.AreEqual(expected, actual);
                //Assert.Inconclusive("Verify the correctness of this test method.");
            }
        }