Ejemplo n.º 1
0
        public void Apply_Action(
            Random randomness_provider,
            PD_Action playerAction
            )
        {
            CurrentAvailableMacros = new List <PD_MacroAction>();

            if (CurrentAvailablePlayerActions.Contains(playerAction) == false)
            {
                throw new System.Exception("non applicable action");
            }

            PlayerActionsHistory.Add(playerAction);

            game_FSM.OnCommand(randomness_provider, this, playerAction);

            UpdateAvailablePlayerActions();

            // after an action is applied, see if the next action is auto action
            // and if so, apply it automatically.
            if (
                CurrentAvailablePlayerActions != null &&
                CurrentAvailablePlayerActions.Count > 0
                )
            {
                if (CurrentAvailablePlayerActions[0] is I_Auto_Action)
                {
                    Apply_Action(
                        randomness_provider,
                        CurrentAvailablePlayerActions[0]
                        );
                }
            }
        }
        public override PD_GameStateBase OnCommand(
            Random randomness_provider,
            PD_Game game,
            PD_Action command)
        {
            if (command.GetType() == typeof(PA_Discard_AfterDrawing))
            {
                command.Execute(
                    randomness_provider,
                    game
                    );

                // condition checks:
                bool playerHandBiggerThanPermitted =
                    game.GQ_SS_CurrentPlayerHandIsBiggerThanPermitted();

                if (playerHandBiggerThanPermitted == false)
                {
                    return(new PD_GS_DrawingNewInfectionCards());
                }
                else
                {
                    return(null); // stay in same state
                }
            }
            return(null);
        }
        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 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);
        }
Ejemplo n.º 5
0
        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);
            }
        }
        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>());
        }
Ejemplo n.º 7
0
 public override PD_GameStateBase OnCommand(
     Random randomness_provider,
     PD_Game game,
     PD_Action command
     )
 {
     return(null);
 }
