tmcp


Nametmcp JSON
Version 0.8.0 PyPI version JSON
download
home_pagehttps://github.com/ViliamVadocz/tmcp/
SummaryHelper classes for the Team Match Communication Protocol.
upload_time2021-03-02 18:51:25
maintainer
docs_urlNone
authorViliam Vadocz
requires_python
licenseMIT
keywords rlbot protocol
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # tmcp
## Helper classes for the Team Match Communication Protocol

Learn more about [TMCP](https://github.com/RLBot/RLBot/wiki/Team-Match-Communication-Protocol).

---

## How to use

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

```py
from tmcp import TMCPHandler

class MyBot(BaseAgent):
    def initialize_agent(self):
        self.tmcp_handler = TMCPHandler(self)
```

Usage is also very straightforward:

```py
from tmcp import TMCPMessage, ActionType

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

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

        # Or you can create them and send them more directly:
        my_message = TMCPMessage.ball_action(self.team, self.index, estimated_time_of_arrival)
        self.tmcp_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:

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

...
# Sending returns false if a message was not sent.
if not self.tmcp_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.tmcp_handler.send(backlog_message):
        self.backlog.insert(0, backlog_message)
```

## Avoiding breaking changes

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

In your requirements.txt:

```txt
tmcp==0.7
```

In your bot.cfg:

```toml
[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.

```py
from tcmp import TCMP_VERSION

if TCMP_VERSION != [0, 7]:
    my_handler.disable()
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ViliamVadocz/tmcp/",
    "name": "tmcp",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "RLBot,protocol",
    "author": "Viliam Vadocz",
    "author_email": "viliam.vadocz@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/19/eb/c1d385be908310fb04c03ae9fb216d34b26343d0bfd59ab04d7b4ff084ae/tmcp-0.8.0.tar.gz",
    "platform": "",
    "description": "# tmcp\n## Helper classes for the Team Match Communication Protocol\n\nLearn more about [TMCP](https://github.com/RLBot/RLBot/wiki/Team-Match-Communication-Protocol).\n\n---\n\n## How to use\n\nStart by creating an instance of the TMCPHandler.\nYou should pass in your agent.\n\n```py\nfrom tmcp import TMCPHandler\n\nclass MyBot(BaseAgent):\n    def initialize_agent(self):\n        self.tmcp_handler = TMCPHandler(self)\n```\n\nUsage is also very straightforward:\n\n```py\nfrom tmcp import TMCPMessage, ActionType\n\n...\n    def get_output(self, packet: GameTickPacket) -> SimpleControllerState:\n        # Receive and parse all new matchcomms messages into TMCPMessage objects.\n        new_messages: List[TMCPMessage] = self.tmcp_handler.recv()\n        # Handle TMCPMessages.\n        for message in new_messages:\n            if message.action_type == ActionType.BALL:\n                print(message.time)\n        \n        ...\n\n        # You can send messages like this.\n        self.tmcp_handler.send_boost_action(pad_index)\n\n        # Or you can create them and send them more directly:\n        my_message = TMCPMessage.ball_action(self.team, self.index, estimated_time_of_arrival)\n        self.tmcp_handler.send(my_message)\n```\n\nThe handler will throttle your messages if you send them too quickly.\nIf you want to make sure all of your messages are sent, you can create a backlog like this:\n\n```py\n# During initialization, create a backlog list.\nself.backlog = []\n\n...\n# Sending returns false if a message was not sent.\nif not self.tmcp_handler.send(message):\n    self.backlog.append(message)\n\n...\n# In your main loop, check whether you have any messages in the backlog.\nif self.backlog:\n    backlog_message = self.backlog.pop(0)\n    # Try sending the message again. If it doesn't work, return it to the backlog.\n    if not self.tmcp_handler.send(backlog_message):\n        self.backlog.insert(0, backlog_message)\n```\n\n## Avoiding breaking changes\n\nThis package is regularly updated according to the latest TMCP specification.\nTo avoid your bot breaking during tournaments, you can use a virtual_environment and pin a specific version of this package.\n\nIn your requirements.txt:\n\n```txt\ntmcp==0.7\n```\n\nIn your bot.cfg:\n\n```toml\n[Locations]\nuse_virtual_environment = true\nrequirements_file = ./requirements.txt\n```\n\nIf you don't want to do this, you can also disable the handler if a different version of the package is used.\nThis will not send or receive any messages, but will pretend as if it was sending all and receiving none.\n\n```py\nfrom tcmp import TCMP_VERSION\n\nif TCMP_VERSION != [0, 7]:\n    my_handler.disable()\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Helper classes for the Team Match Communication Protocol.",
    "version": "0.8.0",
    "split_keywords": [
        "rlbot",
        "protocol"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "1c94434d879c803743e8b28c5369ec12",
                "sha256": "13eae8d00f57c7007aec0a982d34e7a8a0abc072f9f310df2cd42f7b0400211e"
            },
            "downloads": -1,
            "filename": "tmcp-0.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1c94434d879c803743e8b28c5369ec12",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4831,
            "upload_time": "2021-03-02T18:51:25",
            "upload_time_iso_8601": "2021-03-02T18:51:25.007037Z",
            "url": "https://files.pythonhosted.org/packages/19/eb/c1d385be908310fb04c03ae9fb216d34b26343d0bfd59ab04d7b4ff084ae/tmcp-0.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-03-02 18:51:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "ViliamVadocz",
    "error": "Could not fetch GitHub repository",
    "lcname": "tmcp"
}
        
Elapsed time: 0.27137s