Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7935701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:00:20+00:00 2026-06-03T22:00:20+00:00

I have 2 classes, a robot class to move units and a map class

  • 0

I have 2 classes, a robot class to move units and a map class to keep track of where they are. There is one atlas class and multiple robot classes in a atlas. How can i use a function in Atlas from class Robot.

class Atlas:
    def __init__(self):
        self.robots = []
        self.currently_occupied = {}

    def add_robot(self, robot):
        self.robots.append(robot)
        self.currently_occupied = {robot:[]}   

    def all_occupied(self):
        return self.currently_occupied

    def occupy_spot(self, x, y, name):
        self.currently_occupied[name] = [x, y]


class Robot():
    def __init__(self, rbt):
        self.xpos = 0
        self.ypos = 0
        atlas.add_robot(rbt)  #<-- is there a better way than explicitly calling this atlas
        self.name = rbt

    def step(self, axis):
        if axis in "xX":
            self.xpos += 1 
        elif axis in "yY":
            self.ypos += 1
        atlas.occupy_spot(self.xpos, self.ypos, self.name)

    def walk(self, axis, steps=2):
        for i in range(steps):
            self.step(axis)



atlas = Atlas()  #<--  this may change in the future from 'atlas' to 'something else' and would break script
robot1 = Robot("robot1")
robot1.walk("x", 5)
robot1.walk("y", 1)
print atlas.all_occupied()

I am 14 years old and new to programming. this is a practice program and i canno’t find this on google or yahoo. please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:00:22+00:00Added an answer on June 3, 2026 at 10:00 pm

    You can only access methods of objects you have a reference to. Perhaps you should pass an instance of Atlas to the initializer.

    class Robot():
      def __init__(self, rbt, atlas):
        self.atlas = atlas
         ...
        self.atlas.add_robot(rbt)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two abstract classes called Robot and GeometricElement . Each one of them
Within our namespaced class files, there're various classes which have the namespace prefixed with
I have classes which have automatic properties only like public customerName {get; set;}. They
I have classes structured like this: Public MustInherit Class A ' several properties End
If I have classes of Type A and B: public class A { public
Assume I have classes A1 and A2 and a class B that has elements
I have downloaded a third party library and they have classes I need to
I have these three classes: Command: package pack; public abstract class Command impements java.io.Serializable
I have this code (two classes) class url { private $profile_id; private $short; public
I have two classes defined in different h files and each class has some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.