Ejemplo n.º 1
0
        public BoardInitialize Clone(int Length, int width)
        {
            BoardInitialize b = new BoardInitialize(Length, width);

            b.gameBoard = (user[, ]) this.gameBoard.Clone();
            return(b);
        }
Ejemplo n.º 2
0
        private static void boardLoad()
        {
            turn += 1;
            int    Length = 0;
            string input  = "";

            do
            {
                Console.WriteLine("Enter the level of the game");
                Console.WriteLine("1. easy, 2. medium, 3. hard");
                input = Console.ReadLine().Trim();
                Level = Convert.ToInt32(input);
                if (!(Level >= 1 && Level <= 3))
                {
                    Console.WriteLine("Wrong input!Enter only between 1 to 3");
                }
            } while (!((Level >= 1 && Level <= 3)));
            Console.WriteLine("Please enter the board size:");
            input  = Console.ReadLine().Trim();
            Length = Convert.ToInt32(input);
            Console.WriteLine("User is X and Computer is O");
            gb = new BoardInitialize(Length, Length);
            if (turn % 2 == 1)
            {
                dispBoard(Length);
                NextMove(Length);
                Console.ReadLine();
            }
            else
            {
                if (Level == 1)
                {
                    easyLevel(Length);
                }
                else if (Level == 2)
                {
                    mediumLevel(Length);
                }
                else
                {
                    hardLevel(Length);
                }
            }
        }
Ejemplo n.º 3
0
        public static Board.Blank GetBestMove(BoardInitialize gb, Board.user p, int length, int width)
        {
            Board.Blank?       bestSpace  = null;
            List <Board.Blank> openSpaces = gb.blankPlaces(length, width);
            BoardInitialize    newBoard;

            for (int i = 0; i < openSpaces.Count; i++)
            {
                newBoard = gb.Clone(length, width);
                Board.Blank newSpace = openSpaces[i];

                newBoard[newSpace.A, newSpace.B] = p;

                if (newBoard.Winner(length, width) == Board.user.space && newBoard.blankPlaces(length, width).Count > 0)
                {
                    Board.Blank tempMove = GetBestMove(newBoard, (Board.user)(-(int)p), length, width);
                    newSpace.Rank = tempMove.Rank;
                }
                else
                {
                    if (newBoard.Winner(length, width) == Board.user.space)
                    {
                        newSpace.Rank = 0;
                    }
                    else if (newBoard.Winner(length, width) == Board.user.X)
                    {
                        newSpace.Rank = -1;
                    }
                    else if (newBoard.Winner(length, width) == Board.user.O)
                    {
                        newSpace.Rank = 1;
                    }
                }

                if (bestSpace == null ||
                    (p == Board.user.X && newSpace.Rank < ((Board.Blank)bestSpace).Rank) ||
                    (p == Board.user.O && newSpace.Rank > ((Board.Blank)bestSpace).Rank))
                {
                    bestSpace = newSpace;
                }
            }

            return((Board.Blank)bestSpace);
        }