[编程农场][The Farmer Was Replaced]——Carrot & Pumpkin

写在前面

建议大家 无人机数量 ≥ 农场边长。注意以下两个科技树,使其匹配:

农场边长:

无人机数量:

Carrot

python 复制代码
n=get_world_size()
clear()
def make_drone():
    for j in range(n):
        till()
        plant(Entities.Carrot)
        move(North)
    while True: 
        for j in range(n):
            harvest()
            if get_water()<=0.3:
                use_item(Items.Water)
            plant(Entities.Carrot)
            move(North)

for i in range(max_drones()-1):    
    spawn_drone(make_drone)
    move(East)
make_drone()

Pumpkin

南瓜阵型:

用时不到9min

python 复制代码
nn=get_world_size()
#set_execution_speed(2)
p_cnt=200000000
n=6
water_level=0.7
line_level=0.55
clear()
arr_h = [[67, 23, 89, 12, 45, 78, 34, 90, 5, 62, 19, 83, 40, 71, 28, 55, 9, 68, 37, 14, 50, 82, 29, 76, 11, 59, 3, 49, 73, 21, 64, 8],[91, 17, 53, 30, 79, 15, 66, 2, 88, 42, 7, 56, 35, 94, 20, 61, 10, 75, 38, 4, 85, 25, 69, 18, 52, 80, 31, 77, 13, 57, 39, 95],[41, 86, 26, 70, 16, 54, 32, 81, 6, 51, 87, 24, 72, 1, 46, 92, 33, 65, 93, 43, 84, 22, 60, 96, 47, 100, 36, 58, 74, 27, 63, 97],[44, 98, 99, 48, 0, 56, 83, 22, 77, 15, 62, 39, 10, 88, 31, 67, 4, 92, 25, 71, 5, 53, 34, 80, 18, 64, 3, 95, 29, 75, 12, 59]]
arr_v = [[37, 82, 15, 64, 9, 41, 76, 23, 58, 10, 69, 32, 87, 18, 53, 2, 71, 46, 92, 13, 59, 28, 83, 16, 54, 3, 72, 47, 93, 14, 60, 29],[88, 19, 55, 4, 73, 48, 94, 1, 61, 30, 89, 20, 56, 5, 74, 49, 95, 11, 62, 31, 90, 21, 57, 6, 75, 50, 96, 12, 63, 32, 91, 22],[58, 7, 76, 51, 97, 13, 64, 33, 2, 59, 8, 77, 52, 98, 14, 65, 34, 3, 60, 9, 78, 53, 99, 15, 66, 35, 4, 61, 10, 79, 54, 100],[16, 67, 36, 5, 62, 11, 80, 55, 23, 17, 68, 37, 6, 63, 12, 81, 56, 24, 18, 69, 38, 7, 64, 13, 82, 57, 25, 19, 70, 39, 8, 65]]
def snake_move(n,i):
    if i==0 or i%(2*n-2)==1 and i<n*n-n:
        return North
    if i%(2*n-2)==n:
        return South
    if i%(n-1)==0 and i<n*n-n:
        return East
    if i==n*n-n+1:
        return West
    return None
def move_to(x,y):
    x0=get_pos_x()
    y0=get_pos_y()
    for i in range(abs(x-x0)):
        if x-x0 >0:
            move(East)
        else:
            move(West)            
    for i in range(abs(y-y0)):
        if y-y0 >0:
            move(North)
        else:
            move(South)
def drone_h():
    for i in range(nn):
        if get_ground_type() == Grounds.Grassland and get_pos_x()%5!=4:
            till()
            plant(Entities.Pumpkin)
        move(East)
    while True:
        if num_items(Items.Pumpkin) >= p_cnt:
            return
        x = get_pos_x()
        y = get_pos_y()
        if get_water()<=line_level:
            use_item(Items.Water)
        if get_entity_type() == Entities.Dead_Pumpkin or get_entity_type() == None:
            plant(Entities.Pumpkin)
        p=measure()
        if p != None:
            arr_h[y-28][x] = p
        if x>=3:
            if arr_h[y-28][x]==arr_h[y-28][x-1] and arr_h[y-28][x-1]==arr_h[y-28][x-2] and arr_h[y-28][x-2]==arr_h[y-28][x-3]:
                harvest()
        if x>=30:
            if can_harvest():
                harvest()
        move(East)
def drone_h1():
    while True:
        if num_items(Items.Pumpkin) >= p_cnt:
            return
        x = get_pos_x()
        y = get_pos_y()
        if get_water()<=line_level:
            use_item(Items.Water)
        if get_entity_type() == Entities.Dead_Pumpkin or get_entity_type() == None:
            plant(Entities.Pumpkin)
        p=measure()
        if p != None:
            arr_h[y-28][x] = p
        if x<=28:
            if arr_h[y-28][x]==arr_h[y-28][x+1] and arr_h[y-28][x]==arr_h[y-28][x+2] and arr_h[y-28][x]==arr_h[y-28][x+3]:
                harvest()
        if x>=30:
            if can_harvest():
                harvest()
        move(East)
