Multi-Player in HackaGames

Most of the games are multi-players games where Artificial Intelligences, embodied into Bot, fight.

ATTENTION HACKAGAMES CHANGES MAKE THIS TUTORIAL BROKEN AS IT IS

With a simple script

One simple way to start a Python HackaGames game with several players is to instantiate a game and the players/Bots in a launcher script:

# Setup a game:
from hacka.games.aGame import Game
from hacka.games.aGame.firstBot import Bot as Opponent
from myBot import Bot

bot, opponent1, opponent2= Bot(), Opponent(), Opponent()

# Instanciate and start 100 games
number= 100
game= Game()
results=game.launch( [bot, opponent1, opponent2], number )

# Analyze the results
for name, individualResults in zip( ["bob", "natacha", "jad"], results ) :
    print( f"- {name},s average score: {sum(individualResults)/number}" )

Human Interface

The hacka.pylib package provides a very basic shell interface capable of playing any hackagames.

from hacka.pylib.player import PlayerIHM as Interface

Typically it is the one used by py421 game. However, systematically more tailored shell interface is provided.

from hacka.games.aGames.shell import Interface

Those interfaces can replace bot players into the launcher script.

Example with Connect4:

# Setup a game:
from hacka.games.connect4 import GameConnect4 as Game
from hacka.games.connect4.firstBot import Bot
from hacka.games.connect4.shell import Interface

# Instanciate and start 100 games
number= 4
game= Game()
results=game.launch( [Bot(), Interface()], number )

# Analyze the results
for name, individualResults in zip( ["bob", "me"], results ) :
    print( f"- {name},s average score: {sum(individualResults)/number}" )

Client-Server Architecture

HackaGames is designed to run as a client-server architecture. The game run as a server, and players (Bots or Human Interfaces) as clients. The game wait for the appropriate number of players before to start.

For instance, on three different shells:

# shell-1
python3 -m hacka.games.tictactoe.serve ultimate -n 2
# shell-2
python3 -m hacka.games.tictactoe.shell
# shell-3
python3 -m hacka.games.tictactoe.firstBot

Each shell process one entity of the game, coordination is provided with hackagame protocol. The shells can be distributed over different machine. To connect a player to a specific hackagames server, the player need to inherite from hacka.pylib abstract player (AbsPlayer) and take a seat on a game....

from ... import pylib as hk

def main() :
    player= MyBot()
    player.takeASeat( "xxx.local" )

class MyBot( hk.AbsPlayer ) :

    # Player interface :
    def wakeUp(self, playerId, numberOfPlayers, gamePod ):
        ...

    def perceive(self, gameState):
        ...

    def decide(self):
        ...

    #def sleep(self, result):
        ...

# Script :
if __name__ == '__main__' :
    main()
...