[编程农场][The Farmer Was Replaced]——Bones/Dinasour

写在前面

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

农场边长:

无人机数量:

Bones

python 复制代码
def plant_dinosaur():
    clear()
    tail_len=0
    change_hat(Hats.Dinosaur_Hat)
    next_x,next_y=measure()
    tail_len+=1
    while tail_len<=(get_world_size()**2)//2+1:
        #平铺身体
        for i in range((tail_len-1)//(get_world_size()-1)+1):
            if i%2==0:
                while get_pos_x()!=get_world_size()-1:
                    move(East)
                    if get_entity_type()==Entities.Apple:
                        next_x,next_y=measure()
                        tail_len+=1
            else:
                while get_pos_x()!=1:
                    move(West)
                    if get_entity_type()==Entities.Apple:
                        next_x,next_y=measure()
                        tail_len+=1
            move(North)
            if get_entity_type()==Entities.Apple:
                next_x,next_y=measure()
                tail_len+=1
        #找苹果
        while 1:
            #若下一个不在最后一行
            if next_y!=get_world_size()-1:
                #若下一个不在第一列
                if next_x!=0:
                    #>当前行
                    if next_y>get_pos_y():
                        while get_pos_y()!=next_y:
                            move(North)
                            if get_entity_type()==Entities.Apple:
                                next_x,next_y=measure()
                                tail_len+=1
                                break
                        if next_x>get_pos_x():
                            while get_pos_x()!=next_x:
                                move(East)
                                if get_entity_type()==Entities.Apple:
                                    next_x,next_y=measure()
                                    tail_len+=1
                                    break
                        elif next_x<get_pos_x():
                            while get_pos_x()!=next_x:
                                move(West)
                                if get_entity_type()==Entities.Apple:
                                    next_x,next_y=measure()
                                    tail_len+=1
                                    break
                    #=当前行
                    elif next_y==get_pos_y():
                        if next_x>get_pos_x():
                            if can_move(East):
                                while get_pos_x()!=next_x:
                                    move(East)
                                    if get_entity_type()==Entities.Apple:
                                        next_x,next_y=measure()
                                        tail_len+=1
                                        break
                            else:
                                while get_pos_x()!=0:
                                    move(West)
                                while get_pos_y()!=0:
                                    move(South)
                                break
                        elif next_x<get_pos_x():
                            if can_move(West):
                                while get_pos_x()!=0:
                                    move(West)
                                    if get_entity_type()==Entities.Apple:
                                        next_x,next_y=measure()
                                        tail_len+=1
                                        break
                            else:
                                move(North)
                    #<当前行
                    else:
                        if not can_move(West):
                            move(North)
                        while get_pos_x()!=0:
                            move(West)
                            if get_entity_type()==Entities.Apple:
                                next_x,next_y=measure()
                                tail_len+=1
                        while get_pos_y()!=0:
                            move(South)
                            if get_entity_type()==Entities.Apple:
                                next_x,next_y=measure()
                                tail_len+=1
                        break
                #若下一个在第一列
                elif next_x==0:
                    #若当前不在第一列
                    if get_pos_x()!=0:
                        #若>当前行
                        if next_y>get_pos_y():
                            while get_pos_y()!=next_y:
                                move(North)
                            while get_pos_x()!=0:
                                move(West)
                                if get_entity_type()==Entities.Apple:
                                    next_x,next_y=measure()
                                    tail_len+=1
                            while get_pos_y()!=0:
                                move(South)
                                if get_entity_type()==Entities.Apple:
                                    next_x,next_y=measure()
                                    tail_len+=1
                            break
                        #若=当前行
                        elif next_y==get_pos_y():
                            if not can_move(West):
                                move(North)
                            while get_pos_x()!=0:
                                move(West)
                                if get_entity_type()==Entities.Apple:
                                    next_x,next_y=measure()
                                    tail_len+=1
                            while get_pos_y()!=0:
                                move(South)
                                if get_entity_type()==Entities.Apple:
                                    next_x,next_y=measure()
                                    tail_len+=1
                            break
                        #若<当前行
                        else:
                            if not can_move(West):
                                move(North)
                            while get_pos_x()!=0:
                                move(West)
                            while get_pos_y()!=0:
                                move(South)
                                if get_entity_type()==Entities.Apple:
                                    next_x,next_y=measure()
                                    tail_len+=1
                            break
                    #若当前在第一列
                    else:
                        while get_pos_y()!=0:
                            move(South)
                            if get_entity_type()==Entities.Apple:
                                next_x,next_y=measure()
                                tail_len+=1
                        break
            #若下一个在最后一行
            elif next_y==get_world_size()-1:
                #若当前在倒数第二行
                if get_pos_y()==get_world_size()-2:
                    #若不能向东
                    if not can_move(East):
                        #若不在最后一列
                        if get_pos_x()!=get_world_size()-1:
                            while get_pos_x()!=0:
                                move(West)
                            while get_pos_y()!=0:
                                move(South)
                            break
                        #若在最后一列
                        else:
                            move(North)
                            if get_entity_type()==Entities.Apple:
                                next_x,next_y=measure()
                                tail_len+=1
                            while get_pos_x()!=0:
                                move(West)
                                if get_entity_type()==Entities.Apple:
                                    next_x,next_y=measure()
                                    tail_len+=1
                            while get_pos_y()!=0:
                                move(South)
                                if get_entity_type()==Entities.Apple:
                                    next_x,next_y=measure()
                                    tail_len+=1
                            break
                    #若能向东
                    else:
                        while get_pos_x()!=get_world_size()-1:
                            move(East)
                        move(North)
                        if get_entity_type()==Entities.Apple:
                            next_x,next_y=measure()
                            tail_len+=1
                        while get_pos_x()!=0:
                            move(West)
                            if get_entity_type()==Entities.Apple:
                                next_x,next_y=measure()
                                tail_len+=1
                        while get_pos_y()!=0:
                            move(South)
                            if get_entity_type()==Entities.Apple:
                                next_x,next_y=measure()
                                tail_len+=1
                        break
                #若当前在倒数第一行
                elif get_pos_y()==get_world_size()-1:
                    while get_pos_x()!=0:
                        move(West)
                        if get_entity_type()==Entities.Apple:
                            next_x,next_y=measure()
                            tail_len+=1
                    while get_pos_y()!=0:
                        move(South)
                        if get_entity_type()==Entities.Apple:
                            next_x,next_y=measure()
                            tail_len+=1
                    break
                #若当前不在倒数后两行
                else:
                    if not can_move(East):
                        move(North)
                    while get_pos_x()!=get_world_size()-1:
                        move(East)
                    while get_pos_y()!=get_world_size()-1:
                        move(North)
                        if get_entity_type()==Entities.Apple:
                            next_x,next_y=measure()
                            tail_len+=1
                            break
                    while get_pos_x()!=0:
                        move(West)
                        if get_entity_type()==Entities.Apple:
                            next_x,next_y=measure()
                            tail_len+=1
                    while get_pos_y()!=0:
                        move(South)
                        if get_entity_type()==Entities.Apple:
                            next_x,next_y=measure()
                            tail_len+=1
                    break
    while tail_len>(get_world_size()**2)//2+1:
        for i in range(get_world_size()):
            if i%2==0:
                while get_pos_x()!=get_world_size()-1:
                    if not move(East):
                        change_hat(Hats.Brown_Hat)
                        return
            else:
                while get_pos_x()!=1:
                    if not move(West):
                        change_hat(Hats.Brown_Hat)
                        return
            if get_pos_y()!=get_world_size()-1:
                if not move(North):
                    change_hat(Hats.Brown_Hat)
                    return
            else:
                while get_pos_x()!=0:
                    if not move(West):
                        change_hat(Hats.Brown_Hat)
                        return
                while get_pos_y()!=0:
                    if not move(South):
                        change_hat(Hats.Brown_Hat)
                        return
    return
plant_dinosaur()
相关推荐
zyk_computer2 分钟前
AI 时代,或许 Rust 比 Python 更合适
人工智能·后端·python·ai·rust·ai编程·vibe coding
weixin199701080164 分钟前
【保姆级教程】淘宝/天猫商品详情 API(item_get)接入指南:Python/Java/PHP 调用示例与 JSON 返回值解析
java·python·php
萌新小码农‍11 分钟前
python装饰器
开发语言·前端·python
KK溜了溜了14 分钟前
Python从入门到精通
服务器·开发语言·python
2401_8844541528 分钟前
mysql处理复杂SQL性能_InnoDB优化器与MyISAM差异
jvm·数据库·python
m0_470857641 小时前
golang如何实现目录大小统计_golang目录大小统计实现方案
jvm·数据库·python
消晨消晨1 小时前
MONAI初上手——模型构建
pytorch·python·monai
weixin_444012931 小时前
如何在多实例管理时隐藏MySQL版本信息_安全混淆与配置
jvm·数据库·python
weixin_459753941 小时前
SQL处理大规模分组聚合的内存限制_调整服务器配置
jvm·数据库·python
Rust语言中文社区2 小时前
【Rust日报】2026-05-14 Pyrefly v1.0 正式发布:快速的 Python 类型检查器和语言服务器
开发语言·后端·python·rust