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
37
38
39
40
41
42
import { agentHandler } from "https://esm.town/v/saolsen/gameplay_agent";
import { GameKind, JsonObject } from "https://esm.town/v/saolsen/gameplay_games";
import {
PokerAction,
PokerActionKind,
PokerAgentResponse,
PokerView,
} from "https://esm.town/v/saolsen/gameplay_poker";
function agent(view: PokerView, _agent_data?: JsonObject): PokerAgentResponse {
const round = view.rounds[view.round];
const player = round.active_player;
const chips = view.player_chips[player];
const amount_to_call = round.bet - round.player_bets[player];
if (round.bet === 0) {
const action: PokerAction = { kind: PokerActionKind.Bet, amount: chips };
return { action };
} else if (amount_to_call >= chips) {
const action: PokerAction = { kind: PokerActionKind.Call };
return { action };
} else {
const raise_amount = chips - amount_to_call;
const action: PokerAction = {
kind: PokerActionKind.Raise,
amount: raise_amount,
};
return { action };
}
}
export default agentHandler(
[
{
game: GameKind.Poker,
agentname: "all_in",
agent: agent,
},
],
);
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.