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.0.3.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

ploupy_sdk-0.0.3-py3-none-any.whl (37.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ploupy-sdk-0.0.3.tar.gz
  • Upload date:
  • Size: 29.9 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.0.3.tar.gz
Algorithm Hash digest
SHA256 e5317d0e62988d00e1440fa05f395943369b23a596b6ce366eb24a517a434610
MD5 d0327d54d6bfbb7f946ba1f45698a348
BLAKE2b-256 49a9e0c79c63231dd63fc416bfe185a762eb4e8d7ff18408d6d33f882788ad13

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ploupy_sdk-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 37.5 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.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 48b2fe495791e0d1df5241d591ba8568dc3868f1b2f32c8f6bb2923729d795de
MD5 374fb59ecda5e72e9d9f17e002629a32
BLAKE2b-256 cd64cbbc9602f299db8e67663a520259af5696794573dd09b841ba1aca8c79c0

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