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); }
/// <summary> /// This is the method that defines the agent's operation. /// </summary> /// <param name="game"></param> /// <returns></returns> public override PD_Action GetNextAction( Random randomness_provider, PD_Game game ) { var availableActions = game.CurrentAvailablePlayerActions; return(availableActions.GetOneRandom(randomness_provider)); }
protected override PD_MacroAction MainPlayerActions_Behaviour( Random randommness_provider, PD_Game game, PD_AI_PathFinder pathFinder ) { var allMacros = game.CurrentAvailableMacros; return(allMacros.GetOneRandom(randommness_provider)); }
protected override PD_MacroAction Discarding_AfterDrawing_Behaviour( Random randomness_provider, PD_Game game, PD_AI_PathFinder pathFinder ) { var allMacros = game.CurrentAvailableMacros; return(allMacros.GetOneRandom(randomness_provider)); }
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 override double EvaluateGameState(PD_Game game) { double score = _score_calculator.CalculateScore(game); if (game.GQ_Is_Won()) { return(1); } else if (game.GQ_Is_Ongoing()) { return(score); } else { return(0); } }
private bool Games_Practically_Equal(PD_Game game_1, PD_Game game_2) { if (game_1.unique_id != game_2.unique_id) { return(false); } else if (game_1.game_settings.Equals(game_2.game_settings) == false) { return(false); } else if (game_1.game_FSM.Equals(game_2.game_FSM) == false) { return(false); } else if (game_1.game_state_counter.Equals(game_2.game_state_counter) == false) { return(false); } else if (game_1.players.List_Equals(game_2.players) == false) { return(false); } else if (game_1.map.Equals(game_2.map) == false) { return(false); } else if (PracticalGameComparison_Cards(game_1, game_2) == false) { return(false); } else if (PracticalGameComparison_MapElements(game_1, game_2) == false) { return(false); } else if ( game_1.CurrentAvailablePlayerActions.List_Equals( game_2.CurrentAvailablePlayerActions ) == false ) { return(false); } return(true); }
public bool PracticalGameComparison_MapElements(PD_Game game_1, PD_Game game_2) { // inactive player pawns for (int t = 0; t < 4; t++) { if ( game_1.map_elements.available_infection_cubes__per__type[t] != game_2.map_elements.available_infection_cubes__per__type[t] ) { return(false); } } foreach (int city in game_1.map.cities) { for (int t = 0; t < 4; t++) { if ( game_1.GQ_Num_InfectionCubes_OfType_OnCity(city, t) != game_2.GQ_Num_InfectionCubes_OfType_OnCity(city, t) ) { return(false); } } } if (game_1.map_elements.available_research_stations != game_2.map_elements.available_research_stations) { return(false); } else if (game_1.map_elements.research_stations__per__city.Dictionary_Equals( game_2.map_elements.research_stations__per__city) == false) { return(false); } else { return(true); } }
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 ); } } }
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); } } } }
public bool PracticalGameComparison_Cards(PD_Game game_1, PD_Game game_2) { if (game_1.cards.divided_deck_of_infection_cards.List_Equals( game_2.cards.divided_deck_of_infection_cards) == false) { return(false); } else if (game_1.cards.active_infection_cards.List_Equals( game_2.cards.active_infection_cards) == false) { return(false); } else if (game_1.cards.deck_of_discarded_infection_cards.List_Equals( game_2.cards.deck_of_discarded_infection_cards) == false) { return(false); } else if (game_1.cards.divided_deck_of_player_cards.List_Equals( game_2.cards.divided_deck_of_player_cards) == false) { return(false); } else if (game_1.cards.deck_of_discarded_player_cards.List_Equals( game_2.cards.deck_of_discarded_player_cards) == false) { return(false); } else if (game_1.cards.deck_of_discarded_player_cards.List_Equals( game_2.cards.deck_of_discarded_player_cards) == false) { return(false); } else if (game_1.cards.player_hand__per__player.Dictionary_Equals( game_2.cards.player_hand__per__player) == false) { return(false); } else { return(true); } }
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 )); }
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)); }
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"); }
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); } }
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)); } }