Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- area = [
- ['[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]'],
- ['[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]'],
- ['[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]'],
- ['[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]'],
- ['[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]'],
- ['[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]'],
- ['[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]'],
- ['[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]'],
- ['[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]'],
- ['[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]'],
- ['[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]', '[ ]'],
- ]
- class Ant:
- def __init__(self, y, x, direction):
- self.y = y
- self.x = x
- self.direction = direction
- def change_area(self):
- if area[self.y][self.x] == '[ ]':
- area[self.y][self.x] = '[#]'
- elif area[self.y][self.x] == '[#]':
- area[self.y][self.x] = '[ ]'
- def change_location(self):
- if self.direction == 1:
- self.y -= 1
- elif self.direction == 2:
- self.x += 1
- elif self.direction == 3:
- self.y += 1
- elif self.direction == 4:
- self.x -= 1
- def choose_turn_angle(self):
- if area[self.y][self.x] == '[ ]':
- return True
- else:
- return False
- def right_turn(self):
- self.direction += 1
- if self.direction == 5:
- self.direction = 1
- def left_turn(self):
- self.direction -= 1
- if self.direction == 0:
- self.direction = 4
- def show_area(self):
- for row in area:
- print(" ".join(map(str, row))) # analyze
- def show_testing_data(self):
- print(f"y = {self.y} | x = {self.x} | kierunkowy = {self.direction}")
- ant = Ant(5, 5, 1)
- timer = 1
- while timer<=200:
- ant.change_area()
- ant.change_location()
- if ant.choose_turn_angle():
- ant.right_turn()
- else:
- ant.left_turn()
- timer += 1
- ant.show_area()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement