Inheritance: MonoBehaviour
        public void TrafficLightShouldProgressAsExpected(Light initialState, Light newState)
        {
            var trafficLight = new TrafficLight(initialState);

            trafficLight.ProgressToState(newState);
            trafficLight.State.Select(x => x).Subscribe(state => { state.Should().Be(newState); });
        }
    public static TrafficLight MakeTheTrafficLight(string dirStr, string name, string stoppedStr, List<TrafficLight> Lights)
    {
        TrafficLight light;
        StreetDirection direction =	 (StreetDirection)Enum.Parse(typeof(StreetDirection), dirStr);
        bool stopped = bool.Parse(stoppedStr);

        GameObject go;
        if(name == "none"){
            go = null;
            light = new TrafficLight(direction, go, stopped);

        }
        else{
            go = GameObject.Find(name);
            int index = DataCalculations.ContainsLight(go, Lights);
            if(index == -1){
                light = new TrafficLight(direction, go, stopped);
                Lights.Add(light);
            }
            else{
                light = Lights[index];
            }
        }

        return light;
    }
Exemple #3
0
    private int _vehiclesNumber; //this is the number of all of the vehciles that would be generated arround the whole game time (should be generated in the game master class)

    #endregion Fields

    #region Constructors

    //constructor
    public Street(int id, Vector3 startPoint, Vector3 endPoint, TrafficLight trafficLight, float stopPosition, float minDistOpenLight, int streetCapacity)
    {
        _id = id;
        _startPoint = startPoint;
        _endPoint = endPoint;
        _myLight = trafficLight;
        _stopPosition = stopPosition;
        _minDistanceToOpenTrafficLight = minDistOpenLight;
        _streetCapacity = streetCapacity;

        _queue = new Queue();
        _vehiclesNumber = 0;
        _existedVehiclesNumberOnYellow = 0;
    }
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            light = new TrafficLight();

            light.TransitionCompleted += HandleTransitionCompleted;

            currentPictureBox = offPictureBox;
            currentUmlPictureBox = umlOffPictureBox;

            Application.ThreadException += Application_ThreadException;
        }
