Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (ringGraphics.roadway[ii].modified == false)
- {
- // if the cell is one of the two at the turning point....
- if ((ii == 0 || ii == ringGraphics.numberCells/2) && ringGraphics.roadway[ii].turningDecision == 0) {
- // decide if the vehicle is going to turn or not
- // if (Math.random() > percentTurn)
- // ringGraphics.roadway[ii].turningDecision = 1;
- // else
- // ringGraphics.roadway[ii].turningDecision = 2;
- if (Math.random() > adaptiveness)
- {
- if (Math.random() > percentTurn)
- ringGraphics.roadway[ii].turningDecision = 1;
- else
- ringGraphics.roadway[ii].turningDecision = 2;
- }
- else
- {
- if (ii == 0)
- {
- if (ringGraphics.currentVehicles1 >= ringGraphics.currentVehicles2)
- {
- if (Math.random() > percentTurn)
- ringGraphics.roadway[ii].turningDecision = 1;
- else
- ringGraphics.roadway[ii].turningDecision = 2;
- }
- else
- ringGraphics.roadway[ii].turningDecision = 1;
- }
- else
- {
- if (ringGraphics.currentVehicles2 >= ringGraphics.currentVehicles1)
- {
- if (Math.random() > percentTurn)
- ringGraphics.roadway[ii].turningDecision = 1;
- else
- ringGraphics.roadway[ii].turningDecision = 2;
- }
- else
- ringGraphics.roadway[ii].turningDecision = 1;
- }
- }
- }
- // logic for if the manual turning button is pushed
- if (ii == 0 && turnLeftToRight == true)
- ringGraphics.roadway[ii].turningDecision = 2;
- if (ii == ringGraphics.numberCells/2 && turnRightToLeft == true)
- ringGraphics.roadway[ii].turningDecision = 2;
- // decide what the destination cell is, depending on if the vehicle is turning or not
- if (ringGraphics.roadway[ii].turningDecision < 2)
- next = ringGraphics.roadway[ii].nextCell;
- else
- next = ringGraphics.roadway[ii].turningCell1;
- // if the cell is occupied, then add this to the time of vehicles in the system
- if (ringGraphics.roadway[ii].occupied == true) {
- vehTimeTraveled++;
- if (ii < ringGraphics.numberCells/2)
- vehTimeTraveled1++;
- else
- vehTimeTraveled2++;
- }
- // move the vehicle if it can and add this movement to the total movement of vehicles in the system
- if (ringGraphics.roadway[ii].occupied == true && ringGraphics.roadway[next].timeEmpty >= minEmptyTime-1 &&
- (ringGraphics.roadway[ii].cycle == 0 || ((ringGraphics.tt+ringGraphics.roadway[ii].offset) % ringGraphics.roadway[ii].cycle < ringGraphics.roadway[ii].green )))
- {
- ringGraphics.roadway[next].occupied = true;
- ringGraphics.roadway[next].timeEmpty = 0;
- ringGraphics.roadway[next].modified = true;
- ringGraphics.roadway[next].turningDecision = 0;
- ringGraphics.roadway[ii].turningDecision = 0;
- ringGraphics.roadway[ii].occupied = false;
- ringGraphics.roadway[ii].timeEmpty = 1;
- ringGraphics.roadway[ii].modified = true;
- vehDistTraveled++;
- if (ii < ringGraphics.numberCells/2)
- vehDistTraveled1++;
- else
- vehDistTraveled2++;
- }
- // if the vehicles change rings, then change the count of vehicles on each ring
- if (next == ringGraphics.roadway[ii].turningCell1 && ii == 0 && ringGraphics.roadway[ii].turningDecision == 0) {
- ringGraphics.currentVehicles1--;
- ringGraphics.currentVehicles2++;
- turnLeftToRight = false;
- }
- if (next == ringGraphics.roadway[ii].turningCell1 && ii == ringGraphics.numberCells/2 && ringGraphics.roadway[ii].turningDecision == 0) {
- ringGraphics.currentVehicles1++;
- ringGraphics.currentVehicles2--;
- turnRightToLeft = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement