예제 #1
0
        public void TestInitialize()
        {
            lane  = new Lane(FieldTest.CELLS_NUM);
            unit1 = new Unit(UnitType.SWORDSMEN, PlayerType.PLAYER1);
            unit2 = new Unit(UnitType.SWORDSMEN, PlayerType.PLAYER2);

            lane.AddUnit(unit1);
            lane.AddUnit(unit2);
        }
예제 #2
0
파일: Utilites.cs 프로젝트: haivido/Vido
        public static bool Entry(IDatabase database, string cardId, ILane lane)
        {
            var time = DateTime.Now;
              var dailyDirectoryName = DailyDirectoryName(time);

              if (!Directory.Exists(dailyDirectoryName))
              {
            Directory.CreateDirectory(dailyDirectoryName);
              }

              var prefixFileName = dailyDirectoryName +
            Path.DirectorySeparatorChar +
            lane.Name.ToUpper() + time.ToString("HHmmss") + EntryString;

              var plateNumber = string.Empty;
              var plateFileName = string.Empty;
              var faceFileName = string.Empty;

              if (lane.PlateCamera != null)
              {
            plateFileName = prefixFileName + SuffixPlateFileName;
            if (!TakeAndSave(lane.PlateCamera, plateFileName))
            {
              // Error
            }

            // Todo: Get Plate number.
              }
              else
              {
            // Error
              }

              if (lane.FaceCamera != null)
              {
            faceFileName = prefixFileName + SuffixFaceFileName;
            if (!TakeAndSave(lane.FaceCamera, faceFileName))
            {
              faceFileName = string.Empty;
            }
              }

              if (CanEntry(database, cardId, plateNumber))
              {
            var paramater = new Dictionary<string, string>();
            paramater["CardId"] = cardId;
            paramater["EntryTime"] = time.ToString();
            paramater["EntryPlateNumber"] = plateNumber;
            paramater["EntryPlateImage"] = plateFileName.Remove(0, RootImageDirectoryName.Length);
            paramater["EntryFaceImage"] = faceFileName.Remove(0, RootImageDirectoryName.Length);

            return (database.Insert("EntryExit", paramater));
              }

              return (false);
        }
예제 #3
0
        public void TestScoreAndDespawn()
        {
            lane = new Lane(FieldTest.CELLS_NUM);
            lane.AddUnit(unit1);

            for (int i = 0; i < FieldTest.CELLS_NUM; i++)
            {
                Assert.AreEqual(i, lane.GetUnits()[unit1]);
                lane.Update();
            }

            Assert.AreEqual(1, lane.GetScore(PlayerType.PLAYER1));
            Assert.IsFalse(lane.GetUnits().ContainsKey(unit1));
        }
예제 #4
0
 private void Start()
 {
     for (int i = 0; i < _laneAmount; i++)
     {
         ILane lane = Instantiate(_lanePrefab, transform.position + Vector3.forward * _settings.LaneSpacing * i, Quaternion.identity, transform);
         lane.Init(
             $"Lane {(i + 1).ToString()}",
             _settings.ZombiesAmount,
             _settings.ZombiesReward * Mathf.Pow(_settings.ZombiesRewardGrowthLane, i),
             _settings.CopDamage * Mathf.Pow(_settings.CopDamageGrowthLane, i),
             _settings.ZombiesHP * Mathf.Pow(_settings.ZombiesHPGrowthLane, i),
             _settings.ZombiesSpawnDelay,
             _settings.CopAttackDelay * Mathf.Pow(_settings.CopAttackDelayGrowthLane, i),
             _settings.UpgradeCost * Mathf.Pow(_settings.UpgradeCostGrowthLane, i));
     }
 }
