private async Task EnginMoves(WebSocket client) { var rnd = new Random(); await Task.Delay(rnd.Next(800, 1500)); await Send(client, new ActionDto { actionName = ActionNames.rolled }); var moves = Engine.GetBestMoves(); var noMoves = true; for (int i = 0; i < moves.Length; i++) { var move = moves[i]; if (move == null) { continue; } await Task.Delay(rnd.Next(800, 1500)); var moveDto = move.ToDto(); moveDto.animate = true; var dto = new OpponentMoveActionDto { move = moveDto, }; Game.MakeMove(move); if (Game.CurrentPlayer == Player.Color.Black) { Game.BlackPlayer.FirstMoveMade = true; } else { Game.WhitePlayer.FirstMoveMade = true; } noMoves = false; await Send(client, dto); } if (noMoves) { await Task.Delay(4000); // if turn is switch right away, ui will not have time to display dice. } await NewTurn(client); }
private async Task EnginMoves(WebSocket client) { var moves = Engine.GetBestMoves(); for (int i = 0; i < moves.Length; i++) { var move = moves[i]; Thread.Sleep(1500); var moveDto = move.ToDto(); moveDto.animate = true; var dto = new OpponentMoveActionDto { move = moveDto, }; Game.MakeMove(move); await Send(client, dto); } await NewTurn(client); }