public async Task <IActionResult> DeleteGame() { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _context.Game.ForEachAsync(p => _context.Game.Remove(p)); await _context.GameMove.ForEachAsync(p => _context.GameMove.Remove(p)); await _context.SaveChangesAsync(); _engine.Reset(); var game = new Game() { Status = GameStatus.Initial }; var webSocketMessage = new WebSocketMessage() { Type = "Game", Payload = game }; await _socketService.BroadcastMessage(webSocketMessage); return(Ok()); }
private async Task AutoPlay() { var game = await GetGame(); if (game.Status != GameStatus.Playing) { return; } // Call victoria engine var board = _adapter.FromGameMoves(_context.GameMove.ToArray()); var cordinate = _engine.FindBestMove(board, Color.White, TimeSpan.FromSeconds(10)); var autoMove = _adapter.ToGameMove(cordinate, Color.White); // Call simple alpha-beta algorithm //AutoPlayMove[][] board = _adapter.GameMovesToAutoPlayMoves(_context.GameMove.ToArray()); //AutoPlayMove decision = _autoPlayService.MakeDecision(board); //var autoMove = _adapter.AutoPlayMovesToGameMove(decision); _context.GameMove.Add(autoMove); if (await Judge(autoMove)) { game.Status = GameStatus.WhiteSideWon; } else { game.NextPlayer = game.BlackSidePlayer; } await _context.SaveChangesAsync(); var message = new WebSocketMessage() { Type = "GameMove", Payload = autoMove }; await _socket.BroadcastMessage(message); message = new WebSocketMessage() { Type = "Game", Payload = game }; await _socket.BroadcastMessage(message); }