[编程农场][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()
相关推荐
Zhichao_9716 分钟前
【UE5.3 C++】ARPG游戏 05-准备角色攻击的武器和动画
游戏·ue5
清水白石00829 分钟前
解构异步编程的两种哲学:从 asyncio 到 Trio,理解 Nursery 的魔力
运维·服务器·数据库·python
山海青风33 分钟前
图像识别零基础实战入门 1 计算机如何“看”一张图片
图像处理·python
彼岸花开了吗1 小时前
构建AI智能体:八十、SVD知识整理与降维:从数据混沌到语义秩序的智能转换
人工智能·python·llm
山土成旧客1 小时前
【Python学习打卡-Day40】从“能跑就行”到“工程标准”:PyTorch训练与测试的规范化写法
pytorch·python·学习
闲人编程1 小时前
消息通知系统实现:构建高可用、可扩展的企业级通知服务
java·服务器·网络·python·消息队列·异步处理·分发器
大神君Bob2 小时前
【AI办公自动化】如何使用Pytho让Excel表格处理自动化
python
Heorine2 小时前
数学建模 绘图 图表 可视化(6)
python·数学建模·数据可视化
栈与堆2 小时前
LeetCode-1-两数之和
java·数据结构·后端·python·算法·leetcode·rust
智航GIS3 小时前
10.7 pyspider 库入门
开发语言·前端·python