Created
September 16, 2021 18:33
-
-
Save gma/f48a73e264316b0b33831cfbb48ee2c3 to your computer and use it in GitHub Desktop.
Python NW group coding session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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