Exemple #5
0
	public static List<LightsGroup> Lights(List<LightsGroup> lightsGroups, List<Street> Streets, List<TrafficLight> Lights){
		List<Street> temp;
		
		lightsGroups = new List<LightsGroup>() ;
		
		List<TrafficLight> lightsList1 = new List<TrafficLight>();
		List<TrafficLight> lightsList2 = new List<TrafficLight>();
		List<TrafficLight> lightsList3 = new List<TrafficLight>();
		List<TrafficLight> lightsList4 = new List<TrafficLight>();	
		
		
		TrafficLight [] temp1 = new TrafficLight[4];
		TrafficLight [] temp2 = new TrafficLight[4];
		TrafficLight [] temp3 = new TrafficLight[4];
		TrafficLight [] temp4 = new TrafficLight[4];
		
		for(int i= 0; i<Lights.Count; i++){
			temp = new List<Street>();
			//group 1
			if(Lights[i].tLight.name == "lightDown4"){
				temp.Add(Streets[10]);
				Lights[i].AttachedStreets = temp;
				temp1[0] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightRight4"){
				temp.Add(Streets[2]);
				Lights[i].AttachedStreets = temp;
				temp1[1] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightUp2"){
				temp.Add(Streets[1]);
				Lights[i].AttachedStreets = temp;
				temp1[2] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightLeft2"){
				temp.Add(Streets[5]);
				Lights[i].AttachedStreets = temp;
				temp1[3] = Lights[i];
			}
			
			//group 2
			else if(Lights[i].tLight.name == "lightDown1"){
				temp.Add(Streets[20]);
				Lights[i].AttachedStreets = temp;
				temp2[0] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightRight1"){
				temp.Add(Streets[14]);
				Lights[i].AttachedStreets = temp;
				temp2[1] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightUp4"){
				temp.Add(Streets[11]);
				Lights[i].AttachedStreets = temp;
				temp2[2] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightLeft3"){
				temp.Add(Streets[17]);
				Lights[i].AttachedStreets = temp;
				temp2[3] = Lights[i];
			}
			
			
			//group 3
			else if(Lights[i].tLight.name == "lightDown3"){
				temp.Add(Streets[12]);
				Lights[i].AttachedStreets = temp;
				temp3[0] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightRight3"){
				temp.Add(Streets[4]);
				Lights[i].AttachedStreets = temp;
				temp3[1] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightUp1"){
				temp.Add(Streets[7]);
				Lights[i].AttachedStreets = temp;
				temp3[2] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightLeft4"){
				temp.Add(Streets[9]);
				Lights[i].AttachedStreets = temp;
				temp3[3] = Lights[i];
			}
			//group 4
			else if(Lights[i].tLight.name == "lightDown2"){
				temp.Add(Streets[22]);
				Lights[i].AttachedStreets = temp;
				temp4[0] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightRight2"){
				temp.Add(Streets[16]);
				Lights[i].AttachedStreets = temp;
				temp4[1] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightUp3"){
				temp.Add(Streets[13]);
				Lights[i].AttachedStreets = temp;
				temp4[2] = Lights[i];
			}
			else if(Lights[i].tLight.name == "lightLeft1"){
				temp.Add(Streets[19]);
				Lights[i].AttachedStreets = temp;
				temp4[3] = Lights[i];
			}
			
		}
		
		for(int i =0 ; i<4; i++){
			lightsList1.Add(temp1[i]);
			lightsList2.Add(temp2[i]);
			lightsList3.Add(temp3[i]);
			lightsList4.Add(temp4[i]);
		}
		
		lightsGroups.Add(new LightsGroup(lightsList1));
		lightsGroups.Add(new LightsGroup(lightsList2));
		lightsGroups.Add(new LightsGroup(lightsList3));
		lightsGroups.Add(new LightsGroup(lightsList4));
		
		return lightsGroups;
	}
    public void InitStreetAndVehicleAttributes()
    {
        _path			= myVehicle.MyPath;
        _street 		= myVehicle.CurrentStreet;
        _direction 		= myVehicle.CurrentDirection;
        speed 			= myVehicle.Speed;
        _size 			= myVehicle.Size;
        vehType			= myVehicle.Type;

        _light 			= _street.StreetLight;
        _stopPosition 	= _street.StopPosition;
        _endPosition 	= _street.EndPoint;
        _myQueue 		= _street.StrQueue;

        _nextDirection = myVehicle.NextStreet.StreetLight.Type;

        myRayCastRange = Globals.RAY_CAST_RANGE + _size;
        if(vehType == VehicleType.Taxi){
            taxiStops = Taxi.SetGetTaxiRandomStops(gameMasterScript.gameTime -5, gameMasterScript.gameTime-10);
        }
    }
    private void ResetVehicleAttributes()
    {
        if(myVehicle.NextStreet != null){
            myVehicle.CurrentStreet = myVehicle.NextStreet;
            myVehicle.CurrentDirection = myVehicle.CurrentStreet.StreetLight.Type;
            myVehicle.CurrentStreetNumber ++;

            //Debug.Log(myVehicle.CurrentStreetNumber);

            if(myVehicle.CurrentStreetNumber+1 != _path.PathStreets.Count ){
                myVehicle.NextStreet =_path.PathStreets[myVehicle.CurrentStreetNumber+1];
                _nextDirection = myVehicle.NextStreet.StreetLight.Type;
            }
            else{
                myVehicle.NextStreet = null;
        //				Debug.Log("next street is null " );
            }

            _street = myVehicle.CurrentStreet;
            _direction 		= myVehicle.CurrentDirection;

            _street.VehiclesNumber++;

            _light 			= _street.StreetLight;
            _stopPosition 	= _street.StopPosition;
            _endPosition 	= _street.EndPoint;
            _myQueue 		= _street.StrQueue;

            dequeued = false;
            enqueued = false;
            passed = false;
            stoppingTimerforAnger = 0;
            stoppingTimerforAngerSet = false;
            satisfyAdjustedOnTime = false;
            angerMount = 0.5f;
            dist = 0;
        }
    }
 public void ForSafetyATrafficLightShouldDefaultToRed()
 {
     var trafficLight = new TrafficLight();
     trafficLight.State.Select(x => x).Subscribe(state => { state.Should().Be(Light.Red); });
 }
Exemple #9
0
        public void ProcessEvent(Event nextEvent, double time)
        {
            switch (nextEvent.EventType)
            {
            case EventType.TrafficLightChange:
            {
                // Dodaj sledecu promenu semafora
                AddEvent(new Event(EventType.TrafficLightChange, time + 60.0));

                // Dodaj dogadjaj za pesake
                AddEvent(new Event(EventType.StartCrossing, time));

                // Dodaj dogadjaj za vozila
                AddEvent(new Event(EventType.EnterIntersection, time));

                // Promeni svetlo na semaforu
                if (trafficLight == TrafficLight.EW)
                {
                    trafficLight = TrafficLight.NS;
                }
                else
                {
                    trafficLight = TrafficLight.EW;
                }
            }
            break;

            case EventType.Arrival:
            {
                // Uvek dodaj novi dolazak
                AddEvent(new Event(EventType.Arrival, time + arrival.NextValue()));

                TravelType       traveler  = travelers.NextValue();
                IntersectionPart direction = intersectionPart.NextValue();

                if (traveler == TravelType.Pedestrian)
                {
                    // Dodaj ga u red cekanja
                    pedestrianQue[(int)direction].Enqueue(time);

                    // Proveri da li je novi red veci od poslednjeg najveceg
                    if (pedestrianQue[(int)direction].Count > largestPedestrianQue)
                    {
                        largestPedestrianQue = pedestrianQue[(int)direction].Count;
                    }

                    // Zabelezi statistiku reda cekanja
                    pedestrianQueLength[(int)direction].Add(new DoublePair(time, pedestrianQue[(int)direction].Count));

                    // Proveri semafor, zatim gledaj suprotne pesacke
                    if ((int)trafficLight != (int)direction / 2)
                    {
                        // Dodaj dogadjaj za prelazenje
                        AddEvent(new Event(EventType.StartCrossing, time));
                    }
                }
                else
                {
                    // Dodaj vozila u red cekanja
                    vehicleQue[(int)direction].Enqueue(time);

                    // Zabelezi statistiku reda cekanja
                    vehicleQueLength[(int)direction].Add(new DoublePair(time, vehicleQue[(int)direction].Count));

                    // Proveri da li je novi red veci od poslednjeg najveceg
                    if (vehicleQue[(int)direction].Count > largestVehicleQue)
                    {
                        largestVehicleQue = vehicleQue[(int)direction].Count;
                    }

                    // Proveri semafor
                    if ((int)trafficLight == (int)direction / 2)
                    {
                        if (intersectionInUse[(int)direction] == VehicleDirection.Free)
                        {
                            // Dodaj dogadjaj za prelazenje
                            AddEvent(new Event(EventType.EnterIntersection, time));
                        }
                    }
                }
            }
            break;

            case EventType.StartCrossing:
            {
                for (int i = 0; i < 2; i++)
                {
                    // Zapad i istok su otvoreni pesacki kada je semafor za automobile sever i jug
                    int direction = trafficLight == TrafficLight.NS ? 2 + i : i;

                    // Pokreni sve pesake za North tj. East
                    while (pedestrianQue[direction].Count != 0)
                    {
                        double timeOfArrival = pedestrianQue[direction].Dequeue();

                        // Zabelezi koliko je cekao pesak
                        pedestrianWait.Add(time - timeOfArrival);

                        // Vreme da predje
                        double timeToCross = time + pedestrianService.NextValue();

                        // Dodaj dogadjaj da je pesak zavrsio prelazenje
                        AddEvent(new Event(EventType.EndCrossing, timeToCross));

                        // Zauzmi pesacki
                        peopleOnCrossing[direction]++;
                        peopleCrossing.Add(new Tuple <double, int>(timeToCross, direction));
                        crossingInUse[direction] = true;
                    }
                    // Zabelezi da su svi pesaci prosli
                    pedestrianQueLength[direction].Add(new DoublePair(time, 0));
                }
                // Sortiraj pesake od najranije do najkasnijeg
                peopleCrossing.Sort();
            }
            break;

            case EventType.EndCrossing:
            {
                // Pronadji koji prelaz je presao pesak
                int direction = peopleCrossing[0].Item2;

                // Oslobodi prelaz ako nema pesaka na njemu
                peopleOnCrossing[direction]--;
                if (peopleOnCrossing[direction] == 0)
                {
                    crossingInUse[direction] = false;

                    // Ako se oslobodio pesacki, obavesti vozila ako postoje, prvo levo iza, ako nema, onda desno iza
                    int left = WhichWayIsLeft(direction);
                    // Proveri da li vozilo ide desno
                    if (intersectionInUse[left] == VehicleDirection.Right)
                    {
                        // Pronadji da li lokacija postoji u listi servisiranja
                        if (vehicleCrossing.Select((t) => t.Item2).ToArray().Contains(left) == false)
                        {
                            AddEvent(new Event(EventType.ExitIntersection, time));
                            vehicleCrossing.Add(new Tuple <double, int>(time, left));
                            vehicleCrossing.Sort();
                        }
                    }
                    // Ako nema vozila koje skrece desno, proveri da li je ta pozicija prazna
                    else if (intersectionInUse[left] == VehicleDirection.Free)
                    {
                        int right = WhichWayIsRight(direction);
                        // Proveri da li vozilo ide levo
                        if (intersectionInUse[right] == VehicleDirection.Left)
                        {
                            // Pronadji da li lokacija postoji u listi servisiranja
                            if (vehicleCrossing.Select((t) => t.Item2).ToArray().Contains(right) == false)
                            {
                                AddEvent(new Event(EventType.ExitIntersection, time));
                                vehicleCrossing.Add(new Tuple <double, int>(time, right));
                                vehicleCrossing.Sort();
                            }
                        }
                    }
                }

                // Ukloni tog pesaka iz liste
                peopleCrossing.RemoveAt(0);
            }
            break;

            case EventType.EnterIntersection:
            {
                for (int i = 0; i < 2; i++)
                {
                    // Sever/Jug(0) -> Sever(0), Jug(1), Istok/Zapad(1) -> Istok(2), Zapad(3)
                    int direction = ((int)trafficLight * 2) + i;

                    if (intersectionInUse[direction] == VehicleDirection.Free)
                    {
                        if (vehicleQue[direction].Count != 0)
                        {
                            double timeToCross   = vehicleService.NextValue();
                            double timeOfArrival = vehicleQue[direction].Dequeue();

                            // Zabelezi koliko je cekao pesak
                            vehicleWait.Add(time - timeOfArrival);

                            // Obelezio deo raskrsnice kao zauzet
                            intersectionInUse[direction] = vehicleDirection.NextValue();

                            // Zabelezi statistiku reda cekanja
                            vehicleQueLength[(int)direction].Add(new DoublePair(time, vehicleQue[(int)direction].Count));

                            // Dodaj dogadjaj za izlazak iz raskrsnice
                            AddEvent(new Event(EventType.ExitIntersection, time + timeToCross));

                            // Kada se desi dogadjaj za izlazak iz raskrsnice, treba da se zna koji je najraniji za izlazak
                            vehicleCrossing.Add(new Tuple <double, int>(timeToCross, (int)direction));
                            vehicleCrossing.Sort();
                        }
                    }
                }
            }
            break;

            case EventType.ExitIntersection:
            {
                int direction = vehicleCrossing[0].Item2;
                vehicleCrossing.RemoveAt(0);
                int across = WhichWayIsAcross(direction);

                // Za slucaj da se semafor promenio u medjuvremenu,
                // oslobodi ovaj deo raskrsnice kome je crveno svetlo, a usli su u raskrsnicu
                if ((int)trafficLight != direction / 2)
                {
                    intersectionInUse[direction] = VehicleDirection.Free;
                }
                else
                {
                    // Proveri u kom pravcu ide vozilo
                    if (intersectionInUse[direction] == VehicleDirection.Straight)
                    {
                        intersectionInUse[direction] = VehicleDirection.Free;
                        if (vehicleQue[direction].Count != 0)
                        {
                            AddEvent(new Event(EventType.EnterIntersection, time));
                        }
                        else
                        {
                            if (intersectionInUse[across] == VehicleDirection.Left)
                            {
                                if (vehicleCrossing.Select((t) => t.Item2).ToArray().Contains(across) == false)
                                {
                                    AddEvent(new Event(EventType.ExitIntersection, time));
                                    vehicleCrossing.Add(new Tuple <double, int>(time, across));
                                    vehicleCrossing.Sort();
                                }
                            }
                        }
                    }
                    else if (intersectionInUse[direction] == VehicleDirection.Right)
                    {
                        int right = WhichWayIsRight(direction);
                        if (crossingInUse[right] == false)
                        {
                            intersectionInUse[direction] = VehicleDirection.Free;
                            if (vehicleQue[direction].Count != 0)
                            {
                                AddEvent(new Event(EventType.EnterIntersection, time));
                            }
                            else
                            {
                                if (intersectionInUse[across] == VehicleDirection.Left)
                                {
                                    if (vehicleCrossing.Select((t) => t.Item2).ToArray().Contains(across) == false)
                                    {
                                        AddEvent(new Event(EventType.ExitIntersection, time));
                                        vehicleCrossing.Add(new Tuple <double, int>(time, across));
                                        vehicleCrossing.Sort();
                                    }
                                }
                            }
                        }
                    }
                    else if (intersectionInUse[direction] == VehicleDirection.Left)
                    {
                        int left = WhichWayIsLeft(direction);

                        // Vozilo moze da skrene levo ako vozilo prekoputa skrece levo
                        // ili ako je prekoputa prazno i niko ne ide u susret
                        if ((intersectionInUse[across] == VehicleDirection.Left) ||
                            ((intersectionInUse[across] == VehicleDirection.Free) && (vehicleQue[across].Count == 0)))
                        {
                            if (crossingInUse[left] == false)
                            {
                                intersectionInUse[direction] = VehicleDirection.Free;
                                if (vehicleQue[direction].Count != 0)
                                {
                                    AddEvent(new Event(EventType.EnterIntersection, time));
                                }
                                else
                                {
                                    if (intersectionInUse[across] == VehicleDirection.Left)
                                    {
                                        if (vehicleCrossing.Select((t) => t.Item2).ToArray().Contains(across) == false)
                                        {
                                            AddEvent(new Event(EventType.ExitIntersection, time));
                                            vehicleCrossing.Add(new Tuple <double, int>(time, across));
                                            vehicleCrossing.Sort();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            break;
            }
        }
 public void Init()
 {
     _mock         = new Mock <Battery>();
     _trafficLight = new TrafficLight(_mock.Object);
 }
Exemple #11
0
        /// <summary>
        /// Updates _conflictPoints array
        /// </summary>
        public void UpdateConflictPoints()
        {
            _conflictPointMatrix = new List <Pair <SpecificIntersection, double> > [_entries.Count, _entries.Count];
            _interimTimes        = new double[_entries.Count, _entries.Count];

            // calculate bounds of intersection
            double minX, maxX, minY, maxY;

            minX = minY = Double.PositiveInfinity;
            maxX = maxY = Double.NegativeInfinity;
            foreach (TimelineEntry te in _entries)
            {
                TrafficLight tl = te as TrafficLight;
                if (tl != null)
                {
                    foreach (LineNode ln in tl.assignedNodes)
                    {
                        minX = Math.Min(minX, Math.Min(ln.position.X, Math.Min(ln.inSlopeAbs.X, ln.outSlopeAbs.X)));
                        maxX = Math.Max(maxX, Math.Max(ln.position.X, Math.Max(ln.inSlopeAbs.X, ln.outSlopeAbs.X)));
                        minY = Math.Min(minY, Math.Min(ln.position.Y, Math.Min(ln.inSlopeAbs.Y, ln.outSlopeAbs.Y)));
                        maxY = Math.Max(maxY, Math.Max(ln.position.Y, Math.Max(ln.inSlopeAbs.Y, ln.outSlopeAbs.Y)));
                    }
                }
            }
            RectangleF bounds = new RectangleF((float)minX, (float)minY, (float)(maxX - minX), (float)(maxY - minY));

            // Gather all intersections from each entry to each entry within bounds
            _conflictPoints = new List <Pair <SpecificIntersection, double> > [_entries.Count];
            for (int i = 0; i < _entries.Count; i++)
            {
                _conflictPoints[i] = new List <Pair <SpecificIntersection, double> >();

                // initialize working stack
                Stack <Pair <NodeConnection, double> > connectionsToLook = new Stack <Pair <NodeConnection, double> >();
                TrafficLight tl = _entries[i] as TrafficLight;
                if (tl != null)
                {
                    foreach (LineNode ln in tl.assignedNodes)
                    {
                        foreach (NodeConnection nc in ln.nextConnections)
                        {
                            connectionsToLook.Push(new Pair <NodeConnection, double>(nc, 0));
                        }
                    }
                }

                // work down stack
                double maxDistance = bounds.Width + bounds.Height;
                while (connectionsToLook.Count > 0)
                {
                    // get NodeConnection-Distance pair
                    Pair <NodeConnection, double> p = connectionsToLook.Pop();

                    // add intersections
                    foreach (Intersection inter in p.Left.intersections)
                    {
                        _conflictPoints[i].Add(new Pair <SpecificIntersection, double>(new SpecificIntersection(p.Left, inter), p.Right + inter.GetMyArcPosition(p.Left)));
                    }

                    // add next connections if within bounds
                    double distance = p.Right + p.Left.lineSegment.length;
                    if (distance < maxDistance && bounds.Contains(p.Left.endNode.position))
                    {
                        if (p.Left.endNode.tLight == null || !_entries.Contains(p.Left.endNode.tLight))
                        {
                            foreach (NodeConnection nc in p.Left.endNode.nextConnections)
                            {
                                connectionsToLook.Push(new Pair <NodeConnection, double>(nc, distance));
                            }
                        }
                    }
                }
            }

            // now build conflictPoints array
            for (int from = 0; from < _entries.Count; from++)
            {
                for (int to = 0; to < _entries.Count; to++)
                {
                    _conflictPointMatrix[from, to] = new List <Pair <SpecificIntersection, double> >();
                    _interimTimes[from, to]        = -1;

                    if (from == to)
                    {
                        continue;
                    }

                    foreach (Pair <SpecificIntersection, double> pFrom in _conflictPoints[from])
                    {
                        foreach (Pair <SpecificIntersection, double> pTo in _conflictPoints[to])
                        {
                            if (pFrom.Left.intersection == pTo.Left.intersection)
                            {
                                _conflictPointMatrix[from, to].Add(pFrom);
                                _interimTimes[from, to] = pFrom.Right / (10 * pFrom.Left.nodeConnection.targetVelocity);
                            }
                        }
                    }
                }
            }
        }
Exemple #12
0
    public void AddDetailes(int greenLight, int rPercentage, int lPercentage, int sPercentage, int carQuantity)
    {
        List<int> Percentages = new List<int>();

        TotalCars = new Car[carQuantity];

        LeftPercentageList = new List<int>();
        RightPercentageList = new List<int>();
        StraightPercentageList = new List<int>();

        for (int i = 1; i < 101; i++)
        {
            Percentages.Add(i);
        }

        while (StraightPercentageList.Count != sPercentage)
        {
            StraightPercentageList.Add(Percentages[0]);
            Percentages.RemoveAt(0);
        }

        while (LeftPercentageList.Count != lPercentage)
        {
            LeftPercentageList.Add(Percentages[0]);
            Percentages.RemoveAt(0);
        }

        while (RightPercentageList.Count != rPercentage)
        {
            RightPercentageList.Add(Percentages[0]);
            Percentages.RemoveAt(0);
        }

        trafficLight = new TrafficLight(this.crossing, greenLight, this.FeederID, simulation);

        switch (this.FeederID)
        {
            case 1:
                for (int i = 0; i < carQuantity; i++)
                {
                    TotalCars[i] = new Car(new Point(-3, 112));
                }
                break;
            case 2:
                for (int i = 0; i < carQuantity; i++)
                {
                    TotalCars[i] = new Car(new Point(82, -3));
                }
                break;
            case 3:
                for (int i = 0; i < carQuantity; i++)
                {
                    TotalCars[i] = new Car(new Point(199, 82));
                }
                break;
            case 4:
                for (int i = 0; i < carQuantity; i++)
                {
                    TotalCars[i] = new Car(new Point(112, 199));
                }
                break;
        }
    }
Exemple #13
0
        private static void MyTrafficLight()
        {
            TrafficLight trafficLight = new TrafficLight();

            trafficLight.StartTrafficLight();
        }
Exemple #14
0
 void Start()
 {
     signal = GetComponent <TrafficLight> ();
 }
Exemple #15
0
        public void ForSafetyATrafficLightShouldDefaultToRed()
        {
            var trafficLight = new TrafficLight();

            trafficLight.State.Select(x => x).Subscribe(state => { state.Should().Be(Light.Red); });
        }
Exemple #16
0
        public object Solve()
        {
            var positions = new Position[2*N, 2*M];

            for (int i = 0; i < 2 * N; i++)
            {
                for( int j=0 ; j< 2*M; j++ )
                {
                    positions[i, j] = new Position();
                }
            }

            positions[0, 0].BestTime = 0;
            positions[0, 0].HasRecentlyChanged = true;

            var links = new List<Link> ();

            for (int n=0; n < N; n++)
            {
                for (int m = 0; m < M; m++)
                {
                    var eSLight = new TrafficLight {
                        OnPeriod = S[n,m],
                        OffPeriod = W[n,m],
                        StartTime = T[n, m]
                    };

                    eSLight.End1 = positions[2 * n, 2 * m];
                    eSLight.End2 = positions[2 * n, 2 * m + 1];

                    var wSLight = (TrafficLight)eSLight.Clone();
                    wSLight.End1 = positions[2 * n + 1 , 2 * m];
                    wSLight.End2 = positions[2 * n + 1, 2 * m + 1];

                    var sWLight =  new TrafficLight {
                        OnPeriod = W[n, m],
                        OffPeriod = S[n, m],
                        StartTime = T[n, m] + S[n, m]
                    };
                    sWLight.End1 = positions[2 * n, 2 * m];
                    sWLight.End2 = positions[2 * n + 1, 2 * m];

                    var nWLight = (TrafficLight)sWLight.Clone();
                    nWLight.End1 = positions[2 * n, 2 * m + 1];
                    nWLight.End2 = positions[2 * n + 1, 2 * m + 1];

                    links.Add(eSLight);
                    links.Add(sWLight);
                    links.Add(wSLight);
                    links.Add(nWLight);
                }
            }

            for (int n = 0; n < N-1; n++)
            {
                for (int m = 0; m < M-1; m++)
                {
                    var sBlock = new Block();
                    sBlock.End1 = positions[2 * n + 1, 2 * m + 1];
                    sBlock.End2 = positions[2 * n + 1, 2 * m + 2];

                    var wBlock = new Block();
                    sBlock.End1 = positions[2 * n + 1, 2 * m + 1];
                    sBlock.End2 = positions[2 * n + 2, 2 * m + 1];

                    links.Add(sBlock);
                    links.Add(wBlock);
                }
            }

            foreach (var link in links)
            {
                link.End1.Neighboors.Add(Tuple.Create(link, link.End2));
                link.End2.Neighboors.Add(Tuple.Create(link, link.End1));
            }

            bool changedSomething = true;

            while (changedSomething)
            {
                changedSomething = false;

                foreach (var pos in positions)
                {
                    if (pos.Process())
                        changedSomething = true;
                }
            }

            return positions[2 * N - 1, 2 * M - 1].BestTime;
        }
        private void addTrafficLightButton_Click(object sender, EventArgs e)
        {
            TimelineGroup parentGroup = groupComboBox.SelectedItem as TimelineGroup;

            if (parentGroup != null)
                {
                TimelineEntry te = new TrafficLight();
                te.parentGroup = parentGroup;
                te.name = trafficLightNameEdit.Text;
                if (te.name == "")
                    {
                    te.name = "LSA " + (parentGroup.entries.Count + 1).ToString();
                    }
                steuerung.AddEntry(te);
                }
            else
                {
                MessageBox.Show("Keine Gruppe ausgewählt!");
                }
        }
        static void Main(string[] args)
        {
            #region Init
            TrafficLight trafficLight = new TrafficLight();
            Car          Auto1        = new Car();
            Car          Auto2        = new Car();
            Motorcycle   Motorrad     = new Motorcycle();
            #endregion

            #region ExampleOne
            Console.WriteLine("Blaues Auto fährt Ampel an. registerObserver() wird aufgerufen");
            Console.WriteLine("Ampel ist " + trafficLight.getState());
            trafficLight.registerObserver(Auto1);
            Console.ReadKey();
            Console.WriteLine("Anzahl Beobachter = " + trafficLight.observers.Count);
            Console.ReadKey();
            #endregion

            trafficLight.setState(false);
            Console.WriteLine("Ampel schaltet auf " + trafficLight.getState() + ". setState() wird aufgerufen.");
            Console.ReadKey();

            #region ExampleTwo
            Console.WriteLine("Gelbes Auto und Motorrad fahren Ampel an. registerObserver() wird aufgerufen");
            trafficLight.registerObserver(Auto2);
            trafficLight.registerObserver(Motorrad);
            Console.ReadKey();

            Console.WriteLine("Anzahl Beobachter = " + trafficLight.observers.Count);
            Console.ReadKey();

            trafficLight.setState(true);
            Console.WriteLine("Ampel schaltet auf " + trafficLight.getState() + ". setState() wird aufgerufen.");
            Console.ReadKey();

            Console.WriteLine("Auto2 fährt = " + Auto2.isDriving + ". unregisterObserver() wird aufgerufen.");
            Console.WriteLine("Motorrad fährt = " + Motorrad.isDriving + ". unregisterObserver() wird aufgerufen.");
            trafficLight.unregisterObserver(Auto2);
            trafficLight.unregisterObserver(Motorrad);
            Console.ReadKey();
            Console.WriteLine("Anzahl Beobachter = " + trafficLight.observers.Count);
            Console.ReadKey();

            #endregion

            trafficLight.setState(false);
            Console.WriteLine("Ampel schaltet auf " + trafficLight.getState() + ". setState() wird aufgerufen.");
            Console.ReadKey();

            #region ExampleThree
            for (int a = 0; a < 20; a++)
            {
                Car car = new Car();
                trafficLight.registerObserver(car);
            }
            trafficLight.setState(true);
            for (var i = 0; i < 5; i++)
            {
                trafficLight.unregisterObserver(trafficLight.observers[i]);
            }
            #endregion
        }