private bool TakeDirectFlightIfSensible(IPandemicTurn turn, PandemicPlayerState currentPlayerState)
        {
            var weakCityCards = _handManagementHelper.GetWeakCityCards(turn.State,
                                                                       currentPlayerState.PlayerRole, currentPlayerState.PlayerHand);

            if (weakCityCards == null || !weakCityCards.Any())
            {
                return(false);
            }

            if (_d20.Roll() >= 14)
            {
                return(false);
            }

            var valueOfCurrentLocation = _routeHelper.GetLocationValue(turn.State, currentPlayerState.Location);

            foreach (var candidateCity in weakCityCards)
            {
                var valueOfCandidateCity    = _routeHelper.GetLocationValue(turn.State, (City)candidateCity.Value);
                var distanceToCandidateCity = _routeHelper.GetDistance(turn.State, currentPlayerState.Location, (City)candidateCity.Value);

                if ((valueOfCandidateCity - valueOfCurrentLocation > 3) && distanceToCandidateCity > 3)
                {
                    BroadCastThought($"I should take a direct flight to {(City)candidateCity.Value}");
                    turn.DirectFlight((City)candidateCity.Value);
                    return(true);
                }
            }

            return(false);
        }
        private bool BuildResearchStationIfSensible(IPandemicTurn turn, PandemicPlayerState currentPlayerState)
        {
            var shouldBuildResearchStation = _researchStationHelper.ShouldBuildResearchStation(
                turn.State, currentPlayerState.Location, currentPlayerState.PlayerRole, currentPlayerState.PlayerHand);

            if (shouldBuildResearchStation)
            {
                BroadCastThought($"I should build a research station at {currentPlayerState.Location}");
                turn.BuildResearchStation(currentPlayerState.Location);
                return(true);
            }

            return(false);
        }
        private bool CureIfAtResearchStationAndHaveCure(IPandemicTurn turn, List <Disease> curableDiseases, bool atResearchStation,
                                                        PandemicPlayerState currentPlayerState)
        {
            if (curableDiseases.Any() && atResearchStation)
            {
                var disease            = curableDiseases[0];
                var cureCardsToDiscard = _handManagementHelper.GetCardsToDiscardToCure(
                    turn.State, disease, currentPlayerState.PlayerRole, currentPlayerState.PlayerHand);
                turn.DiscoverCure(disease, cureCardsToDiscard);
                BroadCastThought($"I should cure {disease}");
                return(true);
            }

            return(false);
        }
        private bool IfThereIsDiseaseHereThenTreatIt(IPandemicTurn turn, PandemicPlayerState currentPlayerState)
        {
            while (turn.State.Cities.Single(n => n.City == currentPlayerState.Location).DiseaseCubeCount > 2)
            {
                var mapNodeToTreatDiseases = turn.State.Cities.Single(n => n.City == currentPlayerState.Location);
                foreach (var disease in Enum.GetValues(typeof(Disease)).Cast <Disease>())
                {
                    if (mapNodeToTreatDiseases.DiseaseCubes[disease] > 0)
                    {
                        BroadCastThought($"I should treat the disease {disease} in my city of {currentPlayerState.Location}");
                        turn.TreatDisease(disease);
                        return(true);
                    }
                }
            }

            return(false);
        }
        private bool TakeCharterFlightIfSensible(IPandemicTurn turn, PandemicPlayerState currentPlayerState)
        {
            if (!_handManagementHelper.HasCityCardForCurrentLocation(currentPlayerState))
            {
                return(false);
            }

            var currentCityValue   = _routeHelper.GetLocationValue(turn.State, currentPlayerState.Location);
            var bestCity           = _routeHelper.GetBestLocationOnBoard(turn.State.Cities);
            var bestCityValue      = _routeHelper.GetLocationValue(turn.State, bestCity);
            var distanceToBestCity = _routeHelper.GetDistance(turn.State, currentPlayerState.Location, bestCity);

            if ((bestCityValue - currentCityValue <= 3) || distanceToBestCity <= 3)
            {
                return(false);
            }

            BroadCastThought($"I should take a charter flight to {bestCity}");
            turn.CharterFlight(bestCity);
            return(true);
        }
        private bool MoveTowardsNearestResearchStationIfHaveCure(IPandemicTurn turn, bool atResearchStation,
                                                                 PandemicPlayerState currentPlayerState, List <Disease> curableDiseases)
        {
            if (!atResearchStation)
            {
                var nearestCityWithResearchStation =
                    _routeHelper.GetNearestCitywithResearchStation(turn.State, currentPlayerState.Location);
                var routeToNearestResearchStation = nearestCityWithResearchStation == null
                    ? new List <City>()
                    : _routeHelper.GetShortestPath(turn.State, currentPlayerState.Location,
                                                   nearestCityWithResearchStation.Value);
                if (nearestCityWithResearchStation != null &&
                    curableDiseases.Any() &&
                    routeToNearestResearchStation != null &&
                    routeToNearestResearchStation.Count > 1)
                {
                    BroadCastThought($"I should move torwards the research station at {nearestCityWithResearchStation} so I can cure a disease");
                    turn.DriveOrFerry(routeToNearestResearchStation[1]);
                    return(true);
                }
            }

            return(false);
        }
        private void MoveTowardsNearestDiseaseWithoutDiscarding(IPandemicTurn turn, PandemicPlayerState currentPlayerState)
        {
            var bestCityToTravelToWithoutDiscard =
                _routeHelper.GetBestCityToTravelToWithoutDiscarding(turn.State, currentPlayerState.Location);
            var startingNode    = turn.State.Cities.Single(n => n.City.Equals(currentPlayerState.Location));
            var destinationNode = turn.State.Cities.Single(n => n.City.Equals(bestCityToTravelToWithoutDiscard));

            if (startingNode.ConnectedCities.Contains(bestCityToTravelToWithoutDiscard))
            {
                BroadCastThought($"I should drive/ferry to {bestCityToTravelToWithoutDiscard} so I can move towards disease");
                turn.DriveOrFerry(bestCityToTravelToWithoutDiscard);
                return;
            }
            else if (startingNode.HasResearchStation && destinationNode.HasResearchStation)
            {
                BroadCastThought($"I should take a shuttle flight to {destinationNode.City} so I can move towards disease");
                turn.ShuttleFlight(bestCityToTravelToWithoutDiscard);
                return;
            }
            else
            {
                throw new CardboardException("Cant make this move");
            }
        }
