Bot-Man-Toe/server.py

63 lines
1.6 KiB
Python

"""
This module enables a user to host a server that is able to play games.
"""
from __future__ import annotations
import random
from pyserver import PyServer
from typing import Any
def main() -> int:
"""
Start a server.
:return: Exit code
:rtype: int
"""
player = PyServer(
# Customize this to whatever you'd like to call your player
name="Mute",
# Custom information that you can use to tell people about this player
profile={
"me.noordstar.peanuts.agent.version": "1.0.0",
"me.noordstar.peanuts.is_ai": False,
"me.noordstar.peanuts.author": "Bram",
"me.noordstar.peanuts.containerized": True,
"version": "1.0.0",
},
# Unless you know what you're doing, don't touch this.
import_name=__name__,
)
# Register games! Comment out any you don't want your player to play.
player.add_tic_tac_toe(on_move=respond_mute, profile={})
# Start listening for games
player.start(
host="0.0.0.0", # Comment out when using only locally
port=5000,
)
return 0
def respond_mute(payload : dict[str, Any]) -> dict[str, Any]:
"""
Always respond with an empty dictionary. This means the user should
always take the "default" move.
A well-programmed game must NOT raise an error as a result of this.
:param payload: The game state which is completely ignored.
:type payload: dict[str, Any]
:return: An empty dictionary
:rtype: dict[str, Any]
"""
return {}
if __name__ == "__main__":
raise SystemExit(main())