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 Robot:
""" """
Class representing a single "Toy Robot". Robots instances have knowledge 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: Attributes:
DEFAULT_MAX_X (int): The default maximum allowable horizontal 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. DIRECTIONS (dict): A dictionary (str: int) of direction names (e.g.
NORTH, EAST etc) and their numerical encoding. Only the keys are NORTH, EAST etc) and their numerical encoding. Only the keys are
intended for use externally as a list of valid directions. 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 DEFAULT_MAX_X = 5
@ -328,5 +335,5 @@ class Robot:
return "{},{},{}".format( return "{},{},{}".format(
self._position_x, self._position_x,
self._position_y, 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(): def main():
print('a)') print('a)')
feed_file('example_a.txt', toyrobot.Robot(6, 6)) feed_file('example_a.txt', toyrobot.Robot())
print() print()
print('b)') print('b)')
feed_file('example_b.txt', toyrobot.Robot(6, 6)) feed_file('example_b.txt', toyrobot.Robot())
print() print()
print('c)') print('c)')
feed_file('example_c.txt', toyrobot.Robot(6, 6)) feed_file('example_c.txt', toyrobot.Robot())
print() print()
print('d)') print('d)')
feed_file('example_d.txt', toyrobot.Robot(6, 6)) feed_file('example_d.txt', toyrobot.Robot())
print() print()
if __name__ == "__main__": if __name__ == "__main__":