示例#1
0
def setup(robot_name,argv):
    """
    Sets up the obstacles
    """
    global obstacles_list,module
    try:
        module = ih.dynamic_import(f"maze.{argv[2]}")
        print(f"{robot_name}: Loaded {argv[2]}")
    except IndexError:
        module = ih.dynamic_import("maze.obstacles")
    obstacles_list = module.get_obstacles()
    if len(obstacles_list) > 0:
        print("There are some obstcles:")
        for obs in obstacles_list:
            x = obs[0]
            y = obs[1]
            print(f"- At position {x},{y} (to {x+4},{y+4})")
示例#2
0
def setup(robot_name, argv):
    """
    Sets up the main screen for turtle
    """
    global turtleboi
    turtleboi = turtle.Turtle()

    #Setting up border
    turtleboi.penup()
    turtleboi.speed(1000)
    turtleboi.goto(100, 200)
    turtleboi.pencolor("cyan")
    turtleboi.pensize(3)
    turtleboi.pendown()
    turtleboi.goto(-100, 200)
    turtleboi.goto(-100, -200)
    turtleboi.goto(100, -200)
    turtleboi.goto(100, 200)
    turtleboi.penup()

    #Setting up the obstacles
    global obstacles_list, module
    try:
        module = ih.dynamic_import(f"maze.{argv[2]}")
        print(f"{robot_name}: Loaded {argv[2]}")
    except IndexError:
        module = ih.dynamic_import("maze.obstacles")
    obstacles_list = module.get_obstacles()
    draw_obstacles(turtleboi)
    turtleboi.penup()
    turtleboi.goto(0, 0)
    turtleboi.left(90)
    turtleboi.speed(2)
    turtleboi.pencolor("black")
    turtleboi.pensize(0.5)
    turtleboi.pendown()
示例#3
0
def turtle_draw_obstacles(robot_name):
    """
        draws all obstacles one by one and resets turtle
    """
    global obstacles

    #importing obstacles module
    argv_value = sys.argv[len(sys.argv) - 1].lower()
    if argv_value == "turtle":
        argv_value = "obstacles"

    obstacles = import_helper.dynamic_import("maze." + argv_value)
    print('' + robot_name + ': Loaded ' + argv_value + '.')

    #Drawing obstacles
    list_of_obst = obstacles.get_obstacles()
    for each in list_of_obst:
        draw_one_obstacle(each[0], each[1])
示例#4
0
import sys
import import_helper

try:
    obstacles = import_helper.dynamic_import('maze.' + sys.argv[2])
    obs_module = sys.argv[2]
except:
    from maze import obstacles
    obs_module = "obstacles"

# variables tracking position and direction
position_x = 0
position_y = 0
directions = ['forward', 'right', 'back', 'left']
current_direction_index = 0

# area limit vars
min_y, max_y = -200, 200
min_x, max_x = -100, 100

# global obstacle_list to only make obtacles once
obstacle_list = []


def setup_world(robot_name):
    """
    initialise global variables
    """
    global position_x, position_y, current_direction_index, obstacle_list
    print(f"{robot_name}: Loaded {obs_module}.")
    obstacle_list = obstacles.get_obstacles()
示例#5
0
import robot, import_helper, sys
from maze import mazerunner
if len(sys.argv) > 2:
    if "maze" in sys.argv[2]:
        maze = import_helper.dynamic_import("maze." + sys.argv[2])
    else:
        maze = import_helper.dynamic_import("maze.obstacles")
else:
    sys.argv.append("obstacles")
    maze = import_helper.dynamic_import("maze.obstacles")

# list of valid command names
valid_commands = [
    'off', 'help', 'replay', 'forward', 'back', 'right', 'left', 'sprint'
]
move_commands = valid_commands[3:]

# variables tracking position and direction
position_x = 0
position_y = 0
directions = ['forward', 'right', 'back', 'left']
current_direction_index = 0

# area limit vars
min_y, max_y = -200, 200
min_x, max_x = -100, 100
obstacles_flag = False


def obs_aware():
    """
def use_maze(maze_ob):
    """imports the maze and uses it instead of the randomly generated obstacles"""
    global ob
    o = import_helper.dynamic_import(maze_ob)
    ob = o.get_obstacles()
    return (ob)
示例#7
0
import sys
import import_helper

global obstacles, argv_value

obstacles = import_helper.dynamic_import("maze.obstacles")
argv_value = "obstacles"
    
if "text" in sys.argv and len(sys.argv) == 3:
    argv_value = sys.argv[len(sys.argv)-1]
    obstacles = import_helper.\
                dynamic_import("maze."+argv_value)


def return_obst_import():
    """
        function returns module
        :returns obstacles: this module
    """
    global obstacles

    return obstacles


def print_obstacles(robot_name):
    """
        print all obstacles
        :param list_of_obst: list with obstacles
    """
    global obstacles, argv_value
示例#8
0
from unittest.mock import patch
from import_helper import dynamic_import
import sys, os.path, re
from io import StringIO
import argparse
import unittest
# import setup
import sys

configure = dynamic_import('config.configure')
setup = dynamic_import('config.setup')


class TestCase(unittest.TestCase):

    maxDiff = None

    @patch("sys.stdin", StringIO(' \nfapatel'))
    def test_get_users_home_dir(self):

        self.assertEqual(setup.get_users_home_dir(), 'fapatel')
        self.assertEqual(setup.get_users_home_dir(), 'fapatel')

    @patch("sys.stdin", StringIO('JhB\nJHB\ncape town\nJohannesburg'))
    def test_get_campus(self):

        campus = ['jhb', 'JHB', 'JOHANNESBURG', 'Johannesburg', 'johannesburg']

        self.assertNotEqual(setup.get_campus(campus), 'JhB')
        self.assertEqual(setup.get_campus(campus), 'Johannesburg')
from import_helper import dynamic_import
import os
import sys
configure = dynamic_import('config.configure')


def main():
    """
    Function takes information from the commandline.
    """
    args = configure.set_parser()
    t = args.t
    r = args.r
    d = args.d
    n = args.n
    m = args.m
    os.system(
        f'python3 config/configure.py -n {n} -r {r} -m {m} -d {d} -t {t}')


if __name__ == '__main__':
    main()