Skip to content

Commit 56748e6

Browse files
authored
Merge pull request #4 from se2-w19-group24/is2
Parameter verification for Pong and RaycastMaze
2 parents 5c5e273 + 003cdb0 commit 56748e6

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

ple/games/pong.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ class Pong(PyGameWrapper):
196196

197197
def __init__(self, width=64, height=48, cpu_speed_ratio=0.6, players_speed_ratio = 0.4, ball_speed_ratio=0.75, MAX_SCORE=11):
198198

199+
assert width > 0, "Error: width must be greater than 0"
200+
assert height > 0, "Error: height must be greater than 0"
201+
assert cpu_speed_ratio > 0, "Error: cpu_speed_ratio must be greater than 0"
202+
assert players_speed_ratio > 0, "Error: player_speed_ratio must be greater than 0"
203+
assert ball_speed_ratio > 0, "Error: ball_speed_ration must be greater than 0"
204+
assert MAX_SCORE > 0, "Error: MAX_SCORE must be greater than 0"
205+
199206
actions = {
200207
"up": K_w,
201208
"down": K_s

ple/games/raycastmaze.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ def __init__(self,
4343
move_speed=20, turn_speed=13,
4444
map_size=10, height=48, width=48, init_pos_distance_to_target=None):
4545

46-
assert map_size > 5, "map_size must be gte 5"
46+
for x in init_pos:
47+
assert (x >= 0) and (x < map_size), "Error: init_pos must be on the map (0 to map_size)"
48+
assert resolution > 0, "Error: resolution must be greater than 0"
49+
assert move_speed > 0, "Error: move_speed must be greater than 0"
50+
assert move_speed < 100, "Error: move_speed must be less than 100"
51+
assert turn_speed > 0, "Error: turn_speed must be greater than 0"
52+
assert turn_speed < 100, "Error: turn_speed must be less than 100"
53+
assert (map_size > 5) and (map_size <= 100), "Error: map_size must be >= 5 and <= 100"
54+
assert (height > 0) and (width > 0) and (height == width), "Error: height and width must be equal and greater than 0"
4755

4856
# do not change
4957
init_dir = (1.0, 0.0)

tests/test_pong.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,15 @@ def test_invalid_max_score():
5959
with pytest.raises(Exception):
6060
game=Pong(MAX_SCORE=-1)
6161

62-
def test_invalid_action_input():
63-
game=Pong()
64-
p=PLE(game, display_screen=True, fps=20, force_fps=1)
65-
p.init()
66-
time.sleep(.5)
67-
with pytest.raises(Exception):
68-
p.act(10)
62+
#I'm commenting out this test currently because it is unclear whether the game should
63+
# throw an exception for an undefinied action, or do nothing (basically a wait step)
64+
# Refer to ple.py lines 361-367 in the definition of act(int) for this
65+
#
66+
#def test_invalid_action_input():
67+
# game=Pong()
68+
# p=PLE(game, display_screen=True, fps=20, force_fps=1)
69+
# p.init()
70+
# time.sleep(.5)
71+
# with pytest.raises(Exception):
72+
# p.act(10)
6973

0 commit comments

Comments
 (0)