[编程农场][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()
相关推荐
vxiam14xxx7 小时前
【Java Swing 项目】java 聊天系统
java·开发语言·python
Howard在远程7 小时前
[编程农场][The Farmer Was Replaced]——Carrot & Pumpkin
python
PieroPc7 小时前
用python streamlit sqlite3 写一个聊天室
python·streamlit·聊天室
低头不见7 小时前
策略模式上下文管理
windows·python·策略模式
Xander W7 小时前
基于K8s集群的PyTorch DDP 框架分布式训练测试(开发机版)
人工智能·pytorch·分布式·python·深度学习·kubernetes
文火冰糖的硅基工坊8 小时前
[人工智能-大模型-103]:模型层 - M个神经元组成的单层神经网络的本质
python·算法·机器学习
坚持就完事了8 小时前
XPath语法及Python的lxml包学习
python
孤独的追光者8 小时前
使用Qt Designer开发上位机
开发语言·python·qt
杨超越luckly8 小时前
HTML应用指南:利用POST请求获取全国爱回收门店位置信息
大数据·前端·python·信息可视化·html