예제 #5
0
파일: Form1.cs 프로젝트: haivido/Vido
        public Form1()
        {
            InitializeComponent();

              lane = new Lane()
              {
            Name = "lane 1",
            PlateCamera = new JpegStream()
            {
              Configs = new CaptureConfigs()
              {
            Source = @"http://pasteldth.dyndns.org/cgi-bin/net_jpeg.cgi?ch=2",
            Username = "******",
            Password = "******",
            FrameInterval = 0
              }
            },
            FaceCamera = new MJpegStream()
            {
              Configs = new CaptureConfigs()
              {
            Source = @"http://64.122.208.241:8000/axis-cgi/mjpg/video.cgi?resolution=320x240",
            Username = "******",
            Password = "******",
            FrameInterval = 0
              }
            }
              };

              lane.PlateCamera.NewFrame += capture1_NewFrame;
              lane.FaceCamera.NewFrame += capture2_NewFrame;

              lane.FaceCamera.Start();
              lane.PlateCamera.Start();
              lane.UidDevice = rfidReader;
              rfidReader.Uid += rfidReader_UidRead;
              rawInput = new RawInput.RawInput(Handle);
              rawInput.AddMessageFilter();

              //    rawInput.Keyboard.DevicesChanged += Keyboard_DevicesChanged;
              //    rawInput.Keyboard.EnumerateDevices();

              var s = SerializeToString(lane);
              MessageBox.Show(s);
        }
예제 #6
0
    internal static void Spawn(ILane lane)
    {
        Zombie zombie;

        if (_spawnableZombies.Count > 0)
        {
            zombie = _spawnableZombies.Pop() as Zombie;
            zombie.gameObject.SetActive(true);
        }
        else
        {
            zombie = Instantiate(_zombiePrefabRef, lane.ZombieParent);
        }
        zombie.transform.localRotation = Quaternion.Euler(0, -90, 0);
        zombie.transform.position      = lane.ZombieParent.position
                                         + zombie.transform.forward * UnityEngine.Random.Range(-1f, 1f) + zombie.transform.right * UnityEngine.Random.Range(-1f, 1f);

        _moveBehaviour  = new ZombieMoveBehaviour(zombie);
        _meleeBehaviour = new ZombieMeleeBehaviour(zombie);
        zombie.Init(lane.ZombieHP, _zombieSpeedRef, lane.RewardPerZombie, _moveBehaviour, _meleeBehaviour);

        lane.AddZombie(zombie);
    }
예제 #7
0
        /// <summary>
        /// This method attempts to create the OUTPUT QRACLE table.
        /// If will do nothing but print an error if the table already exists.
        /// </summary>
        //public void TryCreateTbale()
        //{

        //    using (SqlConnection con = new SqlConnection())
        //    {
        //        con.ConnectionString = ConfigurationManager.AppSettings["SqlConnectionString"];
        //        con.Open();
        //        try
        //        {
        //            using (SqlCommand command = new SqlCommand(
        //                "CREATE TBALE OUTPUT1(LocationId INT, CellularTowerId INT, EventType TEXT, EventTimeSpan TEXT)", con))
        //            {
        //                command.ExecuteNonQuery();
        //            }
        //        }
        //        catch
        //        {
        //            Console.WriteLine("Table already exists, or something wrong with the connection");
        //        }
        //    }
        //}

        public void Run()
        {
            vissim = new Vissim();
            ///Load Vissim net work
            vissim.LoadNet(VissimSimulatorFilePath, false);

            //initialize the cellular network
            cellularNetwork.LoadFromFile(CellLinkRelationFilePath, Delimiter);
            ///initialize the table
            //TryCreateTbale();
            //set up the collector threads. For now, only need one thread on this
            //for now, we only need 1 worker to collect the event

            using (StreamWriter writer = new StreamWriter(VissimEventsFilePath))
            {
                CollectorWorker worker        = new CollectorWorker(writer);
                Task            collectorTask = Task.Factory.StartNew(() =>
                {
                    foreach (CellularTowerEvent cEvent in cellularTowerEvents.GetConsumingEnumerable())
                    {
                        worker.Process(cEvent);
                    }
                });

                //simulation thread: including vissim simulation, events generation and detection
                Task simulator = Task.Factory.StartNew(() =>
                {
                    for (int currentTick = 0; currentTick < SimulationTicks; currentTick++)
                    {
                        foreach (IVehicle vehicle in vissim.Net.Vehicles)
                        {
                            //get the vehicle id+
                            int vehicleId = (int)vehicle.AttValue["No"];
                            //get the current vehicle link
                            ILane lane    = vehicle.Lane;
                            string linkId = lane.AttValue["Link"];
                            //Console.WriteLine(string.Format("vehicle {0} at link {1}", vehicleId, linkId));
                            //first check if this vehicle has event
                            if (vehicleEvents.ContainsKey(vehicleId.ToString()))
                            {
                                CellularTowerEvent cEvent = DetectEvent(vehicleId.ToString(), linkId, currentTick);
                                if (cEvent != null)
                                {
                                    cellularTowerEvents.Add(cEvent);
                                }
                            }
                            else //if no vehicle event, that means this is new vehicle entering the vissim network
                            {
                                GenerateEvent(vehicleId.ToString(), currentTick);
                            }
                        }
                        //make the Vissim simulation move forward one tick
                        vissim.Simulation.RunSingleStep();
                    }
                });
                try
                {
                    Task.WaitAll(simulator, collectorTask);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(string.Format("there are some exceptions happened: {0}", ex.Message));
                    throw ex;
                }
            }
        }
