143k views
5 votes
Create a class called WanderBot. WanderBot is a bot that will wander around randomly.

Instance Attibutes:

A. character - string
B. position - list of [int, int]
C. moves - list of list of [int, int]
D. grid_size - None or int

User Amseager
by
8.0k points

1 Answer

5 votes

Final answer:

We need to create a WanderBot class with attributes character, position, moves, and grid_size. The bot is designed to wander around a grid randomly, with moves indicating possible directions it can take.

Step-by-step explanation:

We need to create a class called WanderBot. This bot is designed to wander around a grid in a random manner. Let's define the WanderBot class with the following instance attributes;

  • Character - A string representation of the bot.
  • Position - A list containing two integers which represent the bot's current position on the grid.
  • Moves - A list of lists, where each sublist contains two integers representing a move that the bot can make.
  • Grid_size - An optional integer that sets the size of the grid the bot is wandering on; if not set, it will default to None.

Here is a simple Python class to represent the WanderBot:

class WanderBot:
def __init__(self, character, grid_size=None):
self.character = character
self.position = [0, 0]
self.moves = [[-1, 0], [1, 0], [0, -1], [0, 1]]
self.grid_size = grid_size

# Additional methods to enable the bot to wander could be added here

The position attribute starts at [0, 0], but can be updated as the WanderBot moves around the grid. The moves list represents potential moves the WanderBot could make, with each move being a vector that changes the position.

User Nhan Phan
by
8.6k points