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>()); }
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 static double Calculate_Percent_AbilityToCureDiseases( PD_Game game, bool squared ) { return(PD_AI_CardEvaluation_Utilities.Calculate_Percent_AbilityToCureDiseases( game, squared )); }
public static double Calculate_Percent_CuredDiseases_Gradient( PD_Game game, bool squared ) { return(PD_AI_CardEvaluation_Utilities.Calculate_PercentCuredDiseases_Gradient( game, squared )); }
public override double CalculateScore(PD_Game gameState) { int[,] numCardsTable = PD_AI_CardEvaluation_Utilities.NumCardsTable( gameState ); double[,] percentComplete_Table = PD_AI_CardEvaluation_Utilities.Calculate_Percent_CompleteSetsOfCards_Table( gameState, numCardsTable ); double[,] groupAbilityToCureDiseases_Table = PD_AI_CardEvaluation_Utilities.Calculate_Percent_AbilityToCureDiseases_Table( gameState, percentComplete_Table, false ); double[,] finalTable = groupAbilityToCureDiseases_Table.CustomDeepCopy(); int numTypes = groupAbilityToCureDiseases_Table.Height(); int numPlayers = groupAbilityToCureDiseases_Table.Width(); for (int type = 0; type < numTypes; type++) { bool isDiseaseCured = gameState.GQ_Is_DiseaseCured_OR_Eradicated(type); if (isDiseaseCured) { for (int playerIndex = 0; playerIndex < numPlayers; playerIndex++) { finalTable[type, playerIndex] = 1.3; } } else { for (int playerIndex = 0; playerIndex < numPlayers; playerIndex++) { finalTable[type, playerIndex] = groupAbilityToCureDiseases_Table[type, playerIndex]; } } } double[,] normalized_Table = finalTable.Divided_By(1.3); return (normalized_Table .RowMax_PerRow() .Average()); }
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 static List <PD_MacroAction> TakePosition_Positive_NextRound_OtherPlayerWithinFourSteps( 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) { // find all of them that could be executed by the other player in one turn (4 steps) List <PD_MacroAction> executableByOtherPlayerInOneTurn = new List <PD_MacroAction>(); foreach (var macro in takePosition_Positive_NextRound) { if ( macro.NonExecutable_ShareKnowledge_Action.GetType() == typeof(PA_ShareKnowledge_GiveCard) ) { PA_ShareKnowledge_GiveCard action = (PA_ShareKnowledge_GiveCard)macro.NonExecutable_ShareKnowledge_Action; int destination = action.CityCardToGive; int otherPlayer = action.OtherPlayer; int otherPlayerLocation = game.GQ_PlayerLocation(otherPlayer); int distanceFromOtherPlayer = pathFinder.GetPrecalculatedShortestDistance( game, game.GQ_ResearchStationCities(), destination, otherPlayerLocation ); if (distanceFromOtherPlayer < 4) { executableByOtherPlayerInOneTurn.Add(macro); } } else if ( macro.NonExecutable_ShareKnowledge_Action.GetType() == typeof(PA_ShareKnowledge_TakeCard) ) { PA_ShareKnowledge_TakeCard action = (PA_ShareKnowledge_TakeCard)macro.NonExecutable_ShareKnowledge_Action; int destination = action.CityCardToTake; int otherPlayer = action.OtherPlayer; int otherPlayerLocation = game.GQ_PlayerLocation(otherPlayer); int distanceFromOtherPlayer = pathFinder.GetPrecalculatedShortestDistance( game, game.GQ_ResearchStationCities(), destination, otherPlayerLocation ); if (distanceFromOtherPlayer < 4) { executableByOtherPlayerInOneTurn.Add(macro); } } } if (executableByOtherPlayerInOneTurn.Count > 0) { return(executableByOtherPlayerInOneTurn); } } } 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 var allTreatMacros_ExecutableNow = allMacros.FindAll( x => x.Is_TypeOf_TreatDisease_Any() && x.Is_ExecutableNow() ); if (allTreatMacros_ExecutableNow.Count == 0) { return(new List <PD_MacroAction>()); } List <PD_MacroAction> noNegativeEffect_TreatMacros = new List <PD_MacroAction>(); foreach (var macro in allTreatMacros_ExecutableNow) { double value = PD_AI_CardEvaluation_Utilities .Calculate_ListOfPlayerActions_Effect_On_Percent_AbilityToCureDiseases( game, macro.Actions_Executable_Now, true ); if (value == 0) { noNegativeEffect_TreatMacros.Add(macro); } } if (noNegativeEffect_TreatMacros.Count == 0) { return(new List <PD_MacroAction>()); } List <PD_MacroAction> treatMacros_ofCities_InfectedWith_RequestedNumCubes = new List <PD_MacroAction>(); foreach (var macro in noNegativeEffect_TreatMacros) { if ( macro.MacroAction_Type == PD_MacroAction_Type.TreatDisease_Macro ) { PA_TreatDisease treatAction = (PA_TreatDisease)macro.Find_LastCommand(); int destination = treatAction.CityToTreatDiseaseAt; int treatType = treatAction.TypeOfDiseaseToTreat; int numCubesThisTypeOnThatCity = game.GQ_Num_InfectionCubes_OfType_OnCity( destination, treatType ); if (numCubesThisTypeOnThatCity >= MinSameCubes) { treatMacros_ofCities_InfectedWith_RequestedNumCubes.Add(macro); } } else if ( macro.MacroAction_Type == PD_MacroAction_Type.TreatDisease_Medic_Macro ) { PA_TreatDisease_Medic treatAction = (PA_TreatDisease_Medic)macro.Find_LastCommand(); int destination = treatAction.CityToTreatDiseaseAt; int treatType = treatAction.TypeOfDiseaseToTreat; int numCubesThisTypeOnThatCity = game.GQ_Num_InfectionCubes_OfType_OnCity( destination, treatType ); if (numCubesThisTypeOnThatCity >= MinSameCubes) { treatMacros_ofCities_InfectedWith_RequestedNumCubes.Add(macro); } } else if ( macro.MacroAction_Type == PD_MacroAction_Type.AutoTreatDisease_Medic_Macro ) { int destination = macro.Find_Destination(); int treatType = game.GQ_City_InfectionType(destination); int numCubesThisTypeOnThatCity = game.GQ_Num_InfectionCubes_OfType_OnCity( destination, treatType ); if (numCubesThisTypeOnThatCity >= MinSameCubes) { treatMacros_ofCities_InfectedWith_RequestedNumCubes.Add(macro); } } } if (treatMacros_ofCities_InfectedWith_RequestedNumCubes.Count > 0) { return(treatMacros_ofCities_InfectedWith_RequestedNumCubes); } else { 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."); } if (Max_TotalNum_RS < 1 || Max_TotalNum_RS > 6) { throw new System.Exception("this is not possible"); } if (Min_Dist_Between_RS < 1 || Min_Dist_Between_RS > 10) { throw new System.Exception("this is not possible"); } #endif // check if maximum number of RS is already reached var rs_cities = game.GQ_ResearchStationCities(); if (rs_cities.Count >= Max_TotalNum_RS) { return(new List <PD_MacroAction>()); } // find legitimate cities for RS var cities_Legitimate_ForRS = pathFinder.FindCitiesThatAreAwayFromResearchStations( game, Min_Dist_Between_RS ); if (cities_Legitimate_ForRS.Count == 0) { return(new List <PD_MacroAction>()); } var buildResearchStationMacros_ExecutableNow = allMacros.FindAll( x => x.Is_TypeOf_BuildResearchStation_Any() && x.Is_ExecutableNow() ); if (buildResearchStationMacros_ExecutableNow.Count == 0) { return(new List <PD_MacroAction>()); } List <PD_MacroAction> nonHarmful_BuildRS_Macros = new List <PD_MacroAction>(); foreach (var macro in buildResearchStationMacros_ExecutableNow) { double value = PD_AI_CardEvaluation_Utilities .Calculate_ListOfPlayerActions_Effect_On_Percent_AbilityToCureDiseases( game, macro.Actions_Executable_Now, true ); if (value == 0) { nonHarmful_BuildRS_Macros.Add(macro); } } if (nonHarmful_BuildRS_Macros.Count == 0) { return(new List <PD_MacroAction>()); } List <PD_MacroAction> legit_BuildRS_Macros = new List <PD_MacroAction>(); foreach (var macro in nonHarmful_BuildRS_Macros) { int destination = macro.Find_Destination(); if (cities_Legitimate_ForRS.Contains(destination)) { legit_BuildRS_Macros.Add(macro); } } if (legit_BuildRS_Macros.Count > 0) { return(legit_BuildRS_Macros); } else { return(new List <PD_MacroAction>()); } }