Ejemplo n.º 1
0
        public void AIPlace()
        {
            AI.Place();

            if (CheckGame.CheckWin(AI.AIRow, AI.AICol))
            {
                WinNotify?.Invoke(PlayingPlayer);
                return;
            }

            PlayingPlayer = (State)(3 - (int)PlayingPlayer); //Change player again
        }
Ejemplo n.º 2
0
        public bool Place(int Row, int Col)
        {
            if (ChessBoard[Row, Col] != State.Free)
            {
                Notify?.Invoke("You Cannot Place Here!");
                return(false);
            }

            ChessBoard[Row, Col] = PlayingPlayer;

            if (CheckGame.CheckWin(Row, Col))
            {
                WinNotify?.Invoke(PlayingPlayer);
                return(true);
            }

            PlayingPlayer = (State)(3 - (int)PlayingPlayer); //Change player

            return(true);
        }
Ejemplo n.º 3
0
        //Ham tim nuoc di cho may
        public static void FindMove()
        {
            if (depth > maxDepth)
            {
                return;
            }
            depth++;

            fWin = false;
            //bool fLose = false;
            Point pcMove    = new Point();
            Point humanMove = new Point();
            int   countMove = 0;

            EvalBoard(2);

            //Lay ra MaxMove buoc di co diem cao nhat
            Point temp = new Point();

            for (int i = 0; i < maxMove; i++)
            {
                temp      = MaxPos();
                PCMove[i] = temp;
                AIBoard[(int)temp.Y, (int)temp.X] = 0;
            }

            //Lay nuoc di trong PCMove[] ra danh thu
            countMove = 0;
            while (countMove < maxMove)
            {
                pcMove = PCMove[countMove++];
                Board.ChessBoard[(int)pcMove.Y, (int)pcMove.X] = PC;
                WinMove.SetValue(pcMove, depth - 1);

                //Tim cac nuoc di toi uu cua nguoi
                ResetBoard();
                EvalBoard(0);
                //Lay ra maxMove nuoc di co diem cao nhat cua nguoi
                for (int i = 0; i < maxMove; i++)
                {
                    temp         = MaxPos();
                    HumanMove[i] = temp;
                    AIBoard[(int)temp.Y, (int)temp.X] = 0;
                }
                //Danh thu cac nuoc di
                for (int i = 0; i < maxMove; i++)
                {
                    humanMove = HumanMove[i];

                    Board.ChessBoard[(int)humanMove.Y, (int)humanMove.X] = PC;
                    if (CheckGame.CheckWin((int)humanMove.Y, (int)humanMove.X))
                    {
                        fWin = true;
                    }

                    Board.ChessBoard[(int)humanMove.Y, (int)humanMove.X] = Human;
                    if (CheckGame.CheckWin((int)humanMove.Y, (int)humanMove.X))
                    {
                        isLose = true;
                    }
                    if (isLose)
                    {
                        Board.ChessBoard[(int)pcMove.Y, (int)pcMove.X]       = State.Free;
                        Board.ChessBoard[(int)humanMove.Y, (int)humanMove.X] = State.Free;
                        break;
                    }
                    if (fWin)
                    {
                        Board.ChessBoard[(int)pcMove.Y, (int)pcMove.X]       = State.Free;
                        Board.ChessBoard[(int)humanMove.Y, (int)humanMove.X] = State.Free;
                        return;
                    }
                    FindMove();
                    Board.ChessBoard[(int)humanMove.Y, (int)humanMove.X] = State.Free;
                }
                Board.ChessBoard[(int)pcMove.Y, (int)pcMove.X] = State.Free;
            }
        }