Beispiel #1
0
        //Copy constructor
        public Board(Board b)
        {
            length = b.GetLength();

            width = b.GetWidth();

            connectR = Board.GetConnectR();

            board = new Cell[length, width];

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    Cell cell = new Cell(b.getCell(i, j));

                    board[i, j] = cell;
                }
            }
        }
Beispiel #2
0
        public override void Move(Board b)
        {
            if(moveCount == b.GetLength() * b.GetWidth())
            {
                Console.WriteLine("Game Over, you both lose");
            }

            Boolean moveMade = false;

            b.printBoard();

            if(this.getOpponent() != null)
            {
                Console.WriteLine(" ");
            }

            Console.WriteLine(this.getColorToString() + " player's turn");

            while(!moveMade)
            {
                Console.Write("Select a Move: " + "0 - " + (b.GetWidth() - 1) + ": ");

                int choice = Convert.ToInt32(Console.ReadLine());

                for (int i = b.GetLength() - 1; i >= 0; i--)
                {
                    if(choice < 0 || choice > b.GetWidth() - 1)
                    {
                        break;
                    }

                    cell = b.getCell(i, choice);

                    if (cell.isPlayable())
                    {
                        cell.setState((int)color);

                        cell.isPlayable(false);

                        if (i != 0)
                        {
                            b.getCell(i - 1, choice).isPlayable(true);
                        }

                        moveMade = true;

                        moveCount++;

                        if (MiniMaxTree.TerminalTest(cell))
                        {
                            b.printBoard();
                            Console.WriteLine("GameOver: " + this.getColorToString() + " wins");
                            b.isGameOver(true);
                        }

                        break;
                    }
                }

            }
        }