2021-03-26 16:36:21 +01:00
|
|
|
import pygame
|
|
|
|
import project_constants as const
|
|
|
|
import json_generator as js
|
|
|
|
import json
|
|
|
|
|
|
|
|
# Class of our agent, initialization of it
|
|
|
|
# movment functions (those defiend by the 'go_' prefix are not meant to actually move our agent, they just return some values
|
|
|
|
# that are later used by another function called 'is_valid_move' (which is defined in Minefield));
|
|
|
|
|
|
|
|
class Agent:
|
|
|
|
def __init__(self, json_path):
|
|
|
|
with open(json_path) as json_data:
|
|
|
|
data = json.load(json_data)
|
2021-04-11 19:04:06 +02:00
|
|
|
self.row, self.column = data['agent_starting_position'].split(",")
|
|
|
|
self.position = [int(self.row), int(self.column)]
|
2021-04-17 18:03:16 +02:00
|
|
|
#self.direction = const.Direction()
|
|
|
|
self.direction = 0
|
|
|
|
|
|
|
|
|
|
|
|
def rotate_left (self):
|
|
|
|
self.direction = self.direction.previous()
|
|
|
|
def rotate_right(self):
|
|
|
|
self.direction = self.direction.next()
|
|
|
|
|
|
|
|
def go(self):
|
|
|
|
if (self.direction == const.Direction.RIGHT ):
|
|
|
|
temp = go_right()
|
|
|
|
self.position[1] = temp[1]
|
|
|
|
elif (self.direction == const.Direction.LEFT ):
|
|
|
|
temp = go_left()
|
|
|
|
self.position[1] = temp[1]
|
|
|
|
elif (self.direction == const.Direction.UP):
|
|
|
|
temp = go_up()
|
|
|
|
self.position[0] = temp[0]
|
|
|
|
elif (self.direction == const.Direction.DOWN):
|
|
|
|
temp = temp = go_down()
|
|
|
|
self.position[0] = temp[0]
|
|
|
|
|
2021-03-26 16:36:21 +01:00
|
|
|
def go_right(self):
|
2021-04-17 18:03:16 +02:00
|
|
|
|
2021-04-11 19:04:06 +02:00
|
|
|
return self.position[0], self.position[1] + 1
|
2021-03-26 16:36:21 +01:00
|
|
|
|
|
|
|
def go_left(self):
|
2021-04-17 18:03:16 +02:00
|
|
|
|
2021-04-11 19:04:06 +02:00
|
|
|
return self.position[0], self.position[1] - 1
|
2021-03-26 16:36:21 +01:00
|
|
|
|
|
|
|
def go_up(self):
|
|
|
|
|
2021-04-11 19:04:06 +02:00
|
|
|
return self.position[0] - 1, self.position[1]
|
2021-03-26 16:36:21 +01:00
|
|
|
|
|
|
|
def go_down(self):
|
|
|
|
|
2021-04-17 18:03:16 +02:00
|
|
|
return self.position[0] + 1, self.position[1]
|
|
|
|
|