Skip to content

Instantly share code, notes, and snippets.

@abiduzz420
Created March 8, 2019 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abiduzz420/92dad9fd83d098d8646f276bbd0a47b8 to your computer and use it in GitHub Desktop.
Save abiduzz420/92dad9fd83d098d8646f276bbd0a47b8 to your computer and use it in GitHub Desktop.
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