Auftrag 1
Studiere im Wiki das Kapitel 3.1 und 3.3.1 (call by value vs. call by reference) zu den Variablen
Folgende Fragen sollten beantwortet werden können:
Auftrag 2
Auftrag 3
Schreibe ein Programm, welches deinen Agenten dazu bringt, Diamanten einzusammeln und Knochen nicht einzusammeln (bzw. wieder wegzuwerfen)
Erstelle dazu eine flache Welt und kopiere den untenstehenden Code in deinen Codebuilder.
def build_arena():
blocks.fill(SANDSTONE, world(0,-61,0),world(30,-61,30))
blocks.fill(212, world(0,-60,30), world(30,-59,30))
blocks.fill(212, world(30,-60,30), world(30,-59,0))
blocks.fill(212, world(30,-60,0), world(0,-59,0))
blocks.fill(212, world(0,-60,0), world(0,-59,30))
blocks.fill(AIR, world(30,-58,0), world(0,-58,0))
blocks.fill(211, world(0,-62,0),world(30,-62,30))
player.on_chat("build_arena", build_arena)
def spread_items():
for i in range(10):
agent.set_item(DIAMOND, 1, 1)
a = randint(1, 29)
b = randint(1,29)
agent.teleport(world(a, -60, b), WEST)
agent.drop(BACK, 1, 1)
for i in range(10):
agent.set_item(BONE,2,2)
a = randint(1, 29)
b = randint(1,29)
agent.teleport(world(a, -60, b), WEST)
agent.drop(BACK, 2, 1)
player.on_chat("spread_items", spread_items)
def teleport_agent():
a = randint(1, 29)
b = randint(1,29)
agent.teleport(world(a, -60, b), WEST)
def start():
teleport_agent()
time1 = gameplay.time_query(GAME_TIME)
while gameplay.time_query(GAME_TIME)-time1<2000:
#agent.turn_left()
u = randint(1,3)
agent.move(FORWARD, u)
agent.collect_all()
agent.move(FORWARD, 1)
agent.collect_all()
agent.turn_left()
if u==2:
agent.turn_left()
player.on_chat("start", start)
#agent.detect(AgentDetection.BLOCK, FORWARD)
#agent.inspect(AgentInspection.BLOCK, FORWARD)
#agent.get_item_detail(1)