Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
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);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Deserialize_ExistingGame_NewRepresentation_Test()
        {
            Random randomness_provider = new Random(1001);

            string saved_games_path = System.IO.Path.Combine(
                System.IO.Directory.GetCurrentDirectory(),
                "ParameterTuning_TestBed_NewRepresentation"
                );
            var game_file_paths = PD_IO_Utilities.GetFilePathsInFolder(saved_games_path);

            // play the games until the end, using single actions
            foreach (var game_file_path in game_file_paths)
            {
                string serialized_mini_game = PD_IO_Utilities.ReadFile(game_file_path);

                PD_MiniGame deserialized_mini_game =
                    JsonConvert.DeserializeObject <PD_MiniGame>(serialized_mini_game);

                PD_Game game = deserialized_mini_game.Convert_To_Game();

                // play the game until the end...
                while (game.GQ_Is_Ongoing())
                {
                    var available_actions = game.CurrentAvailablePlayerActions;
                    var random_action     = available_actions.GetOneRandom(randomness_provider);
                    game.Apply_Action(
                        randomness_provider,
                        random_action
                        );
                }

                Assert.IsTrue(game.GQ_Is_Ongoing() == false);
            }

            // play the games until the end, using single actions
            foreach (var game_file_path in game_file_paths)
            {
                PD_Game game = PD_IO_Utilities.DeserializeGame_From_MiniGameJsonFile(game_file_path);

                // play the game until the end...
                while (game.GQ_Is_Ongoing())
                {
                    var available_actions = game.CurrentAvailablePlayerActions;
                    var random_action     = available_actions.GetOneRandom(randomness_provider);
                    game.Apply_Action(
                        randomness_provider,
                        random_action
                        );
                }

                Assert.IsTrue(game.GQ_Is_Ongoing() == false);
            }

            // play the games until the end, using macro actions
            PD_AI_PathFinder pathFinder = new PD_AI_PathFinder();

            foreach (var game_file_path in game_file_paths)
            {
                string serialized_mini_game = PD_IO_Utilities.ReadFile(game_file_path);

                PD_MiniGame deserialized_mini_game =
                    JsonConvert.DeserializeObject <PD_MiniGame>(serialized_mini_game);

                PD_Game game = deserialized_mini_game.Convert_To_Game();

                // play the game until the end...
                while (game.GQ_Is_Ongoing())
                {
                    var available_macro_actions = game.GetAvailableMacros(pathFinder);
                    var random_macro_action     = available_macro_actions.GetOneRandom(randomness_provider);
                    game.Apply_Macro_Action(
                        randomness_provider,
                        random_macro_action
                        );
                }

                Assert.IsTrue(game.GQ_Is_Ongoing() == false);
            }

            // play the games until the end, using macro actions
            foreach (var game_file_path in game_file_paths)
            {
                PD_Game game = PD_IO_Utilities.DeserializeGame_From_MiniGameJsonFile(game_file_path);

                // play the game until the end...
                while (game.GQ_Is_Ongoing())
                {
                    var available_macro_actions = game.GetAvailableMacros(pathFinder);
                    var random_macro_action     = available_macro_actions.GetOneRandom(randomness_provider);
                    game.Apply_Macro_Action(
                        randomness_provider,
                        random_macro_action
                        );
                }

                Assert.IsTrue(game.GQ_Is_Ongoing() == false);
            }
        }
Ejemplo n.º 4
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));
            }
        }