Ejemplo n.º 8
0
 public override bool Equals(PD_Action other)
 {
     if (other is PA_DriveFerry other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 9
0
 public override bool Equals(PD_Action other)
 {
     if (other is PA_Discard_AfterDrawing other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
 public override bool Equals(PD_Action other)
 {
     if (other is PA_ApplyEpidemicCard other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
 public override bool Equals(PD_Action other)
 {
     if (other is PA_ShareKnowledge_TakeCard_FromResearcher other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 12
0
 public override bool Equals(PD_Action other)
 {
     if (other is PA_MoveResearchStation other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
 public override bool Equals(PD_Action other)
 {
     if (other is PA_DrawNewPlayerCards other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 14
0
 public override bool Equals(PD_Action other)
 {
     if (other is PA_OperationsExpert_Flight other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 15
0
 public override bool Equals(PD_Action other)
 {
     if (other is PA_DiscoverCure_Scientist other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 16
0
 public override bool Equals(PD_Action other)
 {
     if (other is PA_ShuttleFlight other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
 public override bool Equals(PD_Action other)
 {
     if (other is PA_ShareKnowledge_GiveCard other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 18
0
 public override bool Equals(PD_Action other)
 {
     if (other is PA_TreatDisease other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 19
0
 public override bool Equals(PD_Action other)
 {
     if (other is PA_Discard_DuringMainPlayerActions other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 20
0
 public override bool Equals(PD_Action other)
 {
     if (other is PA_BuildResearchStation_OperationsExpert other_action)
     {
         return(Equals(other_action));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 21
0
 public override PD_GameStateBase OnCommand(
     Random randomness_provider,
     PD_Game game,
     PD_Action command)
 {
     if (command.GetType() == typeof(PA_DrawNewInfectionCards))
     {
         command.Execute(
             randomness_provider,
             game
             );
         return(new PD_GS_ApplyingInfectionCards());
     }
     return(null);
 }
Ejemplo n.º 22
0
        public static double Calculate_PlayerAction_Effect_On_Percent_AbilityToCureDiseases(
            PD_Game game,
            PD_Action action,
            bool squared
            )
        {
            int[,] current_NumCardsTable = NumCardsTable(game);
            double[,] current_Percent_Complete_SetsOfCards = Calculate_Percent_CompleteSetsOfCards_Table(
                game,
                current_NumCardsTable
                );
            double[,] current_GroupAbilityToCureDiseases_Table = Calculate_Percent_AbilityToCureDiseases_Table(
                game,
                current_Percent_Complete_SetsOfCards,
                squared
                );
            double current_GroupAbilityToCureDiseases = Calculate_Percent_AbilityToCureDiseases(
                game,
                current_GroupAbilityToCureDiseases_Table
                );

            int[,] supposed_NumCardsTable = NumCardsTable_AfterApplying_PlayerAction(
                game,
                current_NumCardsTable,
                action
                );
            double[,] supposed_Percent_Complete_SetsOfCards = Calculate_Percent_CompleteSetsOfCards_Table(
                game,
                supposed_NumCardsTable
                );
            double[,] supposed_GroupAbilityToCureDiseases_Table = Calculate_Percent_AbilityToCureDiseases_Table(
                game,
                supposed_Percent_Complete_SetsOfCards,
                squared
                );
            double supposed_GroupAbilityToCureDiseases = Calculate_Percent_AbilityToCureDiseases(
                game,
                supposed_GroupAbilityToCureDiseases_Table
                );

            return(supposed_GroupAbilityToCureDiseases - current_GroupAbilityToCureDiseases);
        }
        public override PD_GameStateBase OnCommand(
            Random randomness_provider,
            PD_Game game,
            PD_Action command)
        {
            if (command.GetType() == typeof(PA_ApplyEpidemicCard))
            {
                command.Execute(
                    randomness_provider,
                    game
                    );

                // condition checks:
                bool playerHandIncludesEpidemicCard = game.GQ_SS_CurrentPlayerHandIncludesEpidemicCard();
                bool playerHandBiggerThanPermitted  = game.GQ_SS_CurrentPlayerHandIsBiggerThanPermitted();

                if (game.GQ_SS_DeadlyOutbreaks() == true)
                {
                    return(new PD_GS_GameLost());
                }
                else if (game.GQ_SS_NotEnoughDiseaseCubestoCompleteAnInfection() == true)
                {
                    return(new PD_GS_GameLost());
                }
                else if (playerHandIncludesEpidemicCard == true)
                {
                    return(new PD_GS_ApplyingEpidemicCard());
                }
                else if (playerHandBiggerThanPermitted == true)
                {
                    return(new PD_GS_Discarding_AfterDrawing());
                }
                else
                {
                    return(new PD_GS_DrawingNewInfectionCards());
                }
            }
            return(null);
        }
Ejemplo n.º 24
0
        public static int[,] NumCardsTable_AfterApplying_PlayerAction(
            PD_Game game,
            int[,] initialNumCardsTable,
            PD_Action action
            )
        {
            int[,] hypothetical_NumCardsTable = initialNumCardsTable.CustomDeepCopy();
            if (action is PA_ShareKnowledge_GiveCard give_card_action)
            {
                int cardType    = game.GQ_City_InfectionType(give_card_action.CityCardToGive);
                int giver_Index = game.players.IndexOf(give_card_action.Player);
                int taker_Index = game.players.IndexOf(give_card_action.OtherPlayer);

                hypothetical_NumCardsTable[cardType, giver_Index] -= 1;
                hypothetical_NumCardsTable[cardType, taker_Index] += 1;

                return(hypothetical_NumCardsTable);
            }
            else if (action is PA_ShareKnowledge_GiveCard_ResearcherGives researcher_gives_action)
            {
                int cardType    = game.GQ_City_InfectionType(researcher_gives_action.CityCardToGive);
                int giver_Index = game.players.IndexOf(researcher_gives_action.Player);
                int taker_Index = game.players.IndexOf(researcher_gives_action.OtherPlayer);

                hypothetical_NumCardsTable[cardType, giver_Index] -= 1;
                hypothetical_NumCardsTable[cardType, taker_Index] += 1;

                return(hypothetical_NumCardsTable);
            }
            else if (action is PA_ShareKnowledge_TakeCard take_card_action)
            {
                int cardType    = game.GQ_City_InfectionType(take_card_action.CityCardToTake);
                int taker_Index = game.players.IndexOf(take_card_action.Player);
                int giver_Index = game.players.IndexOf(take_card_action.OtherPlayer);

                hypothetical_NumCardsTable[cardType, giver_Index] -= 1;
                hypothetical_NumCardsTable[cardType, taker_Index] += 1;

                return(hypothetical_NumCardsTable);
            }
            else if (action is PA_ShareKnowledge_TakeCard_FromResearcher take_card_from_researcher_action)
            {
                int cardType    = game.GQ_City_InfectionType(take_card_from_researcher_action.CityCardToTake);
                int taker_Index = game.players.IndexOf(take_card_from_researcher_action.Player);
                int giver_Index = game.players.IndexOf(take_card_from_researcher_action.OtherPlayer);

                hypothetical_NumCardsTable[cardType, giver_Index] -= 1;
                hypothetical_NumCardsTable[cardType, taker_Index] += 1;

                return(hypothetical_NumCardsTable);
            }
            else if (action is PA_DirectFlight directFlightAction)
            {
                int cardType    = game.GQ_City_InfectionType(directFlightAction.UsedCard);
                int playerIndex = game.players.IndexOf(directFlightAction.Player);
                hypothetical_NumCardsTable[cardType, playerIndex] -= 1;

                return(hypothetical_NumCardsTable);
            }
            else if (action is PA_CharterFlight charter_flight_action)
            {
                int cardType    = game.GQ_City_InfectionType(charter_flight_action.UsedCard);
                int playerIndex = game.players.IndexOf(charter_flight_action.Player);
                hypothetical_NumCardsTable[cardType, playerIndex] -= 1;

                return(hypothetical_NumCardsTable);
            }
            else if (action is PA_OperationsExpert_Flight operations_expert_flight_action)
            {
                int cardType    = game.GQ_City_InfectionType(operations_expert_flight_action.UsedCard);
                int playerIndex = game.players.IndexOf(operations_expert_flight_action.Player);
                hypothetical_NumCardsTable[cardType, playerIndex] -= 1;

                return(hypothetical_NumCardsTable);
            }
            else if (action is PA_BuildResearchStation build_research_station_action)
            {
                int cardType    = game.GQ_City_InfectionType(build_research_station_action.UsedCard);
                int playerIndex = game.players.IndexOf(build_research_station_action.Player);
                hypothetical_NumCardsTable[cardType, playerIndex] -= 1;

                return(hypothetical_NumCardsTable);
            }
            else if (action is PA_MoveResearchStation move_research_station_action)
            {
                int cardType    = game.GQ_City_InfectionType(move_research_station_action.Used_CityCard);
                int playerIndex = game.players.IndexOf(move_research_station_action.Player);
                hypothetical_NumCardsTable[cardType, playerIndex] -= 1;

                return(hypothetical_NumCardsTable);
            }
            else if (action is PA_Discard_DuringMainPlayerActions discard_during_action)
            {
                int cardType    = game.GQ_City_InfectionType(discard_during_action.PlayerCardToDiscard);
                int playerIndex = game.players.IndexOf(discard_during_action.Player);
                hypothetical_NumCardsTable[cardType, playerIndex] -= 1;

                return(hypothetical_NumCardsTable);
            }
            else if (action is PA_Discard_AfterDrawing discard_after_action)
            {
                int cardType    = game.GQ_City_InfectionType(discard_after_action.PlayerCardToDiscard);
                int playerIndex = game.players.IndexOf(discard_after_action.Player);
                hypothetical_NumCardsTable[cardType, playerIndex] -= 1;

                return(hypothetical_NumCardsTable);
            }
            else
            {
                return(hypothetical_NumCardsTable);
            }
        }
Ejemplo n.º 25
0
        public override PD_GameStateBase OnCommand(
            Random randommness_provider,
            PD_Game game,
            PD_Action command)
        {
            command.Execute(
                randommness_provider,
                game
                );

            game.game_state_counter.IncreasePlayerActionIndex();

            // after executing a main player action:
            bool playerActionsFinished   = game.SS_PlayerActionsFinished();
            bool allDiseasesCured        = game.GQ_SS_AllDiseasesCured();
            bool anyPlayerNeedsToDiscard = game.GQ_SS_AnyPlayerHandIsBiggerThanPermitted();
            bool enoughPlayerCardsToDraw = game.GQ_SS_EnoughPlayerCardsToDraw();


            bool stayAt_Applying_MainPlayerActions =
                playerActionsFinished == false
                &&
                anyPlayerNeedsToDiscard == false;

            bool goTo_DrawingNewPlayerCards =
                playerActionsFinished == true
                &&
                anyPlayerNeedsToDiscard == false
                &&
                enoughPlayerCardsToDraw == true
                &&
                allDiseasesCured == false;

            bool goTo_Discarding_During_MainPlayerActions =
                anyPlayerNeedsToDiscard == true;

            bool goTo_GameLost =
                playerActionsFinished == true
                &&
                allDiseasesCured == false
                &&
                enoughPlayerCardsToDraw == false;

            bool goTo_GameWon =
                playerActionsFinished == true
                &&
                allDiseasesCured == true
                &&
                anyPlayerNeedsToDiscard == false;


            if (stayAt_Applying_MainPlayerActions)
            {
                return(null);
            }
            else if (goTo_DrawingNewPlayerCards)
            {
                return(new PD_GS_DrawingNewPlayerCards());
            }
            else if (goTo_Discarding_During_MainPlayerActions)
            {
                return(new PD_GS_Discarding_DuringMainPlayerActions());
            }
            else if (goTo_GameLost)
            {
                game.game_state_counter.insufficient_player_cards_to_draw = true;
                return(new PD_GS_GameLost());
            }
            else if (goTo_GameWon)
            {
                return(new PD_GS_GameWon());
            }
            else
            {
                throw new System.Exception("something wrong here");
            }
        }
Ejemplo n.º 26
0
 public abstract PD_GameStateBase OnCommand(
     Random randomness_provider,
     PD_Game game,
     PD_Action command
     );
Ejemplo n.º 27
0
        public override PD_GameStateBase OnCommand(
            Random randomness_provider,
            PD_Game game,
            PD_Action command
            )
        {
            if (command.GetType() == typeof(PA_Discard_DuringMainPlayerActions))
            {
                command.Execute(
                    randomness_provider,
                    game);

                bool playerActionsFinished   = game.SS_PlayerActionsFinished();
                bool allDiseasesCured        = game.GQ_SS_AllDiseasesCured();
                bool anyPlayerNeedsToDiscard = game.GQ_SS_AnyPlayerHandIsBiggerThanPermitted();
                bool enoughPlayerCardsToDraw = game.GQ_SS_EnoughPlayerCardsToDraw();

                // stay in same state
                bool stayAt_Discarding_During_MainPlayerActions =
                    anyPlayerNeedsToDiscard == true;

                // go back to applying main player actions
                bool goTo_Applying_MainPlayerActions =
                    playerActionsFinished == false
                    &&
                    anyPlayerNeedsToDiscard == false;

                // proceed to drawing new player cards
                bool goTo_Drawing_New_PlayerCards =
                    playerActionsFinished == true
                    &&
                    anyPlayerNeedsToDiscard == false
                    &&
                    enoughPlayerCardsToDraw == true
                    &&
                    allDiseasesCured == false;

                // go to game lost
                bool goTo_GameLost =
                    playerActionsFinished == true
                    &&
                    allDiseasesCured == false
                    &&
                    enoughPlayerCardsToDraw == false;

                // go to game won
                bool goTo_GameWon =
                    playerActionsFinished == true
                    &&
                    allDiseasesCured == true
                    &&
                    anyPlayerNeedsToDiscard == false;


                if (stayAt_Discarding_During_MainPlayerActions)
                {
                    return(null); // stay in same state
                }
                else if (goTo_Applying_MainPlayerActions)
                {
                    return(new PD_GS_ApplyingMainPlayerActions());
                }
                else if (goTo_Drawing_New_PlayerCards)
                {
                    return(new PD_GS_DrawingNewPlayerCards());
                }
                else if (goTo_GameLost)
                {
                    return(new PD_GS_GameLost());
                }
                else if (goTo_GameWon)
                {
                    return(new PD_GS_GameWon());
                }
                else
                {
                    throw new System.Exception("something wrong here...");
                }
            }
            else
            {
                throw new System.Exception("something wrong here");
            }
        }