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