示例#1
0
        /// <summary>
        /// Direct Flight Action:
        /// Player discards a card and moves immediately to the city of that card
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        private static List <PA_DirectFlight> FindAvailable_DirectFlight_Actions(
            PD_Game game
            )
        {
            int current_player          = game.GQ_CurrentPlayer();
            int current_player_location = game.GQ_CurrentPlayer_Location();

            List <int> city_cards_in_player_hand = game.GQ_CityCardsInCurrentPlayerHand();

            var directFlightActions = new List <PA_DirectFlight>();

            foreach (int cityCard in city_cards_in_player_hand)
            {
                if (cityCard != current_player_location)
                {
                    directFlightActions.Add(
                        new PA_DirectFlight(
                            current_player,
                            cityCard,
                            cityCard
                            )
                        );
                }
            }

            return(directFlightActions);
        }
        public override void Execute(
            Random randomness_provider,
            PD_Game game
            )
        {
#if DEBUG
            if (game.GQ_IsInState_ApplyingMainPlayerActions() == false)
            {
                throw new System.Exception("wrong state!");
            }
            else if (Player != game.GQ_CurrentPlayer())
            {
                throw new System.Exception("wrong player!");
            }
            else if (game.GQ_Player_Role(Player) == PD_Player_Roles.Researcher)
            {
                throw new System.Exception("wrong player role!");
            }
            else if (game.GQ_PlayerLocation(Player) != game.GQ_PlayerLocation(OtherPlayer))
            {
                throw new System.Exception("Players do not share the same location");
            }
            else if (game.GQ_PlayerLocation(Player) != CityCardToGive)
            {
                throw new System.Exception("Player is not on the correct city");
            }
#endif
            game.cards.player_hand__per__player[Player].Remove(CityCardToGive);
            game.cards.player_hand__per__player[OtherPlayer].Add(CityCardToGive);
        }
        public void OnCommand(
            Random randomness_provider,
            PD_Game game,
            PD_Action command
            )
        {
            PD_GameStateBase nextState = CurrentState.OnCommand(
                randomness_provider,
                game,
                command
                );

            if (nextState == null)
            {
                // just stay on the same state
            }
            else if (nextState.GetType() == CurrentState.GetType())
            {
                CurrentState.OnExit(game);
                CurrentState = nextState;
                CurrentState.OnEnter(game);
            }
            else
            {
                CurrentState.OnExit(game);
                CurrentState = nextState;
                CurrentState.OnEnter(game);
            }
        }
示例#4
0
        public override void Execute(
            Random randomness_provider,
            PD_Game game
            )
        {
#if DEBUG
            if (game.GQ_IsInState_ApplyingMainPlayerActions() == false)
            {
                throw new System.Exception("wrong state!");
            }
            else if (Player != game.GQ_CurrentPlayer())
            {
                throw new System.Exception("wrong player...");
            }
            else if (game.GQ_Is_City_ResearchStation(game.GQ_CurrentPlayer_Location()) == false)
            {
                throw new System.Exception("current player location is NOT a research station!");
            }
            else if (game.GQ_Is_City_ResearchStation(ToCity) == false)
            {
                throw new System.Exception("final location is NOT a research station!");
            }
#endif

            game.GO_MovePawn_ToCity(
                Player,
                ToCity
                );

            game.Medic_MoveTreat(ToCity);
        }
示例#5
0
        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 static void SerializeGameToJsonAndSave(
            PD_Game gameToSerialize,
            bool compressed,
            string saveFilePath,
            bool overwriteIfExists,
            bool throwErrorIfExists
            )
        {
            // more details: https://www.newtonsoft.com/json/help/html/SerializeTypeNameHandling.htm

            // convert the game to a .json string...
            string gameSerializedToString =
                JsonConvert.SerializeObject(
                    gameToSerialize,
                    compressed ? Formatting.None : Formatting.Indented,
                    new JsonSerializerSettings
            {
                TypeNameHandling           = TypeNameHandling.All,
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            }
                    );

            CreateFile(
                saveFilePath,
                overwriteIfExists,
                throwErrorIfExists
                );

            AppendToFile(
                saveFilePath,
                gameSerializedToString
                );
        }
