public override Task <DotnetAIResponse> Request(DotnetAIRequest request, ServerCallContext context) { Console.WriteLine("Dotnet AI match request received"); if (CurrentMatch != null) { Console.WriteLine("Only one match can be run. Aborted"); return(Task.FromResult( new DotnetAIResponse { Type = DotnetAIResponse.Types.Type.Occupied })); } try { // Get dotnet AI with a specified name IGameAI dotnetAI = FindAI.GetAI(request.DotnetAiName); Console.WriteLine($"... Found AI '{request.DotnetAiName}'"); // Generate SabberStoneCore.Model.Game Game modelGame = SabberHelpers.GenerateGame(request.DotnetAiDeckstring, request.PythonAiDeckstring, request.History, request.Seed); // Create a match instance CurrentMatch = new Match(dotnetAI, modelGame, request.DotnetAiName); if (ConsoleOutput) { Console.WriteLine("########## Initial State #########"); SabberHelpers.Printers.PrintGame(modelGame); Console.WriteLine("##################################"); } var apiGame = new API.Game(CurrentMatch.CurrentPartiallyObservableGame); CurrentMatch.APIGameId = apiGame.Id.Value; // Return Current Partially Observable Game return(Task.FromResult(new DotnetAIResponse { Type = DotnetAIResponse.Types.Type.Success, Game = apiGame })); } catch (FindAI.AINotFoundException) { return(Task.FromResult(new DotnetAIResponse { Type = DotnetAIResponse.Types.Type.NotFound })); } catch (Exception) { return(Task.FromResult(new DotnetAIResponse { Type = DotnetAIResponse.Types.Type.InvalidDeckstring })); } }
public Game(SabberStoneCore.Model.Game game, int id = -1) { if (id < 0) { Id = _id_gen++; } else { Id = id; } State = (int)game.State; Turn = game.Turn; CurrentPlayer = new Controller(game.CurrentPlayer); CurrentOpponent = new Controller(game.CurrentOpponent); }
public Game(SabberStoneCore.Model.Game game, int id = -1) { currentPlayer_ = new Controller(game.CurrentPlayer); currentOpponent_ = new Controller(game.CurrentOpponent); state_ = (Types.State)game.State; turn_ = game.Turn; if (id < 0) { id = _id_gen++;; ManagedObjects.Games.Add(id, game); ManagedObjects.InitialGames.Add(id, game.Clone()); //ManagedObjects.InitialGameAPIs.Add(id, this); ManagedObjects.OptionBuffers.Add(id, new List <Option>(50)); } id_ = new GameId(id); }
public PowerOptionChoice PowerOptions(Game game, List <PowerOption> powerOptionList) { while (StateTCS == null) { Thread.Sleep(1); } Console.WriteLine(SabberHelpers.Printers.PrintGame(game)); StateTCS.SetResult(new GameState(game)); Option option = OptionTCS.Task.Result; PlayerTask task = SabberHelpers.GetPlayerTask(option, game); Console.WriteLine(SabberHelpers.Printers.PrintAction(task)); StateTCS = null; OptionTCS = null; return(SabberStoneContract.Helper.SabberStoneConverter.CreatePowerOption(task)); }
public bool PlayGame(bool addToGameStats = true, bool debug = false) { SabberStoneCore.Model.Game game = new SabberStoneCore.Model.Game(gameConfig, setupHeroes); //var game = new Game(gameConfig, setupHeroes); player1.InitializeGame(); player2.InitializeGame(); AbstractAgent currentAgent; Stopwatch currentStopwatch; POGame poGame; PlayerTask playertask = null; Stopwatch[] watches = new[] { new Stopwatch(), new Stopwatch() }; bool printGame = false; game.StartGame(); if (gameConfig.SkipMulligan == false) { var originalStartingPlayer = game.CurrentPlayer; var originalStartinOpponent = game.CurrentOpponent; game.CurrentPlayer = originalStartingPlayer; currentAgent = gameConfig.StartPlayer == 1 ? player1 : player2; poGame = new POGame(game, debug); playertask = currentAgent.GetMove(poGame); game.Process(playertask); game.CurrentPlayer = originalStartinOpponent; currentAgent = gameConfig.StartPlayer == 1 ? player2 : player1; poGame = new POGame(game, debug); playertask = currentAgent.GetMove(poGame); game.Process(playertask); game.CurrentPlayer = originalStartingPlayer; game.MainReady(); } #if DEBUG try { #endif while (game.State != State.COMPLETE && game.State != State.INVALID) { //if (debug) //Console.WriteLine("Turn " + game.Turn); if (printGame) { //Console.WriteLine(MCGS.SabberHelper.SabberUtils.PrintGame(game)); printGame = false; } if (game.Turn >= maxTurns) { break; } currentAgent = game.CurrentPlayer == game.Player1 ? player1 : player2; Controller currentPlayer = game.CurrentPlayer; currentStopwatch = game.CurrentPlayer == game.Player1 ? watches[0] : watches[1]; poGame = new POGame(game, debug); currentStopwatch.Start(); playertask = currentAgent.GetMove(poGame); currentStopwatch.Stop(); game.CurrentPlayer.Game = game; game.CurrentOpponent.Game = game; if (debug) { //Console.WriteLine(playertask); } if (playertask.PlayerTaskType == PlayerTaskType.END_TURN) { printGame = true; } game.Process(playertask); } #if DEBUG } catch (Exception e) //Current Player loses if he throws an exception { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); game.State = State.COMPLETE; game.CurrentPlayer.PlayState = PlayState.CONCEDED; game.CurrentOpponent.PlayState = PlayState.WON; if (addToGameStats && game.State != State.INVALID) { gameStats.registerException(game, e); } } #endif if (game.State == State.INVALID || (game.Turn >= maxTurns && repeatDraws)) { return(false); } if (addToGameStats) { gameStats.addGame(game, watches); } player1.FinalizeGame(); player2.FinalizeGame(); return(true); }
public PowerChoices PowerChoices(Game game, PowerChoices powerChoices) { throw new NotImplementedException(); }
public PlayerTask GetMove(Game game) { throw new NotImplementedException(); }