Skip to content

Commit

Permalink
feat(ai): provides container with the model
Browse files Browse the repository at this point in the history
  • Loading branch information
Neosoulink committed Dec 10, 2024
1 parent 2a10b4a commit 436527e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
34 changes: 21 additions & 13 deletions packages/ai/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import { isObject } from "@quick-threejs/utils";
import { Chess } from "chess.js";
import { container } from "tsyringe";
import { container as parentContainer, DependencyContainer } from "tsyringe";

import { AiModel, SupportedAiModel } from "../shared";
import { ZeyuModule } from "./zeyu/zeyu.module";

/**
* @description
*/
export interface RegisterReturn {
container: DependencyContainer;
model: AiModel | undefined;
}

/** @description Registers the AI model to be used in the game. */
export const register = (
model: SupportedAiModel,
app: Chess
): AiModel | undefined => {
if (!isObject(app))
throw new Error("Unable to retrieve the application context.");
aiModel: SupportedAiModel,
game: Chess
): RegisterReturn => {
if (!isObject(game)) throw new Error("Unable to retrieve the game context.");

const container = parentContainer.createChildContainer();
container.register(Chess, {
useValue: app
useValue: game
});

if (model === SupportedAiModel.zeyu)
return container.resolve<AiModel>(ZeyuModule);
let model: AiModel | undefined = undefined;

if (aiModel === SupportedAiModel.zeyu)
model = container.resolve<AiModel>(ZeyuModule);

return undefined;
return {
container,
model
};
};
2 changes: 1 addition & 1 deletion packages/ai/src/shared/enums/register.enum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export enum SupportedAiModel {
zeyu
zeyu = "AI_MODEL_ZEYU"
}

0 comments on commit 436527e

Please sign in to comment.