I'm an incumbent college student and I have a question about Python coding.
I'd like to know how to fix the code below with bubble sort.
under the code
------------------------------------------------------
p_x, p_y, p_z =(0, 4, 5)
player.teleport(world(p_x ,p_y, p_z))
def agent_home():#에이전트 초기 위치
a_h_x=p_x
a_h_y=p_y
a_h_z=p_z-3
agent.teleport(world(a_h_x, a_h_y, a_h_z),NORTH)
def base_loc(x):#에이전트 작업 위치
base_x= p_x-5+x
base_y= p_y
base_z= p_z-4
agent.teleport(world(base_x, base_y, base_z ), NORTH)
def block_set():
item=[]
i=0
cnt=0
while(cnt<11):
item[cnt]=randint(523, 533)
player.say(str(cnt)+" " +str(item[cnt]))
if cnt:
for i in range(cnt):
if item[i] == item[cnt]:
break
if i == cnt:
agent.set_item(item[cnt], 1, 1)
base_loc(cnt)
agent.destroy(FORWARD)
agent.place(FORWARD)
cnt = cnt + 1
agent_home()
def sort_block():
for i in range(10):
base_loc(i)
min_i=agent.inspect(AgentInspection.BLOCK, FORWARD)
min_old=min_i
agent.set_item(min_i, 1, 1)
for j in range(i+1,11):
base_loc(j)
min_new=agent.inspect(AgentInspection.BLOCK, FORWARD)
if min_old > min_new:
min_old=min_new
loc=j
agent.set_item(min_old, 1, 2)
if min_i > min_old:
base_loc(i)
agent.destroy(FORWARD)
agent.set_slot(2)
agent.place(FORWARD)
base_loc(loc)
agent.destroy(FORWARD)
agent.set_slot(1)
agent.place(FORWARD)
agent.drop_all(BACK)
def on_chat():
agent_home()
block_set()
player.on_chat("set", on_chat)
def on_chat2():
agent_home()
sort_block()
agent_home()
player.on_chat("sort",on_chat2)
----------------------------------------------------
please help me
-
Thanks for posting! This is a large amount of code to post without comments. Please comment your code so we can know your intention for each section.
Also, your code is not posting with indentation, so that makes it pretty tricky to understand. =]
Try something like this throughout the code:
# This function causes the agent to.... by ... with function ...
def on_chat2():
agent_home()
sort_block(). # calling this function changes the ...
agent_home()Just as an initial question, you have variables which are not easily recognized. For example, you set cnt to 0, but then you have an if statement treating it as Boolean "if cnt:"
It is always helpful at first use of a variable to clarify type and purpose.
0
Please sign in to leave a comment.
Comments
1 comment