Skip to content

Instantly share code, notes, and snippets.

@mauricioaniche
Created November 25, 2020 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricioaniche/704291ff0a94ee937b44c47bb9b1f508 to your computer and use it in GitHub Desktop.
Save mauricioaniche/704291ff0a94ee937b44c47bb9b1f508 to your computer and use it in GitHub Desktop.
# @ -> our hero
# G -> ghosts
# P -> pills
# . -> empty spaces
# | and - -> walls
map = [
"|--------|",
"|G..|..G.|",
"|...PP...|",
"|G...@.|.|",
"|........|",
"|--------|"
]
def find_pacman(map):
pacman_x = -1
pacman_y = -1
for x in range(len(map)):
for y in range(len(map[x])):
if map[x][y] == '@':
pacman_x = x
pacman_y = y
return pacman_x, pacman_y
import unittest
from pacman import find_pacman
class PacmanTest(unittest.TestCase):
def test_find_pacman(self):
map = [
"|--------|",
"|G..|..G.|",
"|...PP...|",
"|G...@.|.|",
"|........|",
"|--------|"
]
x, y = find_pacman(map)
self.assertEqual(x, 3)
self.assertEqual(y, 5)
def test_find_pacman_when_pacman_doesnt_exist(self):
map = [
"|--------|",
"|G..|..G.|",
"|...PP...|",
"|G.....|.|",
"|........|",
"|--------|"
]
x, y = find_pacman(map)
self.assertEqual(x, -1)
self.assertEqual(y, -1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment