Added additional comments, removed redundant initializer code.

This commit is contained in:
Chris Davoren 2023-10-07 17:26:17 +10:00
parent 26cc28193b
commit 730fab5287
2 changed files with 13 additions and 6 deletions

View File

@ -1,7 +1,11 @@
class Robot:
"""
Class representing a single "Toy Robot". Robots instances have knowledge
of their position, direction, and movement limits.
of their position, direction, and movement limits (i.e. "board" size).
Note: Direction is specified via compass points (north, west, etc). As per
the original problem description, the coordinates (0, 0) represent the
SOUTHWEST corner of the board.
Attributes:
DEFAULT_MAX_X (int): The default maximum allowable horizontal
@ -11,6 +15,9 @@ class Robot:
DIRECTIONS (dict): A dictionary (str: int) of direction names (e.g.
NORTH, EAST etc) and their numerical encoding. Only the keys are
intended for use externally as a list of valid directions.
VALID_COMMANDS (list): A list of valid commands that can be interpreted
by the robot. The PLACE command requires at least two additional
parameters. See the complete problem description for more details.
"""
DEFAULT_MAX_X = 5
@ -328,5 +335,5 @@ class Robot:
return "{},{},{}".format(
self._position_x,
self._position_y,
{v: k for k, v in Robot.DIRECTIONS.items()}[self._direction],
self.get_direction()
)

View File

@ -11,19 +11,19 @@ def feed_file(filename: str, robot: toyrobot.Robot):
def main():
print('a)')
feed_file('example_a.txt', toyrobot.Robot(6, 6))
feed_file('example_a.txt', toyrobot.Robot())
print()
print('b)')
feed_file('example_b.txt', toyrobot.Robot(6, 6))
feed_file('example_b.txt', toyrobot.Robot())
print()
print('c)')
feed_file('example_c.txt', toyrobot.Robot(6, 6))
feed_file('example_c.txt', toyrobot.Robot())
print()
print('d)')
feed_file('example_d.txt', toyrobot.Robot(6, 6))
feed_file('example_d.txt', toyrobot.Robot())
print()
if __name__ == "__main__":