Rooms

Chef's Hat Environment Diagram

The Rooms are available in two different settings: a local room, where the room and the agents run in the same process, and a remote room that allows the room and the agents to room in different processes.

While the local room is ideal for training and evaluating runing simulations on artificial agents, the remote room allows the agents to run on different machines, for example, which can extend the type of agents you can use.

Both rooms share the same game parameters:

Rooms parameters

Parameter

Description

Default Value

room_name

name of the room, no special character is allowed

game_type

The type of end game criteria game: “POINTS”, based on score or “MATCHES”, based on played matches.

“MATCHES”

stop_criteria

The max value of “POINTS” or “MATCHES” to determine the end of the game.

10

max_rounds

The maximum number of rounds per match, if -1, the players will play until all of them have 0 cards at hand.

-1

verbose

room verbose

False

save_dataset

If a dataset will be generated by the game environment

False

save_game_log

If a game log will be generated by the game environment

False

log_directory

The directory where the gamelog will be saved. If none, it will be saved in temp/

None

timeout_player_response

Amount in seconds that the room will wait until a player do its action. If the timeout is reached, the player will perform a pass action.

5

Local Rooms

When initializing a local room, the room parameters have to be passed. As that implement the ChefsHatGym.agents.chefs_hat_agent.ChefsHatAgent class, have to be added. And the game can start, by calling the .start_new_game() function:

from ChefsHatGym.gameRooms.chefs_hat_room_local import ChefsHatRoomLocal
from ChefsHatGym.env import ChefsHatEnv
from ChefsHatGym.agents.agent_random import AgentRandon

# Room parameters
room_name = "Testing_1_Local"
timeout_player_response = 5
verbose = True

# Game parameters
game_type = ChefsHatEnv.GAMETYPE["POINTS"]
stop_criteria = 15
maxRounds = -1

# Start the room
room = ChefsHatRoomLocal(
        room_name,
        timeout_player_response=timeout_player_response,
        game_type=game_type,
        stop_criteria=stop_criteria,
        max_rounds=maxRounds,
        verbose=verbose,
        save_dataset=True,
        save_game_log=True
)

# Create the players
p1 = AgentRandon(name="01")
p2 = AgentRandon(name="02")
p3 = AgentRandon(name="03")
p4 = AgentRandon(name="04")

# Adding players to the room
for p in [p1, p2, p3, p4]:
        room.add_player(p)


# Start the game
info = room.start_new_game(game_verbose=True)

print(f"Performance score: {info['performanceScore']}")
print(f"Scores: {info['score']}")

In this example, both dataset and gamelog will be generated from the game environment. A log for the room will also be generated. After the game is played, a game summary dictionary is passed.

Server Rooms

To setup a server room, besides using the room parameters, you have to set a url and port for the TCP/IP connection.

The remote room uses sockets to communicate with the agents, mantaining an open channel during the entire game.

The messages shared between the agents and the room follow a standard protocol, and are encapsulated in a dictionary.

The messages from the room are send on a broadcast manner, that updates the agent about the different events that happen during the game, or in a response request manner, where the room requires an action from a specific agent.

For more information on the communication prtocol, please check:

Here is an example of a server room, that will wait for connections on a specified url and port:

from ChefsHatGym.gameRooms.chefs_hat_room_server import ChefsHatRoomServer
from ChefsHatGym.env import ChefsHatEnv

# Room parameters
room_name = "server_room1"
room_password = "password"
timeout_player_subscribers = 5
timeout_player_response = 5
verbose = True


# Game parameters
game_type = ChefsHatEnv.GAMETYPE["MATCHES"]
stop_criteria = 50
maxRounds = -1


# Create the room
room = ChefsHatRoomServer(
        room_name,
        room_pass=room_password,
        timeout_player_subscribers=timeout_player_subscribers,
        timeout_player_response=timeout_player_response,
        game_type=game_type,
        stop_criteria=stop_criteria,
        max_rounds=maxRounds,
        verbose=verbose,
        save_dataset=True,
        save_game_log=True,
)

And here an example of agents connecting to the room. Once the room has four valid agents connected, it will start the game.

from ChefsHatGym.agents.agent_random import AgentRandon
room_pass = "password"
room_url = "localhost"
room_port = 10000


# Create the players
p1 = AgentRandon(name="01", verbose=True)
p2 = AgentRandon(name="02", verbose=True)
p3 = AgentRandon(name="03", verbose=True)
p4 = AgentRandon(name="04", verbose=True)

# Join agents

p1.joinGame(room_pass=room_pass, room_url=room_url, room_port=room_port)
p2.joinGame(room_pass=room_pass, room_url=room_url, room_port=room_port)
p3.joinGame(room_pass=room_pass, room_url=room_url, room_port=room_port)
p4.joinGame(room_pass=room_pass, room_url=room_url, room_port=room_port)