コード例 #1
0
 private bool checkWin(string pColor)
 {
     int[][] directions = board.GetDirections();
     // Debug.Log("checking for winner on col" + col);
     for (int col = 0; col < HorizontalSize; col++)
     {
         for (int i = 0; i < directions.Length / 2; i++)
         {
             var direction1 = directions[i];
             var direction2 = directions[directions.Length - (i + 1)];
             int row        = board.findRowInCol(col) - 1;
             if (board.GetPieceAt(col, row) != null && board.GetPlayerAt(col, row).Equals(pColor))
             {
                 var scoreDirection1 = board.checkScoreFromPoint(1, col, row, direction1[0], direction1[1], pColor);
                 var scoreDirection2 = board.checkScoreFromPoint(1, col, row, direction2[0], direction2[1], pColor);
                 var tempScore       = (scoreDirection1 + scoreDirection2 - 1);
                 //Debug.Log("Point [" + col + ", " + row + "] Direction: [x:" + direction1[0] + "; y: " + direction1[1] + "] has a score of: " + scoreDirection1);
                 //Debug.Log("Point [" + col + ", " + row + "] Direction: [x:" + direction2[0] + "; y: " + direction2[1] + "] has a score of: " + scoreDirection2);
                 //Debug.Log("score direction1: " + scoreDirection1);
                 //Debug.Log("score opposite: " + scoreDirection2);
                 if (tempScore >= scoreToWin)
                 {
                     // Debug.Log(playerName + " is the winner");
                     return(true);
                 }
             }
         }
     }
     return(false);
 }