Exemplo n.º 1
0
import grobot
import random

d = grobot.NewRobot("Bob", 2, 2, "Green")

world = [[
    True, True, True, True, True, True, True, True, True, True, True, True,
    True, True, True, True, True, True, True, True, True, True, True, True,
    True, True, True, True, True, True
],
         [
             True, True, True, True, True, True, True, True, True, True, True,
             True, True, True, True, True, True, True, True, True, True, True,
             True, True, True, True, True, True, True, True
         ],
         [
             True, True, True, True, True, True, True, True, True, True, True,
             True, True, True, True, True, True, True, True, True, True, True,
             True, True, True, True, True, True, True, True
         ],
         [
             True, True, True, True, True, True, True, True, True, True, True,
             True, True, True, True, True, True, True, True, True, True, True,
             True, True, True, True, True, True, True, True
         ],
         [
             True, True, True, True, True, True, True, True, True, True, True,
             True, True, True, True, True, True, True, True, True, True, True,
             True, True, True, True, True, True, True, True
         ],
         [
    exit1 = str(input("Exit = E"))
    if exit1 == "E":
        print("Exiting...")
        break
    count -= 1

Sia.init(x,y)

inc y when going north
dec y when going south

inc x when going east
dec x when going west 
"""

Sia = grobot.NewRobot("Sia", 4, 2, "green")

count = 500
while count > 0:
    f = Sia.look()[2]
    l = Sia.look()[0]
    ld = Sia.look()[1]
    r = Sia.look()[4]
    rd = Sia.look()[3]
    if f == None:
        print("Sia forward", Sia.forward())
    elif r == None:
        print("Sia right", Sia.right())
        print("Sia right", Sia.forward())
    elif l == None:
        print("Sia left", Sia.left())
import grobot
import random

hamza = grobot.NewRobot("hamza", 4, 3, "Orange")
count = 500
while count > 0:
    f = hamza.look()[2]
    l = hamza.look()[0]
    ld = hamza.look()[1]
    rd = hamza.look()[3]
    r = hamza.look()[4]
    All = [f, l, ld, rd, r]
    print(All)
    if f == 'Wall' and l == None and ld == None and rd == 'Wall' and r == 'Wall':
        n = random.randint(0, 1)
        if n == 0:
            print(hamza.left())
            print(hamza.forward())
        else:
            print(hamza.left())
            print(hamza.forward())
            print(hamza.right())
            print(hamza.forward)
    elif f == None and l == 'Wall' and ld == 'Wall' and rd == 'Wall' and r == 'Wall':
        print(hamza.forward())
        print('If statement - 1')
    elif f == None and l == None and ld == 'Wall' and rd == 'Wall' and r == 'Wall':
        n = random.randint(0, 2)
        print('Random no:', n)
        if n <= 1:
            print(hamza.forward())
Exemplo n.º 4
0
import grobot
import random

bot = grobot.NewRobot('Robot', 15, 15, 'Blue')


def start():
    loop()


def forwardd(x, y, heading):
    if heading == 'north':
        y += 1
    elif heading == 'east':
        x += 1
    elif heading == 'south':
        y -= 1
    else:
        x -= 1
    return x, y


def leftt(heading):
    if heading == 'north':
        heading == 'west'
    elif heading == 'west':
        heading = 'south'
    elif heading == 'south':
        heading = 'east'
    else:
        heading = 'north'
Exemplo n.º 5
0
import grobot

print('This is a simple user interface where you\ncan control a robot using few simple commands.')
print()
print('Commands\nf = Forward\nl = Turn Left\nr = TurnRight')
print()
h = grobot.NewRobot("Hamza", 2, 2, "Red")
x = 2
y = 2
heading = "north"
print('Current heading & location\nHeading: {0}\nx:{1} y:{2}'.format(heading,x,y))
print()

def outofBounds(heading,x,y):
  if x + 1 > 30 and heading == "east":
    heading = turnRight(heading)
    heading = turnRight(heading)
  elif x -1 < 1 and heading == "eest":
    heading = turnRight(heading)
    heading = turnRight(heading)
  elif y - 1 <= 0 and heading == "south":
    heading = turnRight(heading)
    heading = turnRight(heading)
  elif y +1 > 30 and heading == "north":
    heading = turnRight(heading)
    heading = turnRight(heading)
  return heading

def forward(x,y,heading):
  print(h.forward())
  if heading == 'north':
Exemplo n.º 6
0
import grobot
import random
d = grobot.NewRobot("cat", 27, 9, "Green")
x = 27
y = 9
heading = "north"
print('Current heading & location\nHeading: {0}\nx:{1}\ny:{2}'.format(heading,x,y))
print()
xd = int(input('Enter your destionation x coordinate: '))
yd = int(input('Enter your destionation y coordinate: '))
count = 10000
while count > 0:
  print()
  f = d.look()[2]
  l = d.look()[0]
  ld = d.look()[1]
  rd = d.look()[3]
  r = d.look()[4]
  All = [l,ld,f,rd,r]
  print(All)
  if f == None:
    nn = random.randint(0,7)
    if nn == 0:
      if l == 'Wall' and ld == 'Wall' and f == None and rd == 'Wall' and r == None:
        print(d.right())
        if heading == 'west':
          heading = 'north'
        elif heading == 'north':  
          heading = 'east'
        elif heading == 'east':
          heading = 'south'
import grobot
import random
x = 4
y = 2
xx = 15
yy = 15
bob = grobot.NewRobot("bob", x,y,"Purple")
tom = grobot.NewRobot("tom", xx, yy, "Red")
bob.right()
tom.left()
def move_bob(bl,bld,bf,brd,br,beyes):
    if bf == "tom" or bf == "d" or bf == "hamza":
              print('Hi tom, how you doing?')
              print(bob.right())
              print(bob.forward())
    if beyes == [None,None,None,None,None]:
        r = random.randint(0,10)
        if r == 0:
            print(bob.left())
        elif r == 2:
            print(bob.left())
            print(bob.forward())
            print(bob.right())
            print(bob.forward())

        elif r == 3:
            print(bob.right())
            print(bob.forward())
            print(bob.left())
            print(bob.forward())
        elif r == 1:
Exemplo n.º 8
0
import grobot
import random

hamza = grobot.NewRobot("hamza", 2, 2, "Orange")
count = 20
iff1 = 0
iff2 = 0
iff3 = 0
iff4 = 0
iff5 = 0
iff6 = 0
iff7 = 0
iff8 = 0
iff9 = 0
iff10 = 0
iff11 = 0
iff12 = 0
iff13 = 0
iff14 = 0
iff15 = 0
iff15 = 0
iff16 = 0
iff17 = 0
iff18 = 0
iff19 = 0
iff20 = 0
iff21 = 0
iff22 = 0
iff23 = 0
iff24 = 0
iff25 = 0
Exemplo n.º 9
0
import grobot
import random
import itertools

hamza = grobot.NewRobot("hamza", 1, 1, "Orange")
count = 5
while count > 0:
    f = hamza.look()[2]
    l = hamza.look()[0]
    ld = hamza.look()[1]
    rd = hamza.look()[3]
    r = hamza.look()[4]
    lst_f = [[l, ld, rd, r]]
    print(lst_f)
    for L in range(0, len(lst_f) + 1):
        for subset_f in itertools.combinations(lst_f, L):
            print(subset_f)
    if f == None and subset_f == (['Wall', 'Wall', 'Wall', 'Wall']):
        print(hamza.forward())

    count -= 1
Exemplo n.º 10
0
import grobot

print('This is a simple user interface where you\ncan control a robot using few simple commands')
print('Commands\nf = Forward\nl = Go Left\nr = Go Right')
h = grobot.NewRobot("Hamza", 2, 2, "Blue")

h.forward() * (5)