Пример #1
0
 def test_no_move_without_start(self):
     game.join(self.r, 'game', 'max')
     game.join(self.r, 'game', 'jenny')
     game.start(self.r, 'game', 'jenny')
     self.assertFalse(game.move(self.r, 'game', 'jenny', 'han'))
     info = game.info(self.r, 'game', 'jenny').next()
     self.assertEquals('camp', info['you']['state'])
Пример #2
0
    def test_all_must_approve_start(self):
        game.join(self.r, 'game', 'alpha')
        game.join(self.r, 'game', 'beta')
        game.join(self.r, 'game', 'gaga')
        game.start(self.r, 'game', 'alpha')
        game.start(self.r, 'game', 'beta')

        info = game.info(self.r, 'game').next()
        self.assertNotIn('round', info['state'])
Пример #3
0
 def test_move(self):
     game.join(self.r, 'game', 'max')
     game.join(self.r, 'game', 'jenny')
     game.start(self.r, 'game', 'max')
     game.start(self.r, 'game', 'jenny')
     self.assertTrue(game.move(self.r, 'game', 'jenny', 'han'))
     info = game.info(self.r, 'game', 'jenny').next()
     self.assertEquals([{ 'name': 'jenny',
                          'state': 'moved'},
                        { 'name': 'max',
                          'state': 'undecided'}], info['state']['players'])
     self.assertEquals('han', info['you']['state'])
Пример #4
0
    def test_start_game(self):
        game.join(self.r, 'game', 'alpha')
        game.join(self.r, 'game', 'beta')
        game.start(self.r, 'game', 'alpha')

        game.start(self.r, 'game', 'beta')

        info = game.info(self.r, 'game').next()
        self.assertEquals('1', info['state']['round'])
        self.assertEquals([{ 'name': 'alpha',
                             'state': 'undecided'},
                           { 'name': 'beta',
                             'state': 'undecided'}], info['state']['players'])
Пример #5
0
 def test_start_statuses(self):
     game.join(self.r, 'game', 'dave')
     self.assertTrue(game.start(self.r, 'game', 'dave'))
     info = game.info(self.r, 'game', 'dave').next()
     self.assertDictContainsSubset({
             'state': 'camp',
             'name': 'dave' }, info['you'])
     self.assertEquals([{'name': 'dave', 'state': 'camp' }],
                       info['state']['players'])
Пример #6
0
def run_player(r, k, name, wait_for_n_players, sleeper,
               ai=random_ai, sleep_time=0):
    """
    A self-contained player.  Joins game, plays when it can.
    """

    game.join(r, k, name)

    for info in game.info(r, k, name):
        sleeper.sleep(sleep_time)

        player_state = info['you']['state']
        if player_state == 'joined':
            if len(info['state']['players']) == wait_for_n_players:
                game.start(r, k, name)
            else:
                pass
        elif player_state == 'undecided':
            game.move(r, k, name, ai())
        elif player_state in ['won', 'lost']: # done!
            return True

        sleeper.sleep(sleep_time)
Пример #7
0
    def test_single_player_starting_gets_more_players_update(self):
        game.join(self.r, 'game', 'hermit')
        game.start(self.r, 'game', 'hermit')
        info = game.info(self.r, 'game').next()

        self.assertDictContainsSubset({'more_players': True}, info['updates'].pop(0))
Пример #8
0
 def test_needs_multiple_players_to_start(self):
     game.join(self.r, 'game', 'hermit')
     game.start(self.r, 'game', 'hermit')
     info = game.info(self.r, 'game').next()
     self.assertNotIn('round', info['state'])