コード例 #1
0
        public static List <PD_Game> Generate_Random_Games(
            Random randomness_provider,
            int numberOfGames,
            int numberOfPlayers,
            int gameDifficulty
            )
        {
            List <int> roles_list = new List <int>()
            {
                PD_Player_Roles.Operations_Expert,
                PD_Player_Roles.Researcher,
                PD_Player_Roles.Medic,
                PD_Player_Roles.Scientist
            };
            List <PD_Game> games = new List <PD_Game>();

            for (int i = 0; i < numberOfGames; i++)
            {
                games.Add(
                    PD_Game.Create_Game__AvailableRolesList(
                        randomness_provider,
                        numberOfPlayers,
                        gameDifficulty,
                        roles_list
                        )
                    );
            }
            return(games);
        }
コード例 #2
0
        public void RandomSeed_Tests()
        {
            List <int> available_roles = new List <int>()
            {
                PD_Player_Roles.Operations_Expert,
                PD_Player_Roles.Researcher,
                PD_Player_Roles.Medic,
                PD_Player_Roles.Scientist
            };

            Random randomness_provider = new Random(1000);

            PD_Game game_1 = PD_Game.Create_Game__AvailableRolesList(
                randomness_provider,
                4,
                0,
                available_roles
                );

            randomness_provider = new Random(1000);

            PD_Game game_2 = PD_Game.Create_Game__AvailableRolesList(
                randomness_provider,
                4,
                0,
                available_roles
                );

            randomness_provider = new Random(1000);
            while (game_1.GQ_Is_Ongoing())
            {
                game_1.Apply_Action(
                    randomness_provider,
                    game_1.CurrentAvailablePlayerActions.GetOneRandom(randomness_provider)
                    );
            }

            randomness_provider = new Random(1000);
            while (game_2.GQ_Is_Ongoing())
            {
                game_2.Apply_Action(
                    randomness_provider,
                    game_2.CurrentAvailablePlayerActions.GetOneRandom(randomness_provider)
                    );
            }

            game_2.unique_id = game_1.unique_id;
            game_2.OverrideStartTime(game_1.start_time);
            game_2.OverrideEndTime(game_1.end_time);

            Assert.IsTrue(game_1.Equals(game_2));
            Assert.IsTrue(game_1 == game_2);
            Assert.IsTrue(game_1.GetHashCode() == game_2.GetHashCode());
        }
        public void Calculate_NumCardsTable_Test()
        {
            Random randomness_provider = new Random();

            List <int> roles_list = new List <int>()
            {
                PD_Player_Roles.Operations_Expert,
                PD_Player_Roles.Researcher,
                PD_Player_Roles.Medic,
                PD_Player_Roles.Scientist
            };

            PD_Game game = PD_Game.Create_Game__AvailableRolesList(
                randomness_provider,
                4,
                0,
                roles_list
                );

            PD_AI_PathFinder pathFinder = new PD_AI_PathFinder();

            int[,] numCardsTable = PD_AI_CardEvaluation_Utilities.NumCardsTable(game);
            int numTypes   = numCardsTable.Height();
            int numPlayers = numCardsTable.Width();

            for (int playerIndex = 0; playerIndex < numPlayers; playerIndex++)
            {
                for (int type = 0; type < numTypes; type++)
                {
                    int numCards = numCardsTable[type, playerIndex];

                    int        player                = game.players[playerIndex];
                    List <int> playerCards           = game.GQ_CityCardsInPlayerHand(player);
                    List <int> playerCardsOfThisType = playerCards.FindAll(
                        x =>
                        game.map.infection_type__per__city[x] == type
                        );

                    Assert.IsTrue(
                        playerCardsOfThisType.Count == numCards
                        );
                }
            }
        }
コード例 #4
0
        public void Generate_Game_Without_Data()
        {
            Random     randomness_provider = new Random(1000);
            List <int> available_roles     = new List <int>()
            {
                PD_Player_Roles.Operations_Expert,
                PD_Player_Roles.Researcher,
                PD_Player_Roles.Medic,
                PD_Player_Roles.Scientist
            };

            // generate 100 games for every possible settings selection
            for (int num_players = 2; num_players <= 4; num_players++)
            {
                for (int game_difficulty = 0; game_difficulty <= 2; game_difficulty++)
                {
                    // repeat the process 100 times!
                    for (int i = 0; i < 1000; i++)
                    {
                        PD_Game game = PD_Game.Create_Game__AvailableRolesList(
                            randomness_provider,
                            num_players,
                            game_difficulty,
                            available_roles
                            );

                        while (game.GQ_Is_Ongoing())
                        {
                            var random_action = game
                                                .CurrentAvailablePlayerActions
                                                .GetOneRandom(randomness_provider);

                            game.Apply_Action(
                                randomness_provider,
                                random_action
                                );
                        }

                        Assert.IsTrue(game.GQ_Is_Ongoing() == false);
                    }
                }
            }
        }
