Пример #1
0
def task():
        def turnSB15(a):
                for i in range(a):
                        sb15.turnLeft()
        def turnKarel(a):
                for i in range(a):
                        karel.turnLeft()
#       Commands to control the "world"
        world.readWorld("stepsWorld.kwld")    # open a particular world file
        world.setSize(10,10)               # set the size of the visible world
        #^^ should be 10
        world.setDelay(90)                # set simulation speed. 0-fastest, 100-slowest

        karel = UrRobot(2,3,East, 1,fill="blue")
        sb15 = UrRobot(1,6,North, 10, fill="green")
        sb15.move()
        karel.turnLeft()
        turnSB15(1)
        sb15.move()
        turnSB15(3)
        sb15.move()
        turnSB15(1)
        sb15.move()
        turnSB15(1)
        turnKarel(1)
        karel.move()
        turnKarel(1)
        karel.move()
        turnKarel(2)
        turnSB15(2)
Пример #2
0
def task():
    #Commands to control the "world"
    #Open a particular world file
    world.readWorld("beeperWorld.kwld")
    #Set the size of the visible world
    world.setSize(10, 10)
    #Set the speed of the robot
    world.setDelay(30)

    sb15 = UrRobot(5, 6, North, 1, fill='green', outline='blue')

    def turn(a):
        for i in range(a):
            sb15.turnLeft()

    def pickAndTurn(a):
        for i in range(a):
            sb15.pickBeeper()
            sb15.turnLeft()
            sb15.move()
            turn(3)
            sb15.move()

    #Write the code to make your robot pick up all the beepers.
    sb15.turnLeft()
    sb15.move()
    pickAndTurn(4)
    sb15.pickBeeper()
    time.sleep(3)
Пример #3
0
def task():
#       Commands to control the "world"
        world.readWorld("steps2.kwld")    # open a particular world file
        world.setSize(10,10)               # set the size of the visible world
        world.setDelay(50)                # set simulation speed. 0-fastest, 100-slowest

        mrP = Climber(1,1,North, 1)     #Creating an UrRobot called mrP
Пример #4
0
 def setUp(self):
     world.setSize(10, 10)
     world.reset()
     world.setDelay(0)
     self.karel = UrRobot(5, 5, North, 0)
     world.setVisible(
         0
     )  #Doesn't work. It is reset visible whenever Robota is loaded again.
Пример #5
0
def task():
        #Commands to control the "world"
        #Opens a particular world file
        world.setSize(10,10)
        #Sets the size of the visible world
        world.setDelay(30)
        #set simulation speed. 0-fastest, 100-slowest
        sb15 = Dancer(3,3,North,1,fill="green", outline="blue")
        sb2 = Dancer(3,6,North,1,fill="blue", outline="green")
        #Write the code to test the methods of Dancer Class with different robots
        sb2.dance(1)
        sb15.partnerDance(1)
Пример #6
0
    def __init__(self,
                 name,
                 street,
                 avenue,
                 direction,
                 beepers,
                 fill=None,
                 outline=None):
        self.karel = UrRobot(street, avenue, direction, beepers, fill, outline)
        #        self.window = window()
        world.setDelay(0)
        self.fill = fill
        self.name = name
        global offset
        offset += 20
        window = gtk.Dialog()
        window.set_has_separator(False)
        try:
            color = gtk.gdk.color_parse(fill)
            window.modify_bg(gtk.STATE_NORMAL, color)
        except:
            pass

        window.connect("destroy", self.destroy)
        window.set_title(name)
        window.set_size_request(100, 150)

        moveButton = gtk.Button("Move")
        moveButton.connect("clicked", self.move)
        moveButton.show()
        window.vbox.pack_start(moveButton, True, False, 0)

        turnButton = gtk.Button("TurnLeft")
        turnButton.connect("clicked", self.turnLeft)
        turnButton.show()
        window.vbox.pack_start(turnButton, True, False, 0)

        pickButton = gtk.Button("PickBeeper")
        pickButton.connect("clicked", self.pickBeeper)
        pickButton.show()
        window.vbox.pack_start(pickButton, True, False, 0)

        putButton = gtk.Button("PutBeeper")
        putButton.connect("clicked", self.putBeeper)
        putButton.show()
        window.vbox.pack_start(putButton, True, False, 0)

        turnOffButton = gtk.Button("TurnOff")
        turnOffButton.connect("clicked", self.turnOff)
        turnOffButton.show()
        window.vbox.pack_start(turnOffButton, True, False, 0)
        window.show()
        window.move(500 + offset, 20 + offset)