示例#7
0
        public override void Execute(
            Random randomness_provider,
            PD_Game game
            )
        {
#if DEBUG
            if (game.GQ_IsInState_ApplyingMainPlayerActions() == false)
            {
                throw new System.Exception("wrong state!");
            }
            else if (Player != game.GQ_CurrentPlayer())
            {
                throw new System.Exception("wrong player...");
            }
            else if (Build_RS_On != game.GQ_CurrentPlayer_Location())
            {
                throw new System.Exception("selected city does not match current player position");
            }
            else if (game.GQ_CurrentPlayer_Role() != PD_Player_Roles.Operations_Expert)
            {
                throw new System.Exception("wrong player role!");
            }
#endif
            game.GO_Place_ResearchStation_OnCity(Build_RS_On);
        }
 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
            )
        {
            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 = "";
            }
        }
示例#10
0
        GAQ_FindAvailable_DiscardDuringMainPlayerActions_Actions(
            PD_Game game
            )
        {
            List <PA_Discard_DuringMainPlayerActions> discardDuringMainPlayerActions_Actions =
                new List <PA_Discard_DuringMainPlayerActions>();

            if (game.GQ_IsInState_DiscardDuringMainPlayerActions())
            {
                foreach (var player in game.players)
                {
                    var cityCardsInPlayerHand = game.GQ_CityCardsInPlayerHand(player);
                    if (cityCardsInPlayerHand.Count > 7)
                    {
                        foreach (var cardToDiscard in cityCardsInPlayerHand)
                        {
                            PA_Discard_DuringMainPlayerActions discardAction = new PA_Discard_DuringMainPlayerActions(
                                player,
                                cardToDiscard
                                );
                            discardDuringMainPlayerActions_Actions.Add(discardAction);
                        }
                    }
                }
            }
            return(discardDuringMainPlayerActions_Actions);
        }
示例#11
0
        GAQ_FindAvailable_DiscardAfterDrawing_Actions(
            PD_Game game
            )
        {
            List <PA_Discard_AfterDrawing> discardAfterDrawing_Actions = new List <PA_Discard_AfterDrawing>();

            if (game.GQ_IsInState_DiscardAfterDrawing())
            {
                int currentPlayer = game.GQ_CurrentPlayer();

                List <int> cityCardsInCurrentPlayerHand = game.GQ_CityCardsInCurrentPlayerHand();
                if (cityCardsInCurrentPlayerHand.Count > 7)
                {
                    foreach (var cardToDiscard in cityCardsInCurrentPlayerHand)
                    {
                        PA_Discard_AfterDrawing discardAction = new PA_Discard_AfterDrawing(
                            currentPlayer,
                            cardToDiscard
                            );
                        discardAfterDrawing_Actions.Add(discardAction);
                    }
                }
            }
            return(discardAfterDrawing_Actions);
        }
示例#12
0
        private static List <PA_TreatDisease_Medic> FindAvailable_TreatDisease_Medic_Actions(
            PD_Game game
            )
        {
            int currentPlayer = game.GQ_CurrentPlayer();

            bool currentPlayerIsMedic = game.GQ_CurrentPlayer_Role() == PD_Player_Roles.Medic;

            if (currentPlayerIsMedic == false)
            {
                return(new List <PA_TreatDisease_Medic>());
            }

            var        currentPlayerLocation     = game.GQ_PlayerLocation(currentPlayer);
            List <int> infectionCubesTypesOnCity =
                game.GQ_InfectionCubeTypes_OnCity(currentPlayerLocation);

            List <PA_TreatDisease_Medic> availableTreatDiseaseMedicActions = new List <PA_TreatDisease_Medic>();

            foreach (var type in infectionCubesTypesOnCity)
            {
                var action = new PA_TreatDisease_Medic(currentPlayer, currentPlayerLocation, type);
                availableTreatDiseaseMedicActions.Add(action);
            }

            return(availableTreatDiseaseMedicActions);
        }
