Skip to main content

Helper classes for the Team Group Data Sharing Medium & Electronic Local Link System.

Project description

tgdsmells

Helper classes for the Team Group Data Sharing Medium & Electronic Local Link System

Learn more about TGDSMELLS.

Upgrading from TMCP

Upgrading from TMCP to TGDSMELLS is simple. All you need to do is replace tmcp with tgdsmells in your requirements.txt, then replace from tmcp import with from tgdsmells import.


How to use

Start by creating an instance of the TGDSMELLSHandler. You should pass in your agent.

from tgdsmells import TGDSMELLSHandler

class MyBot(BaseAgent):
    def initialize_agent(self):
        self.tgdsmells_handler = TGDSMELLSHandler(self)

Usage is also very straightforward:

from tgdsmells import TGDSMELLSMessage, ActionType

...
    def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        # Receive and parse all new matchcomms messages into TGDSMELLSMessage objects.
        new_messages: List[TGDSMELLSMessage] = self.tgdsmells_handler.recv()
        # Handle TGDSMELLSMessages.
        for message in new_messages:
            if message.action_type == ActionType.BALL:
                print(message.time)
        
        ...

        # You can send messages like this.
        self.tgdsmells_handler.send_boost_action(pad_index)

        # Or you can create them and send them more directly:
        my_message = TGDSMELLSMessage.ball_action(self.team, self.index, estimated_time_of_arrival)
        self.tgdsmells_handler.send(my_message)

The handler will throttle your messages if you send them too quickly. If you want to make sure all of your messages are sent, you can create a backlog like this:

# During initialization, create a backlog list.
self.backlog = []

...
# Sending returns false if a message was not sent.
if not self.tgdsmells_handler.send(message):
    self.backlog.append(message)

...
# In your main loop, check whether you have any messages in the backlog.
if self.backlog:
    backlog_message = self.backlog.pop(0)
    # Try sending the message again. If it doesn't work, return it to the backlog.
    if not self.tgdsmells_handler.send(backlog_message):
        self.backlog.insert(0, backlog_message)

Avoiding major breaking changes

This package is regularly updated according to the latest TGDSMELLS specification. To avoid your bot breaking during tournaments due to major version updates, you can use a virtual_environment and pin a specific version of this package.

In your requirements.txt:

tgdsmells==1.*

In your bot.cfg:

[Locations]
use_virtual_environment = true
requirements_file = ./requirements.txt

If you don't want to do this, you can also disable the handler if a different version of the package is used. This will not send or receive any messages, but will pretend as if it was sending all and receiving none.

from tgdsmells import TGDSMELLS_VERSION

if TGDSMELLS_VERSION[0] != 1:
    my_handler.disable()

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

tgdsmells-1.0.0.tar.gz (7.5 kB view details)

Uploaded Source

File details

Details for the file tgdsmells-1.0.0.tar.gz.

File metadata

  • Download URL: tgdsmells-1.0.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.5

File hashes

Hashes for tgdsmells-1.0.0.tar.gz
Algorithm Hash digest
SHA256 553b24771402e62299e610050ef959545379a58433d02f3bfcdb7d5ff11bfd46
MD5 d44fb184b0993825064292e2a44460d5
BLAKE2b-256 5647d7bda21227ef7979989a4ca76a87ed68ebcb3325113972f3598d3e3739f3

See more details on using hashes here.

Supported by

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