Better greed

This commit is contained in:
2025-11-06 09:16:57 -08:00
parent eb084e1f07
commit 1c8a2695c4

View File

@@ -1,5 +1,3 @@
// Return a random valid action on the given board.
// Used as a last resort.
fn random_action(board) {
@@ -85,7 +83,6 @@ fn place_number(board, minimize) {
return random_action(board);
}
// Get the most influential position
let pos = influence[-1][0];
let val = influence[-1][1];
@@ -139,25 +136,20 @@ fn place_op(board, minimize) {
return ();
}
// Main step function (shared between min and max)
fn greed_step(board, minimize) {
let action = place_op(board, minimize);
// We could not place an op, so place a number
if action == () {
action = place_number(board, minimize);
}
if board.can_play(action) {
return action;
}
// Prevent invalid moves, random fallback
if board.can_play(action) { return action; }
return random_action(board);
}
// Minimizer step
fn step_min(board) {
greed_step(board, true)