예제 #1
0
        private void CalculateInvincibility(
            IOrderedEnumerable<Tuple<PlayCardEvent, Card>> cardsPlayedOnTeam,
            TeamState teamState)
        {
            teamState.InvincibleToAccidents = IsInvincibleCardEffectPlayedForTeam(
                cardsPlayedOnTeam,
                EffectCardType.ACCIDENT
            );

            teamState.InvincibleToFuel = IsInvincibleCardEffectPlayedForTeam(
                cardsPlayedOnTeam,
                EffectCardType.FUEL
            );

            teamState.InvincibleToTire = IsInvincibleCardEffectPlayedForTeam(
                cardsPlayedOnTeam,
                EffectCardType.TIRE
            );

            teamState.InvinciblePriority = IsInvincibleCardEffectPlayedForTeam(
                cardsPlayedOnTeam,
                EffectCardType.TRAFFIC_LIGHT | EffectCardType.SPEED_LIMIT
            );
        }
예제 #2
0
        private TeamState GetTeamState(Game game, int teamIndex)
        {
            if (teamIndex == 0)
            {
                return null;
            }

            var teams = game.PlayerGame
                .Select(pg => pg.Team)
                .Distinct()
                .ToArray();

            if (!teams.Contains(teamIndex))
            {
                return null;
            }

            var cardsPlayedOnTeam = game.GameEvent
                .Where(ge => ge.Type == GameEventType.PLAY_CARD)
                .Cast<PlayCardEvent>()
                .Where(pc => pc.TargetTeamIndex == teamIndex)
                .ToList()
                .Join(
                    CardDefinitions.Cards,
                    pc => pc.DrawCardEvent.CardIndex,
                    cd => cd.CardId,
                    (pc, cd) => Tuple.Create(pc, cd)
                )
                .OrderByDescending(x => x.Item1.GameEventId);

            var teamState = new TeamState()
            {
                TeamIndex = teamIndex
            };

            teamState.HasAccident = IsTeamUnderEffect(
                cardsPlayedOnTeam,
                EffectCardType.ACCIDENT
            );

            teamState.IsOutOfFuel = IsTeamUnderEffect(
                cardsPlayedOnTeam,
                EffectCardType.FUEL
            );

            teamState.HasFlatTire = IsTeamUnderEffect(
                cardsPlayedOnTeam,
                EffectCardType.TIRE
            );

            teamState.IsUnderSpeedLimit = IsTeamUnderEffect(
                cardsPlayedOnTeam,
                EffectCardType.SPEED_LIMIT
            );

            ComputePlayedCardEffects(cardsPlayedOnTeam, teamState);
            bool accidentPlayed = teamState.PlayedCardEffects.HasFlag(EffectCardType.ACCIDENT);
            bool outOfFuelPlayed = teamState.PlayedCardEffects.HasFlag(EffectCardType.FUEL);
            bool flatTirePlayed = teamState.PlayedCardEffects.HasFlag(EffectCardType.TIRE);

            // Une équipe peut partir si elle a joué un feu vert.
            // Elle doit aussi, pour chaque effet dans [accident, essence, pneus],
            // avoir joué la carte qui la contre si une carte d'effet négatif
            // a été jouée contre l'équipe (les trois ifs).
            //
            // Le booléen détermine aussi si une carte feu vert peut être jouée,
            // les ifs évitent qu'un feu vert peut être joué lorsqu'il y a bris
            // non-réglé.
            //
            teamState.CanGo = IsTeamUnderEffect(
                cardsPlayedOnTeam,
                EffectCardType.TRAFFIC_LIGHT
            );

            if (accidentPlayed)
            {
                if (teamState.HasAccident)
                {
                    teamState.CanGo = false;
                }
            }
            if (outOfFuelPlayed)
            {
                if (teamState.IsOutOfFuel)
                {
                    teamState.CanGo = false;
                }
            }
            if (flatTirePlayed)
            {
                if (teamState.HasFlatTire)
                {
                    teamState.CanGo = false;
                }
            }

            // Une équipe ne peut partir immédiatement après un bris.
            if (teamState.CanGo)
            {
                var cardsPlayedOnTeamWithOrder = cardsPlayedOnTeam
                    .OrderBy(tu => tu.Item1.GameEventId)
                    .Select((tu, inx) => Tuple.Create(tu.Item1, tu.Item2, inx));

                var lastAccident = GetLastCardEffectPlayedForTeam(
                    cardsPlayedOnTeamWithOrder,
                    EffectCardType.ACCIDENT
                );
                var lastFuel = GetLastCardEffectPlayedForTeam(
                    cardsPlayedOnTeamWithOrder,
                    EffectCardType.FUEL
                );
                var lastTire = GetLastCardEffectPlayedForTeam(
                    cardsPlayedOnTeamWithOrder,
                    EffectCardType.TIRE
                );

                var lastLight = GetLastCardEffectPlayedForTeam(
                    cardsPlayedOnTeamWithOrder,
                    EffectCardType.TRAFFIC_LIGHT
                );

                if (lastAccident != null && lastAccident.Item3 > lastLight.Item3)
                {
                    teamState.CanGo = false;
                }
                if (lastFuel != null && lastFuel.Item3 > lastLight.Item3)
                {
                    teamState.CanGo = false;
                }
                if (lastTire != null && lastTire.Item3 > lastLight.Item3)
                {
                    teamState.CanGo = false;
                }
            }

            teamState.IsBrokenDown = teamState.CurrentlyBrokenDown;

            teamState.DistanceTraveled = cardsPlayedOnTeam
                .Where(x => x.Item2.CardType == CardType.VALUE)
                .Sum(x => x.Item2.Value);

            CalculateInvincibility(cardsPlayedOnTeam, teamState);

            return teamState;
        }
예제 #3
0
        private void ComputePlayedCardEffects(
            IOrderedEnumerable<Tuple<PlayCardEvent, Card>> cardsPlayedOnTeam,
            TeamState teamState)
        {
            teamState.PlayedCardEffects = EffectCardType.NONE;

            if (IsCardEffectPlayedForTeam(
                cardsPlayedOnTeam,
                EffectCardType.ACCIDENT))
            {
                teamState.PlayedCardEffects |= EffectCardType.ACCIDENT;
            }

            if (IsCardEffectPlayedForTeam(
                cardsPlayedOnTeam,
                EffectCardType.FUEL))
            {
                teamState.PlayedCardEffects |= EffectCardType.FUEL;
            }

            if (IsCardEffectPlayedForTeam(
                cardsPlayedOnTeam,
                EffectCardType.TIRE))
            {
                teamState.PlayedCardEffects |= EffectCardType.TIRE;
            }

            if (IsCardEffectPlayedForTeam(
                cardsPlayedOnTeam,
                EffectCardType.SPEED_LIMIT))
            {
                teamState.PlayedCardEffects |= EffectCardType.SPEED_LIMIT;
            }

            if (IsCardEffectPlayedForTeam(
                cardsPlayedOnTeam,
                EffectCardType.TRAFFIC_LIGHT))
            {
                teamState.PlayedCardEffects |= EffectCardType.TRAFFIC_LIGHT;
            }
        }
예제 #4
0
        private TeamState[] GetTeamsState(Game game)
        {
            var teams = game.PlayerGame
               .Select(pg => pg.Team)
               .Distinct()
               .ToArray();

            TeamState[] teamStates = new TeamState[teams.Length];

            int index = 0;
            foreach (var team in teams)
            {
                teamStates[index] = GetTeamState(game, team);
                index++;
            }

            return teamStates;
        }