feat: 1vs BOT

This commit is contained in:
shahdlala66
2026-04-19 01:06:13 +02:00
parent 5497997455
commit bc644c16e3
5 changed files with 201 additions and 4 deletions
+21 -1
View File
@@ -7,7 +7,8 @@ import {
GameFull,
GameState,
GameStreamEvent,
LegalMovesResponse
LegalMovesResponse,
PlayerInfo
} from '../models/game.models';
@Injectable({ providedIn: 'root' })
@@ -21,6 +22,25 @@ export class GameApiService {
return this.http.post<GameFull>(`${this.apiBase}/api/board/game`, {});
}
createGameVsBot(difficulty: 'easy' | 'medium' | 'hard' = 'medium'): Observable<GameFull> {
const playerColor = Math.random() > 0.5 ? 'white' : 'black';
const playerInfo: PlayerInfo = {
id: `player-${Date.now()}`,
displayName: 'You'
};
const botInfo: PlayerInfo = {
id: `bot-${difficulty}`,
displayName: `Bot (${difficulty})`
};
const payload =
playerColor === 'white'
? { white: playerInfo, black: botInfo }
: { white: botInfo, black: playerInfo };
return this.http.post<GameFull>(`${this.apiBase}/api/board/game`, payload);
}
getGame(gameId: string): Observable<GameFull> {
return this.http.get<GameFull>(`${this.apiBase}/api/board/game/${gameId}`);
}