Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- class VPoint:
- def __init__(self, x, y, vx, vy):
- self.x = x
- self.y = y
- self.vx = vx
- self.vy = vy
- self.flag1 = False
- @staticmethod
- def parse_str(line):
- m = re.findall("-?\d+", line)
- vp = VPoint(int(m[0]),
- int(m[1]),
- int(m[2]),
- int(m[3]))
- return vp
- def move(self):
- self.x += self.vx
- self.y += self.vy
- def is_neighbour(self, vpoint):
- return (self.x == vpoint.x and self.y == vpoint.y - 1) \
- or (self.x == vpoint.x and self.y == vpoint.y + 1) \
- or (self.x == vpoint.x - 1 and self.y == vpoint.y - 1) \
- or (self.x == vpoint.x - 1 and self.y == vpoint.y) \
- or (self.x == vpoint.x - 1 and self.y == vpoint.y + 1) \
- or (self.x == vpoint.x + 1 and self.y == vpoint.y - 1) \
- or (self.x == vpoint.x + 1 and self.y == vpoint.y) \
- or (self.x == vpoint.x + 1 and self.y == vpoint.y + 1)
- def depth_search(vpoint, grid):
- count = 0
- if vpoint.flag1 == True:
- return 0
- vpoint.flag1 = True
- for vp in grid:
- if vpoint.is_neighbour(vp):
- count += depth_search(vp, grid)
- return count + 1
- def get_non_flagged(grid):
- for vp in grid:
- if not vp.flag1:
- return vp
- return None
- def unflag(grid):
- for vp in grid:
- vp.flag1 = False
- def print_grid(grid, vp, size):
- ggg = [ ["." for _ in range(size)] for _ in range(size)]
- print("Hello")
- def move_all(grid):
- for vp in grid:
- vp.move()
- def main():
- with open("data.txt") as f:
- lines = f.readlines()
- points = []
- for line in lines:
- points.append(VPoint.parse_str(line))
- while True:
- unflag(points)
- while True:
- ufVPoint = get_non_flagged(points)
- if ufVPoint is None:
- move_all(points)
- break
- if depth_search(ufVPoint, points) > 5:
- print_grid(points, ufVPoint, 20)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement