-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ai): provides container with the model
- Loading branch information
1 parent
2a10b4a
commit 436527e
Showing
2 changed files
with
22 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export enum SupportedAiModel { | ||
zeyu | ||
zeyu = "AI_MODEL_ZEYU" | ||
} |