roomai.common package

Submodules

roomai.common.common module

class roomai.common.common.AbstractAction(key)[source]

Bases: object

The abstract class of an action.

key

The key of the action. Every action in RoomAI has a key as its identification. We strongly recommend you to use the lookup function to get an action with the specified key

classmethod lookup(key)[source]

Get an action with the specified key. We strongly recommend you to use the lookup function to get an action with the specified key, rather than use the constructor function.

Parameters:key – the specified key
Returns:the action with the specified key
class roomai.common.common.AbstractEnv[source]

Bases: object

The abstract class of game environment

classmethod available_actions(public_state, person_state)[source]

Generate all valid actions given the public state and the person state

Parameters:
  • public_state
  • person_state
Returns:

A dict(action_key, action) contains all valid actions

backward()[source]

The game goes back to the previous states

:returns:infos, public_state, person_states, private_state :raise:Env has reached the initialization state and can’t go back further.

classmethod compete(env, players)[source]

Use the game environment to hold a compete for the players

Parameters:
  • env – The game environment
  • players – The players
Returns:

scores for the players

forward(action)[source]

The game environment steps with the action taken by the current player

:param action, chance_action :returns:infos, public_state, person_states, private_state, other_chance_actions

init(params={})[source]

Initialize the game environment

Parameters:params
Returns:infos, public_state, person_states, private_state, other_chance_actions
classmethod is_action_valid(action, public_state, person_state)[source]

Is the action valid given the public state and the person state

Parameters:
  • action
  • public_state
  • person_state
Returns:

A boolean variable indicating whether is the action valid

class roomai.common.common.AbstractPersonState[source]

Bases: object

The abstract class of the person state. The information in the person state is public to the corresponding player and hidden from other players

available_actions

All valid actions for the player expected to take an action. The person state w.r.t no-current player contains empty available_actions

id

The id of player w.r.t this person state

class roomai.common.common.AbstractPlayer[source]

Bases: object

The abstract class of a player

receive_info(info)[source]

Receive information

:param:info: the information produced by a game environments :raises: NotImplementedError: An error occurred when we doesn’t implement this function

reset()[source]

reset for a new game

take_action()[source]
Returns:The action produced by this player
class roomai.common.common.AbstractPrivateState[source]

Bases: object

The Abstract class of the private state. The information in the private state is hidden from every player

class roomai.common.common.AbstractPublicState[source]

Bases: object

The abstract class of the public state. The information in the public state is public to every player

is_terminal

is_terminal = true means the game is over. At this time, scores is not None, scores = [float0,float1,...] for player0, player1,..

previous_action

players[previous_id] took previous_action in the previous epoch

previous_id

players[previous_id] took an action in the previous epoch

scores

is_terminal = true means the game is over. At this time, scores is not None, scores = [float0,float1,...] for player0, player1,..

turn

players[turn] is expected to take an action

class roomai.common.common.FrozenDict[source]

Bases: dict

class roomai.common.common.Info[source]

Bases: object

The class of information sent by env to a player. The Info class contains the public state and the corresponding person state

person_state

The person state in the information

public_state

The public state in the information

class roomai.common.common.PokerCard(point, suit=None)[source]

Bases: object

A Poker Card. A Poker Card has a point (2,3,4,....,K,A,r,R) and a suit (Spade, Heart, Diamond, Club, ForKing). Different points have different ranks, for example the point 2 ‘s rank is 0, and the point A ‘s rank is 12. Different suits have different ranks too. The “ForKing” suit is a placeholder used for the card with the point “r” or “R” A Poker Card has a key (point_suit). We strongly recommend you to get a poker card by using the class function lookup with the key. Examples of the class usages: >> import roomai.common >> card = roomai.common.PokerCard.lookup(“2_Spade”) >> card.point 2 >> card.suit Spade >> card.point_rank 0 >> card.suit_rank 0 >> card.key “2_Spade”

classmethod compare(pokercard1, pokercard2)[source]

Compare two poker cards with their point ranks and suit ranks. The poker card with the higher point rank has the higher rank. With the same point rank, the poker card with the higher suit rank has the higher rank.

Parameters:
  • pokercard1
  • pokercard2
Returns:

A number, which is >0 when the poker card1 has the higher rank than the poker card2, =0 when their share the same rank, <0 when the poker card1 has the lower rank than the poker card2

key

The key of the poker card

classmethod lookup(key)[source]

lookup a PokerCard with the specified key

Parameters:key – The specified key
Returns:The PokerCard with the specified key
point

The point of the poker card

point_rank

The point rank of the poker card

suit

The suit of the poker card

suit_rank

The suit rank of the poker card

class roomai.common.common.RandomPlayer[source]

Bases: roomai.common.common.AbstractPlayer

The RandomPlayer is a player, who randomly takes an action. The RandomPlayer is as a common baseline

receive_info(info)[source]
reset()[source]
take_action()[source]
roomai.common.common.version()[source]
Returns:The version of RoomAI

Module contents