Esempio n. 1
0
        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
                }));
            }
        }
Esempio n. 2
0
        public override Task <Game> Process(Option request, ServerCallContext context)
        {
            Game test()
            {
                var game = ManagedObjects.Games[request.GameId];

                try
                {
                    var playerTask = SabberHelpers.GetPlayerTask(request, game);

                    // Use option ids instead?
                    //Console.WriteLine(SabberHelpers.Printers.PrintAction(playerTask));

                    game.Process(playerTask);

                    //Console.WriteLine(SabberHelpers.Printers.PrintGame(game));

                    return(new Game(game, request.GameId));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    throw e;
                }
            }

            return(Task.FromResult(test()));
        }
Esempio n. 3
0
        public override Task <Game> NewGame(DeckStrings request, ServerCallContext context)
        {
            Console.WriteLine("NewGame service is called!");
            Console.WriteLine("Deckstring #1: " + request.Deck1);
            Console.WriteLine("Deckstring #2: " + request.Deck2);

            return(Task.FromResult(SabberHelpers.GenerateGameAPI(request.Deck1, request.Deck2)));
        }
Esempio n. 4
0
        public void SaveHistory()
        {
            if (!_game.History)
            {
                return;
            }

            const string HISTORY_DIR = "history";

            Directory.CreateDirectory(HISTORY_DIR);
            string fileName = $"{DotnetAgentName}_{DateTime.Now:ddMMyy_HHmmss}.log";

            string path = Path.Combine(HISTORY_DIR, fileName);

            SabberHelpers.DumpHistories(_game, path);
        }
Esempio n. 5
0
        public static void DeckStringDeserialize()
        {
            string      deckString = @"AAEBAf0EAA8MTXHDAZ4CuwKLA5UDvwOABLQE5gSgBewFuQYA";
            List <Card> mageExpert = new List <Card>
            {
                Cards.FromName("Mana Addict"),
                Cards.FromName("Mana Addict"),
                Cards.FromName("Polymorph"),
                Cards.FromName("Polymorph"),
                Cards.FromName("Counterspell"),
                Cards.FromName("Counterspell"),
                Cards.FromName("Mirror Entity"),
                Cards.FromName("Mirror Entity"),
                Cards.FromName("Vaporize"),
                Cards.FromName("Vaporize"),
                Cards.FromName("Fireball"),
                Cards.FromName("Fireball"),
                Cards.FromName("Water Elemental"),
                Cards.FromName("Water Elemental"),
                Cards.FromName("Mana Wyrm"),
                Cards.FromName("Mana Wyrm"),
                Cards.FromName("Arcane Explosion"),
                Cards.FromName("Arcane Explosion"),
                Cards.FromName("Frost Elemental"),
                Cards.FromName("Frost Elemental"),
                Cards.FromName("Arcane Missiles"),
                Cards.FromName("Arcane Missiles"),
                Cards.FromName("Sorcerer's Apprentice"),
                Cards.FromName("Sorcerer's Apprentice"),
                Cards.FromName("Kobold Geomancer"),
                Cards.FromName("Kobold Geomancer"),
                Cards.FromName("Kirin Tor Mage"),
                Cards.FromName("Kirin Tor Mage"),
                Cards.FromName("Azure Drake"),
                Cards.FromName("Azure Drake"),
            };

            SabberHelpers.Deck deck = SabberHelpers.Deserialise(deckString, "Mage Expert");

            List <Card> list = deck.GetCardList();
            CardClass   cls  = deck.Class;

            if (cls != CardClass.MAGE || !Enumerable.SequenceEqual(mageExpert, list))
            {
                throw new Exception();
            }
        }
Esempio n. 6
0
        public void ProcessPythonOption(API.Option apiOption)
        {
            PlayerTask playerTask = SabberHelpers.GetPlayerTask(apiOption, _game);

            if (DotnetAIServiceImpl.ConsoleOutput)
            {
                Console.WriteLine($"Option from python is received: {SabberHelpers.Printers.PrintAction(playerTask)}");
            }


            _game.Process(playerTask);

            if (_game.CurrentPlayer.PlayerId == 1)
            {
                GetDotnetAgentMoves();
            }
        }
Esempio n. 7
0
        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));
        }