[编程农场][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()
相关推荐
ZhengEnCi7 分钟前
M3-markconv库找不到wkhtmltopdf问题
python
2301_764441333 小时前
LISA时空跃迁分析,地理时空分析
数据结构·python·算法
chushiyunen4 小时前
python rest请求、requests
开发语言·python
cTz6FE7gA4 小时前
Python异步编程:从协程到Asyncio的底层揭秘
python
baidu_huihui4 小时前
在 CentOS 9 上安装 pip(Python 的包管理工具)
开发语言·python·pip
南 阳4 小时前
Python从入门到精通day63
开发语言·python
lbb 小魔仙4 小时前
Python_RAG知识库问答系统实战指南
开发语言·python
FreakStudio4 小时前
MicroPython LVGL基础知识和概念:底层渲染与性能优化
python·单片机·嵌入式·电子diy
素玥5 小时前
实训5 python连接mysql数据库
数据库·python·mysql