You'll have to call your function recursively for every possible move from that state and choose the move with max/ min score based on the player in current ply. In general, the best pseudo code for minimax implementation I've seen so far is in the "Artificial Intelligence: A modern approach" book by Peter Norvig. All the pseudocode in the book is on it's github page and here's the minimax code -
function MINIMAX-DECISION(state) returns an action
return arg max a ∈ ACTIONS(s) MIN-VALUE(RESULT(state, a))
function MAX-VALUE(state) returns a utility value
if TERMINAL-TEST(state) the return UTILITY(state)
v ← −∞
for each a in ACTIONS(state) do
v ← MAX(v, MIN-VALUE(RESULT(state, a)))
return v
function MIN-VALUE(state) returns a utility value
if TERMINAL-TEST(state) the return UTILITY(state)
v ← ∞
for each a in ACTIONS(state) do
v ← MIN(v, MAX-VALUE(RESULT(state, a)))
return v
Few things to note for a depth-limited implementation:
- Make sure to decrement the depth and pass it to MAX-VALUE and MIN-VALUE functions.
- When you reach the depth = 0, replace the UTILITY function with your heuristic-score function.