Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hsywhu committed Sep 12, 2019
1 parent a6fdff7 commit 71c1bf3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
20 changes: 10 additions & 10 deletions rlcard/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,21 @@ class Round(object):
round_id = None

def __init__(self):
""" When the game starts, round id should be 1
"""
''' When the game starts, round id should be 1
'''

pass

def proceed_round(self):
""" Call other Classes's functions to keep the game running
"""
''' Call other Classes's functions to keep the game running
'''

pass


class Game(object):
""" Game class. This class will interact with outer environment.
"""
''' Game class. This class will interact with outer environment.
'''

def init_game(self):
''' Initialize all characters in the game and start round 1
Expand All @@ -166,14 +166,14 @@ def get_player_num(self):
pass

def get_action_num(self):
""" Return the number of possible actions in the game
"""
''' Return the number of possible actions in the game
'''

pass

def get_player_id(self):
""" Return the current player that will take actions soon
"""
''' Return the current player that will take actions soon
'''

pass

Expand Down
56 changes: 28 additions & 28 deletions rlcard/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
from core import Card, Player

def init_standard_deck():
""" Return a list of Card objects which form a standard 52 cards deck
"""
''' Return a list of Card objects which form a standard 52 cards deck
'''

suit_list = ['S', 'H', 'D', 'C']
rank_list = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
res = [Card(suit, rank) for suit in suit_list for rank in rank_list]
return res

def init_54_deck():
""" Return a list of Card objects which include a standard 52 cards deck, BJ and RJ
"""
''' Return a list of Card objects which include a standard 52 cards deck, BJ and RJ
'''

suit_list = ['S', 'H', 'D', 'C']
rank_list = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
Expand All @@ -27,7 +27,7 @@ def init_54_deck():


def get_random_cards(cards, num, seed = None):
""" Randomly get a number of chosen cards out of a list of cards
''' Randomly get a number of chosen cards out of a list of cards
Args:
cards: list of Card object
Expand All @@ -37,7 +37,7 @@ def get_random_cards(cards, num, seed = None):
Returns:
list: list of chosen cards
list: list of remained cards
"""
'''
assert num > 0, "Invalid input number"
assert num <= len(cards), "Input number larger than length of cards"
remained_cards = []
Expand All @@ -49,34 +49,34 @@ def get_random_cards(cards, num, seed = None):
return chosen_cards, remained_cards

def is_pair(cards):
"""
'''
Args:
cards: list of Card object
Returns:
boolean: whether the input list is a pair or not
"""
'''

if len(cards) == 2 and cards[0].rank == cards[1].rank:
return True
else:
return False

def is_single(cards):
"""
'''
Args:
cards: list of Card object
Returns:
boolean: whether the input list is a single card or not
"""
'''
if len(cards) == 1:
return True
else:
return False

def rank2int(rank):
""" Get the coresponding number of a rank.
''' Get the coresponding number of a rank.
Args:
rank: rank stored in Card object
Expand All @@ -87,7 +87,7 @@ def rank2int(rank):
Note:
If the input rank is an empty string, the function will return -1.
If the input rank is not valid, the function will return None.
"""
'''

if rank == '':
return -1
Expand All @@ -109,7 +109,7 @@ def rank2int(rank):
return None

def get_cards_from_ranks(player, ranks):
""" get chosen cards and remained cards from a player's hand according to input rank list
''' get chosen cards and remained cards from a player's hand according to input rank list
Args:
player: Player object
Expand All @@ -121,7 +121,7 @@ def get_cards_from_ranks(player, ranks):
Note:
This function will not affect the player's original hand.
"""
'''

chosen_cards = []
remained_cards = player.hand.copy()
Expand All @@ -133,7 +133,7 @@ def get_cards_from_ranks(player, ranks):
return chosen_cards, remained_cards

def take_out_cards(cards, remove_cards):
""" Take out specific cards from a list of cards
''' Take out specific cards from a list of cards
Args:
cards (list): list of Card objects from which to be taken out some cards
Expand All @@ -148,7 +148,7 @@ def take_out_cards(cards, remove_cards):
2. For each card in 'remove_cards' list, it will make only one card in 'cards' list taken out,
which means to take out one kind of cards with the same suit and rank in 'cards' list,
you need to have the same number of cards with the same suit and rank in 'remove_cards' list.
"""
'''

remove_cards_cp = remove_cards
for card in cards:
Expand All @@ -159,15 +159,15 @@ def take_out_cards(cards, remove_cards):
return remove_cards_cp

def is_in_cards(origin_cards, check_cards):
""" Check if a list of Card objects contains another list of Card objects
''' Check if a list of Card objects contains another list of Card objects
Args:
cards: list of Card objects which to be checked if it contains another list of Card objects
check_cards: list of Card objects which to be checked if it is in a list of Card objecrts
Returns:
boolean
"""
'''

check_cards_cp = check_cards.copy()
cards = origin_cards.copy()
Expand All @@ -188,47 +188,47 @@ def is_in_cards(origin_cards, check_cards):
return len(check_cards_cp) == 0

def init_players(n):
""" Return a list of Player objects with n players
''' Return a list of Player objects with n players
Args:
n: int, number of players to be initialized
Returns:
list of Player objects with player_id(s) start from 0 and are consequent
"""
'''

players = []
for idx in range(n):
players.append(Player(idx))
return players

def get_upstream_player_id(player, players):
""" Return the upsteam player's player_id
''' Return the upsteam player's player_id
Note:
This function assumes player_id(s) in 'players' list starts from 0, and are consequent.
"""
'''
return (player.player_id-1)%len(players)

def get_downstream_player_id(player, players):
""" Return the downsteam player's player_id
''' Return the downsteam player's player_id
Note:
This function assumes player_id(s) in 'players' list start from 0, and are consequent.
"""
'''

return (player.player_id+1)%len(players)

def reorganize(trajectories, payoffs):
""" Reorganize the trajectory to make it RL friendly
''' Reorganize the trajectory to make it RL friendly
Args:
trajectory: original one
Returns:
A new one
"""
'''

player_num = len(trajectories)
new_trajectories = [[] for _ in range(player_num)]
Expand All @@ -248,13 +248,13 @@ def reorganize(trajectories, payoffs):
return new_trajectories

def set_global_seed(seed):
""" Set the global see for reproducing results
''' Set the global see for reproducing results
Args:
seed (int): The seed
Note: If using other modules with randomness, they also need to be seeded
"""
'''

if seed is not None:
import numpy as np
Expand Down

0 comments on commit 71c1bf3

Please sign in to comment.