def test_add_hoizontal_valid_empty_board(self): starting_board = new_board() b = add_horizontal(starting_board, (5, 3), "remove") for row_index in (i for i in range(0, 15) if i != 5): self.assertEqual(' ', b[row_index]) self.assertEqual(' remove ', b[5]) self.assertNotEqual(starting_board, b)
def is_valid_arrangement(board): if board == new_board(): return True if board[7][7] == ' ': return False tiles = set() for row in range(0,15): for col in range(0,15): if board[row][col] != ' ': tiles.add((row, col)) check_contiguous((7,7), tiles) return not tiles
def test_add_vertical_valid_inertsect(self): starting_board = new_board() starting_board = starting_board[:5] \ + (' remove ',) \ + starting_board[6:] b = add_vertical(starting_board, (4, 6), "dg") for row_index in (i for i in range(0, 15) if i not in [4, 5, 6]): self.assertEqual(' ', b[row_index]) self.assertEqual(' d ', b[4]) self.assertEqual(' remove ', b[5]) self.assertEqual(' g ', b[6]) self.assertNotEqual(starting_board, b)
def test_add_vertical_valid_empty_board(self): starting_board = new_board() b = add_vertical(starting_board, (5, 3), "remove") self.assertEqual(' r ', b[5]) self.assertEqual(' e ', b[6]) self.assertEqual(' m ', b[7]) self.assertEqual(' o ', b[8]) self.assertEqual(' v ', b[9]) self.assertEqual(' e ', b[10]) for row_index in (i for i in range(0, 15) if i not in range(5, 11)): self.assertEqual(' ', b[row_index]) self.assertNotEqual(starting_board, b)
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_add_horizontal_valid_intersect(self): starting_board = new_board() starting_board = starting_board[:4] \ + (' d ', ' o ', ' g ') \ + starting_board[7:] b = add_horizontal(starting_board, (5, 3), "remve") for row_index in (i for i in range(0, 15) if i not in [4, 5, 6]): self.assertEqual(' ', b[row_index]) self.assertEqual(' d ', b[4]) self.assertEqual(' remove ', b[5]) self.assertEqual(' g ', b[6]) self.assertNotEqual(starting_board, b)
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 test_add_vertical_invalid_off_board(self): starting_board = new_board() with self.assertRaises(InvalidTilePlacementError): add_vertical(starting_board, (12, 5), "remove")
def test_new_board(self): b = new_board() for row in range(0, 15): for column in range(0, 15): self.assertEqual(' ', b[row][column])
def test_add_horizontal_invalid_off_board(self): starting_board = new_board() with self.assertRaises(InvalidTilePlacementError): add_horizontal(starting_board, (5, 12), "remove")
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': '', 'score': 0,
def new_game(players): return Game(bag=new_bag(), board=new_board(), players=tuple([Player(name, 0, '') for name in players]), next_player=0)