Fixed LLM bot support
This commit is contained in:
1 parent
792f12b925
commit
e1d059d72c
3 files changed
+50
-30
No files matched your search
@@ -117,7 +117,7 @@ class YarnGame {
|
||||
console.log("Creating bots...")
|
||||
for (let i = 0; i < botCount; i++) {
|
||||
const bot_id = randomUUID()
|
||||
const bot = BotFactory.createBot("random");
|
||||
const bot = BotFactory.createBot("llm");
|
||||
this.bots.push({ bot_id, bot });
|
||||
const bot_player = {
|
||||
player_id: bot_id,
|
||||
@@ -130,23 +130,24 @@ class YarnGame {
|
||||
}
|
||||
}
|
||||
|
||||
startGame(settings) {
|
||||
async startGame(settings) {
|
||||
this.gameSettings = { ...this.gameSettings, ...settings };
|
||||
this.startBots(this.gameSettings.botCount);
|
||||
this.inProgress = true;
|
||||
this.yarnStory = [{ player: "Narrator", str: this.gameSettings.startText }];
|
||||
this.players.forEach(p => p.score = 0);
|
||||
this.startWritingPhase();
|
||||
await this.startWritingPhase();
|
||||
}
|
||||
|
||||
processBotWriting() {
|
||||
async processBotWriting() {
|
||||
for (const botObj of this.bots) {
|
||||
const botText = botObj.bot.Write(this.getStoryText());
|
||||
const botText = await botObj.bot.Write(this.getStoryText());
|
||||
console.log(`Bot text: ${botText}`)
|
||||
this.submitEntry(botObj.bot_id, botText)
|
||||
}
|
||||
}
|
||||
|
||||
startWritingPhase() {
|
||||
async startWritingPhase() {
|
||||
this.currentPhase = 'writing';
|
||||
this.round_data = [];
|
||||
this.submittedPlayers = new Set();
|
||||
@@ -176,18 +177,18 @@ class YarnGame {
|
||||
return this.submittedPlayers.size >= this.players.length;
|
||||
}
|
||||
|
||||
processBotVoting() {
|
||||
async processBotVoting() {
|
||||
for (const botObj of this.bots) {
|
||||
const botVote = botObj.bot.Vote(this.getStoryText(), this.round_data);
|
||||
const botVote = await botObj.bot.Vote(this.getStoryText(), this.round_data);
|
||||
this.submitVote(botObj.bot_id, botVote)
|
||||
}
|
||||
}
|
||||
|
||||
startVotingPhase() {
|
||||
async startVotingPhase() {
|
||||
this.currentPhase = 'voting';
|
||||
this.votedPlayers = new Set();
|
||||
this.timeRemaining = 30; // 30 seconds for voting
|
||||
this.processBotVoting()
|
||||
await this.processBotVoting()
|
||||
}
|
||||
|
||||
submitVote(playerId, entryIndex) {
|
||||
@@ -390,7 +391,7 @@ io.on('connection', (socket) => {
|
||||
io.to(currentRoom).emit('settingsUpdate', game.gameSettings);
|
||||
});
|
||||
|
||||
socket.on('startGame', (settings) => {
|
||||
socket.on('startGame', async (settings) => {
|
||||
if (!currentRoom || !playerId) return;
|
||||
|
||||
const game = games[currentRoom];
|
||||
@@ -401,13 +402,13 @@ io.on('connection', (socket) => {
|
||||
}
|
||||
|
||||
console.log(`Starting new game with settings ${JSON.stringify(settings)}`)
|
||||
game.startGame(settings);
|
||||
await game.startGame(settings);
|
||||
io.to(currentRoom).emit('gameStarted', game.getState());
|
||||
|
||||
startTimer(game);
|
||||
await startTimer(game);
|
||||
});
|
||||
|
||||
socket.on('submitEntry', (data) => {
|
||||
socket.on('submitEntry', async (data) => {
|
||||
if (!currentRoom || !playerId) return;
|
||||
|
||||
const game = games[currentRoom];
|
||||
@@ -420,7 +421,7 @@ io.on('connection', (socket) => {
|
||||
|
||||
if (game.allPlayersSubmitted()) {
|
||||
clearInterval(game.timer);
|
||||
game.startVotingPhase();
|
||||
await game.startVotingPhase();
|
||||
io.to(currentRoom).emit('votingPhase', {
|
||||
entries: game.round_data.map((e, i) => ({
|
||||
index: i,
|
||||
@@ -495,10 +496,10 @@ io.on('connection', (socket) => {
|
||||
});
|
||||
});
|
||||
|
||||
function startTimer(game) {
|
||||
async function startTimer(game) {
|
||||
if (game.timer) clearInterval(game.timer);
|
||||
|
||||
game.timer = setInterval(() => {
|
||||
game.timer = setInterval(async () => {
|
||||
game.timeRemaining--;
|
||||
io.to(game.roomName).emit('timerUpdate', game.timeRemaining);
|
||||
|
||||
@@ -512,7 +513,7 @@ function startTimer(game) {
|
||||
}
|
||||
}
|
||||
|
||||
game.startVotingPhase();
|
||||
await game.startVotingPhase();
|
||||
io.to(game.roomName).emit('votingPhase', {
|
||||
entries: game.round_data.map((e, i) => ({
|
||||
index: i,
|
||||
@@ -558,10 +559,10 @@ function endVotingPhase(game) {
|
||||
});
|
||||
} else {
|
||||
// Start next round after a short delay
|
||||
setTimeout(() => {
|
||||
setTimeout(async () => {
|
||||
game.startWritingPhase();
|
||||
io.to(game.roomName).emit('newRound', game.getState());
|
||||
startTimer(game);
|
||||
await startTimer(game);
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user