Beispiel #1
0
    def capture(self, pos: tuple, vec: tuple):
        dir = self.move_direction()

        t_pos = add(pos, mult(vec, dir))
        if not self.valid_position(t_pos) or not self.is_enemy(t_pos):
            return None
        
        n_pos = add(pos, mult(vec, dir * 2))
        if not self.valid_position(n_pos) or not self.is_empty(n_pos):
            return None

        n_state = self.copy()
        n_state.remove_piece(pos)
        n_state.remove_piece(t_pos)

        if self.in_last_row(n_pos):
            n_state.enter_place_mode()
        else:
            n_state.place_piece(n_pos, self.player)
            if not (n_state.can_capture(dir, n_pos, Direction.WEST) or 
                n_state.can_capture(dir, n_pos, Direction.NORTHWEST) or 
                n_state.can_capture(dir, n_pos, Direction.NORTH) or 
                n_state.can_capture(dir, n_pos, Direction.NORTHEAST) or 
                n_state.can_capture(dir, n_pos, Direction.EAST)):
                n_state.next_turn()
            else:
                n_state.action = [3, n_pos]
        
        return n_state
Beispiel #2
0
 def can_capture(self, dir: int, pos: tuple, vec: tuple) -> bool:
     t_pos = add(pos, mult(vec, dir))
     if not self.valid_position(t_pos) or not self.is_enemy(t_pos):
         return False
     
     n_pos = add(pos, mult(vec, dir * 2))
     if not self.valid_position(n_pos) or not self.is_empty(n_pos):
         return False
     
     return True
Beispiel #3
0
    def move(self, pos: tuple, vec: tuple):
        
        dir = self.move_direction()
        n_pos = add(pos, mult(vec, dir))

        if not State.valid_position(n_pos):
            return None
        if not self.is_empty(n_pos):
            return None
        
        n_state = self.copy()
        n_state.remove_piece(pos)

        if self.in_last_row(n_pos):
            n_state.enter_place_mode()
        else:
            n_state.place_piece(n_pos, self.player)
            n_state.next_turn()

        return n_state