private void gameBoardChanged() { sounds.playTick(); int winner = gameBoardData.calculateWinner(gameBoardData); if (winner != NONE) { gameEnded(winner); } }
private int getRating() { board.insert(insertPosition, playersTurn); deep--; //Fist check for winner or draw int winner = board.calculateWinner(board); if (winner == playerMe) { //Debug.Log ("Me winner"); return(int.MaxValue); } else if (winner == GameManager.DRAW) { //Debug.Log ("Draw"); return(0); } else if (winner != GameManager.NONE) { //enemy wins //Debug.Log("enemy winner"); return(int.MinValue); } if (deep > 0) { int newPlayersTurn = playersTurn; if (playersTurn == GameManager.FIRSTPLAYER) { newPlayersTurn = GameManager.SECONDPLAYER; } else if (playersTurn == GameManager.SECONDPLAYER) { newPlayersTurn = GameManager.FIRSTPLAYER; } int choosenRating = 0; List <int> turns = board.getValidTurns(); for (int i = 0; i < turns.Count; i++) { DeepSearch search; if (i == 0) { search = new DeepSearch(board.clone(), turns[i], deep, newPlayersTurn, playerMe, lowerBound, upperBound); } if (newPlayersTurn == playerMe) { search = new DeepSearch(board.clone(), turns [i], deep, newPlayersTurn, playerMe, choosenRating, upperBound); } else { search = new DeepSearch(board.clone(), turns [i], deep, newPlayersTurn, playerMe, lowerBound, choosenRating); } int rating = search.getRating(); if (i == 0) { choosenRating = rating; } else { //if this is my move than choose the highest value //if this is not my move than choose the lowest value if (newPlayersTurn == playerMe) { if (rating > choosenRating) { choosenRating = rating; if (choosenRating == int.MaxValue) { //we found one of the best moves now we can exit return(choosenRating); } else if (choosenRating <= lowerBound) { return(lowerBound); } } } else { if (rating < choosenRating) { choosenRating = rating; if (choosenRating == int.MinValue) { //we found one of the best moves now we can exit return(choosenRating); } else if (choosenRating >= upperBound) { return(upperBound); } } } } } return(choosenRating); } else { return(calculateRating()); } }