[编程农场][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()
相关推荐
上不如老下不如小30 分钟前
2025年第七届全国高校计算机能力挑战赛初赛 Python组 编程题汇总
开发语言·python·算法
Q_Q51100828537 分钟前
python+django/flask的结合人脸识别和实名认证的校园论坛系统
spring boot·python·django·flask·node.js·php
Q_Q51100828538 分钟前
python+django/flask的选课系统与课程评价整合系统
spring boot·python·django·flask·node.js·php
charlie11451419143 分钟前
勇闯前后端Week2:后端基础——Flask API速览
笔记·后端·python·学习·flask·教程
豐儀麟阁贵1 小时前
8.2异常的抛出与捕捉
java·开发语言·python
interception1 小时前
爬虫js逆向,jsdom补环境,抖音,a_bogus
javascript·爬虫·python
林炳然1 小时前
Python-Basic Day-5 函数-生成器&装饰器
python
Yue丶越2 小时前
【Python】基础语法入门(四)
linux·开发语言·python
AI街潜水的八角5 小时前
Python电脑屏幕&摄像头录制软件(提供源代码)
开发语言·python