# Path: tests/base_unittest.py
# class BaseUnitTest(unittest.TestCase):
# 
#   def eq(self, expected, target):
#     return self.assertEqual(expected, target)
# 
#   def neq(self, expected, target):
#     return self.assertNotEqual(expected, target)
# 
#   def true(self, target):
#     return self.assertTrue(target)
# 
#   def false(self, target):
#     return self.assertFalse(target)
# 
# Path: pypokerengine/utils/game_state_utils.py
# def restore_game_state(round_state):
#     return {
#             "round_count": round_state["round_count"],
#             "small_blind_amount": round_state["small_blind_amount"],
#             "street": _street_flg_translator[round_state["street"]],
#             "next_player": round_state["next_player"],
#             "table": _restore_table(round_state)
#             }
# 
# def attach_hole_card(game_state, uuid, hole_card):
#     deepcopy = deepcopy_game_state(game_state)
#     target = [player for player in deepcopy["table"].seats.players if uuid==player.uuid]
#     if len(target)==0: raise Exception('The player whose uuid is "%s" is not found in passed game_state.' % uuid)
#     if len(target)!=1: raise Exception('Multiple players have uuid "%s". So we cannot attach hole card.' % uuid)
#     target[0].hole_card = hole_card
#     return deepcopy
# 
# def replace_community_card(game_state, community_card):
#     deepcopy = deepcopy_game_state(game_state)
#     deepcopy["table"]._community_card = community_card
#     return deepcopy
# 
# def attach_hole_card_from_deck(game_state, uuid):
#     deepcopy = deepcopy_game_state(game_state)
#     hole_card = deepcopy["table"].deck.draw_cards(2)
#     return attach_hole_card(deepcopy, uuid, hole_card)
# 
# def replace_community_card_from_deck(game_state):
#     deepcopy = deepcopy_game_state(game_state)
#     card_num = _street_community_card_num[deepcopy["street"]]
#     community_card = deepcopy["table"].deck.draw_cards(card_num)
#     return replace_community_card(deepcopy, community_card)
# 
# Path: pypokerengine/engine/card.py
# class Card:
# 
#   CLUB = 2
#   DIAMOND = 4
#   HEART = 8
#   SPADE = 16
# 
#   SUIT_MAP = {
#       2  : 'C',
#       4  : 'D',
#       8  : 'H',
#       16 : 'S'
#   }
# 
#   RANK_MAP = {
#       2  :  '2',
#       3  :  '3',
#       4  :  '4',
#       5  :  '5',
#       6  :  '6',
#       7  :  '7',
#       8  :  '8',
#       9  :  '9',
#       10 : 'T',
#       11 : 'J',
#       12 : 'Q',
#       13 : 'K',
#       14 : 'A'
#   }
# 
# 
#   def __init__(self, suit, rank):
#     self.suit = suit
#     self.rank = 14 if rank == 1 else rank
# 
#   def __eq__(self, other):
#     return self.suit == other.suit and self.rank == other.rank
# 
#   def __str__(self):
#     suit = self.SUIT_MAP[self.suit]
#     rank = self.RANK_MAP[self.rank]
#     return "{0}{1}".format(suit, rank)
# 
#   def to_id(self):
#     rank = 1 if self.rank == 14 else self.rank
#     num = 0
#     tmp = self.suit >> 1
#     while tmp&1 != 1:
#       num += 1
#       tmp >>= 1
# 
#     return rank + 13 * num
# 
#   @classmethod
#   def from_id(cls, card_id):
#     suit, rank = 2, card_id
#     while rank > 13:
#       suit <<= 1
#       rank -= 13
# 
#     return cls(suit, rank)
# 
#   @classmethod
#   def from_str(cls, str_card):
#     assert(len(str_card)==2)
#     inverse = lambda hsh: {v:k for k,v in hsh.items()}
#     suit = inverse(cls.SUIT_MAP)[str_card[0].upper()]
#     rank = inverse(cls.RANK_MAP)[str_card[1]]
#     return cls(suit, rank)
# 
# Path: pypokerengine/engine/poker_constants.py
# class PokerConstants:
# 
#   class Action:
#     FOLD  = 0
#     CALL  = 1
#     RAISE = 2
#     SMALL_BLIND = 3
#     BIG_BLIND = 4
#     ANTE = 5
# 
#   class Street:
#     PREFLOP = 0
#     FLOP = 1
#     TURN = 2
#     RIVER = 3
#     SHOWDOWN = 4
#     FINISHED = 5


from nose.tools import raises
from tests.base_unittest import BaseUnitTest
from pypokerengine.utils.game_state_utils import restore_game_state,\
        attach_hole_card, replace_community_card,\
        attach_hole_card_from_deck, replace_community_card_from_deck
from pypokerengine.engine.card import Card
from pypokerengine.engine.poker_constants import PokerConstants as Const

class GameStateUtils(BaseUnitTest):

    def test_attach_hole_card_from_deck(self):
        game_state = restore_game_state(TwoPlayerSample.round_state)
        self.eq(48, game_state["table"].deck.size())

