Skip to content

Commit

Permalink
Merge pull request #147 from tammysalmon/hacktoberfest-issue-121
Browse files Browse the repository at this point in the history
Hacktoberfest issue 121 (RandomActuator return NO_DIR when moveset is empty).
  • Loading branch information
arnauddupuis committed Oct 28, 2020
2 parents 1b1e748 + 067cc2a commit a65c87a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ venv.bak/
hac-maps/test-write-board.json
settings-suparex*
test-*

# PyCharm
.idea/
4 changes: 3 additions & 1 deletion pygamelib/actuators.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ def next_move(self):
randomactuator.next_move()
"""
if self.state == constants.RUNNING:
if self.state == constants.RUNNING and self.moveset:
return random.choice(self.moveset)
else:
return constants.NO_DIR


class PathActuator(Actuator):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_actuators.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def test_random(self):
self.assertEqual(a.moveset, [constants.UP])
self.assertEqual(a.next_move(), constants.UP)

def test_random_empty(self):
a = actuators.RandomActuator()
self.assertEqual(a.moveset, [])
self.assertEqual(a.next_move(), constants.NO_DIR)

def test_path(self):
a = actuators.PathActuator([constants.UP])
a.pause()
Expand Down

0 comments on commit a65c87a

Please sign in to comment.