public (V FirstCarNextFlag, V SecondCarNextFlag) GetNextFlagsFor(RaceState state)
        {
            var firstCar  = state.FirstCar;
            var secondCar = state.SecondCar;

            var flag1 = state.GetNextFlag();
            var flag2 = state.GetNextFlag(1);

            var dist1to1 = flag1.DistTo(firstCar.Pos + firstCar.V);
            var dist2to1 = flag1.DistTo(secondCar.Pos + secondCar.V);

            //правило: если одна из машинок ближе к обоим флагам, то она назначается на первый

            if (dist1to1 <= dist2to1)
            {
                return(flag1, flag2);
            }

            return(flag2, flag1);
        }
        public (V FirstCarNextFlag, V SecondCarNextFlag) GetNextFlagsFor(RaceState state)
        {
            V   flag      = null;
            var maxDist   = 0.0;
            var flagIndex = 0;

            for (var i = 1; i < state.Track.Flags.Count; i++)
            {
                var curF1 = state.Track.Flags[i];
                var curF2 = i == state.Track.Flags.Count - 1 ? state.Track.Flags[0] : state.Track.Flags[i + 1];

                var curDist = curF1.DistTo(curF2);
                if (curDist > maxDist)
                {
                    maxDist   = curDist;
                    flag      = curF2;
                    flagIndex = i + 1;
                }
            }

            var nextFlag = state.GetNextFlag();

            if (state.FlagsTaken % state.Track.Flags.Count >= flagIndex)
            {
                flag = state.Track.Flags[0];
            }

            var dist1ToNextFlag = nextFlag.DistTo(state.FirstCar.Pos + state.FirstCar.V);
            var dist2ToNextFlag = nextFlag.DistTo(state.SecondCar.Pos + state.SecondCar.V);

            if (dist1ToNextFlag < dist2ToNextFlag)
            {
                return(nextFlag, flag);
            }

            return(flag, nextFlag);
        }