示例#1
0
    bool CanFork(int player)
    {
        /* Check if there is a scenario where a player can create two possible ways to win */
        DetectWinner isWinner = new DetectWinner(ROWS, COLS);

        for (int i = 0; i < ROWS; i++)
        {
            for (int j = 0; j < COLS; j++)
            {
                /* Place a temporary counter at coords and then see if there are 2 ways to win the game */
                if (IsSpaceOwned(j, i, 0))
                {
                    isWinner.SetBoard(board);
                    isWinner.EditSpace(j, i, player);
                    if (isWinner.HowManyWaysToWin(player) >= 2)
                    {
                        validMoves.Add(new Vector2Int(j, i));
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
    void CheckForWinner()
    {
        DetectWinner myWin = new DetectWinner(ROWS, COLS);

        myWin.SetBoard(board);
        if (myWin.IsGameWon(1))
        {
            WinText.GetComponent <WinTextBox>().ChangeText(1); GameOver = true;
        }
        if (myWin.IsGameWon(2))
        {
            WinText.GetComponent <WinTextBox>().ChangeText(2); GameOver = true;
        }
        if (myWin.IsGameDraw())
        {
            WinText.GetComponent <WinTextBox>().ChangeText(0); GameOver = true;
        }
    }
示例#3
0
    /* Check if p can win this round */
    bool CanWin(int p)
    {
        DetectWinner isWinner = new DetectWinner(ROWS, COLS);

        for (int i = 0; i < ROWS; i++)
        {
            for (int j = 0; j < COLS; j++)
            {
                if (IsSpaceOwned(j, i, 0))
                {
                    isWinner.SetBoard(board);
                    isWinner.EditSpace(j, i, p);
                    if (isWinner.IsGameWon(p))
                    {
                        validMoves.Add(new Vector2Int(j, i));
                        return(true);
                    }
                }
            }
        }

        return(false);
    }