Exemplo n.º 1
0
        private void CombineTiles(IReadOnlyCollection <Tile> allOptions)
        {
            int size         = (int)Math.Sqrt(allOptions.Count / 16);
            var combineTiles = new CombineHelper[size, size];

            var usedIds = new HashSet <int>();

            for (int i = 0; i < size * size; i++)
            {
                int yPos = i / size;
                int xPos = i % size;
                combineTiles[yPos, xPos] ??= new CombineHelper();
                var helper = combineTiles[yPos, xPos];

                if (helper.Tile != null)
                {
                    usedIds.Remove(helper.Tile.Id);
                    helper.AlreadyUsed.Add(helper.Tile);
                    helper.Tile = null;
                }

                var query = allOptions
                            .Where(tile => !usedIds.Contains(tile.Id))
                            .Where(tile => !helper.AlreadyUsed.Contains(tile));

                if (xPos > 0)
                {
                    var lastTile = combineTiles[yPos, xPos - 1].Tile;
                    query = query.Where(tile => tile.LeftEdge == lastTile.RightEdge);
                }

                if (yPos > 0)
                {
                    var aboveTile = combineTiles[yPos - 1, xPos].Tile;
                    query = query.Where(tile => tile.TopEdge == aboveTile.BottomEdge);
                }

                var thisTile = query
                               .FirstOrDefault();

                if (thisTile == null)
                {
                    i -= 2;
                    continue;
                }

                helper.Tile = thisTile;
                usedIds.Add(thisTile.Id);
            }


            tiles = new Tile[size, size];
            for (int i = 0; i < size; ++i)
            {
                for (int j = 0; j < size; ++j)
                {
                    tiles[i, j] = combineTiles[i, j].Tile;
                }
            }
        }
Exemplo n.º 2
0
        public void SetMainRoute_Test()
        {
            var trip = TripMaker.GetTrip();

            trip = CombineHelper.SetMainRoute(trip);

            Assert.IsTrue(trip.MainRoute);
            Assert.IsTrue(trip.Stops.First().MainTrip);
        }
Exemplo n.º 3
0
        public void GetMainRoute_Start_Test()
        {
            var list = TripMaker.GetOrganizedTripList(true);
            var ch   = new CombineHelper(new StopComparer());

            var tripToCheck = ch.GetMainRoute(list, TripKey.START);

            Assert.IsTrue(tripToCheck.MainRoute);
        }
