Esempio n. 1
0
 def test_can_not_mark_dot_in_already_marked_cell(self):
     field = Field.Field(5, 5)
     player = Player(1, field)
     another = Player(2, field)
     field.mark_dot(0, 0, player)
     field.mark_dot(0, 0, another)
     self.assertEqual(field.field_array[0][0].owner, player)
Esempio n. 2
0
 def test_can_not_mark_dot_inside_others_occupied_area(self):
     field = Field.Field(5, 5)
     player = Player(1, field)
     field.mark_dot(0, 1, player)  # _x
     field.mark_dot(1, 0, player)  # xzx
     field.mark_dot(2, 1, player)  # _x
     field.mark_dot(1, 2, player)  #
     Cycles.find_occupied_dots(field)
     success = field.mark_dot(1, 1, Player(2, field))
     self.assertFalse(success)
Esempio n. 3
0
 def test_can_not_mark_at_the_edge(self):
     field = Field.Field(5, 5)
     player = Player(1, field)
     field.mark_dot(-1, -1, player)
     field.mark_dot(5, 5, player)
     field.mark_dot(-1, 5, player)
     field.mark_dot(5, -1, player)
     self.assertTrue(is_empty(field))
Esempio n. 4
0
 def test_group_by_x_3_dots_in_line_vertically(self):
     player = occupier = Player(-1)
     c1 = Cell.Cell(0, 0, player, occupier)
     c2 = Cell.Cell(0, 1, player, occupier)
     c3 = Cell.Cell(0, 2, player, occupier)
     cells = {c1, c2, c3}
     expected = {}
     self.assertEqual(expected, Cell.group_by_x(cells))
Esempio n. 5
0
 def test_group_by_x_3_dots_in_line_horizontally(self):
     player = occupier = Player(-1)
     c1 = Cell.Cell(0, 0, player, occupier)
     c2 = Cell.Cell(1, 0, player, occupier)
     c3 = Cell.Cell(2, 0, player, occupier)
     cells = {c1, c2, c3}
     expected = {1: {c2}}
     self.assertEqual(expected, Cell.group_by_x(cells))
Esempio n. 6
0
    def test_cell_marked_as_occupied_staggered_layout_with_enemy(self):
        field = Field.Field(3, 3)
        player_x = Player(1, field)
        player_z = Player(2, field)
        field.mark_dot(0, 1, player_z)  # xzx
        field.mark_dot(1, 0, player_z)  # zxz
        field.mark_dot(2, 1, player_z)  # xzx
        field.mark_dot(1, 2, player_z)  #

        field.mark_dot(0, 0, player_x)
        field.mark_dot(0, 2, player_x)
        field.mark_dot(2, 2, player_x)
        field.mark_dot(2, 0, player_x)
        field.mark_dot(1, 1, player_x)

        Cycles.find_occupied_dots(field)
        self.assertEqual(field.field_array[1][1].occupier, player_z)
Esempio n. 7
0
 def test_occupied_cell_marked_as_occupied(self):
     field = Field.Field(5, 5)
     occupier = Player(1, field)
     field.mark_dot(0, 1, occupier)  # _x
     field.mark_dot(1, 0, occupier)  # xzx
     field.mark_dot(2, 1, occupier)  # _x
     field.mark_dot(1, 2, occupier)  #
     Cycles.find_occupied_dots(field)
     self.assertEqual(field.field_array[1][1].occupier, occupier)
Esempio n. 8
0
 def test_cell_marked_as_occupied_staggered_layout_with_empty(self):
     field = Field.Field(3, 3)
     occupier = Player(1, field)
     field.mark_dot(0, 1, occupier)  # _x
     field.mark_dot(1, 0, occupier)  # xzx
     field.mark_dot(2, 1, occupier)  # _x
     field.mark_dot(1, 2, occupier)  #
     Cycles.find_occupied_dots(field)
     self.assertEqual(field.field_array[1][1].occupier, occupier)
Esempio n. 9
0
 def test_belongs(self):
     field = Field.Field(5, 5)
     player = Player(1, field)
     field.mark_dot(0, 1, player)  # _x
     field.mark_dot(1, 0, player)  # xzx
     field.mark_dot(2, 1, player)  # _x
     field.mark_dot(1, 2, player)  #
     actually = field.field_array[1][1].belongs_smb()
     self.assertFalse(actually)
Esempio n. 10
0
 def test_can_mark_dot_inside_its_own_occupied_area(self):
     field = Field.Field(5, 5)
     player = Player(1, field)
     field.mark_dot(0, 1, player)  # _x
     field.mark_dot(1, 0, player)  # xzx
     field.mark_dot(2, 1, player)  # _x
     field.mark_dot(1, 2, player)  #
     Cycles.find_occupied_dots(field)
     success = field.mark_dot(1, 1, player)
     self.assertTrue(success)
