Skip to content

Commit 37a53a0

Browse files
committed
add aimulator :|
1 parent a5cb72e commit 37a53a0

File tree

2 files changed

+135
-1
lines changed

2 files changed

+135
-1
lines changed

aimulator.mjs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env node
2+
import * as GPT from './GPT.mjs';
3+
import * as Claude from './Claude.mjs';
4+
import process from "process";
5+
import fs from 'fs/promises';
6+
import os from 'os';
7+
import path from 'path';
8+
9+
const MODEL = "claude-3-opus-20240229";
10+
11+
const SYSTEM = `
12+
You're a game emulator. You can emulate ANY game, but text-based. Your goal is
13+
to be a fully playable text-based version of the game, emulating as close to the
14+
original as possible, from start to end.
15+
16+
You'll be provided with:
17+
1. The chosen game.
18+
2. The current game log / history.
19+
20+
You'll must answer with:
21+
1. A description of the current game screen.
22+
2. A text-based UI of the current game screen.
23+
3. A labelled list of options that the player can take.
24+
25+
Note that the screen must emulate all game screen elements in a well-positioned,
26+
well-aligned 2D canvas. IT IS NOT ASCII ART. It is a textual UI. For example:
27+
28+
# Example 1: Pokémon Red Battle Screen
29+
30+
You're in a Pokémon battle.
31+
32+
Blastoise LV30 💦🐢💣
33+
HP: |||....... 🔫🐚🛡️
34+
35+
Charizard LV32 🔥🐉🦇
36+
HP: ||||||.... 🌋🦖😤
37+
38+
Options:
39+
A) [FIGHT] B) [PKMN]
40+
C) [ITEM] D) [RUN]
41+
42+
Notes:
43+
1. The screen was drawn as compactly as possible.
44+
2. Key in-game screen elements were positioned in 2D.
45+
3. HP bars were drawn visually, to make it appealing.
46+
4. Emojis (NOT ASCII art) were used to represent images.
47+
5. We expanded the FIGHT option for faster interactions.
48+
49+
# Example 2: Zelda Majora's Mask - Odolwa Boss Fight Room
50+
51+
HP ❤️ ❤️ ❤️ 🤍🤍🤍🤍 :: [A] PutAway [B] 🗡
52+
MANA 🟩🟩🟩⬜⬜⬜⬜⬜⬜⬜ :: [<] 🪈 [V] 💣 [>] 🎣
53+
54+
Link Navi Door-A
55+
[🗡️🧝🛡️] [🧚] [🚪🔒]
56+
57+
Odolwa Jar Door-B Chest
58+
[🗡️🎭🗡️] [🏺] [🚪🔒] [🎁🔒]
59+
60+
Grss Grss Grss
61+
[🌿] [🌿] [🌿]
62+
63+
💎 000 :: [_|7|_|_|_|_|_|_|_|_|_|_] ☀️ 1st
64+
65+
Options:
66+
A) Talk to Navi B) Use Item
67+
C) Attack Odolwa D) Attack Jar
68+
E) Open Door-A F) Open Door-B
69+
G) Move to Grass H) Press Start
70+
71+
Notes:
72+
1. The screen was drawn as compactly as possible.
73+
2. The room layout was positioned in a 2D grid.
74+
3. Key room elements like Link, Odolwa, doors, etc were positioned spatially.
75+
4. HP/Mana bars and Rupee count were drawn visually.
76+
5. Emojis represent Link's current weapon, characters, items, etc.
77+
6. ASCII diagrams used for Rupee count bar and day cycle.
78+
7. Start button menu option included for completeness.
79+
8. Expanded item usage controls for faster interactions.
80+
81+
IMPORTANT: You ARE the videogame. Stay in character. Answer ONLY with the
82+
game screen. Do NOT answer with assistant-like explanations.
83+
84+
IMPORTANT: Stay LOYAL to the original game, including its core mechanics, order
85+
of events and gameplay, from the initial menu all the way to the end screen.
86+
87+
At some points of the interaction, the player may add comments and hints after a
88+
hashtag ('#'). Use this feedback to adjust and improve the experience.`;
89+
90+
(async () => {
91+
console.clear();
92+
93+
const ASCII_ART = `
94+
\x1b[1m\x1b[36m█▀▀▀▀▀█ ▀ ▄▀▄ █▀▀▀▀▀█\x1b[0m
95+
\x1b[1m\x1b[36m█ ███ █ ▀ ▀█▀ █ ███ █\x1b[0m
96+
\x1b[1m\x1b[36m█ ▀▀▀ █ █ ▄█▄ █ ▀▀▀ █\x1b[0m
97+
\x1b[1m\x1b[36m▀▀▀▀▀▀▀ ▀ ▀▀▀ ▀▀▀▀▀▀▀\x1b[0m
98+
\x1b[2mA I E M U L A T O R\x1b[0m
99+
`.trim();
100+
101+
console.log(ASCII_ART);
102+
103+
console.log("");
104+
console.log(`\x1b[32mUsing \x1b[1m${MODEL}\x1b[0m`);
105+
console.log("");
106+
107+
// TODO: get game input
108+
process.stdout.write("Game: ");
109+
const game = (await new Promise(resolve => process.stdin.once('data', data => resolve(data.toString())))).trim();
110+
111+
console.log(`Emulating ${game}...\n\n`);
112+
113+
let log = '';
114+
115+
while (true) {
116+
console.clear();
117+
118+
const response = await Claude.ask({
119+
system: SYSTEM,
120+
model: MODEL,
121+
prompt: `# GAME: ${game}\n# LOG:\n${log}\n\n# TASK: You must continue the game from here. Write your answer below, including the next screen's description, textual UI and player options:`,
122+
max_tokens: 4096,
123+
temperature: 0.9,
124+
});
125+
126+
log += `# SCREEN:\n\n${response}\n\n`;
127+
128+
process.stdout.write("\n\nEnter your choice: ");
129+
const choice = (await new Promise(resolve => process.stdin.once('data', data => resolve(data.toString())))).trim().toUpperCase();
130+
log += `# ACTION: ${choice}\n\n`;
131+
132+
await fs.writeFile(path.join(os.homedir(), '.log.txt'), log);
133+
}
134+
})();

holefill.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ console.log("model_label:", model);
7777

7878
for (let hole of holes) {
7979
console.log("next_filled: " + hole + "...");
80-
var prompt = curr_code + "\nTASK: Fill the {{"+hole+"}} hole. Answer only with the EXACT completion to replace {{"+hole+"}} with. INDENT IT BASED ON THE CONTEXT. DO NOT USE BACKTICKS.";
80+
var prompt = curr_code + "\nTASK: Fill the {{"+hole+"}} hole. Answer only with the EXACT completion to replace {{"+hole+"}} with. INDENT IT BASED ON THE CONTEXT.";
8181
var answer = await ask({system, prompt, model});
8282
file_code = file_code.replace(hole, answer);
8383
}

0 commit comments

Comments
 (0)