Created
November 25, 2020 13:11
-
-
Save mauricioaniche/704291ff0a94ee937b44c47bb9b1f508 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# @ -> 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 |
This file contains hidden or 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
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