-
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.
- Loading branch information
1 parent
436527e
commit f75ebbc
Showing
11 changed files
with
210 additions
and
204 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
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
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,20 +1,23 @@ | ||
import { register, SupportedAiModel } from "@chess-d/ai"; | ||
import { inject, singleton } from "tsyringe"; | ||
import { Chess, validateFen } from "chess.js"; | ||
import { AiModel } from "@chess-d/ai"; | ||
|
||
@singleton() | ||
export class AiService { | ||
constructor( | ||
@inject(Chess) private readonly game: Chess, | ||
@inject(AiModel) private readonly ai: AiModel | ||
) {} | ||
constructor(@inject(Chess) private readonly game: Chess) {} | ||
|
||
public handleWillPerformMove = (ai?: SupportedAiModel, fen?: string) => { | ||
if (!ai) return console.warn("Received invalid AI model"); | ||
|
||
public handleWillPerformMove = (fen?: string) => { | ||
if (!fen || !validateFen(fen).ok) | ||
return console.warn("AI received invalid FEN string"); | ||
|
||
this.game.load(fen); | ||
const { container, model } = register(ai, this.game); | ||
const move = model?.getMove(this.game.turn()); | ||
|
||
container.clearInstances(); | ||
|
||
return this.ai?.getMove(this.game.turn()); | ||
return move; | ||
}; | ||
} |
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
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
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 @@ | ||
export * from "./use-ai.hook"; | ||
export * from "./use-game.hook"; | ||
export * from "./use-socket.hook"; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.