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 + " blocked the other players win :-)");
                return(true);
            }
            else
            {
                Debug.Log(playerColor + " got confused");
            }
        }



        for (int i = 0; i < board.GetHorizontalSize(); i++)
        {
            var score = board.checkCol(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 = board.checkCol(i, playerColor);
            }
            // 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];

        board.AddPiece(colToPlay, playerColor);

        //Debug.Log("______________________________________" + playerName + " is playing column " + colToPlay);
        return(true);
    }
Ejemplo n.º 2
0
 public int canOtherPlayerWin()
 {
     for (int i = 0; i < board.GetHorizontalSize(); i++)
     {
         var tmpScore = board.checkCol(i, opponentColor);
         //Debug.Log("it was not " + playerColor + ", other players tmp score for " + i + " is " + tmpScore);
         if (tmpScore >= 3)
         {
             return(i);
         }
     }
     return(-1);
 }