Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/$%7Bart_info.art.src%7D?q=function&page=1647&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=function

Returns an array of strings in format "username" or "username/projectName"

Found 18948 results for "function"(2973ms)

connect4_agent_mctsmain.tsx3 matches

@saolsen•Updated 1 year ago
11const SIMULATIONS = 10000;
12
13function rand_action(state: Connect4State): Connect4Action {
14 const player = state.active_player;
15 while (true) {
22}
23
24function score_action(
25 current_state: Connect4State,
26 action: Connect4Action,
63}
64
65function 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

@saolsen•Updated 1 year ago
83 /** The name of the agent. */
84 agentname: string;
85 /** The agent function. */
86 agent: Connect4Agent<T> | Connect4AsyncAgent<T>;
87}
99 /** The name of the agent. */
100 agentname: string;
101 /** The agent function. */
102 agent: 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<
137 T extends Json = Json,
138>(
139 agents: AgentSpec<T>[],
140): (req: Request) => Promise<Response> {
141 return async function(request: Request): Promise<Response> {
142 if (request.method === "GET") {
143 return Response.json({

gameplay_pokermain.tsx21 matches

@saolsen•Updated 1 year ago
100
101/**
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 {
109 const rank_s = s.slice(0, -1);
110 const rank = RANK_NAMES.indexOf(rank_s);
121
122/**
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 {
130 return RANK_NAMES[c.rank] + SUIT_NAMES[c.suit];
131}
137 * @returns {Card[]} A deck of cards.
138 */
139export function deck(): Card[] {
140 const cards: Card[] = [];
141 for (let rank: Rank = 0; rank <= Rank.Ace; rank++) {
156 * @param {Card[]} cards The deck of cards to shuffle.
157 */
158export function shuffle(cards: Card[]) {
159 let i = cards.length;
160 while (i !== 0) {
339
340/**
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 {
348 if (cards.length !== 5) {
349 throw new Error(`Invalid number of cards: ${cards.length}`);
443
444/**
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[] {
462 const hand_rank: number[] = [hand.kind];
463 switch (hand.kind) {
509
510/**
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 {
521 const a_rank = handRank(a);
522 const 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 {
545 console.assert(cards.length === 7);
546 const hand_cards = [];
788
789/**
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(
799 args: 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(
872 state: PokerState | PokerView,
873 player: number,
947 * there are no more {@link RoundPlayerStatus.Playing} players.
948 */
949function playerAfter(
950 player: number | null,
951 player_status: RoundPlayerStatus[],
977 * or an error if the action is invalid.
978 */
979export function applyAction(
980 state: PokerState,
981 player: number,
1322 * @returns {PokerView | GameError} The player's game view.
1323 */
1324export function getView(
1325 state: PokerState,
1326 player: number,
1366
1367/**
1368 * Function type for a Poker Agent.
1369 *
1370 * * Takes the current game state and optional agent data.
1392
1393/**
1394 * Function type for an async Poker Agent.
1395 *
1396 * * Takes the current game state and optional agent data.

gameplay_connect4main.tsx15 matches

@saolsen•Updated 1 year ago
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 */
80
81/**
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(
91 args: Connect4Args,
92): [Connect4State, Status] | GameError {
115
116/**
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 {
126 return state.board[col][row];
127}
128
129/**
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(
138 state: Connect4State,
139 col: number,
144}
145
146function check_slots_eq(a: Slot, b: Slot, c: Slot, d: Slot): Slot {
147 if (a === b && b === c && c === d) {
148 return a;
162 * or an error if the game state is invalid.
163 */
164export function checkStatus(state: Connect4State): Status | GameError {
165 // Check Vertical Win
166 for (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(
259 state: Connect4State,
260 player: number,
285 * or an error if the action is invalid.
286 */
287export function applyAction(
288 state: Connect4State,
289 player: 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(
319 state: Connect4State,
320 _player: number,
343
344/**
345 * Function type for a Connect4 Agent.
346 *
347 * * Takes the current game state and optional agent data.
369
370/**
371 * Function type for an async Connect4 Agent.
372 *
373 * * Takes the current game state and optional agent data.

gameplay_gamesmain.tsx5 matches

@saolsen•Updated 1 year ago
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.
246 kind: 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

HTMXQuillmain.tsx1 match

@rayman•Updated 1 year ago
3// import Quill from "npm:quill";
4
5export default async function(req: Request) {
6 if (req.method === "POST") {
7 const name = (await req.formData()).get("name");

myspaceHtmlmain.tsx3 matches

@jdan•Updated 1 year ago
70}
71
72export function myspaceHtml(
73 {
74 displayName,
627}
628
629function top8FriendsHtml(friends: Friend[]) {
630 // Divide friends into groups of at most four
631 const friendRows = [];
655}
656
657function commentHtml(comment: {
658 friend: Friend;
659 timestamp: string;

ValCommitsmain.tsx1 match

@iamseeley•Updated 1 year ago
3import { jsx, Fragment } from 'https://deno.land/x/hono/middleware.ts'
4
5export default function ValCommits

GithubCommitsmain.tsx1 match

@iamseeley•Updated 1 year ago
3import { jsx, Fragment } from 'https://deno.land/x/hono/middleware.ts'
4
5export default function GithubCommits({}) {
6 return (
7 <>

myspaceCSSmain.tsx1 match

@jdan•Updated 1 year ago
1export function myspaceCSS() {
2 return `
3 .verdana12 {

getFileEmail4 file matches

@shouser•Updated 2 weeks ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblk•Updated 2 weeks ago
Simple functional CSS library for Val Town
lost1991
import { OpenAI } from "https://esm.town/v/std/openai"; export default async function(req: Request): Promise<Response> { if (req.method === "OPTIONS") { return new Response(null, { headers: { "Access-Control-Allow-Origin": "*",
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.