示例#13
0
        /// <summary>
        /// Shuttle flight action:
        /// Player moves from a research station city to another research station city
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        private static List <PA_ShuttleFlight> FindAvailable_ShuttleFlight_Actions(
            PD_Game game
            )
        {
            int currentPlayer           = game.GQ_CurrentPlayer();
            var current_player_location = game.GQ_CurrentPlayer_Location();

            if (game.GQ_Is_City_ResearchStation(current_player_location) == false)
            {
                return(new List <PA_ShuttleFlight>());
            }

            List <int> other_research_station_cities
                = game.GQ_ResearchStationCities();

            other_research_station_cities.Remove(current_player_location);

            if (other_research_station_cities.Count == 0)
            {
                return(new List <PA_ShuttleFlight>());
            }

            var shuttleFlightActions = new List <PA_ShuttleFlight>();

            foreach (var target_city in other_research_station_cities)
            {
                var action = new PA_ShuttleFlight(
                    currentPlayer,
                    target_city
                    );
                shuttleFlightActions.Add(action);
            }

            return(shuttleFlightActions);
        }
示例#14
0
        /// <summary>
        /// Charter Flight Action:
        /// Player discards the card of the city they are standing on,
        /// and they move to any city on the map
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        private static List <PA_CharterFlight> FindAvailable_CharterFlight_Actions(
            PD_Game game
            )
        {
            int currentPlayer             = game.GQ_CurrentPlayer();
            int current_player_location   = game.GQ_CurrentPlayer_Location();
            var city_cards_in_player_hand = game.GQ_CityCardsInCurrentPlayerHand();

            if (city_cards_in_player_hand.Contains(current_player_location))
            {
                int used_card = current_player_location;

                var charterFlightActions = new List <PA_CharterFlight>();

                foreach (int target_city in game.map.cities)
                {
                    if (target_city != current_player_location)
                    {
                        var action = new PA_CharterFlight(
                            currentPlayer,
                            target_city,
                            used_card
                            );
                        charterFlightActions.Add(action);
                    }
                }

                return(charterFlightActions);
            }
            else
            {
                return(new List <PA_CharterFlight>());
            }
        }
        public override PD_GameStateBase OnCommand(
            Random randomness_provider,
            PD_Game game,
            PD_Action command)
        {
            if (command.GetType() == typeof(PA_DrawNewPlayerCards))
            {
                command.Execute(randomness_provider, game);

                // conditional checking...
                bool playerHandIncludesEpidemicCard  = game.GQ_SS_CurrentPlayerHandIncludesEpidemicCard();
                bool playerHandIsBiggerThanPermitted = game.GQ_SS_CurrentPlayerHandIsBiggerThanPermitted();

                if (playerHandIncludesEpidemicCard == true)
                {
                    return(new PD_GS_ApplyingEpidemicCard());
                }
                else if (playerHandIncludesEpidemicCard == false)
                {
                    if (playerHandIsBiggerThanPermitted == true)
                    {
                        return(new PD_GS_Discarding_AfterDrawing());
                    }
                    else if (playerHandIsBiggerThanPermitted == false)
                    {
                        return(new PD_GS_DrawingNewInfectionCards());
                    }
                }
            }
            return(null);
        }
示例#16
0
        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 static void SerializeGame_To_MiniGameJson_AndSave(
            PD_Game game,
            string saveFilePath,
            bool compressed
            )
        {
            PD_MiniGame mini_game = game.Convert_To_MiniGame();

            string serialized_mini_game = JsonConvert.SerializeObject(
                mini_game,
                compressed ? Formatting.None : Formatting.Indented,
                new JsonSerializerSettings
            {
                TypeNameHandling           = TypeNameHandling.All,
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            }
                );

            CreateFile(
                saveFilePath,
                false,
                true
                );

            AppendToFile(
                saveFilePath,
                serialized_mini_game
                );
        }
 public PD_GR_P_GameStateEvaluationMetrics(
     PD_Game game,
     PD_AI_PathFinder pathFinder
     )
 {
     Update(game, pathFinder);
 }
 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 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);
        }
