[编程农场][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()
相关推荐
困死,根本不会32 分钟前
蓝桥杯python备赛笔记之(十)数论基础 & 日期问题
笔记·python·蓝桥杯
輕華36 分钟前
Python 命令行参数处理:sys.argv 与 argparse 深度对比
python
清水白石0081 小时前
Python 内存陷阱深度解析——浅拷贝、深拷贝与对象复制的正确姿势
开发语言·python
国家二级编程爱好者1 小时前
删除typora文档没有引用的资源文件
git·python
进击的雷神1 小时前
邮箱编码解码、国际电话验证、主办方过滤、多页面深度爬取——柬埔寨塑料展爬虫四大技术难关攻克纪实
爬虫·python
深蓝电商API2 小时前
多线程 vs 异步 vs 多进程爬虫性能对比
爬虫·python
进击的雷神2 小时前
相对路径拼接、TEL前缀清洗、多链接过滤、毫秒级延迟控制——日本东京塑料展爬虫四大技术难关攻克纪实
爬虫·python
云溪·2 小时前
Milvus向量数据库混合检索召回案例
python·ai·milvus
柒.梧.2 小时前
Java集合核心知识点深度解析:数组与集合区别、ArrayList原理及线程安全问题
java·开发语言·python
AsDuang3 小时前
Python 3.12 MagicMethods - 49 - __imatmul__
开发语言·python