Basic draft library #19

Merged
hamcha merged 13 commits from feature/draft-lib into master 2019-09-16 13:53:07 +00:00
6 changed files with 70 additions and 6 deletions
Showing only changes of commit 5688e499fc - Show all commits

View file

@ -1,6 +1,5 @@
import { Card } from "../types"; import { Card, getCards } from "@/mlpccg";
import { Pack, PackSchema, AlternateProvider } from "./types"; 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 { Card, cardFromIDs } from "@/mlpccg";
import { getCards, cardFromIDs } from "../database";
import axios from "axios";
import { PackSchema } from "./types"; import { PackSchema } from "./types";
import axios from "axios";
export class Cube { export class Cube {
private pool: Card[]; private pool: Card[];

View file

@ -1,3 +1,5 @@
export * from "./cube"; export * from "./cube";
export * from "./booster"; export * from "./booster";
export * from "./types"; 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>; export type Provider = Iterator<Card>;
@ -18,3 +18,29 @@ export interface AlternateProvider {
probability: number; probability: number;
provider: Provider; 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;