Exemplo n.º 4
0
        static async void ConfigureUpdateDataService()
        {
            var documentStoreRepository   = new DocumentStoreRepository();
            var publicTransportRepository = new PublicTransportRepository();

            UpdateDataService.DocumentStoreRepository = documentStoreRepository;

            var delayJsonService = new DelayJsonService(publicTransportRepository);

            DelaysHub.DelayService = new DelayService(delayJsonService);
            DelayService.DocumentStoreRepository = documentStoreRepository;

            var timeService = new DCNC.Service.PublicTransport.Time.TimeService();

            var stopComparer       = new StopComparer();
            var combineHelper      = new CombineHelper(stopComparer);
            var combiner           = new Combiner(combineHelper);
            var combineTripService = new CombineTripService(combiner);

            var joinTripMappingService = new JoinTripMappingService();

            var organizer  = new Organizer();
            var stopHelper = new StopHelper();
            var tripsWithBusStopsService = new TripsWithBusStopsService(organizer, stopHelper);
            var joiner = new Joiner(combineTripService, joinTripMappingService, tripsWithBusStopsService);

            var grouper = new Grouper();

            var tripService         = new TripService(documentStoreRepository, publicTransportRepository);
            var busStopService      = new BusStopService(documentStoreRepository, publicTransportRepository);
            var busLineService      = new BusLineService(documentStoreRepository, publicTransportRepository);
            var expeditionService   = new ExpeditionService(documentStoreRepository, publicTransportRepository);
            var stopInTripService   = new StopInTripService(documentStoreRepository, publicTransportRepository);
            var busStopModelService = new BusStopModelService();

            var updateServiceHelper = new UpdateServiceHelper(joiner, grouper, timeService, tripService, busStopService,
                                                              busLineService, expeditionService, stopInTripService, busStopModelService, documentStoreRepository);

            documentStoreRepository.DeleteAllTimeTableJsons();
            await UpdateDataService.Init(timeService, updateServiceHelper);

            ConfigureServices(documentStoreRepository, publicTransportRepository);
        }
    public static void Test()
    {
        List <int> test = new List <int>();

        for (int i = 0; i < 4; ++i)
        {
            test.Add(i + 1);
        }
        CombineHelper <int> combineHelper = new CombineHelper <int>(test, 2);

        foreach (List <int> oneSet in combineHelper)
        {
            foreach (var iter in oneSet)
            {
                Console.Write(iter + ",");
            }
            Console.WriteLine();
        }

        //Console.ReadLine();
    }
    void Check24(List <Param> inputSet)
    {
        if (inputSet.Count == 2)
        {
            //OneCalculate oneCalculate = new OneCalculate();
            //oneCalculate.m_param1 = inputSet[0];
            //oneCalculate.m_param2 = inputSet[1];

            for (int i = 1; i <= 4; ++i)
            {
                //oneCalculate.m_operator = (Operator)i;
                float  result      = 0;
                string operatorStr = "";

                if (i == 1)
                {
                    operatorStr = "+";
                    result      = inputSet[0].m_param + inputSet[1].m_param;
                }
                else if (i == 2)
                {
                    operatorStr = "-";
                    result      = inputSet[0].m_param - inputSet[1].m_param;
                }
                else if (i == 3)
                {
                    operatorStr = "*";
                    result      = inputSet[0].m_param * inputSet[1].m_param;
                }
                else if (i == 4)
                {
                    operatorStr = "/";
                    if (Math.Abs(inputSet[1].m_param) < 0.01)
                    {
                        result = float.MaxValue;
                    }
                    else
                    {
                        result = inputSet[0].m_param / inputSet[1].m_param;
                    }
                }

                //m_calculateList.Add(oneCalculate);

                if (Math.Abs(result - 24) < 0.01f)
                {
                    //Check24AndGenExpression();
                    string express = "(" + inputSet[0].m_paramSource + operatorStr + inputSet[1].m_paramSource + ")";
                    m_result.Add(express);
                }

                //m_calculateList.RemoveAt(m_calculateList.Count - 1);
            }
        }
        else
        {
            CombineHelper <Param> combineHelper = new CombineHelper <Param>(inputSet, 2);
            foreach (List <Param> oneSet in combineHelper)
            {
                List <Param> lastSet = GetLastSet(inputSet, oneSet);


                //OneCalculate oneCalculate = new OneCalculate();
                //oneCalculate.m_param1 = oneSet[0];
                //oneCalculate.m_param2 = oneSet[1];
                for (int i = 1; i <= 4; ++i)
                {
                    //oneCalculate.m_operator = (Operator)i;
                    Param  result      = new Param();
                    string operatorStr = "";

                    if (i == 1)
                    {
                        operatorStr    = "+";
                        result.m_param = oneSet[0].m_param + oneSet[1].m_param;
                    }
                    else if (i == 2)
                    {
                        operatorStr    = "-";
                        result.m_param = oneSet[0].m_param - oneSet[1].m_param;
                    }
                    else if (i == 3)
                    {
                        operatorStr    = "*";
                        result.m_param = oneSet[0].m_param * oneSet[1].m_param;
                    }
                    else if (i == 4)
                    {
                        operatorStr = "/";
                        if (Math.Abs(oneSet[1].m_param) < 0.01)
                        {
                            result.m_param = float.MaxValue;
                        }
                        else
                        {
                            result.m_param = oneSet[0].m_param / oneSet[1].m_param;
                        }
                    }

                    result.m_paramSource = "(" + oneSet[0].m_paramSource + operatorStr + oneSet[1].m_paramSource + ")";
                    //m_calculateList.Add(oneCalculate);

                    List <Param> newSet = new List <Param>();
                    newSet.Add(result);
                    newSet.AddRange(lastSet);
                    Check24(newSet);

                    //m_calculateList.RemoveAt(m_calculateList.Count - 1);
                }
            }
        }
    }
Exemplo n.º 7
0
 public Combiner(CombineHelper combineHelper)
 {
     _combineHelper = combineHelper;
 }