Beispiel #1
0
 def test_game_with_bumping_on_edge(self):
     i = Input(board_dimension=(5, 5),
               initial_position=(0, 0),
               movements=['S', 'W', 'S'],
               walls={})
     x, y, c = GameOrchestrator(i).play()
     self.assertEqual((x, y, c), (0, 0, 0))
Beispiel #2
0
 def test_game_with_bumping_on_wall(self):
     i = Input(board_dimension=(5, 5),
               initial_position=(1, 1),
               movements=['N', 'N', 'S'],
               walls={(1, 2)})
     x, y, c = GameOrchestrator(i).play()
     self.assertEqual((x, y, c), (1, 0, 1))
Beispiel #3
0
 def test_game_with_coming_back_on_previous_steps(self):
     i = Input(board_dimension=(5, 5),
               initial_position=(1, 1),
               movements=['E', 'W', 'E', 'W', 'W'],
               walls={(1, 2)})
     x, y, c = GameOrchestrator(i).play()
     self.assertEqual((x, y, c), (0, 1, 2))
Beispiel #4
0
 def test_invalid_position_not_in(self):
     i = Input(board_dimension=(5, 5),
               initial_position=(0, 5),
               movements=[],
               walls=set())
     with self.assertRaises(PositionException):
         GameOrchestrator(i)
Beispiel #5
0
 def test_invalid_position_wall(self):
     i = Input(board_dimension=(5, 5),
               initial_position=(1, 1),
               movements=[],
               walls={(1, 1)})
     with self.assertRaises(PositionException) as e:
         GameOrchestrator(i)
     self.assertEqual(
         str(e.exception),
         "The pacman can not be placed at the location: (1, 1)")
Beispiel #6
0
def pacman(input_filename) -> Tuple[int, int, int]:
    """ Use this function to format your input/output arguments. Be sure not change the order of the output arguments.
    Remember that code organization is very important to us, so we encourage the use of helper fuctions and classes as you see fit.

    Input:
        1. input_file (String) = contains the name of a text file you need to read that is in the same directory, includes the ".txt" extension
           (ie. "input.txt")
    Outputs:
        1. final_pos_x (int) = final x location of Pacman
        2. final_pos_y (int) = final y location of Pacman
        3. coins_collected (int) = the number of coins that have been collected by Pacman across all movements
    """
    result = (-1, -1, 0)
    try:
        resources = load(input_filename=input_filename)
        LOG.debug("Parsed input data: %s", resources.input_data)
        game = GameOrchestrator(resources.input_data)
        result = game.play()
        # return final_pos_x, final_pos_y, coins_collected
    except Exception as e:
        LOG.error(str(e))
    return result