/// <summary>
        /// Picks a move based on players last move.
        /// </summary>
        public void BestMove()
        {
            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    if (Game.gameBoardSimulation[x, y] == 1)
                    {
                        if (y + 1 < 3 && x + 1 < 3 && Game.gameBoardSimulation[x + 1, y + 1] == 0)
                        {
                            Game.gameBoardSimulation[x + 1, y + 1] = 2;
                            BoardLayout.DrawPlayerO(BoardFunctions.boardSepearator[x + 1, y + 1]);
                            Game.WinCheck(Pieces.Computer);
                            return;
                        }

                        else if (y + 1 < 3 && Game.gameBoardSimulation[x, y + 1] == 0)
                        {
                            Game.gameBoardSimulation[x, y + 1] = 2;
                            BoardLayout.DrawPlayerO(BoardFunctions.boardSepearator[x, y + 1]);
                            Game.WinCheck(Pieces.Computer);
                            return;
                        }

                        else if (y - 1 < 3 && y - 1 >= 0 && Game.gameBoardSimulation[x, y - 1] == 0)
                        {
                            Game.gameBoardSimulation[x, y - 1] = 2;
                            BoardLayout.DrawPlayerO(BoardFunctions.boardSepearator[x, y - 1]);
                            Game.WinCheck(Pieces.Computer);
                            return;
                        }


                        else if (x - 1 >= 0 && Game.gameBoardSimulation[x - 1, y] == 0)
                        {
                            Game.gameBoardSimulation[x - 1, y] = 2;
                            BoardLayout.DrawPlayerO(BoardFunctions.boardSepearator[x - 1, y]);
                            Game.WinCheck(Pieces.Computer);
                            return;
                        }

                        else if (x + 1 < 3 && Game.gameBoardSimulation[x + 1, y] == 0)
                        {
                            Game.gameBoardSimulation[x + 1, y] = 2;
                            BoardLayout.DrawPlayerO(BoardFunctions.boardSepearator[x + 1, y]);
                            Game.WinCheck(Pieces.Computer);
                            return;
                        }
                    }
                }
            }
        }
Beispiel #2
0
 private void boardLayoutPanel_Paint(object sender, PaintEventArgs e)
 {
     boardFunctions1.BeginBoard();
     boardLayout1 = new BoardLayout(boardLayoutPanel.CreateGraphics(), new SolidBrush(Color.White), new Pen(Color.Black, 2));
     boardLayout1.DrawBoard();
 }
        public void BoxDetection(Point pLoc)
        {
            if (boardSepearator[0, 0].Contains(pLoc))
            {
                if (Game.gameBoardSimulation[0, 0] == 0)
                {
                    BoardLayout.DrawPlayerX(0, 0, 101, 97);
                    Game.gameBoardSimulation[0, 0] = 1;
                    Game.WinCheck(Pieces.Player);
                    CPU.BestMove();
                }
            }


            if (boardSepearator[1, 0].Contains(pLoc))
            {
                if (Game.gameBoardSimulation[1, 0] == 0)
                {
                    BoardLayout.DrawPlayerX(101, 0, 202, 97);
                    Game.gameBoardSimulation[1, 0] = 1;
                    Game.WinCheck(Pieces.Player);
                    CPU.BestMove();
                }
            }

            if (boardSepearator[2, 0].Contains(pLoc))
            {
                if (Game.gameBoardSimulation[2, 0] == 0)
                {
                    BoardLayout.DrawPlayerX(202, 0, 303, 97);
                    Game.gameBoardSimulation[2, 0] = 1;
                    Game.WinCheck(Pieces.Player);
                    CPU.BestMove();
                }
            }

            if (boardSepearator[0, 1].Contains(pLoc))
            {
                if (Game.gameBoardSimulation[0, 1] == 0)
                {
                    BoardLayout.DrawPlayerX(0, 97, 101, 97 * 2);
                    Game.gameBoardSimulation[0, 1] = 1;
                    Game.WinCheck(Pieces.Player);
                    CPU.BestMove();;
                }
            }

            if (boardSepearator[1, 1].Contains(pLoc))
            {
                if (Game.gameBoardSimulation[1, 1] == 0)
                {
                    BoardLayout.DrawPlayerX(101, 97, 202, 97 * 2);
                    Game.gameBoardSimulation[1, 1] = 1;
                    Game.WinCheck(Pieces.Player);
                    CPU.BestMove();
                }
            }

            if (boardSepearator[2, 1].Contains(pLoc))
            {
                if (Game.gameBoardSimulation[2, 1] == 0)
                {
                    BoardLayout.DrawPlayerX(202, 97, 303, 97 * 2);
                    Game.gameBoardSimulation[2, 1] = 1;
                    Game.WinCheck(Pieces.Player);
                    CPU.BestMove();
                }
            }

            if (boardSepearator[0, 2].Contains(pLoc))
            {
                if (Game.gameBoardSimulation[0, 2] == 0)
                {
                    BoardLayout.DrawPlayerX(0, 97 * 2, 101, 97 * 3);
                    Game.gameBoardSimulation[0, 2] = 1;
                    Game.WinCheck(Pieces.Player);
                    CPU.BestMove();
                }
            }
            if (boardSepearator[1, 2].Contains(pLoc))
            {
                if (Game.gameBoardSimulation[1, 2] == 0)
                {
                    BoardLayout.DrawPlayerX(101, 97 * 2, 202, 97 * 3);
                    Game.gameBoardSimulation[1, 2] = 1;
                    Game.WinCheck(Pieces.Player);
                    CPU.BestMove();
                }
            }

            if (boardSepearator[2, 2].Contains(pLoc))
            {
                if (Game.gameBoardSimulation[2, 2] == 0)
                {
                    BoardLayout.DrawPlayerX(202, 97 * 2, 303, 97 * 3);
                    Game.gameBoardSimulation[2, 2] = 1;
                    Game.WinCheck(Pieces.Player);
                    CPU.BestMove();
                }
            }
        }