from py.pyMover.goArm import GoArm from py.helpers import myloggers import yaml import os LOG = myloggers.getLogger(__name__) class ProblemCollection: problems_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', 'problems', 'problems.yaml') problems = {} counter = {} def __init__(self): #read problems here self.problems = yaml.load(open(self.problems_file)) self.counter = {level: 0 for level in self.problems.keys()} def get_next_problem(self, level): if self.counter[level] >= len(self.problems[level]): self.counter[level] = -1 self.counter[level] += 1 return self.problems[level][self.counter[level] - 1] if __name__ == "__main__": myArm = GoArm() problems = ProblemCollection() def print_menu():
from py.pyMover.goArm import GoArm from py.pyMover.goCam import GoCam from py.pyMover.problems import ProblemCollection from py.helpers.myloggers import getLogger from py.helpers.position import PositionHolder from py.constants import goArmConsts as CONST LOG = getLogger(__name__) def not_implemented(cam): cam.respond(CONST.msg_NOT_IMPLEMENTED) def put_a_problem(arm, problems, cam, level): cam.respond(CONST.msg_OK) try: cam.request(CONST.com_HOLD) problem = problems.get_next_problem(int(level)) LOG.info("Got the problem for you. Playing") arm.put_stones(problem) except Exception as e: LOG.error("Oops, failure putting a position: {}".format(e)) finally: arm.set_position(arm.cam_position) cam.request(CONST.com_RESUME) def main(): arm = GoArm() cam = GoCam() arm.cam = cam