def test_first_draw(self): g0 = new_game(['Player1', 'Player2']) g1 = draw_tiles(g0) self.assertEqual(7, len(g1.players[0].tiles)) self.assertEqual(len(new_bag()) - 7, len(g1.bag)) self.assertEqual(sorted(new_bag()), sorted(g1.bag + g1.players[0].tiles)) self.assertEqual('', g1.players[1].tiles)
def test_new_bag(self): bag = new_bag() self.assertEqual(9, len([tile for tile in bag if tile == 'a'])) self.assertEqual(2, len([tile for tile in bag if tile == 'b'])) self.assertEqual(2, len([tile for tile in bag if tile == 'c'])) self.assertEqual(4, len([tile for tile in bag if tile == 'd'])) self.assertEqual(12, len([tile for tile in bag if tile == 'e'])) self.assertEqual(2, len([tile for tile in bag if tile == 'f'])) self.assertEqual(3, len([tile for tile in bag if tile == 'g'])) self.assertEqual(2, len([tile for tile in bag if tile == 'h'])) self.assertEqual(9, len([tile for tile in bag if tile == 'i'])) self.assertEqual(1, len([tile for tile in bag if tile == 'j'])) self.assertEqual(1, len([tile for tile in bag if tile == 'k'])) self.assertEqual(4, len([tile for tile in bag if tile == 'l'])) self.assertEqual(2, len([tile for tile in bag if tile == 'm'])) self.assertEqual(6, len([tile for tile in bag if tile == 'n'])) self.assertEqual(8, len([tile for tile in bag if tile == 'o'])) self.assertEqual(2, len([tile for tile in bag if tile == 'p'])) self.assertEqual(1, len([tile for tile in bag if tile == 'q'])) self.assertEqual(6, len([tile for tile in bag if tile == 'r'])) self.assertEqual(4, len([tile for tile in bag if tile == 's'])) self.assertEqual(6, len([tile for tile in bag if tile == 't'])) self.assertEqual(4, len([tile for tile in bag if tile == 'u'])) self.assertEqual(2, len([tile for tile in bag if tile == 'v'])) self.assertEqual(2, len([tile for tile in bag if tile == 'w'])) self.assertEqual(1, len([tile for tile in bag if tile == 'x'])) self.assertEqual(2, len([tile for tile in bag if tile == 'y'])) self.assertEqual(1, len([tile for tile in bag if tile == 'z'])) self.assertEqual(2, len([tile for tile in bag if tile == '*'])) self.assertEqual(100, len(bag))
def test_2_players(self): self.maxDiff = None game = new_game(['Player1', 'Player2']) self.assertEqual(new_bag(), game.bag) self.assertEqual(new_board(), game.board) self.assertEqual(2, len(game.players)) self.assertEqual('Player1', game.players[0].name) self.assertEqual(0, game.players[0].score) self.assertEqual('', game.players[0].tiles) self.assertEqual('Player2', game.players[1].name) self.assertEqual(0, game.players[1].score) self.assertEqual('', game.players[1].tiles) self.assertEqual(0, game.next_player)
def test_game_to_db(self): self.assertEqual({ 'bag': new_bag(), 'players': [{ 'name': 'P1', 'tiles': '', 'score': 0, },{ 'name': 'P2', 'tiles': '', 'score': 0, }], 'next_player': 0, 'board': new_board(), },game_to_db(new_game(['P1', 'P2'])))
def print_player(player): print('{} {} [{}] {:.6f}s {}'.format(player['name'], len(player['words']), player['score'], player['time'], player['tiles'])) def draw(game, player): game['bag'] = shake(game['bag']) to_draw = 7 - len(player['tiles']) drawn_tiles = game['bag'][:to_draw] game['bag'] = game['bag'][to_draw:] player['tiles'] = player['tiles'] + drawn_tiles game = { 'bag': shake(new_bag()), 'board': new_board(), } players = [ { 'name': 'Player1', 'tiles': '', 'score': 0, 'strategy': partial(whole_words, scowl(35)), 'time': 0, 'words': [], }, { 'name': 'Player2', 'tiles': '',
def new_game(players): return Game(bag=new_bag(), board=new_board(), players=tuple([Player(name, 0, '') for name in players]), next_player=0)
def test_shake_bag(self): bag = new_bag() bag_s = shake(bag) self.assertNotEqual(bag, bag_s) self.assertEqual(sorted(bag), sorted(bag_s))