NintendoSydmain.tsx1 match
1import { email } from "https://esm.town/v/std/email";
23export default async function(interval: Interval) {
4const resp = await fetch("https://www.nintendo.com/au/nintendo-live-2024-sydney");
5const html = await resp.text();
passkey_scriptmain.tsx7 matches
2021const _logEl = document.getElementById("logs");
22function log(message) {
23console.log(message);
24_logEl.innerHTML += `<pre>${JSON.stringify(message, null, 2)}</pre>`;
2829const _statusEl = document.getElementById("status");
30function status(message) {
31_statusEl.hidden = false;
32_statusEl.innerText = message;
34}
3536async function postJson(url, body?) {
37return await fetch(url, {
38method: "POST",
42}
4344async function handleRegister() {
45const username = document.getElementById("name").value;
4657}
5859async function startAuth(options, conditional) {
60await SimpleWebAuthnBrowser.startAuthentication(options, conditional)
61.then(log)
74});
7576async function handleLogin() {
77const username = document.getElementById("name").value;
7880}
8182async function handleLogout() {
83await postJson("/logout");
84status("✅ Logged out!");
passkeys_demomain.tsx3 matches
2324// UTILS
25function generateJWT(userId: string) {
26return new SignJWT({ userId }).setProtectedHeader({ alg: "HS256" }).sign(SECRET);
27}
28function verifyJWT(token: string) {
29return jwtVerify(token, SECRET);
30}
31function generateRandomString() {
32return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
33}
connect4_agent_randmain.tsx1 match
9import { agentHandler } from "https://esm.town/v/saolsen/gameplay_agent";
1011function rand_action(
12state: Connect4State,
13agent_data?: { counter: number },
poker_agent_foldsmain.tsx1 match
7} from "https://esm.town/v/saolsen/gameplay_poker";
89function fold_action(
10view: PokerView,
11_agent_data?: JsonObject,
poker_agent_all_inmain.tsx1 match
8} from "https://esm.town/v/saolsen/gameplay_poker";
910function agent(view: PokerView, _agent_data?: JsonObject): PokerAgentResponse {
11const round = view.rounds[view.round];
12const player = round.active_player;
connect4_agent_mctsmain.tsx3 matches
11const SIMULATIONS = 10000;
1213function rand_action(state: Connect4State): Connect4Action {
14const player = state.active_player;
15while (true) {
22}
2324function score_action(
25current_state: Connect4State,
26action: Connect4Action,
63}
6465function agent(state: Connect4State): Connect4AgentResponse {
66// For each action we could take, simulate multiple random games from the resulting state.
67// Keep track of the number of wins for each action.
gameplay_agentmain.tsx5 matches
83/** The name of the agent. */
84agentname: string;
85/** The agent function. */
86agent: Connect4Agent<T> | Connect4AsyncAgent<T>;
87}
99/** The name of the agent. */
100agentname: string;
101/** The agent function. */
102agent: PokerAgent<T> | PokerAsyncAgent<T>;
103}
121* a variety of different http server libraries.
122*
123* To see how to write the agent functions,
124* see the {@link Connect4Agent} and {@link PokerAgent}
125*
134* used with an http server that supports the fetch interface.
135*/
136export function agentHandler<
137T extends Json = Json,
138>(
139agents: AgentSpec<T>[],
140): (req: Request) => Promise<Response> {
141return async function(request: Request): Promise<Response> {
142if (request.method === "GET") {
143return Response.json({
gameplay_pokermain.tsx21 matches
100101/**
102* Helper function to create a {@link Card} from a string.
103*
104* @param {string} s The string representation of the card.
106* @returns {Card} The card.
107*/
108export function cardFromString(s: string): Card {
109const rank_s = s.slice(0, -1);
110const rank = RANK_NAMES.indexOf(rank_s);
121122/**
123* Helper function to create a string from a {@link Card}.
124*
125* @param {Card} c The card.
127* @returns {string} The string representation of the card.
128*/
129export function cardToString(c: Card): string {
130return RANK_NAMES[c.rank] + SUIT_NAMES[c.suit];
131}
137* @returns {Card[]} A deck of cards.
138*/
139export function deck(): Card[] {
140const cards: Card[] = [];
141for (let rank: Rank = 0; rank <= Rank.Ace; rank++) {
156* @param {Card[]} cards The deck of cards to shuffle.
157*/
158export function shuffle(cards: Card[]) {
159let i = cards.length;
160while (i !== 0) {
339340/**
341* Function to compute the {@link Hand} of a list of 5 cards.
342*
343* @param {Card[]} cards The list of 5 cards.
345* @returns {Hand} The hand of the cards.
346*/
347export function hand(cards: Card[]): Hand {
348if (cards.length !== 5) {
349throw new Error(`Invalid number of cards: ${cards.length}`);
443444/**
445* Helper function to compute a value for a {@link Hand} that can be compared
446* to other hands.
447*
459* @returns {number[]} The comparison value for the hand.
460*/
461export function handRank(hand: Hand): number[] {
462const hand_rank: number[] = [hand.kind];
463switch (hand.kind) {
509510/**
511* Comparator function for {@link Hand} values.
512*
513* @param {Hand} a A hand to compare.
518* and 0 if they are equal.
519*/
520export function compareHands(a: Hand, b: Hand): number {
521const a_rank = handRank(a);
522const b_rank = handRank(b);
542* @returns {Hand} The best hand (made from 5 of them) from the cards.
543*/
544export function bestHand(cards: Card[]): Hand {
545console.assert(cards.length === 7);
546const hand_cards = [];
788789/**
790* Function to create a new Poker game.
791*
792* @param {PokerArgs} args The arguments to create the game.
796* or an error if the arguments are invalid.
797*/
798export function newGame(
799args: PokerArgs,
800): [PokerState, Status] | GameError {
869* @returns {null | GameError} null if the action is valid, or a GameError if it is invalid.
870*/
871export function checkAction(
872state: PokerState | PokerView,
873player: number,
947* there are no more {@link RoundPlayerStatus.Playing} players.
948*/
949function playerAfter(
950player: number | null,
951player_status: RoundPlayerStatus[],
977* or an error if the action is invalid.
978*/
979export function applyAction(
980state: PokerState,
981player: number,
1322* @returns {PokerView | GameError} The player's game view.
1323*/
1324export function getView(
1325state: PokerState,
1326player: number,
13661367/**
1368* Function type for a Poker Agent.
1369*
1370* * Takes the current game state and optional agent data.
13921393/**
1394* Function type for an async Poker Agent.
1395*
1396* * Takes the current game state and optional agent data.
gameplay_connect4main.tsx15 matches
52* * The board is a 2D array of {@link Slot}.
53* * The first index is the column and the second index is the row.
54* See {@link get} and {@link set} for helper functions
55* to access the board by column and row.
56*/
8081/**
82* Function to create a new Connect4 game.
83*
84* @param {Connect4Args} args The arguments to create the game.
88* or an error if the arguments are invalid.
89*/
90export function newGame(
91args: Connect4Args,
92): [Connect4State, Status] | GameError {
115116/**
117* Helper function to get the slot at a column and row.
118*
119* @param {Connect4State} state The game state.
123* @returns {Slot} The slot at the column and row.
124*/
125export function get(state: Connect4State, col: number, row: number): Slot {
126return state.board[col][row];
127}
128129/**
130* Helper function to set the slot at a column and row.
131*
132* @param {Connect4State} state The game state.
135* @param {Slot} slot The value to set it to.
136*/
137export function set(
138state: Connect4State,
139col: number,
144}
145146function check_slots_eq(a: Slot, b: Slot, c: Slot, d: Slot): Slot {
147if (a === b && b === c && c === d) {
148return a;
162* or an error if the game state is invalid.
163*/
164export function checkStatus(state: Connect4State): Status | GameError {
165// Check Vertical Win
166for (let col = 0; col < COLS; col++) {
256* @returns {null | GameError} null if the action is valid, or a GameError if it is invalid.
257*/
258export function checkAction(
259state: Connect4State,
260player: number,
285* or an error if the action is invalid.
286*/
287export function applyAction(
288state: Connect4State,
289player: number,
306/**
307* Get the player specific view of the game state.
308* This function is required to define a {@link Game},
309* but Connect4 does not have a player specific view because
310* all players can see the entire board.
316* @returns {Connect4State | GameError} The game state.
317*/
318export function getView(
319state: Connect4State,
320_player: number,
343344/**
345* Function type for a Connect4 Agent.
346*
347* * Takes the current game state and optional agent data.
369370/**
371* Function type for an async Connect4 Agent.
372*
373* * Takes the current game state and optional agent data.