2019-11-15 20:43:59 +01:00
|
|
|
import enum
|
2019-11-15 20:29:06 +01:00
|
|
|
|
2019-11-15 21:04:16 +01:00
|
|
|
from pydantic import BaseModel
|
2019-11-15 20:29:06 +01:00
|
|
|
|
2019-11-15 21:04:16 +01:00
|
|
|
|
|
|
|
class Vector(BaseModel):
|
|
|
|
x: int = 0
|
|
|
|
y: int = 0
|
2019-11-15 20:34:34 +01:00
|
|
|
|
|
|
|
|
2019-11-15 20:43:59 +01:00
|
|
|
class Direction(enum.Enum):
|
|
|
|
NORTH = "N"
|
|
|
|
SOUTH = "S"
|
|
|
|
EAST = "E"
|
|
|
|
WEST = "W"
|
|
|
|
|
|
|
|
|
2019-11-15 21:04:16 +01:00
|
|
|
class Rover(BaseModel):
|
|
|
|
pos: Vector = Vector(x=0, y=0)
|
|
|
|
planet_size: Vector = Vector(x=100, y=100)
|
2019-11-15 20:43:59 +01:00
|
|
|
dir: Direction = Direction.NORTH
|
2019-11-15 21:12:07 +01:00
|
|
|
|
|
|
|
def forward(self):
|
|
|
|
if self.dir == Direction.NORTH:
|
|
|
|
self.pos.y += 1
|
|
|
|
elif self.dir == Direction.SOUTH:
|
|
|
|
self.pos.y -= 1
|
|
|
|
elif self.dir == Direction.EAST:
|
|
|
|
self.pos.x += 1
|
|
|
|
elif self.dir == Direction.WEST:
|
|
|
|
self.pos.x -= 1
|
2019-11-15 21:12:51 +01:00
|
|
|
|
|
|
|
if self.pos.x < 0:
|
|
|
|
self.pos.x += self.planet_size.x
|
|
|
|
if self.pos.y < 0:
|
|
|
|
self.pos.y += self.planet_size.y
|