updated
This commit is contained in:
parent
014df61e4f
commit
b60cd485fc
@ -4,7 +4,7 @@ import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
GRIDSIZE = 300
|
||||
INIT_CELLS = int(GRIDSIZE*0.3)
|
||||
INIT_CELLS = int(GRIDSIZE*0.2)
|
||||
MAX_TIME = 300
|
||||
EMPTY_CELL = -1
|
||||
DALLY_LIMIT = 0.2
|
||||
@ -13,6 +13,7 @@ DALLY_LIMIT = 0.2
|
||||
# query distance between two cars
|
||||
def get_distance(grid, i):
|
||||
dist = 0
|
||||
print(grid)
|
||||
while grid[(i+dist+1)%GRIDSIZE] == EMPTY_CELL and dist < 5:
|
||||
dist = dist + 1
|
||||
return dist
|
||||
@ -24,6 +25,9 @@ def update(grid_old, grid_new):
|
||||
if grid_old[i] != EMPTY_CELL:
|
||||
v = np.min((grid_old[i]+1, 5)) # accelerate
|
||||
dist = get_distance(grid_old, i)
|
||||
if i == 295:
|
||||
print(grid_old[i], " ", dist)
|
||||
quit()
|
||||
if v > dist: v = dist # break
|
||||
p = np.random.random()
|
||||
if p == DALLY_LIMIT: v = max(grid_old[i-1], 0)
|
||||
|
||||
@ -10,28 +10,27 @@ MAX_TIME = 300
|
||||
EMPTY_CELL = -1
|
||||
|
||||
# query distance between two cars
|
||||
def get_distance(grid, i):
|
||||
dist = 0
|
||||
def get_distance(grid):
|
||||
""" Compute distance between current position and next car """
|
||||
"""
|
||||
Insert your code here
|
||||
"""
|
||||
|
||||
for n in range(1, (grid[i]+1)&GRIDSIZE):
|
||||
if grid[i + n] != -1:
|
||||
for n in grid:
|
||||
if grid[n] != EMPTY_CELL:
|
||||
return n
|
||||
return -1
|
||||
return 5
|
||||
|
||||
# state transition t -> t + dt
|
||||
def update(grid_old, grid_new):
|
||||
for i in range(GRIDSIZE):
|
||||
dist = get_distance(grid_old, i)
|
||||
""" Update cars according rules using value 'dist' """
|
||||
"""
|
||||
Insert your code here
|
||||
"""
|
||||
if dist != -1:
|
||||
print(dist)
|
||||
if grid_old[i] != EMPTY_CELL:
|
||||
dist = get_distance(grid_old[i+1:i+6])
|
||||
""" Update cars according rules using value 'dist' """
|
||||
"""
|
||||
Insert your code here
|
||||
"""
|
||||
if dist != -1:
|
||||
print(dist)
|
||||
|
||||
# allocate memory and initialise grids
|
||||
grid_old = np.full((GRIDSIZE), EMPTY_CELL, dtype=np.int32)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user