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.
gameplay_gamesmain.tsx5 matches
222/**
223* The type of a game.
224* A game is defined by these functions
225*
226* @template ARGS The type of the game arguments.
246kind: GameKind;
247/**
248* Function for creating a new game.
249*
250* Takes the arguments for creating a new game.
257) => [STATE, Status] | ERROR;
258/**
259* Function for checking if an action is valid.
260*
261* Takes the current game state, the player making the action,
270) => null | ERROR;
271/**
272* Function for applying an action to the game state.
273* It should mutate the passed in game state.
274*
284) => Status | ERROR;
285/**
286* Function for getting a view of the game state
287* for a particular player.
288* The view type is different from the state type so
3// import Quill from "npm:quill";
45export default async function(req: Request) {
6if (req.method === "POST") {
7const name = (await req.formData()).get("name");
myspaceHtmlmain.tsx3 matches
70}
7172export function myspaceHtml(
73{
74displayName,
627}
628629function top8FriendsHtml(friends: Friend[]) {
630// Divide friends into groups of at most four
631const friendRows = [];
655}
656657function commentHtml(comment: {
658friend: Friend;
659timestamp: string;
ValCommitsmain.tsx1 match
3import { jsx, Fragment } from 'https://deno.land/x/hono/middleware.ts'
45export default function ValCommits
GithubCommitsmain.tsx1 match
3import { jsx, Fragment } from 'https://deno.land/x/hono/middleware.ts'
45export default function GithubCommits({}) {
6return (
7<>
myspaceCSSmain.tsx1 match
1export function myspaceCSS() {
2return `
3.verdana12 {