public PD_GR_P_GameStateEvaluationMetrics( PD_Game game, PD_AI_PathFinder pathFinder ) { Update(game, pathFinder); }
protected override PD_MacroAction Discarding_DuringMainPlayerActions_Behaviour( Random randomness_provider, PD_Game game, PD_AI_PathFinder pathFinder ) { var allMacros = game.GetAvailableMacros(pathFinder); if (allMacros == null || allMacros.Count == 0) { return(null); } // DISCARD POLICY var soup_discard_macros = new List <PD_MacroAction>(); foreach (var policy in Available_DiscardPolicies) { soup_discard_macros.AddRange(policy.FilterMacros(game, pathFinder, allMacros)); } if (soup_discard_macros.Count > 0) { return(soup_discard_macros.GetOneRandom(randomness_provider)); } return(allMacros.GetOneRandom(randomness_provider)); }
protected override PD_MacroAction Discarding_DuringMainPlayerActions_Behaviour( Random randomness_provider, PD_Game game, PD_AI_PathFinder pathFinder ) { var allMacros = game.GetAvailableMacros(pathFinder); if (allMacros == null || allMacros.Count == 0) { return(null); } // DISCARD POLICY Available_DiscardPolicies.Shuffle(randomness_provider); foreach (var policy in Available_DiscardPolicies) { var macros = policy.FilterMacros(game, pathFinder, allMacros); if (macros.Count > 0) { return(macros.GetOneRandom(randomness_provider)); } } return(allMacros.GetOneRandom(randomness_provider)); }
public PD_GR_P_ActionStats( PD_Game game, PD_AI_PathFinder pathFinder ) { Update(game, pathFinder); }
public override void Update( PD_Game game, PD_AI_PathFinder pathFinder ) { PercentCuredDiseases = PD_AI_GameStateEvaluation_HelpMethods.Calculate_Percent_CuredDiseases(game); PercentAbilityToCureDiseases = PD_AI_GameStateEvaluation_HelpMethods.Calculate_Percent_AbilityToCureDiseases(game, false); PercentAbilityToCureDiseases_Squared = PD_AI_GameStateEvaluation_HelpMethods.Calculate_Percent_AbilityToCureDiseases(game, true); PercentCuredDiseases_Gradient = PD_AI_GameStateEvaluation_HelpMethods.Calculate_Percent_CuredDiseases_Gradient(game, false); PercentCuredDiseases_Gradient_Squared = PD_AI_GameStateEvaluation_HelpMethods.Calculate_Percent_CuredDiseases_Gradient(game, true); MinimumPercentAvailableDiseaseCubes = PD_AI_GameStateEvaluation_HelpMethods.Calculate_Minimum_PercentAvailableDiseaseCubes_Min_1(game); MultipliedPercentAvailableDiseaseCubes = PD_AI_GameStateEvaluation_HelpMethods.Calculate_Multiplied_Percent_AvailableDiseaseCubes_Min_1(game); AveragePercentAvailableDiseaseCubes = PD_AI_GameStateEvaluation_HelpMethods.Calculate_Average_Percent_AvailableDiseaseCubes_Min_1(game); PercentRemainingOutbreaks = PD_AI_GameStateEvaluation_HelpMethods.Calculate_PercentRemainingOutbreaks_Min_1(game); PercentRemainingPlayerCards = PD_AI_GameStateEvaluation_HelpMethods.Calculate_PercentRemainingPlayerCards(game); }
public PD_GR_P_GameCondition( PD_Game game, PD_AI_PathFinder pathFinder ) { Update(game, pathFinder); }
public string Get_Record_Row( PD_Game game, PD_AI_PathFinder pathFinder, PD_AI_Agent_Base agent, int repetitionIndex ) { string record_Row; List <PD_Report_Part> report_Parts = new List <PD_Report_Part>(); // game state report is included in all cases... GameState_Report.Update(game, pathFinder, repetitionIndex); report_Parts.Add(GameState_Report); // include game stats report? if (Keep_GameStats_Report == true) { GameStats_Report.Update(game, pathFinder); report_Parts.Add(GameStats_Report); } record_Row = PD_Report_Part.Get_Joined_CSV_Row(report_Parts); return(record_Row); }
public override void Update( PD_Game game, PD_AI_PathFinder pathFinder ) { NumPlayers = game.game_state_counter.number_of_players; GameDifficulty = game.game_settings.game_difficulty_level; Player1_Role = game.role__per__player[game.players[0]].ToString(); Player2_Role = game.role__per__player[game.players[1]].ToString(); if (game.players.Count >= 3) { Player3_Role = game.role__per__player[game.players[2]].ToString(); } else { Player3_Role = ""; } if (game.players.Count >= 4) { Player4_Role = game.role__per__player[game.players[3]].ToString(); } else { Player4_Role = ""; } }
public void Expand( Random randomness_provider, PD_Game gameState, PD_AI_PathFinder pathFinder, PD_AI_Macro_Agent_Base defaultPolicyAgent ) { PD_Game generator_GameState = gameState.Request_Randomized_Copy(randomness_provider); int initialTurn = generator_GameState.game_state_counter.turn_index; int finalTurn = initialTurn + MaxGenomeLength - Genome.Count; int currentTurn = initialTurn; // prepare the dictionary of macros! Dictionary <int, List <PD_MacroAction> > macroActionsPerTurn = new Dictionary <int, List <PD_MacroAction> >(); for (int i = initialTurn; i < finalTurn; i++) { macroActionsPerTurn.Add( i, new List <PD_MacroAction>() ); } // create the new macros and put them in the dictionary while ( generator_GameState.GQ_Is_Ongoing() && currentTurn < finalTurn ) { var nextMacro = defaultPolicyAgent.GetNextMacroAction( randomness_provider, generator_GameState, pathFinder ); macroActionsPerTurn[currentTurn].Add(nextMacro); generator_GameState.Apply_Macro_Action( randomness_provider, nextMacro ); currentTurn = generator_GameState.game_state_counter.turn_index; } // expand the genome for (int i = initialTurn; i < finalTurn; i++) { if (macroActionsPerTurn[i].Count > 0) { RH_Gene gene = new RH_Gene( i, macroActionsPerTurn[i] ); Genome.Add(gene); } } }
protected override PD_MacroAction Discarding_AfterDrawing_Behaviour( Random randomness_provider, PD_Game game, PD_AI_PathFinder pathFinder ) { var allMacros = game.GetAvailableMacros(pathFinder); if (allMacros == null || allMacros.Count == 0) { return(null); } foreach (var discardPolicy in Discard_Policies) { var macros = discardPolicy.FilterMacros( game, pathFinder, allMacros ); if (macros.Count > 0) { return(macros.GetOneRandom(randomness_provider)); } } return(allMacros.GetOneRandom(randomness_provider)); }
public PD_MacroAction GetNextMacroAction( Random randomness_provider, PD_Game game, PD_AI_PathFinder pathFinder ) { if (game.GQ_IsInState_ApplyingMainPlayerActions()) { return(MainPlayerActions_Behaviour(randomness_provider, game, pathFinder)); } else if (game.GQ_IsInState_DiscardDuringMainPlayerActions()) { return(Discarding_DuringMainPlayerActions_Behaviour(randomness_provider, game, pathFinder)); } else if (game.GQ_IsInState_DiscardAfterDrawing()) { return(Discarding_AfterDrawing_Behaviour(randomness_provider, game, pathFinder)); } else { throw new System.Exception( "A macro action was requested in an invalid game state" ); } }
public PD_GR_P_GameSettings( PD_Game game, PD_AI_PathFinder pathFinder ) { Update(game, pathFinder); }
public override void Update( PD_Game game, PD_AI_PathFinder pathFinder ) { Num_RemainingPlayerCards = game .cards .divided_deck_of_player_cards .GetNumberOfElementsOfAllSubLists(); Num_Outbreaks = game.game_state_counter.outbreaks_counter; Num_Epidemics = game.game_state_counter.epidemics_counter; Num_CuredDiseases = 0; Num_EradicatedDiseases = 0; for (int i = 0; i < 4; i++) { if (game.game_state_counter.disease_states[i] == 1) { Num_CuredDiseases++; } if (game.game_state_counter.disease_states[i] == 2) { Num_CuredDiseases++; Num_EradicatedDiseases++; } } }
public static List <PD_MacroAction> ShareKnowledge_Positive_Now( PD_Game game, PD_AI_PathFinder pathFinder, List <PD_MacroAction> allMacros ) { #if DEBUG if (game.GQ_IsInState_ApplyingMainPlayerActions() == false) { throw new System.Exception("wrong state."); } #endif var shareKnowledgeMacros_ExecutableNow = allMacros.FindAll( x => x.Is_TypeOf_ShareKnowledge_Any() && x.Is_ExecutableNow() == true ); if (shareKnowledgeMacros_ExecutableNow.Count > 0) { List <PD_MacroAction> positiveShareKnowledgeMacros = new List <PD_MacroAction>(); foreach (var macro in shareKnowledgeMacros_ExecutableNow) { List <PD_Action> walkSequence = macro.Actions_All.CustomDeepCopy(); walkSequence.RemoveAt(walkSequence.Count - 1); double walkSequenceValue = PD_AI_CardEvaluation_Utilities .Calculate_ListOfPlayerActions_Effect_On_Percent_AbilityToCureDiseases( game, walkSequence, true ); if (walkSequenceValue < 0) { continue; } PD_Action lastCommand = macro.Find_LastCommand(); double exchangeValue = PD_AI_CardEvaluation_Utilities .Calculate_PlayerAction_Effect_On_Percent_AbilityToCureDiseases( game, lastCommand, true ); if (exchangeValue > 0.0) { positiveShareKnowledgeMacros.Add(macro); } } if (positiveShareKnowledgeMacros.Count > 0) { return(positiveShareKnowledgeMacros); } } return(new List <PD_MacroAction>()); }
protected override PD_MacroAction Discarding_AfterDrawing_Behaviour( Random randomness_provider, PD_Game game, PD_AI_PathFinder pathFinder ) { return(GeneralAgentBehaviour(randomness_provider, game, pathFinder)); }
protected override PD_MacroAction MainPlayerActions_Behaviour( Random randomness_provider, PD_Game game, PD_AI_PathFinder pathFinder ) { return(GeneralAgentBehaviour(randomness_provider, game, pathFinder)); }
public static List <PD_MacroAction> TakePosition_Positive_NextRound( PD_Game game, PD_AI_PathFinder pathFinder, List <PD_MacroAction> allMacros ) { int numberOfStepsUntilEndOfNextRound = 4 + game.GQ_RemainingPlayerActions_ThisRound(); var takePosition_NextRound = allMacros.FindAll( x => x.Is_TypeOf_TakePositionFor_ShareKnowledge_Any() && x.Is_ExecutableNow() == false && x.Count_Total_Length() <= numberOfStepsUntilEndOfNextRound ); if (takePosition_NextRound.Count > 0) { List <PD_MacroAction> takePosition_Positive_NextRound = new List <PD_MacroAction>(); // find all take position macros that would have a positive outcome (ability to cure) foreach (var macro in takePosition_NextRound) { List <PD_Action> walkSequence = macro.Actions_All; double walkSequenceValue = PD_AI_CardEvaluation_Utilities .Calculate_ListOfPlayerActions_Effect_On_Percent_AbilityToCureDiseases( game, walkSequence, true ); if (walkSequenceValue < 0) { continue; } var lastCommand = macro.NonExecutable_ShareKnowledge_Action; double exchangeValue = PD_AI_CardEvaluation_Utilities .Calculate_PlayerAction_Effect_On_Percent_AbilityToCureDiseases( game, lastCommand, true ); if (exchangeValue > 0.0) { takePosition_Positive_NextRound.Add(macro); } } if (takePosition_Positive_NextRound.Count > 0) { return(takePosition_Positive_NextRound); } } return(new List <PD_MacroAction>()); }
public override void Update(PD_Game game, PD_AI_PathFinder pathFinder) { GameSettings.Update(game, pathFinder); GameCondition.Update(game, pathFinder); GameScores.Update(game, pathFinder); ActionStats.Update(game, pathFinder); GameStateEvaluationMetrics.Update(game, pathFinder); MapStats.Update(game, pathFinder); }
public override List <PD_MacroAction> FilterMacros( PD_Game game, PD_AI_PathFinder pathFinder, List <PD_MacroAction> allMacros) { return(allMacros.FindAll( x => x.Is_TypeOf_Cure_Any() )); }
public override List <PD_MacroAction> FilterMacros( PD_Game game, PD_AI_PathFinder pathFinder, List <PD_MacroAction> allMacros) { return(allMacros.FindAll( x => x.Is_TypeOf_BuildResearchStation_Any_Or_MoveResearchStation() )); }
public void EvaluateSelf( Random randomness_provider, PD_Game initial_GameState, PD_AI_PathFinder pathFinder, PD_AI_Macro_Agent_Base defaultPolicyAgent, List <PD_GameStateEvaluator> gameStateEvaluators ) { EvaluationScores = new List <double>(); List <double> evaluationScoreSums = new List <double>(); foreach (var evaluator in gameStateEvaluators) { EvaluationScores.Add(0.0); evaluationScoreSums.Add(0.0f); } for (int i = 0; i < NumSimulationsForEvaluation; i++) { PD_Game evaluation_GameState = initial_GameState.Request_Randomized_Copy(randomness_provider); foreach (var gene in Genome) { if (evaluation_GameState.GQ_Is_Ongoing()) { gene.ApplySelfOnGameState( randomness_provider, evaluation_GameState, pathFinder, defaultPolicyAgent ); } } if (evaluation_GameState.GQ_Is_Ongoing() && IsComplete() == false) { Expand( randomness_provider, evaluation_GameState, pathFinder, defaultPolicyAgent ); } for (int j = 0; j < gameStateEvaluators.Count; j++) { evaluationScoreSums[j] += gameStateEvaluators[j].EvaluateGameState(evaluation_GameState); } } for (int j = 0; j < gameStateEvaluators.Count; j++) { EvaluationScores[j] = evaluationScoreSums[j] / (double)NumSimulationsForEvaluation; } }
public override List<PD_MacroAction> FilterMacros( PD_Game game, PD_AI_PathFinder pathFinder, List<PD_MacroAction> allMacros) { return allMacros.FindAll( x => x.Is_TypeOf_TreatDisease_Any() && x.Is_ExecutableNow() ); }
public override void Update(PD_Game game, PD_AI_PathFinder pathFinder) { GameID = game.unique_id; CurrentTurn = game.game_state_counter.turn_index; CurrentPlayerAction = game.game_state_counter.player_action_index; CurrentGameStep = CurrentTurn * 4 + CurrentPlayerAction; CurrentGameState = game.game_FSM.CurrentState.GetType().Name.ToString(); long gameDurationTicks = DateTime.UtcNow.Ticks - game.start_time.Ticks; GameDurMillis = (float)gameDurationTicks / 10000.0f; }
public override List <PD_MacroAction> FilterMacros(PD_Game game, PD_AI_PathFinder pathFinder, List <PD_MacroAction> allMacros) { #if DEBUG if (game.GQ_IsInState_ApplyingMainPlayerActions() == false) { throw new System.Exception("wrong state."); } #endif var treatDiseaseMacros = allMacros.FindAll( x => x.Is_TypeOf_TreatDisease_Any() ); if (treatDiseaseMacros.Count == 0) { return(new List <PD_MacroAction>()); } // TREAT 3 var treat_3 = Treat_3.FilterMacros( game, pathFinder, allMacros ); if (treat_3.Count > 0) { return(treat_3); } // TREAT 2 var treat_2 = Treat_2.FilterMacros( game, pathFinder, allMacros ); if (treat_2.Count > 0) { return(treat_2); } // TREAT 1 var treat_1 = Treat_1.FilterMacros( game, pathFinder, allMacros ); if (treat_1.Count > 0) { return(treat_1); } return(new List <PD_MacroAction>()); }
public override List <PD_MacroAction> FilterMacros( PD_Game game, PD_AI_PathFinder pathFinder, List <PD_MacroAction> allMacros ) { #if DEBUG if (game.GQ_IsInState_ApplyingMainPlayerActions() == false) { throw new System.Exception("wrong state."); } #endif // share positive now List <PD_MacroAction> shareKnowledge_Positive_Now = PD_AI_MacroAgent_SubPolicies.ShareKnowledge_Positive_Now( game, pathFinder, allMacros ); if (shareKnowledge_Positive_Now.Count > 0) { return(shareKnowledge_Positive_Now); } // share positive next round List <PD_MacroAction> shareKnowledge_Positive_NextRound_Macros = PD_AI_MacroAgent_SubPolicies.ShareKnowledge_Positive_NextRound( game, pathFinder, allMacros ); if (shareKnowledge_Positive_NextRound_Macros.Count > 0) { return(shareKnowledge_Positive_NextRound_Macros); } // take position positive now - other 4 List <PD_MacroAction> takePosition_Positive_Now_OtherPlayerWithinFourSteps = PD_AI_MacroAgent_SubPolicies.TakePosition_Positive_Now_OtherPlayerWithinFourSteps( game, pathFinder, allMacros ); if (takePosition_Positive_Now_OtherPlayerWithinFourSteps.Count > 0) { return(takePosition_Positive_Now_OtherPlayerWithinFourSteps); } return(new List <PD_MacroAction>()); }
public PD_GameStats_Report( PD_Game game, PD_AI_PathFinder pathFinder ) { GameSettings = new PD_GR_P_GameSettings(game, pathFinder); GameCondition = new PD_GR_P_GameCondition(game, pathFinder); GameScores = new PD_GR_P_GameScores(game, pathFinder); ActionStats = new PD_GR_P_ActionStats(game, pathFinder); GameStateEvaluationMetrics = new PD_GR_P_GameStateEvaluationMetrics(game, pathFinder); MapStats = new PD_GR_P_MapStats(game, pathFinder); Update(game, pathFinder); }
public override List <PD_MacroAction> FilterMacros( PD_Game game, PD_AI_PathFinder pathFinder, List <PD_MacroAction> allMacros) { return(allMacros.FindAll( x => ( x.Is_TypeOf_ShareKnowledge_Any() || x.Is_TypeOf_TakePositionFor_ShareKnowledge_Any() ) )); }
public override List <PD_MacroAction> FilterMacros( PD_Game game, PD_AI_PathFinder pathFinder, List <PD_MacroAction> allMacros ) { #if DEBUG if (game.GQ_IsInState_Discard_Any() == false) { throw new System.Exception("game is not in discard state"); } if ( allMacros.Any( x => x.Is_TypeOf_Discard_Any() == false ) ) { throw new System.Exception("non discard actions are included here..."); } #endif int playerWhoDiscards = ((I_Player_Action)allMacros[0].Actions_All[0]).Player; Dictionary <PD_MacroAction, double> effectPerMacroAction = new Dictionary <PD_MacroAction, double>(); foreach (var macro in allMacros) { double effect = PD_AI_CardEvaluation_Utilities .Calculate_ListOfPlayerActions_Effect_On_Percent_AbilityToCureDiseases( game, macro.Actions_Executable_Now, true ); effectPerMacroAction.Add(macro, effect); } double maximumValue = effectPerMacroAction.Max(x => x.Value); List <PD_MacroAction> maximumValueMacros = new List <PD_MacroAction>(); foreach (var macro in allMacros) { if (effectPerMacroAction[macro] == maximumValue) { maximumValueMacros.Add(macro); } } return(maximumValueMacros); }
public override void Update( PD_Game game, PD_AI_PathFinder pathFinder ) { GameOngoing = game.GQ_Is_Ongoing() ? 1 : 0; GameWon = game.GQ_Is_Won() ? 1 : 0; GameLost = game.GQ_Is_Lost() ? 1 : 0; Lost_Outbreaks = game.GQ_SS_DeadlyOutbreaks() ? 1 : 0; Lost_DiseaseCubes = game.game_state_counter.insufficient_disease_cubes_for_infection ? 1 : 0; Lost_PlayerCards = game.game_state_counter.insufficient_player_cards_to_draw ? 1 : 0; }
public void Update(PD_Game game, PD_AI_PathFinder pathFinder, PolicyBased_RHE_Agent rollingHorizonAgent) { Times_AgentUsed++; Total_Successful_Mutations += rollingHorizonAgent.Num_Successful_Mutations_ThisTime; Total_Successful_Mutations_FirstActionDifferent += rollingHorizonAgent.Num_Successful_Mutations_Different_FirstAction_ThisTime; if (rollingHorizonAgent.Num_Successful_Mutations_ThisTime > 0) { Times_AgentUsed_With_Successful_Mutations++; } if (rollingHorizonAgent.Num_Successful_Mutations_Different_FirstAction_ThisTime > 0) { Times_AgentUsed_With_Successful_Mutations_FirstActionDifferent++; } }