Ejemplo n.º 1
0
    public bool PlayTurn()
    {
        List <int> possibleColsToPlay = new List <int>();
        float      tempScore          = 0f;
        var        blockCol           = canOtherPlayerWin();

        //Debug.Log(playerColor + "'s block col returned block column: " + blockCol);
        if (blockCol >= 0)
        {
            int block = sysrand.Next(100);
            if (block > confusion)
            {
                board.AddPiece(blockCol, playerColor);
                Debug.Log(playerColor + "blocking col: " + blockCol);
                //Debug.Log(playerColor + " blocked the other players win :-)");
                return(true);
            }
            //else
            //{
            Debug.Log(playerColor + " got confused");
            //}
        }



        for (int i = 0; i < board.GetHorizontalSize(); i++)
        {
            var score = board.CheckColScore(i, playerColor);

            if (score == tempScore)
            {
                // Debug.Log("adding " + i + " to possible cols");
                possibleColsToPlay.Add(i);
            }
            else if (score > tempScore)
            {
                // Debug.Log("score " + score + " is new highscore at " + i);
                possibleColsToPlay.Clear();
                possibleColsToPlay.Add(i);
                tempScore = score;
            }
            // Debug.Log("column " + i + " has a value of " + tempScore);
        }
        int indexToPlay = sysrand.Next(possibleColsToPlay.Count);
        //Debug.Log("amount: " + possibleColsToPlay.Count + " index chosen: " + possibleColsToPlay[indexToPlay] + " Highscore: " + tempScore);
        int colToPlay = possibleColsToPlay[indexToPlay];

        Debug.Log(playerColor + "playing col: " + colToPlay);
        board.AddPiece(colToPlay, playerColor);

        //Debug.Log("______________________________________" + playerName + " is playing column " + colToPlay);
        return(true);
    }
Ejemplo n.º 2
0
    public bool PlayTurn()
    {
        myTurn = true;
        if (nextCol >= 0)
        {
            if (board.findRowInCol(nextCol) > 0)
            {
                board.AddPiece(nextCol, playerColor);
                nextCol = -1;
                myTurn  = false;
                return(true);
            }
        }
        int blockCol = canOtherPlayerWin();

        //Debug.Log(playerColor + "'s block col returned block column: " + blockCol);
        return(false);
    }