编程农场吧 关注:163贴子:416
  • 7回复贴,共1

南瓜获取方法思路及代码

只看楼主收藏回复

首先现将所有格子种上一遍南瓜。
在遍历一遍所有格子,用字典记录下所有枯萎南瓜的位置。比如:{(1,1),0}代表1,1位置上的南瓜是枯萎南瓜。
然后再循环遍历该字典,让无人机去往这些枯萎南瓜的位置,并种下南瓜,如果再次遍历该位置时该位置上的南瓜以成熟就将字典中该位置的值更改为1表示以替换为好南瓜,循环往复即可#游戏攻略#完整代码在评论区


IP属地:河南来自Android客户端1楼2025-10-12 14:48回复
    大佬们如果有更好的思路可以分享出来让我学习下吗


    IP属地:河南来自Android客户端2楼2025-10-12 14:49
    回复
      2026-03-17 15:21:42
      广告
      不感兴趣
      开通SVIP免广告
      南瓜文件
      import file
      def move_all(func):
      dict={}
      len=0
      for i in range(get_world_size()):
      for j in range(get_world_size()):
      if func():
      dict[(get_pos_x(),get_pos_y())]=0
      len+=1
      move(North)
      move(East)
      return dict,len
      def move_action():
      file.watering()
      if get_ground_type()!=Grounds.Soil:
      till()
      if get_entity_type()==Entities.Dead_Pumpkin:
      plant(Entities.Pumpkin)
      return True
      return False
      def pumpkin_fun():
      dict={}
      len=0
      file.Plant_all(Entities.Pumpkin)#先全部种上南瓜
      dict,len=move_all(move_action)#获取枯萎南瓜的位置和数量
      while(len!=0):#当枯萎南瓜数量为0时退出循环
      for pos in dict:#遍历枯萎南瓜的位置
      if dict[pos]==1:#值为1代表该位置的枯萎南瓜已经被替换
      continue
      file.position(pos[0],pos[1])#去往枯萎南瓜的位置
      if can_harvest():#如果是个成熟南瓜就代表该位置的枯萎南瓜已被替换
      dict[pos]=1#将值更改为1
      len-=1#数量减1
      else:
      file.fertilize()
      plant(Entities.Pumpkin)
      harvest()
      def pumpkin_get(num=-1):
      file.position(0,0)
      file.plant_template(Items.Pumpkin,pumpkin_fun,num)
      if __name__=='__main__':
      pumpkin_get()


      IP属地:河南来自Android客户端3楼2025-10-12 14:50
      回复
        file文件:
        def move_all(func):
        def wrapper():
        for i in range(get_world_size()):
        for j in range(get_world_size()):
        func()
        move(North)
        move(East)
        return wrapper
        def Plant_all(Plant):
        for i in range(get_world_size()):
        for j in range(get_world_size()):
        if can_harvest():
        harvest()
        if get_ground_type()!=Grounds.Soil:
        till()
        plant(Plant)
        move(North)
        move(East)
        def watering():
        if get_water()<=0.75:
        use_item(Items.Water,(1-get_water())/0.25)
        def fertilize():
        use_item(Items.Fertilizer)
        def plant_template_front(func):
        def wrapper():
        watering()
        if can_harvest():
        harvest()
        else:
        fertilize()
        func()
        return wrapper
        #网页链接 def plant_template(Plant,func,total=-1):
        if total==-1:
        while True:
        func()
        else:
        cur_num=num_items(Plant)
        while cur_num<total:
        cur_num=num_items(Plant)
        func()
        return True
        def move_lenth(vec,lenth):
        dict={North:South,South:North,West:East,East:West}
        if lenth>0:
        for i in range(lenth):
        move(vec)
        else:
        for i in range(abs(lenth)):
        move(dict[vec])
        def position(total_x,total_y):
        cur_x=get_pos_x()
        cur_y=get_pos_y()
        gap_x=total_x-cur_x
        gap_y=total_y-cur_y
        move_lenth(East,gap_x)
        move_lenth(North,gap_y)
        if __name__=='__main__':
        dict={(1,1):1,(2,2):2}
        for i in dict:
        print(dict[i])


        IP属地:河南来自Android客户端4楼2025-10-12 14:51
        收起回复
          先种一遍南瓜,然后遍历一遍,没南瓜的种上南瓜并把坐标加入集合里,然后从集合读坐标回去看有没南瓜,有就把这个坐标删了,没有继续种,集合空了就是所有南瓜都种上了


          IP属地:浙江来自Android客户端5楼2025-10-12 17:07
          收起回复