Пример #7
0
def task():
        #Commands to control the "world"
        world.readWorld("steps2.kwld")
        #Opens a particular world file
        world.setSize(10,10)
        #Sets the size of the visible world
        world.setDelay(30)
        #set simulation speed. 0-fastest, 100-slowest

        sb15 = Climber(1, 1, North, 1, fill="green", outline="blue")        
        #Write the code to make your robot climb the steps and get to the other side
        sb15.climbStep(5)
        sb15.turnOff()
Пример #8
0
def task():
    #       Commands to control the "world"
    world.readWorld("steps2.kwld")  # open a particular world file
    world.setSize(10, 10)  # set the size of the visible world
    world.setDelay(50)  # set simulation speed. 0-fastest, 100-slowest

    robot1 = Turner(
        1, 1, West,
        0)  #Note: this will cause an error until you import the class
    robot2 = Turner(2, 2, South, 0, "pink")
    robot3 = Turner(4, 3, North, 0, "red")
    robot4 = Turner(5, 4, North, 0, "blue")
    robot5 = Turner(6, 7, North, 0, "black")
Пример #9
0
def task():
    #       Commands to control the "world"

    # set the size of the visible world
    world.setSize(9)
    # set simulation speed. 0-fastest, 100-slowest
    world.setDelay(0.001)

    #TO DO: Create a PinSetter Robot, Street 1, Avenue 5, facing North, 10 beepers
    ps = PinSetter(1, 5, North, 17, fill='green', outline='blue')
    hv = Harvester(1, 5, North, 0, fill='blue', outline='green')
    #Wirte the instructions for your robot to set the pins:
    ps.setPins()
    hv.colPins()
Пример #10
0
def task():
        #Commands to control the "world"
        world.readWorld("danceWorld.kwld")
        #Set the size of the visible world
        world.setSize(10,10)
        #Set simulation speed. 0-fastest, 100-slowest
        world.setDelay(20)
        #Start a Dancer at Street 7, Avenue 3, facing North, with 0 beepers:
        dancer1 = Dancer(7,3,North,0)
        #Write the code for the dancer to perform the first dance
        dancer1.danceSteps1()
        #Start 2nd Dancer at Street 7, Avenue 7, facing North, with 0 beepers:
        dancer2 = Dancer(7,7,North,0)
        #Write the code for the second dancer to perform the second dance
        dancer2.danceSteps2()
Пример #11
0
def task():
    #       Commands to control the "world"
    world.readWorld("maze2.kwld")  # open a particular world file
    world.setSize(10, 10)  # set the size of the visible world
    world.setDelay(50)  # set simulation speed. 0-fastest, 100-slowest

    #create a Robot sprite (give it your name) and start it on
    # Street 3, Avenue 1
    sb15 = Robot(3, 1, East, 0, fill='blue', outline='green')

    #Write the code to make your robot find it's way out of the maze and end up
    #on Street 8, Avenue 5 and pick up the beeper that's there
    while not sb15.anyBeepersInBeeperBag():
        if sb15.frontIsClear():
            sb15.move()
        else:
            sb15.turnLeft()
            if not sb15.frontIsClear():
                sb15.turnLeft()
                sb15.turnLeft()
        if sb15.nextToABeeper():
            sb15.pickBeeper()
Пример #12
0
def task():
    #Commands to control the "world"
    size = int(54)
    world.setSize(size, size)  # set the size of the visible world
    world.setDelay(0)  # set simulation speed. 0-fastest, 100-slowest

    #Write the code to test the methods of Dancer Class with different robots
    sb2 = Writer(1, 1, East, infinity)
    #For newLine(a), a = the number of letters in the line before it.
    sb2.s()
    sb2.h()
    sb2.o()
    sb2.e()
    sb2.m()
    sb2.a()
    sb2.k()
    sb2.e()
    sb2.r()
    sb2.newLine(9)
    sb2.t()
    sb2.o()
    sb2.m()
    sb2.m()
    sb2.y()
Пример #13
0
from karel.robotworld import infinity
from karel.robota import world
import sys
from pathlib import Path

world_file = ""
if sys.argv[1].startswith("worlds"):
    path_split = sys.argv[1].split("/")
    worlds_folder = Path(path_split[0])
    world_file = worlds_folder / path_split[1]
else:
    world_file = sys.argv[1]

world.readWorld(world_file)
world.setVisible(True)
world.setDelay(50)

with open(world_file, 'r') as f:
    first_line = f.readline().strip()
configs = first_line.split("-")
direction = None
if configs[2].lower() == "east":
    direction = East
elif configs[2].lower() == "west":
    direction = West
elif configs[2].lower() == "north":
    direction = North
elif configs[2].lower() == "south":
    direction = South
num_beepers = 0
if configs[3].lower() == "inf":