コード例 #5
0
        public static PD_Game Generate_Random_Game(
            Random randomness_provider,
            int numberOfPlayers,
            int gameDifficulty
            )
        {
            List <int> roles_list = new List <int>()
            {
                PD_Player_Roles.Operations_Expert,
                PD_Player_Roles.Researcher,
                PD_Player_Roles.Medic,
                PD_Player_Roles.Scientist
            };

            return(PD_Game.Create_Game__AvailableRolesList(
                       randomness_provider,
                       numberOfPlayers,
                       gameDifficulty,
                       roles_list
                       ));
        }
コード例 #6
0
        public void GetCustomDeepCopy_Test()
        {
            Random randomness_provider = new Random();

            List <int> available_roles = new List <int>()
            {
                PD_Player_Roles.Operations_Expert,
                PD_Player_Roles.Researcher,
                PD_Player_Roles.Medic,
                PD_Player_Roles.Scientist
            };

            PD_Game game = PD_Game.Create_Game__AvailableRolesList(
                randomness_provider,
                4,
                0,
                available_roles
                );
            PD_Game gameCopy = game.GetCustomDeepCopy();

            Assert.IsTrue(gameCopy.Equals(game));
        }
コード例 #7
0
        static void Main(string[] args)
        {
            DateTime   dateTimeOfExperiment = DateTime.UtcNow;
            int        number_of_games      = 1000;
            List <int> roles_list           = new List <int>()
            {
                PD_Player_Roles.Operations_Expert,
                PD_Player_Roles.Researcher,
                PD_Player_Roles.Medic,
                PD_Player_Roles.Scientist
            };

            Random randomness_provider = new Random(1001);

            var watch = System.Diagnostics.Stopwatch.StartNew();

            string report_file_name = "report_" + dateTimeOfExperiment.Ticks.ToString() + ".txt";
            string report_file_path = Path.Combine(
                Directory.GetCurrentDirectory(),
                report_file_name
                );

            PD_IO_Utilities.CreateFile(report_file_path, false, true);

            string report_part = "Date / time: " + dateTimeOfExperiment.ToString();

            Console.WriteLine(report_part);
            PD_IO_Utilities.AppendToFile(report_file_path, report_part + "\n");

            //////////////////////////////////////////////////////////////////////////////
            /// 1.1 Generate the games, from data
            //////////////////////////////////////////////////////////////////////////////
            watch.Restart();
            List <PD_Game> games = new List <PD_Game>();

            for (int i = 0; i < number_of_games; i++)
            {
                games.Add(
                    PD_Game.Create_Game__AvailableRolesList(
                        randomness_provider,
                        4,
                        0,
                        roles_list
                        )
                    );
            }
            watch.Stop();
            long time_to_generate_games = watch.ElapsedMilliseconds;

            report_part = String.Format(
                "Generate {0} games from data and perform game setup: {1}",
                number_of_games,
                time_to_generate_games
                );
            Console.WriteLine(report_part);
            PD_IO_Utilities.AppendToFile(report_file_path, report_part + "\n");

            //////////////////////////////////////////////////////////////////////////////
            /// 1.3 Run all games until the end, by selecting random actions
            //////////////////////////////////////////////////////////////////////////////
            watch.Restart();
            foreach (var game in games)
            {
                while (PD_Game_Queries.GQ_Is_Ongoing(game))
                {
                    game.Apply_Action(
                        randomness_provider,
                        game.CurrentAvailablePlayerActions.GetOneRandom(randomness_provider)
                        );
                }
            }
            watch.Stop();
            long time_to_play_until_the_end_using_random_actions = watch.ElapsedMilliseconds;

            report_part = String.Format(
                "Play {0} games until the end, using random actions: {1}",
                number_of_games,
                time_to_play_until_the_end_using_random_actions
                );
            Console.WriteLine(report_part);
            PD_IO_Utilities.AppendToFile(report_file_path, report_part + "\n");

            //////////////////////////////////////////////////////////////////////////////
            /// 1.4 Make temporary copies of all games...
            //////////////////////////////////////////////////////////////////////////////
            watch.Restart();
            List <PD_Game> game_copies = new List <PD_Game>();

            foreach (var game in games)
            {
                PD_Game game_copy = game.GetCustomDeepCopy();
                game_copies.Add(game_copy);
            }
            watch.Stop();
            long time_to_copy_all_finished_games = watch.ElapsedMilliseconds;

            report_part = String.Format(
                "Copy {0} finished games: {1}",
                number_of_games,
                time_to_copy_all_finished_games
                );
            Console.WriteLine(report_part);
            PD_IO_Utilities.AppendToFile(report_file_path, report_part + "\n");

            // clear the games' list..
            games.Clear();
            game_copies.Clear();

            //////////////////////////////////////////////////////////////////////////////
            /// 2.1 Generate games and automatically perform setup...
            //////////////////////////////////////////////////////////////////////////////
            watch.Restart();
            for (int i = 0; i < number_of_games; i++)
            {
                games.Add(
                    PD_Game.Create_Game__AvailableRolesList(
                        randomness_provider,
                        4,
                        0,
                        roles_list
                        )
                    );
            }
            watch.Stop();
            long time_to_generate_and_setup_games = watch.ElapsedMilliseconds;

            report_part = String.Format(
                "Generate {0} games from data and perform set up: {1}",
                number_of_games,
                time_to_generate_and_setup_games
                );
            Console.WriteLine(report_part);
            PD_IO_Utilities.AppendToFile(report_file_path, report_part + "\n");

            //////////////////////////////////////////////////////////////////////////////
            /// 2.2. Run all games until the end, by selecting random macro actions
            //////////////////////////////////////////////////////////////////////////////
            PD_AI_PathFinder pf = new PD_AI_PathFinder();

            watch.Restart();
            foreach (var game in games)
            {
                while (PD_Game_Queries.GQ_Is_Ongoing(game))
                {
                    var available_macros = game.GetAvailableMacros(pf);
                    game.Apply_Macro_Action(
                        randomness_provider,
                        available_macros.GetOneRandom(randomness_provider)
                        );
                }
            }
            watch.Stop();
            long time_to_play_until_the_end_using_random_macro_actions = watch.ElapsedMilliseconds;

            report_part = String.Format(
                "Play {0} games until the end, using random macro actions: {1}",
                number_of_games,
                time_to_play_until_the_end_using_random_macro_actions
                );
            Console.WriteLine(report_part);
            PD_IO_Utilities.AppendToFile(report_file_path, report_part + "\n");

            //////////////////////////////////////////////////////////////////////////////
            /// 1.4 Make temporary copies of all games...
            //////////////////////////////////////////////////////////////////////////////
            watch.Restart();
            foreach (var game in games)
            {
                PD_Game game_copy = game.GetCustomDeepCopy();
                game_copies.Add(game_copy);
            }
            watch.Stop();
            long time_to_copy_all_macro_finished_games = watch.ElapsedMilliseconds;

            report_part = String.Format(
                "Copy {0} finished games: {1}",
                number_of_games,
                time_to_copy_all_macro_finished_games
                );
            Console.WriteLine(report_part);
            PD_IO_Utilities.AppendToFile(report_file_path, report_part + "\n");


            // clear the games' list..
            games.Clear();
            game_copies.Clear();

            //////////////////////////////////////////////////////////////////////////////
            /// 3.1 Generate games and automatically perform setup...
            //////////////////////////////////////////////////////////////////////////////
            watch.Restart();
            for (int i = 0; i < number_of_games; i++)
            {
                games.Add(
                    PD_Game.Create_Game__AvailableRolesList(
                        randomness_provider,
                        4,
                        0,
                        roles_list
                        )
                    );
            }
            watch.Stop();
            time_to_generate_and_setup_games = watch.ElapsedMilliseconds;
            report_part = String.Format(
                "Generate {0} games from data and perform set up: {1}",
                number_of_games,
                time_to_generate_and_setup_games
                );
            Console.WriteLine(report_part);
            PD_IO_Utilities.AppendToFile(report_file_path, report_part + "\n");

            //////////////////////////////////////////////////////////////////////////////
            /// 3.2. Run all games until the end, by selecting random macro actions
            //////////////////////////////////////////////////////////////////////////////
            //PD_AI_PathFinder pf = new PD_AI_PathFinder();
            PD_AI_MacroAgent_HierarchicalPolicy agent = new PD_AI_MacroAgent_HierarchicalPolicy(
                new List <PD_AI_MacroAgent_MainPolicy_Base>()
            {
                new PD_AI_MacroAgent_Policy_Cure_ASAP(),
                new PD_AI_MacroAgent_Policy_Treat_MinSameCubes_Now_Smart(3),
                new PD_AI_MacroAgent_Policy_ShareKnowledge_1_Variation_A(),
                new PD_AI_MacroAgent_Policy_BuildRS_MaxTotal_MinDistance(6, 3),
                new PD_AI_MacroAgent_Policy_Treat_MinSameCubes_Now_Smart(2),
                new PD_AI_MacroAgent_Policy_Treat_MinSameCubes_Now_Smart(1),
                new PD_AI_MacroAgent_Policy_WalkAway()
            },
                new List <PD_AI_MacroAgent_DiscardPolicy_Base>()
            {
                new PD_AI_MacroAgent_Policy_CardDiscard_Smart()
            }
                );

            watch.Restart();
            foreach (var game in games)
            {
                while (PD_Game_Queries.GQ_Is_Ongoing(game))
                {
                    var macro = agent.GetNextMacroAction(randomness_provider, game, pf);
                    game.Apply_Macro_Action(
                        randomness_provider,
                        macro
                        );
                }
            }
            watch.Stop();
            long time_played = watch.ElapsedMilliseconds;

            report_part = String.Format(
                "Play {0} games until the end, using HPA: {1}",
                number_of_games,
                time_played
                );
            Console.WriteLine(report_part);
            PD_IO_Utilities.AppendToFile(report_file_path, report_part + "\n");
        }
