Skip to main content

rpze: Remote Python, Zombie: Endless

Project description

rpze

Remote Python, Zombie Endless(or endless rp?)

一个远程Python的Plants vs. Zombies TAS及ize测试框架.

主库位于GitHub.

结构

总体分成五个包:

  • rp_extend: 对控制pvz游戏本地运作的基本操作的封装
  • basic: DLL注入, 游戏启动, 汇编代码等基础功能
  • structs: PvZ内数据结构以及部分method的的封装
  • flow: coroutine-like测试编写相关的函数, 和以此实现的IzTest测试功能
  • examples: 上述的测试功能的编写例子

其中, 若仅对Python的pvz框架感兴趣则只需关注前三个包, 对ize测试感兴趣则着重模仿examples并大致了解structs的成员(PlantsZombies).

例子

生物钟

一个生物钟一二路卡相位的例子.

from rpze.basic import InjectedGame
from rpze.flow import *

with InjectedGame(r"your\game\path") as game:
    game.enter_level(70)  # 打开编号为70的关卡, 即ize关卡
    iz_test = IzTest(game.controller).init_by_str('''
        1000 -1
        1-2
        zs_j5
        cptoh
        .....
        .....
        .....
        lz 
        0 
        2-6''')  # 大家熟悉的izt测试

    @iz_test.flow_factory.add_flow()
    async def place_zombie(_):
        plist = iz_test.game_board.plant_list
        flower = plist["2-5"]
        await until(lambda _: flower.hp <= 4)
        place("cg 2-6")  # 2-5花死前一瞬放撑杆
        star = plist["1-5"]  # 1-5杨桃
        await until_plant_last_shoot(star).after(151 - 96)
        await repeat("xg 1-6")  # 星星最后一发攻击发出后1双鬼

    iz_test.start_test(jump_frame=False, speed_rate=5)

从有@的那句话开始一句一句看下去:

  • @iz_test.flow_factory.add_flow(): 一句格式代码, 作用是让测试时执行你下面定义的place_zombie. 抄下来就行.
  • async def place_zombie(_): 同样是格式代码.
    此处, 可以认为async def定义一个非常类似于函数的place_zombie, 这个类似函数的东西接受一个FlowManager类型的参数(在大部分场合用不到, 这里用_表示我用不到)
    不能不写async! place_zombie一定要是有且仅有一个参数的函数!
  • plist = iz_test.game_board.plant_list:
    • game_board是游戏中当前运行的关卡界面的代名词, 关卡上的所有植物, 僵尸, 你的大多操作都通过透过它进行.
    • plant_list是游戏中存放植物对象的数组, 其中有当前对象数量, 最大数量等等信息.
      plant_list类型为PlantList, 继承于ObjList[Plant], 提供了使用[int | slice]索引, ~plist遍历等功能.
  • flower = plist["2-5"]: [f"{row}-{col}"]PlantList特有的方法, 获取在1-1的植物.
  • await until(lambda _: flower.hp <= 4): 意为等待2-5花的血量 $\leq$ 4时往下执行.
    简单的说, 只需要写await until(lambda _: 你希望满足xx条件时再往下执行)即可.
    具体格式为await until(FlowManager -> bool). 和上面的place_zombie一样, 这里忽略FlowManager参数.
  • place("cg 2-6"): 在2-6放撑杆, 非常简单. 这个函数会返回你刚放下来的僵尸, 有需要的话可以用
  • await until_plant_last_shoot(star).after(151 - 96): 在星星最后一次攻击结束后再过(151 - 96)帧往下执行
    • until_plant_last_shoot(plant): 卡相位函数. 相当于until(lambda _: plant攻击后第一次打不出子弹)
    • until(...).after(time) 指等到前面的条件后再过time帧再往下执行.
  • await repeat("xg 1-6") 1-6双小鬼.
    • repeat代表连放僵尸, 默认delay20放两个(大家都是这么做的!), 如想delay30放三个则是repeat("xg 1-6", 2, 30)
    • await必须有. 直观理解, 这里前面有await的理由是repeat函数要等放完了才能往后执行.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rpze-0.1.0.tar.gz (142.8 kB view details)

Uploaded Source

Built Distributions

rpze-0.1.0-cp312-cp312-win_amd64.whl (149.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

rpze-0.1.0-cp311-cp311-win_amd64.whl (150.3 kB view details)

Uploaded CPython 3.11 Windows x86-64

File details

Details for the file rpze-0.1.0.tar.gz.

File metadata

  • Download URL: rpze-0.1.0.tar.gz
  • Upload date:
  • Size: 142.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for rpze-0.1.0.tar.gz
Algorithm Hash digest
SHA256 76505b82da5b4559b08096ac40cecc5499df41c09a48c4c3aae3dd0436e22b25
MD5 637e29bb922073c251cf08e957374b12
BLAKE2b-256 716e4d139244e9a6b42bf5c3a896cbac1d88ffef7106345bd990b9f04ed1643c

See more details on using hashes here.

File details

Details for the file rpze-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: rpze-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 149.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for rpze-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b27ecb5df5db9d531139b35641a207fd17844db6c9a418515878baaa200f6656
MD5 a9158129bd36f5c9bb75a6aff171229e
BLAKE2b-256 7022e62d281210e5dd3007c4b4ee0683f9ec6f9f05dfde7cd9719ddb146b62de

See more details on using hashes here.

File details

Details for the file rpze-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: rpze-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 150.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for rpze-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d6f96768a123c55a0d725ffd1b5e0dd393f8edf2a101795d77479cded72af5ac
MD5 82959a2f662c221f2aae32ff940c34c3
BLAKE2b-256 23885575f5ff954b3337b1343ad01cb6e6740bafeb76df05df9ac66634522cce

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page