private bool checkWin(string playerName) { int[][] directions = board.GetDirections(); // Debug.Log("checking for winner on col" + col); for (int col = 0; col < HorizontalSize; col++) { for (int i = 0; i < board.GetDirections().Length / 2; i++) { var direction1 = directions[i]; var direction2 = directions[directions.Length - (i + 1)]; var scoreDirection1 = board.checkScoreFromPoint(1, col, board.findRowInCol(col) - 1, direction1[0], direction1[1], playerName); var scoreDirection2 = board.checkScoreFromPoint(1, col, board.findRowInCol(col) - 1, direction2[0], direction2[1], playerName); var tempScore = (scoreDirection1 + scoreDirection2 - 1); // Debug.Log("Direction: [x:" + direction[0] + "; y: " + direction[1] + "]"); //Debug.Log("score direction1: " + scoreDirection1); //Debug.Log("score opposite: " + scoreDirection2); if (tempScore >= scoreToWin) { // Debug.Log(playerName + " is the winner"); return(true); } } } return(false); }
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); }
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); }