예제 #1
0
def decode_game(obj):
    """Decode a dictionary made with encode() into a Game object.
    """
    try:
        players = obj['players']
        jacks = obj['jacks']
        library = obj['library']
        pool = obj['pool']
    except KeyError as e:
        raise GTREncodingError(e.message)

    game_dict = copy.deepcopy(obj)

    game_dict['players'] = [decode_player(p) for p in players]

    game_dict['jacks'] = decode_zone(jacks, 'jacks')
    game_dict['library'] = decode_zone(library, 'library')
    game_dict['pool'] = decode_zone(pool, 'pool')

    g = Game()

    for k, v in game_dict.items():
        setattr(g, k, v)

    return g
예제 #2
0
파일: game.py 프로젝트: comat0se/cloaca
    def test_add_player_with_same_name(self):
        """Adding two players with the same name raises GTRError.
        """
        g = Game()
        g.add_player(uuid4(), 'p1')

        with self.assertRaises(GTRError):
            g.add_player(uuid4(), 'p1')
예제 #3
0
파일: game.py 프로젝트: comat0se/cloaca
    def test_add_player(self):

        g = Game()
        g.add_player(uuid4(), 'p1')

        self.assertEqual(len(g.players), 1)

        g.add_player(uuid4(), 'p2')

        self.assertEqual(len(g.players), 2)
예제 #4
0
파일: game.py 프로젝트: comat0se/cloaca
    def test_add_too_many_players(self):
        """Adding a sixth player raises GTRError.
        """
        g = Game()
        g.add_player(uuid4(), 'p1')
        g.add_player(uuid4(), 'p2')
        g.add_player(uuid4(), 'p3')
        g.add_player(uuid4(), 'p4')
        g.add_player(uuid4(), 'p5')

        with self.assertRaises(GTRError):
            g.add_player(uuid4(), 'p6')
예제 #5
0
파일: game.py 프로젝트: comat0se/cloaca
    def test_add_player_after_start(self):
        """Attempting to add a player after the game has started throws
        a GTRError.
        """
        g = Game()
        g.add_player(uuid4(), 'p1')
        g.add_player(uuid4(), 'p2')

        g.start()

        with self.assertRaises(GTRError):
            g.add_player(uuid4(), 'p3')
예제 #6
0
파일: game.py 프로젝트: comat0se/cloaca
    def test_start_again(self):
        """Starting an already-started game raises a GTRError.
        """

        g = Game()
        g.add_player(uuid4(), 'p1')
        g.add_player(uuid4(), 'p2')

        g.start()

        with self.assertRaises(GTRError):
            g.start()
예제 #7
0
파일: server.py 프로젝트: comat0se/cloaca
    def _create_game(self, user):
        """Create a new game."""
        game = Game()
        self.games.append(game)
        game_id = len(self.games) - 1
        lg.info('Creating new game {0:d}'.format(game_id))
        game.game_id = game_id
        game.host = user

        username = self._userinfo(user)['name']
        player_index = game.add_player(user, username)

        return game_id
예제 #8
0
def simple_n_player(n):
    """N-player game with nothing in hands, stockpiles,
    or common piles. Player 1 (p1) goes first.

    One frame of take_turn_stacked is pushed, and the game
    is pumped, so it's ready for the first player (p1) to 
    thinker or lead.
    """
    g = Game()

    players = ['p{0:d}'.format(i + 1) for i in range(n)]

    for p in players:
        uid = uuid4().int
        g.add_player(uid, p)

    g.controlled_start()

    return g
예제 #9
0
파일: game.py 프로젝트: comat0se/cloaca
    def test_start(self):
        """Starting a game puts orders and jacks in the hands of the players,
        populates the pool, and sets the turn number to 1
        """

        g = Game()
        g.add_player(uuid4(), 'p1')
        g.add_player(uuid4(), 'p2')

        g.start()

        self.assertEqual(len(g.jacks), 4)

        # We don't know how many cards because of tiebreakers in determining
        # who goes first but each player at least needs 4 cards + 1 in the pool
        self.assertTrue(len(g.library) <= 134)
        self.assertTrue(len(g.library) > 0)

        for p in g.players:
            self.assertIn('Jack', p.hand)

        self.assertTrue(g.started)
        self.assertEqual(g.expected_action, message.THINKERORLEAD)