示例#21
0
        public override void Execute(
            Random randomness_provider,
            PD_Game game
            )
        {
#if DEBUG
            if (game.GQ_IsInState_ApplyingMainPlayerActions() == false)
            {
                throw new System.Exception("wrong state!");
            }
            else if (Player != game.GQ_CurrentPlayer())
            {
                throw new System.Exception("wrong player!");
            }
            else if (game.GQ_Player_Role(Player) != PD_Player_Roles.Medic)
            {
                throw new System.Exception("wrong player role!");
            }
            else if (CityToTreatDiseaseAt != game.GQ_PlayerLocation(Player))
            {
                throw new System.Exception("wrong player location");
            }
            else if (
                game.GQ_InfectionCubeTypes_OnCity(CityToTreatDiseaseAt)
                .Contains(TypeOfDiseaseToTreat) == false)
            {
                throw new System.Exception("the selected city does not have cubes of this type!");
            }
#endif
            game.Com_PA_TreatDisease_Medic(Player, CityToTreatDiseaseAt, TypeOfDiseaseToTreat);
        }
        public override PD_GameStateBase OnCommand(
            Random randomness_provider,
            PD_Game game,
            PD_Action command
            )
        {
            if (command.GetType() == typeof(PA_ApplyInfectionCard))
            {
                command.Execute(
                    randomness_provider,
                    game
                    );

                // check if game is lost, etc..
                if (game.GQ_SS_NotEnoughDiseaseCubestoCompleteAnInfection())
                {
                    return(new PD_GS_GameLost());
                }
                if (game.GQ_SS_DeadlyOutbreaks())
                {
                    return(new PD_GS_GameLost());
                }
                if (game.GQ_SS_ThereAreActiveInfectionCards())
                {
                    return(null);
                }

                game.game_state_counter.IncreaseCurrentPlayerIndex();
                return(new PD_GS_ApplyingMainPlayerActions());
            }
            return(null);
        }
 public PD_GR_P_ActionStats(
     PD_Game game,
     PD_AI_PathFinder pathFinder
     )
 {
     Update(game, pathFinder);
 }
示例#24
0
        public List <int> Find_AllCities_Within_SpecificRange_From_ReferenceCity(
            PD_Game game,
            int referenceCity,
            List <int> researchStationCities,
            int range
            )
        {
            //if (range < 1)
            //{
            //    throw new System.Exception("range must be greater than zero!");
            //}
            List <int> citiesWithinSpecificRange = new List <int>();

            foreach (int city in game.map.cities)
            {
                if (city != referenceCity)
                {
                    int distanceBetween = GetPrecalculatedShortestDistance(
                        game,
                        researchStationCities,
                        referenceCity,
                        city
                        );
                    if (distanceBetween <= range)
                    {
                        citiesWithinSpecificRange.Add(city);
                    }
                }
            }
            return(citiesWithinSpecificRange);
        }
示例#25
0
 public static void GO_Randomize_InfectionCards_Deck(
     this PD_Game game,
     Random randomness_provider
     )
 {
     game.cards.divided_deck_of_infection_cards.ShuffleAllSubListsElements(randomness_provider);
 }
示例#26
0
        public List <int> Find_AllCities_Of_SpecificDistance_From_ReferenceCity(
            PD_Game game,
            int referenceCity,
            List <int> researchStationCities,
            int distance
            )
        {
            //if (distance < 1)
            //{
            //    throw new System.Exception("distance must be 1 or greater");
            //}
            List <int> citiesOfSpecifiedDistanceFromReferenceCity = new List <int>();

            foreach (int city in game.map.cities)
            {
                if (city != referenceCity)
                {
                    int distanceBetween = GetPrecalculatedShortestDistance(
                        game,
                        researchStationCities,
                        referenceCity,
                        city
                        );
                    if (distanceBetween == distance)
                    {
                        citiesOfSpecifiedDistanceFromReferenceCity.Add(city);
                    }
                }
            }
            return(citiesOfSpecifiedDistanceFromReferenceCity);
        }
 public PD_GR_P_GameCondition(
     PD_Game game,
     PD_AI_PathFinder pathFinder
     )
 {
     Update(game, pathFinder);
 }
示例#28
0
        public int Find_RS_ClosestToCity(
            PD_Game game,
            List <int> researchStationCities,
            int city
            )
        {
            if (researchStationCities.Contains(city))
            {
                return(city);
            }
            else
            {
                var minDist  = 10000000;
                var minRoute = new List <int>();
                foreach (var rsCity in researchStationCities)
                {
                    var route =
                        shortest_path__per__destination__per__origin
                        [city]
                        [rsCity];

                    if (route.Count < minDist)
                    {
                        minDist  = route.Count;
                        minRoute = route;
                    }
                }
                return(minRoute[minRoute.Count - 1]);
            }
        }
        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));
        }