mlpcardgame/src/mlpccg/draft/bot.ts

19 lines
514 B
TypeScript

import { Card } from "@/mlpccg";
import { SessionPlayer } from "./session";
export class DraftBot {
assign(player: SessionPlayer) {
player.on("available-picks", cards => {
const pick = this.pick(cards);
// setTimeout hack to avoid handlers being called before the rest of the code
setTimeout(() => player.pick(pick.ID), 0);
});
}
pick(picks: Card[]): Card {
// For now, pick a random card
const idx = Math.floor(Math.random() * picks.length);
return picks[idx];
}
}