# Path: tests/base_unittest.py
# class BaseUnitTest(unittest.TestCase):
# 
#   def eq(self, expected, target):
#     return self.assertEqual(expected, target)
# 
#   def neq(self, expected, target):
#     return self.assertNotEqual(expected, target)
# 
#   def true(self, target):
#     return self.assertTrue(target)
# 
#   def false(self, target):
#     return self.assertFalse(target)
# 
# Path: pypokerengine/utils/game_state_utils.py
# def restore_game_state(round_state):
#     return {
#             "round_count": round_state["round_count"],
#             "small_blind_amount": round_state["small_blind_amount"],
#             "street": _street_flg_translator[round_state["street"]],
#             "next_player": round_state["next_player"],
#             "table": _restore_table(round_state)
#             }
# 
# def attach_hole_card(game_state, uuid, hole_card):
#     deepcopy = deepcopy_game_state(game_state)
#     target = [player for player in deepcopy["table"].seats.players if uuid==player.uuid]
#     if len(target)==0: raise Exception('The player whose uuid is "%s" is not found in passed game_state.' % uuid)
#     if len(target)!=1: raise Exception('Multiple players have uuid "%s". So we cannot attach hole card.' % uuid)
#     target[0].hole_card = hole_card
#     return deepcopy
# 
# def replace_community_card(game_state, community_card):
#     deepcopy = deepcopy_game_state(game_state)
#     deepcopy["table"]._community_card = community_card
#     return deepcopy
# 
# def attach_hole_card_from_deck(game_state, uuid):
#     deepcopy = deepcopy_game_state(game_state)
#     hole_card = deepcopy["table"].deck.draw_cards(2)
#     return attach_hole_card(deepcopy, uuid, hole_card)
# 
# def replace_community_card_from_deck(game_state):
#     deepcopy = deepcopy_game_state(game_state)
#     card_num = _street_community_card_num[deepcopy["street"]]
#     community_card = deepcopy["table"].deck.draw_cards(card_num)
#     return replace_community_card(deepcopy, community_card)
# 
# Path: pypokerengine/engine/card.py
# class Card:
# 
#   CLUB = 2
#   DIAMOND = 4
#   HEART = 8
#   SPADE = 16
# 
#   SUIT_MAP = {
#       2  : 'C',
#       4  : 'D',
#       8  : 'H',
#       16 : 'S'
#   }
# 
#   RANK_MAP = {
#       2  :  '2',
#       3  :  '3',
#       4  :  '4',
#       5  :  '5',
#       6  :  '6',
#       7  :  '7',
#       8  :  '8',
#       9  :  '9',
#       10 : 'T',
#       11 : 'J',
#       12 : 'Q',
#       13 : 'K',
#       14 : 'A'
#   }
# 
# 
#   def __init__(self, suit, rank):
#     self.suit = suit
#     self.rank = 14 if rank == 1 else rank
# 
#   def __eq__(self, other):
#     return self.suit == other.suit and self.rank == other.rank
# 
#   def __str__(self):
#     suit = self.SUIT_MAP[self.suit]
#     rank = self.RANK_MAP[self.rank]
#     return "{0}{1}".format(suit, rank)
# 
#   def to_id(self):
#     rank = 1 if self.rank == 14 else self.rank
#     num = 0
#     tmp = self.suit >> 1
#     while tmp&1 != 1:
#       num += 1
#       tmp >>= 1
# 
#     return rank + 13 * num
# 
#   @classmethod
#   def from_id(cls, card_id):
#     suit, rank = 2, card_id
#     while rank > 13:
#       suit <<= 1
#       rank -= 13
# 
#     return cls(suit, rank)
# 
#   @classmethod
#   def from_str(cls, str_card):
#     assert(len(str_card)==2)
#     inverse = lambda hsh: {v:k for k,v in hsh.items()}
#     suit = inverse(cls.SUIT_MAP)[str_card[0].upper()]
#     rank = inverse(cls.RANK_MAP)[str_card[1]]
#     return cls(suit, rank)
# 
# Path: pypokerengine/engine/poker_constants.py
# class PokerConstants:
# 
#   class Action:
#     FOLD  = 0
#     CALL  = 1
#     RAISE = 2
#     SMALL_BLIND = 3
#     BIG_BLIND = 4
#     ANTE = 5
# 
#   class Street:
#     PREFLOP = 0
#     FLOP = 1
#     TURN = 2
#     RIVER = 3
#     SHOWDOWN = 4
#     FINISHED = 5


# Path: tests/pypokerengine/utils/game_state_utils_test.py
from nose.tools import raises
from tests.base_unittest import BaseUnitTest
from pypokerengine.utils.game_state_utils import restore_game_state,\
        attach_hole_card, replace_community_card,\
        attach_hole_card_from_deck, replace_community_card_from_deck
from pypokerengine.engine.card import Card
from pypokerengine.engine.poker_constants import PokerConstants as Const


class GameStateUtils(BaseUnitTest):

    def test_attach_hole_card_from_deck(self):
        game_state = restore_game_state(TwoPlayerSample.round_state)
        self.eq(48, game_state["table"].deck.size())

        processed1 = attach_hole_card_from_deck(game_state, "tojrbxmkuzrarnniosuhct")