public void showPreview(int position, int player) { if (player == GameManager.FIRSTPLAYER) { player = GameManager.FIRSTPLAYERPEV; } else if (player == GameManager.SECONDPLAYER) { player = GameManager.SECONDPLAYERPREV; } if (isPreview && previousPreviewPosition == position) { //Preview did not change -> do nothing } else if (isPreview && previousPreviewPosition != position) { //Preview positon changed, reset field to original and insert preview loadElements(clonedValues); boardData.insert(position, player); previousPreviewPosition = position; } else { previousPreviewPosition = position; clonedValues = saveElements(); boardData.insert(position, player); isPreview = true; } }
private void insert(int pos) { gameBoardObject.setInputElementClicked(pos); gameBoardData.insert(pos, actualPlayer); gameProgress.newState(gameBoardData.getBoardAsArray(), pos); gameBoardChanged(); changePlayer(); }
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()); } }