From 5688e499fc1a27b1151da3d904aee9328a46bc8b Mon Sep 17 00:00:00 2001 From: Hamcha Date: Thu, 12 Sep 2019 18:09:39 +0200 Subject: [PATCH] Start work on bot and sessions --- src/mlpccg/draft/booster.ts | 3 +-- src/mlpccg/draft/bot.ts | 9 +++++++++ src/mlpccg/draft/cube.ts | 5 ++--- src/mlpccg/draft/index.ts | 2 ++ src/mlpccg/draft/session.ts | 29 +++++++++++++++++++++++++++++ src/mlpccg/draft/types.ts | 28 +++++++++++++++++++++++++++- 6 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 src/mlpccg/draft/bot.ts create mode 100644 src/mlpccg/draft/session.ts diff --git a/src/mlpccg/draft/booster.ts b/src/mlpccg/draft/booster.ts index 26627a3..e1123b4 100644 --- a/src/mlpccg/draft/booster.ts +++ b/src/mlpccg/draft/booster.ts @@ -1,6 +1,5 @@ -import { Card } from "../types"; +import { Card, getCards } from "@/mlpccg"; import { Pack, PackSchema, AlternateProvider } from "./types"; -import { getCards } from "../database"; /* diff --git a/src/mlpccg/draft/bot.ts b/src/mlpccg/draft/bot.ts new file mode 100644 index 0000000..b6e9ee5 --- /dev/null +++ b/src/mlpccg/draft/bot.ts @@ -0,0 +1,9 @@ +import { Card } from "@/mlpccg"; + +export class DraftBot { + pick(picks: Card[]) { + // For now, pick a random card + const idx = Math.floor(Math.random() * picks.length); + return picks[idx]; + } +} diff --git a/src/mlpccg/draft/cube.ts b/src/mlpccg/draft/cube.ts index b92338e..fc6d4c1 100644 --- a/src/mlpccg/draft/cube.ts +++ b/src/mlpccg/draft/cube.ts @@ -1,7 +1,6 @@ -import { Card } from "../types"; -import { getCards, cardFromIDs } from "../database"; -import axios from "axios"; +import { Card, cardFromIDs } from "@/mlpccg"; import { PackSchema } from "./types"; +import axios from "axios"; export class Cube { private pool: Card[]; diff --git a/src/mlpccg/draft/index.ts b/src/mlpccg/draft/index.ts index cb4f17a..5dee001 100644 --- a/src/mlpccg/draft/index.ts +++ b/src/mlpccg/draft/index.ts @@ -1,3 +1,5 @@ export * from "./cube"; export * from "./booster"; export * from "./types"; +export * from "./session"; +export * from "./bot"; diff --git a/src/mlpccg/draft/session.ts b/src/mlpccg/draft/session.ts new file mode 100644 index 0000000..d9f2bf3 --- /dev/null +++ b/src/mlpccg/draft/session.ts @@ -0,0 +1,29 @@ +import { PackBuilder, Cube, DraftOptions } from "."; + +export class Session { + private options: DraftOptions; + private factory: PackBuilder; + + constructor(options: DraftOptions, factory: PackBuilder) { + this.options = options; + this.factory = factory; + } + + static async create(options: DraftOptions): Promise { + switch (options.type) { + case "set": { + const factory = await PackBuilder.fromSet(options.set); + return new Session(options, factory); + } + case "block": + throw new Error("not implemented"); + case "cube": { + const cube = await Cube.fromURL(options.url); + const factory = new PackBuilder(cube.schema()); + return new Session(options, factory); + } + case "i8pcube": + throw new Error("not implemented"); + } + } +} diff --git a/src/mlpccg/draft/types.ts b/src/mlpccg/draft/types.ts index 62be937..58f4ae7 100644 --- a/src/mlpccg/draft/types.ts +++ b/src/mlpccg/draft/types.ts @@ -1,4 +1,4 @@ -import { Card } from "../types"; +import { Card } from "@/mlpccg"; export type Provider = Iterator; @@ -18,3 +18,29 @@ export interface AlternateProvider { probability: number; provider: Provider; } + +export interface SetDraftOptions { + type: "set"; + set: string; +} + +export interface BlockDraftOptions { + type: "block"; + block: string; +} + +export interface CubeDraftOptions { + type: "cube"; + url: string; +} + +export interface I8PCubeDraftOptions { + type: "i8pcube"; + url: string; +} + +export type DraftOptions = + | SetDraftOptions + | BlockDraftOptions + | CubeDraftOptions + | I8PCubeDraftOptions;