예제 #8
0
        /// <summary>
        /// add the link
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBuild_Click(object sender, EventArgs e)
        {
            MapLinks links = new MapLinks("[[121.2133820,31.285886],[121.2139638, 31.2865935]]", "[[121.2141660, 31.2866371]," +
                                          "[121.2160953, 31.2854671],[121.2163246, 31.2852151],[121.2163601, 31.2851393],[121.2163758, 31.2850646],[121.2163814, 31.2848733]," +
                                          " [121.2163925, 31.2840516],[121.2163873, 31.2839563],[121.2163765, 31.2838958],[121.2163440, 31.2837675],[121.2161880, 31.2834861]," +
                                          "[121.2152711, 31.2823441],[121.2151738, 31.2822313],[121.2150853, 31.2821396],[121.2149775, 31.2820633],[121.2148896, 31.2820111]," +
                                          "[121.2144256, 31.2818966],[121.2142475, 31.2819505],[121.2142216, 31.2819903],[121.2142148, 31.2820574],[121.2142168, 31.2821373]," +
                                          "[121.2142148, 31.2846036],[121.2142126, 31.2847458],[121.2141895, 31.2849460],[121.2140973, 31.2851871],[121.2138221, 31.2854833], " +
                                          "[121.2133835, 31.2857569]]", "[[121.2133550, 31.2856843],[121.2137920, 31.2854163],[121.2139446, 31.2852710],[121.2140375, 31.2851205]," +
                                          "[121.2141033, 31.2849395],[121.2141205, 31.2848163],[121.2141286, 31.2820856],[121.2141338, 31.2820461],[121.2141946, 31.2819106]," +
                                          "[121.2142898, 31.2818595],[121.2144180, 31.2818543],[121.2148526, 31.2819563],[121.2149904, 31.2820246],[121.2150815, 31.2820901]," +
                                          "[121.2151610, 31.2821546],[121.2152441, 31.2822470],[121.2162668, 31.2835153],[121.2163321, 31.2836178],[121.2163766, 31.2837161]," +
                                          "[121.2164089, 31.2838223],[121.2164310, 31.2839981],[121.2164246, 31.2849813],[121.2164263, 31.2850688],[121.2163846, 31.2852246]," +
                                          "[121.2163203, 31.2853258],[121.2162000, 31.2854486],[121.2141725, 31.2866793]]", "[[121.2139551,31.2866538],[121.2133464, 31.2858938]]",
                                          "[[121.2122708,31.2863276],[121.2131735, 31.2857866]]", "[[121.2132083,31.2858663],[121.2123150, 31.2864003]]");

            List <MapConnector> connectors = new List <MapConnector>();

            connectors.Add(new MapConnector(1, 1, 2, 1, 1, "[[121.2139761, 31.2866085],[121.2140386, 31.2866530],[121.2141176, 31.2866628]]"));
            connectors.Add(new MapConnector(2, 1, 1, 1, 1, "[[121.2133590, 31.2857876],[121.2133515, 31.2858090],[121.2133551, 31.2858465]]"));
            connectors.Add(new MapConnector(2, 1, 6, 1, 1, "[[121.2133313, 31.2857863],[121.2133009, 31.2858019],[121.2132711, 31.2858210]]"));
            connectors.Add(new MapConnector(3, 1, 4, 1, 1, "[[121.2141185, 31.2867008],[121.2140918, 31.2867055],[121.2140635, 31.2867065]]"));
            connectors.Add(new MapConnector(4, 1, 6, 1, 1, "[[121.2133193, 31.2858745],[121.2132875, 31.2858613],[121.2132538, 31.2858563]]"));
            connectors.Add(new MapConnector(4, 1, 3, 1, 1, "[[121.2132968, 31.2858205],[121.2132896, 31.2857678],[121.2133031, 31.2857371]]"));
            connectors.Add(new MapConnector(5, 1, 1, 1, 1, "[[121.2132478, 31.2857801],[121.2132943, 31.2857968],[121.2133323, 31.2858291]]"));
            connectors.Add(new MapConnector(5, 1, 3, 1, 1, "[[121.2132310, 31.2857565],[121.2132573, 31.2857410],[121.2132801, 31.2857261]]"));

            try
            {
                ILinkContainer linkCtn = VissimSim.net.Links;
                foreach (ILink link in linkCtn)
                {
                    linkCtn.RemoveLink(link);
                }

                for (int i = 0; i < links.Links.Count(); i++)
                {
                    object[] array = { 3.5 };
                    string   str   = "LineString(";
                    for (int j = 0; j < links.Links[i].nodes.Count(); j++)
                    {
                        List <double> loc1 = Moc(links.Links[i].nodes[j].gpsPot);
                        str += Convert.ToString(loc1[0]) + ' ' + Convert.ToString(loc1[1]) + ',';
                    }
                    str  = str.Remove(str.Length - 1, 1);
                    str += ")";

                    linkCtn.AddLink(links.Links[i].LinkNo, str, array);

                    Thread.Sleep(500); //sleep 500ms
                }


                for (int i = 0; i < connectors.Count(); i++)
                {
                    ILane  laneFrom = linkCtn.ItemByKey[connectors[i].FLinkId].Lanes.ItemByKey[connectors[i].FLaneId];
                    ILane  laneEnd  = linkCtn.ItemByKey[connectors[i].TLinkId].Lanes.ItemByKey[connectors[i].TLaneId];
                    double fromPos  = linkCtn.ItemByKey[connectors[i].FLinkId].AttValue["Length2D"];
                    double toPos    = 0;

                    string str = "LineString(";
                    for (int j = 0; j < connectors[i].link.nodes.Count(); j++)
                    {
                        List <double> loc1 = Moc(connectors[i].link.nodes[j].gpsPot);
                        str += Convert.ToString(loc1[0]) + ' ' + Convert.ToString(loc1[1]) + ',';
                    }
                    str  = str.Remove(str.Length - 1, 1);
                    str += ")";

                    linkCtn.AddConnector(Convert.ToInt32(connectors[i].FLinkId.ToString() + "000" + connectors[i].TLinkId.ToString()), laneFrom, fromPos, laneEnd, toPos, connectors[i].LaneNum, str);

                    Thread.Sleep(500); //sleep 500ms
                }

                foreach (ILink link in linkCtn)
                {
                    if (Convert.ToBoolean(link.AttValue["IsConn"]))
                    {
                        link.RecalculateSpline();
                    }
                }
            }
            catch (Exception ex)
            {
                VissimSim.vissim.Exit();
                MessageBox.Show(ex.ToString());
            }
            //object[] array = { 3.5, 3.5 };
            //    Console.WriteLine(array[0].ToString());
            //    ILink link = linkCtn.AddLink(42, "LINESTRING(1 1,2 2)", array);
            //    Console.WriteLine(Convert.ToString(link.AttValue["FromPos"]));
        }