コード例 #8
0
        public void Serialize_Deserialize_MiniGame()
        {
            Random     randomness_provider = new Random();
            List <int> roles_list          = new List <int>()
            {
                PD_Player_Roles.Operations_Expert,
                PD_Player_Roles.Researcher,
                PD_Player_Roles.Medic,
                PD_Player_Roles.Scientist
            };

            for (int i = 0; i < 2000; i++)
            {
                // create a normal game, for later use
                PD_Game initial_game = PD_Game.Create_Game__AvailableRolesList(
                    randomness_provider,
                    4,
                    0,
                    roles_list
                    );

                // convert to mini game
                PD_MiniGame converted_mini_game = initial_game.Convert_To_MiniGame();

                // serialize the mini game
                string serialized_mini_game = converted_mini_game.To_Json_String(
                    Formatting.None,
                    TypeNameHandling.None,
                    PreserveReferencesHandling.None
                    );

                // deserialize the mini game
                PD_MiniGame deserialized_mini_game
                    = JsonConvert.DeserializeObject <PD_MiniGame>(serialized_mini_game);

                // test that the deserialized game is exactly the same as the mini game
                Assert.IsTrue(converted_mini_game.GetHashCode() == deserialized_mini_game.GetHashCode());
                Assert.IsTrue(converted_mini_game == deserialized_mini_game);
                Assert.IsTrue(converted_mini_game.Equals(deserialized_mini_game));

                // create a normal game, from the deserialized game
                PD_Game final_game = deserialized_mini_game.Convert_To_Game();

                Assert.IsTrue(
                    Games_Practically_Equal(
                        initial_game,
                        final_game
                        )
                    );

                final_game.UpdateAvailablePlayerActions();

                randomness_provider = new Random(i);
                while (final_game.GQ_Is_Ongoing())
                {
                    PD_Action action =
                        final_game
                        .CurrentAvailablePlayerActions
                        .GetOneRandom(randomness_provider);
                    final_game.Apply_Action(
                        randomness_provider,
                        action
                        );
                }
                randomness_provider = new Random(i);
                while (initial_game.GQ_Is_Ongoing())
                {
                    var action = initial_game.CurrentAvailablePlayerActions.GetOneRandom(randomness_provider);
                    initial_game.Apply_Action(
                        randomness_provider,
                        action);
                }

                Assert.IsTrue(Games_Practically_Equal(initial_game, final_game));
            }
        }