Esempio n. 11
0
 def test_dot_inside_occupied_area(self):
     field = Field.Field(5, 5)
     player = Player(1, field)
     field.mark_dot(0, 1, player)  # _x
     field.mark_dot(1, 0, player)  # xzx
     field.mark_dot(2, 1, player)  # _x
     field.mark_dot(1, 2, player)  #
     Cycles.find_occupied_dots(field)
     occ_b_enm = field.field_array[1][1].occupied_by_enemy()
     self.assertTrue(occ_b_enm)
Esempio n. 12
0
 def test_dot_outside_occupied_area_do_not_contact_with_area(self):
     field = Field.Field(6, 6)
     player = Player(1, field)
     field.mark_dot(0, 1, player)  # _x___z
     field.mark_dot(1, 0, player)  # x_x
     field.mark_dot(2, 1, player)  # _x
     field.mark_dot(1, 2, player)  #
     _ = Cycles.find_occupied_dots(field)
     not_occ = field.field_array[5][0].occupied_by_enemy()
     self.assertFalse(not_occ)
Esempio n. 13
0
 def test_hard_occupy_single_enemy_dot(self):
     field = Field(3, 3)
     enemy = Player(0)
     field.field_array[1][1] = Cell(1, 1, enemy)
     hard_bot = HardBot(1)
     for i in range(4):
         hard_bot.act(field)
         Cycles.find_occupied_dots(field)
     self.assertEqual(field.field_array[1][0].owner, hard_bot)
     self.assertEqual(field.field_array[0][1].owner, hard_bot)
     self.assertEqual(field.field_array[2][1].owner, hard_bot)
     self.assertEqual(field.field_array[1][2].owner, hard_bot)
Esempio n. 14
0
 def test_raises_exception_if_owner_is_int_but_not_player_obj(self):
     player = Player(1)
     cell = Cell.Cell(0, 0, player)
     self.assertRaises(TypeError, cell.belongs, player=1)
Esempio n. 15
0
 def test_nobodys_cell_is_not_enemys_cell(self):
     player = Player(1)
     cells = {Cell.Cell(0, 0, owner=None)}
     self.assertFalse(Cell.contains_enemy(cells, player))
Esempio n. 16
0
 def test_others_cell_is_enemy_cell(self):
     player = Player(1)
     other = Player(2)
     cells = {Cell.Cell(0, 0, player)}
     self.assertTrue(Cell.contains_enemy(cells, other))
Esempio n. 17
0
 def test_players_cell_is_not_enemy_cell(self):
     player = Player(1)
     cells = {Cell.Cell(0, 0, player)}
     self.assertFalse(Cell.contains_enemy(cells, player))
Esempio n. 18
0
 def test_doesnt_belongs_to_others_owner(self):
     player = Player(1)
     other = Player(2)
     cell = Cell.Cell(0, 0, player)
     self.assertFalse(cell.belongs(other))
Esempio n. 19
0
 def test_belongs_to_its_owner(self):
     player = Player(-1)
     cell = Cell.Cell(0, 0, player)
     self.assertTrue(cell.belongs(player))
Esempio n. 20
0
 def test_3_cells_with_gap_vertically_middle(self):
     player = occupier = Player(-1)
     cell = Cell.Cell(0, 1, player, occupier)
     cells = {Cell.Cell(0, 0, player, occupier), cell, Cell.Cell(0, 2, player, occupier)}
     self.assertFalse(Cell.is_between_cells(cell, cells))
Esempio n. 21
0
 def test_3_cells_in_line_horizontally_right(self):
     player = occupier = Player(-1)
     cell = Cell.Cell(2, 0, player, occupier)
     cells = {Cell.Cell(1, 0, player, occupier), cell, Cell.Cell(0, 0, player, occupier)}
     self.assertFalse(Cell.is_between_cells(cell, cells))
 def add_human(self):
     self.players.append(Player(self.next_number, None, self.ui))
Esempio n. 23
0
 def test_occupied_cell_without_owner(self):
     player = Player(_id=0)
     cell = Cell(0, 0, owner=None, occupier=player)
     cell.drenched = True
     color = UI.get_color_pair(cell)
     self.assertEqual(1, color)
Esempio n. 24
0
 def test_can_mark_dot(self):
     field = Field.Field(5, 5)
     player = Player(1, field)
     field.mark_dot(2, 3, player)
     self.assertEqual(field.field_array[2][3].owner, player)