Beispiel #8
0
 public bool HasCityCardForCurrentLocation(PandemicPlayerState playerState)
 {
     return(playerState.PlayerHand.Any(c => c.PlayerCardType == PlayerCardType.City && (City)c.Value == playerState.Location));
 }
Beispiel #9
0
        private KnowledgeShare GetSuggestedKnowledgeShareForResearcher(int currentPlayerId, IPandemicState state,
                                                                       List <int> playersWeCouldShareKnowledgeWith, PandemicPlayerState currentPlayerState, Dictionary <Disease, DiseaseState> diseaseStates,
                                                                       List <City> currentPlayerCityCards)
        {
            foreach (var playerWeCouldShareKnowledgeWith in playersWeCouldShareKnowledgeWith)
            {
                var candidatePlayerState = state.PlayerStates[playerWeCouldShareKnowledgeWith];

                foreach (var disease in (Disease[])Enum.GetValues(typeof(Disease)))
                {
                    var ourDiseaseCount = currentPlayerState.PlayerHand
                                          .Count(c => c.PlayerCardType == PlayerCardType.City && ((City)c.Value).GetDefaultDisease() == disease);
                    var candidateDiseaseCount = candidatePlayerState.PlayerHand
                                                .Count(c => c.PlayerCardType == PlayerCardType.City && ((City)c.Value).GetDefaultDisease() == disease);

                    if (diseaseStates[disease] == DiseaseState.NotCured && ourDiseaseCount > 0 &&
                        candidateDiseaseCount > ourDiseaseCount)
                    {
                        {
                            return(new KnowledgeShare
                            {
                                Player1 = currentPlayerId,
                                Player2 = playerWeCouldShareKnowledgeWith,
                                CityCardToGive = currentPlayerCityCards.First(c => c.GetDefaultDisease() == disease)
                            });
                        }
                    }
                }
            }

            return(null);
        }