def drone_v():
    for i in range(nn-4):
        if get_ground_type() == Grounds.Grassland and get_pos_y()%5!=4:
            till()
            plant(Entities.Pumpkin)
        move(North)
    while True:
        if num_items(Items.Pumpkin) >= p_cnt:
            return
        x = get_pos_x()
        y = get_pos_y()
        if get_water()<=line_level:
            use_item(Items.Water)
        if get_entity_type() == Entities.Dead_Pumpkin or get_entity_type() == None:
            plant(Entities.Pumpkin)
        p=measure()
        if p != None:
            arr_v[x-28][y] = p
        if y>=3:
            if arr_v[x-28][y]==arr_v[x-28][y-2] and arr_v[x-28][y]==arr_v[x-28][y-1] and arr_v[x-28][y]==arr_v[x-28][y-3]:
                harvest()
        if y>=25 and y<=27:
            if can_harvest():
                harvest()
        move(North)
def drone_v1():
    while True:
        if num_items(Items.Pumpkin) >= p_cnt:
            return
        x = get_pos_x()
        y = get_pos_y()
        if get_water()<=line_level:
            use_item(Items.Water)
        if get_entity_type() == Entities.Dead_Pumpkin or get_entity_type() == None:
            plant(Entities.Pumpkin)
        p=measure()
        if p != None:
            arr_v[x-28][y] = p
        if y<=28:
            if arr_v[x-28][y]==arr_v[x-28][y+2] and arr_v[x-28][y]==arr_v[x-28][y+1] and arr_v[x-28][y]==arr_v[x-28][y+3]:
                harvest()
        if y>=25 and y<=27:
            if can_harvest():
                harvest()
        move(South)
def make_drone():
    dir=North
    for i in range(n*n):
        if get_ground_type()==Grounds.Grassland:
            till()
            use_item(Items.Water)
            plant(Entities.Pumpkin)
        tmp = snake_move(n,i)
        if tmp!=None:
            dir = tmp
        move(dir)
    while True:
        if num_items(Items.Pumpkin) >= p_cnt:
            return
        bp=[]
        if get_entity_type() == None :
            for i in range(n*n):
                if get_water()<=water_level:
                    use_item(Items.Water)
                plant(Entities.Pumpkin)
                tmp = snake_move(n,i)
                if tmp!=None:
                    dir = tmp
                move(dir)
        for i in range(n*n):
            if get_entity_type() == Entities.Dead_Pumpkin :
                plant(Entities.Pumpkin)
                bp.append((get_pos_x(),get_pos_y()))
            elif not can_harvest():
                bp.append((get_pos_x(),get_pos_y()))
            tmp = snake_move(n,i)
            if tmp!=None:
                dir = tmp
            move(dir)
        while len(bp)!=0:
            xx, yy = bp[0]
            bp.remove((xx,yy))
            move_to(xx,yy)
            if get_entity_type() == Entities.Dead_Pumpkin:
                plant(Entities.Pumpkin)
                bp.append((xx,yy))
            elif not can_harvest():
                bp.append((xx,yy))                
        harvest()
        move_to(get_pos_x()//7*7,get_pos_y()//7*7)
def north_d():
    for i in range(22):
        if i%7==0:
            spawn_drone(east_d)
        move(North)
def east_d():
    for i in range(22):
        if i%7==0:
            spawn_drone(make_drone)
        move(East)
def upper():
    move(South)
    for i in range(4): 
        spawn_drone(drone_h)
        for i in range(10):
            pass
        if i == 3:
            drone_h1()
        move(South)
spawn_drone(north_d)
spawn_drone(upper)
move(West)
for i in range(3):
    spawn_drone(drone_v)
    for i in range(10):
        pass
    spawn_drone(drone_v1)
    move(West)
spawn_drone(drone_v)
for i in range(10):
    pass
drone_v1()
相关推荐
PieroPc7 小时前
用python streamlit sqlite3 写一个聊天室
python·streamlit·聊天室
低头不见7 小时前
策略模式上下文管理
windows·python·策略模式
Xander W7 小时前
基于K8s集群的PyTorch DDP 框架分布式训练测试(开发机版)
人工智能·pytorch·分布式·python·深度学习·kubernetes
文火冰糖的硅基工坊7 小时前
[人工智能-大模型-103]:模型层 - M个神经元组成的单层神经网络的本质
python·算法·机器学习
坚持就完事了8 小时前
XPath语法及Python的lxml包学习
python
孤独的追光者8 小时前
使用Qt Designer开发上位机
开发语言·python·qt
杨超越luckly8 小时前
HTML应用指南:利用POST请求获取全国爱回收门店位置信息
大数据·前端·python·信息可视化·html
TF男孩8 小时前
小技巧:让你写的python代码直接点击运行
python
程序员爱钓鱼8 小时前
Python编程实战 - 面向对象与进阶语法 - 异常类型与捕获
后端·python·ipython