Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gma
Created September 16, 2021 18:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gma/f48a73e264316b0b33831cfbb48ee2c3 to your computer and use it in GitHub Desktop.
Save gma/f48a73e264316b0b33831cfbb48ee2c3 to your computer and use it in GitHub Desktop.
Python NW group coding session
# Pac-man orientation: v < > ∧
# . . .
# .V.
# . . .
grid = [
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
]
pacman_location = [1, 1]
pacman_orientation = "V"
def display_pacman(grid):
characters = {0: " ", 1: "."}
for row in range(len(grid)):
current_line = ""
for column in range(len(grid[row])):
if pacman_location == [column, row]:
character = pacman_orientation
else:
character = characters[grid[row][column]]
current_line += " %s " % character
print(current_line)
def up(pacman_location):
pacman_location[1] -= 1
def down(pacman_location):
pacman_location[1] += 1
if __name__ == "__main__":
display_pacman(grid)
up(pacman_location)
print("")
display_pacman(grid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment