Skip to main content

SDK for writing bots in ploupy.plouc314.ch

Project description

Ploupy Python SDK

Installation

pip install ploupy-sdk

Note
This library requires python 3.10 or higher

Getting started

Here is a minimal example:

import ploupy as pp

class MyBehaviour(pp.Behaviour):
    pass  # the bot code goes here

BOT_KEY = "..." # the key given when creating the bot

bot = pp.Bot(bot_key=BOT_KEY, behaviour_class=MyBehaviour)

if __name__ == "__main__":
    bot.run()

Behaviour

The SDK is events driven. Define the bot by inheriting from the Behaviour class and overriding callback methods (all callbacks are async).

Here is an example of a bot that build a factory as soon as he can:

import ploupy as pp

class MyBehaviour(pp.Behaviour):

    async def on_income(self, money: int) -> None:
        # select the tile to build the factory on
        # using Map instance exposed by Behaviour class
        # and the bot's Player instance
        tiles = self.map.get_buildable_tiles(self.player)
        if len(tiles) == 0:
            return
        tile = tiles[0]

        # check if the bot has enough money
        # using GameConfig instance exposed by Behaviour class
        if money >= self.config.factory_price:
            # send an action to the server
            # this can failed if all the necessary conditions aren't
            # met to perform the action
            try:
                await self.build_factory(tile.coord)
            except pp.ActionFailedException:
                return

Here is an example of a bot that will try to build a turret when attacked:

import ploupy as pp

class MyBehaviour(pp.Behaviour):

    async def on_probes_attack(
        self,
        probes: list[pp.Probe],
        attacked_player: pp.Player,
        attacking_player: pp.Player,
    ) -> None:
        # check that it is the bot that is attacked
        if attacked_player is not self.player:
            return

        # get the center of where the probes are attacking
        target = pp.geometry.get_center([probe.target for probe in probes])

        # get tiles where a turret could be built
        tiles = self.map.get_buildable_tiles(self.player)

        # if none are buildable then too bad...
        if len(tiles) == 0:
            return

        # get the tile that is as close as possible to the center of the attack
        tile = pp.geometry.get_closest_tile(tiles, target)

        # place an order on "build turret" action, the action will be performed
        # when the necessary conditions are met
        await self.place_order(
            pp.BuildTurretOrder(
                self.player,
                tile,
                with_timeout=2.0, # maximum time (sec) before aborting the order
                with_retry=False, # if the action should be retried in case of failure
            )
        )

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

ploupy-sdk-0.1.0.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

ploupy_sdk-0.1.0-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file ploupy-sdk-0.1.0.tar.gz.

File metadata

  • Download URL: ploupy-sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for ploupy-sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 666421c024db493e92a1a34eb98efc6cf609e774cc7168c2d5a7e34c50d2b3a1
MD5 9c89705b5d2fd66357de57e0d3632519
BLAKE2b-256 682e3012e9261b898091502477ae87466078031d96e28018d343bbac2de93b01

See more details on using hashes here.

File details

Details for the file ploupy_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ploupy_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for ploupy_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fbe441445ce19bc01d1f90e11c40c3daba445b584bc041362966220add898a10
MD5 45370965be66c403f5811344c72e403a
BLAKE2b-256 86dd1eb3d570b2d370650f773cde45158003e2b1c22e97debd8e0b58ff4e087d

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