예제 #9
0
 internal void Init(ILane lane)
 {
     gameObject.SetActive(true);
     _currentLane = lane;
     UpdateText();
 }
예제 #10
0
 public void InitLane()
 {
     laneLenght = 15;
     lane       = new Lane(laneLenght);
     unit1      = new Unit(UnitType.Swordsmen, PlayerType.Player1);
 }
예제 #11
0
 public static void UpgradeLane(ILane lane, Action upgradeLane)
 {
     LaneUpgrade = upgradeLane;
     _upgradePopupRef.Init(lane);
 }
예제 #12
0
        public void Execute()
        {
            //assume there will be 10k static cell phone users
            //treat them as vehicles but not moving
            //IList<Link> links = cellularNetwork.Links.Values.ToList();
            //Random rnd = new Random();
            //for (int i = 1; i < CellPhonePopulation; i++)
            //{
            //    int vehicleId = -1 * i;
            //    //get a random number
            //    int linkIndex = rnd.Next(0, links.Count - 1);
            //    GenerateEvent(vehicleId.ToString(), currentTick, links[linkIndex].LinkId);
            //}

            //warm up
            try
            {
                for (int i = 0; i < 1800; i++)
                {
                    vissim.Simulation.RunSingleStep();
                }

                while (currentTick < SimulationTicks)
                {
                    foreach (IVehicle vehicle in vissim.Net.Vehicles)
                    {
                        //get the vehicle id+
                        int vehicleId = (int)vehicle.AttValue["No"];
                        //get the current vehicle link
                        ILane  lane   = vehicle.Lane;
                        string linkId = lane.AttValue["Link"];
                        //Console.WriteLine(string.Format("vehicle {0} at link {1}", vehicleId, linkId));
                        //first check if this vehicle has event
                        if (vehicleEvents.ContainsKey(vehicleId.ToString()))
                        {
                            foreach (CellularTowerEvent cEvent in DetectEvent(vehicleId.ToString(), linkId, currentTick))
                            {
                                if (cEvent != null)
                                {
                                    cellularTowerEvents.Add(cEvent);
                                }
                            }
                        }
                        else //if no vehicle event, that means this is new vehicle entering the vissim network
                        {
                            GenerateEvent(vehicleId.ToString(), currentTick);
                        }
                    }

                    //we should also check all pre-defined vehicle events
                    //for (int i = 1; i < CellPhonePopulation; i++)
                    //{
                    //    int vehicleId = -1 * i;
                    //    if (vehicleEvents.ContainsKey(vehicleId.ToString()))
                    //    {
                    //        foreach (CellularTowerEvent cEvent in DetectEvent(vehicleId.ToString(), null, currentTick))
                    //        {
                    //            if (cEvent != null)
                    //            {
                    //                cellularTowerEvents.Add(cEvent);
                    //            }
                    //        }
                    //    }
                    //}

                    //make the Vissim simulation move forward one tick
                    for (int i = 0; i < DetectionInterval; i++)
                    {
                        vissim.Simulation.RunSingleStep();
                        Interlocked.Increment(ref currentTick);
                    }
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                //set the cancellation token to stop all tasks
                tokenSource.Cancel();

                //let the blockingqueue to know that we stopped adding new events so it will gracefully exit
                cellularTowerEvents.CompleteAdding();
            }
        }