Skip to content
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

improve readability of smartrandom_bot #74

Merged
merged 1 commit into from
May 15, 2024
Merged
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
9 changes: 6 additions & 3 deletions demo03_smartrandom.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ def move(bot, state):
enemy_pos = (enemy[0].position, enemy[1].position)

# sensible positions are all legal positions that do not cause death
sensible_positions = bot.legal_positions[:]
# if we would step on a ghost outside our homezone we discard this move
sensible_positions = []
# loop throuh all legal_positions for this bot
for next_pos in bot.legal_positions:
# each legal position is good unless we step on a ghost outside our homezone
if (next_pos in enemy_pos) and (next_pos not in bot.homezone):
sensible_positions.remove(next_pos)
continue
else:
sensible_positions.append(next_pos)

if len(sensible_positions) == 0:
# we can't go anywhere safe
Expand Down
Loading