Thanks to visit codestin.com
Credit goes to github.com

Skip to content

List to Tuple #603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,14 +661,14 @@ def __init__(self, m):
self.nrows = len(m)
self.ncols = len(m[0])
# list of empty spaces in the map
self.empty = [[i, j] for i in range(self.nrows) for j in range(self.ncols) if not m[i][j]]
self.empty = [(i, j) for i in range(self.nrows) for j in range(self.ncols) if not m[i][j]]

def sample(self):
"""Returns a random kinematic state possible in the map"""
pos = random.choice(self.empty)
# 0N 1E 2S 3W
orient = random.choice(range(4))
kin_state = pos + [orient]
kin_state = pos + (orient,)
return kin_state

def ray_cast(self, sensor_num, kin_state):
Expand All @@ -679,10 +679,10 @@ def ray_cast(self, sensor_num, kin_state):
# 0
# 3R1
# 2
delta = [(sensor_num%2 == 0)*(sensor_num - 1), (sensor_num%2 == 1)*(2 - sensor_num)]
delta = ((sensor_num%2 == 0)*(sensor_num - 1), (sensor_num%2 == 1)*(2 - sensor_num))
# sensor direction changes based on orientation
for _ in range(orient):
delta = [delta[1], -delta[0]]
delta = (delta[1], -delta[0])
range_count = 0
while (0 <= pos[0] < self.nrows) and (0 <= pos[1] < self.nrows) and (not self.m[pos[0]][pos[1]]):
pos = vector_add(pos, delta)
Expand Down
14 changes: 7 additions & 7 deletions tests/test_probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ def P_motion_sample(kin_state, v, w):
# for simplicity the robot first rotates and then moves
orient = (orient + w)%4
for _ in range(orient):
v = [v[1], -v[0]]
pos = list(vector_add(pos, v))
return pos + [orient]
v = (v[1], -v[0])
pos = vector_add(pos, v)
return pos + (orient,)

def P_sensor(x, y):
"""Conditional probability for sensor reading"""
Expand All @@ -207,8 +207,8 @@ def P_sensor(x, y):
return 0

from utils import print_table
a = {'v': [0, 0], 'w': 0}
z = [2, 4, 1, 6]
a = {'v': (0, 0), 'w': 0}
z = (2, 4, 1, 6)
S = monte_carlo_localization(a, z, 1000, P_motion_sample, P_sensor, m)
grid = [[0]*17 for _ in range(11)]
for x, y, _ in S:
Expand All @@ -217,8 +217,8 @@ def P_sensor(x, y):
print("GRID:")
print_table(grid)

a = {'v': [0, 1], 'w': 0}
z = [2, 3, 5, 7]
a = {'v': (0, 1), 'w': 0}
z = (2, 3, 5, 7)
S = monte_carlo_localization(a, z, 1000, P_motion_sample, P_sensor, m, S)
grid = [[0]*17 for _ in range(11)]
for x, y, _ in S:
Expand Down