Start work on bot and sessions
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Hamcha 2019-09-12 18:09:39 +02:00
parent ff6a77d431
commit 5688e499fc
Signed by: hamcha
GPG Key ID: 44AD3571EB09A39E
6 changed files with 70 additions and 6 deletions

View File

@ -1,6 +1,5 @@
import { Card } from "../types";
import { Card, getCards } from "@/mlpccg";
import { Pack, PackSchema, AlternateProvider } from "./types";
import { getCards } from "../database";
/*

9
src/mlpccg/draft/bot.ts Normal file
View File

@ -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];
}
}

View File

@ -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[];

View File

@ -1,3 +1,5 @@
export * from "./cube";
export * from "./booster";
export * from "./types";
export * from "./session";
export * from "./bot";

View File

@ -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<Session> {
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");
}
}
}

View File

@ -1,4 +1,4 @@
import { Card } from "../types";
import { Card } from "@/mlpccg";
export type Provider = Iterator<Card>;
@ -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;