Created
March 8, 2019 10:39
-
-
Save abiduzz420/92dad9fd83d098d8646f276bbd0a47b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public GameState Negamax(GameState node, int depth, int α, int β, bool currentTurn) { | |
List<GameState> childNodes = new List<GameState>(); | |
childNodes = node.GetAvailableChildStates(); | |
if(depth == 0 || childNodes == null) { | |
color = currentTurn ? 1 : -1; | |
return color * node.EvaluateGameState(); | |
} | |
// gamestate should have OrderMoves function which takes list of available child states and returns them in an order | |
childNodes = node.OrderMoves(childNodes); | |
value = -100000 | |
foreach(GameState child in childNodes) { | |
value = max(value, −negamax(child, depth − 1, −β, −α, !currentTurn)) | |
α = max(α, value) | |
if α ≥ β then | |
break (* cut-off *) | |
} | |
return value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment