Ejemplo n.º 1
0
    def test_move_worker_off_board(self):
        """Case for moving a worker outside of the board boundaries."""
        board = Board([[0, 1]], {self.workers[0]: (0, 0)})

        self.assertEqual(board.worker_position(self.workers[0]), (0, 0))
        with self.assertRaises(IndexError) as context:
            board.move_worker(self.workers[0], Direction.NORTH)
        self.assertTrue("Cannot place a worker out of board bounds" in str(
            context.exception))
Ejemplo n.º 2
0
 def test_winner_2(self):
     """Get the winner."""
     board = Board([[1, 2, 3, 4, 3, 2]],
                   workers={
                       self.workers[0]: (0, 0),
                       self.workers[2]: (0, 1)
                   })
     self.assertFalse(rulechecker.get_winner(board))
     board.move_worker(self.workers[2], Direction.EAST)
     self.assertEqual(rulechecker.get_winner(board), "player2")
Ejemplo n.º 3
0
    def test_move_worker_on_worker(self):
        """Case for moving a worker onto another worker."""
        board = Board([[0, 1]], {
            self.workers[0]: (0, 0),
            self.workers[1]: (1, 1)
        })

        self.assertEqual(board.worker_position(self.workers[0]), (0, 0))
        self.assertEqual(board.worker_position(self.workers[1]), (1, 1))
        self.assertTrue(
            board.is_occupied(board.worker_position(self.workers[1])))
        board.move_worker(self.workers[0], Direction.SOUTHEAST)
        self.assertEqual(board.worker_position(self.workers[0]),
                         board.worker_position(self.workers[1]))
Ejemplo n.º 4
0
    def test_is_game_over_goto_h_three(self):
        """Testing game over case.

        a worker is on a building of height 2,
        builds a floor, and moves to a building of
        height 3
        """
        board = Board([[2, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0]],
                      workers={
                          self.workers[0]: (1, 0),
                          self.workers[1]: (1, 1)
                      })
        self.assertFalse(rulechecker.is_game_over(board, self.workers[0:2]))
        board.build_floor(self.workers[0], Direction.NORTH)
        board.move_worker(self.workers[0], Direction.NORTH)
        self.assertTrue(rulechecker.is_game_over(board, self.workers[0:2]))
Ejemplo n.º 5
0
    def test_move_worker_onto_building(self):
        """Case for moving a worker onto a building.

        In this case, the building is 1 floor higher than the current worker
        """
        board = Board([[0, 1]], {self.workers[0]: (0, 0)})
        self.assertEqual(board.worker_position(self.workers[0]), (0, 0))
        self.assertEqual(
            board.get_height(board.worker_position(self.workers[0]),
                             Direction.STAY), 0)
        self.assertEqual(
            board.get_height(board.worker_position(self.workers[0]),
                             Direction.EAST), 1)
        board.move_worker(self.workers[0], Direction.EAST)
        self.assertEqual(board.worker_position(self.workers[0]), (0, 1))
        self.assertEqual(
            board.get_height(board.worker_position(self.workers[0]),
                             Direction.STAY), 1)
Ejemplo n.º 6
0
 def test_move_worker(self):
     """Base case for moving a worker."""
     board = Board([[0, 1]], {self.workers[0]: (0, 0)})
     self.assertEqual(board.worker_position(self.workers[0]), (0, 0))
     board.move_worker(self.workers[0], Direction.EAST)
     self.assertEqual(board.worker_position(self.workers[0]), (0, 1))
     board.move_worker(self.workers[0], Direction.SOUTH)
     self.assertEqual(board.worker_position(self.workers[0]), (1, 1))
     board.move_worker(self.workers[0], Direction.WEST)
     self.assertEqual(board.worker_position(self.workers[0]), (1, 0))
     board.move_worker(self.workers[0], Direction.NORTH)
     self.assertEqual(board.worker_position(self.workers[0]), (0, 0))