1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { GameError, GameKind, JsonObject } from "https://esm.town/v/saolsen/gameplay_games";
import {
COLS,
Connect4,
Connect4Action,
Connect4AgentResponse,
Connect4State,
} from "https://esm.town/v/saolsen/gameplay_connect4";
import { agentHandler } from "https://esm.town/v/saolsen/gameplay_agent";
function rand_action(
state: Connect4State,
agent_data?: { counter: number },
): Connect4AgentResponse {
const counter = agent_data?.counter || 0;
const player = state.active_player;
while (true) {
const column = Math.floor(Math.random() * COLS);
const action: Connect4Action = { column };
if (!(Connect4.checkAction(state, player, action) instanceof GameError)) {
return { action, agent_data: { counter: counter + 1 } };
}
}
}
export default agentHandler(
[
{
game: GameKind.Connect4,
agentname: "rand",
agent: rand_action,
},
],
);
1
Next