def test_merge_branded_with_unbranded(state): grid.place_tile(state, models.Tile(11, 0)) grid.place_tile(state, models.Tile(11, 2)) grid.place_tile(state, models.Tile(11, 3), brand=models.Brand.CONTINENTAL) grid.place_tile(state, models.Tile(10, 1)) assert state.grid[11][0] is not None assert state.grid[11][2] is not None assert state.grid[11][3] is not None assert state.grid[10][1] is not None assert state.grid[11][0] != state.grid[11][2] assert state.grid[10][1] != state.grid[11][2] assert state.grid[10][1] != state.grid[11][0] assert state.grid[11][3] == state.grid[11][2] grid.place_tile(state, models.Tile(11, 1)) assert state.grid[11][0] is not None assert state.grid[11][1] is not None assert state.grid[11][2] is not None assert state.grid[11][3] is not None assert state.grid[10][1] is not None assert state.grid[11][0].brand == models.Brand.CONTINENTAL assert state.grid[11][0] == state.grid[11][2] assert state.grid[11][0] == state.grid[11][1] assert state.grid[11][0] == state.grid[11][3] assert state.grid[11][0] == state.grid[10][1]
def test_grow_chain_choose_brand(state): grid.place_tile(state, models.Tile(4, 6)) grid.place_tile(state, models.Tile(4, 7), brand=models.Brand.FESTIVAL) assert state.grid[4][6] is not None assert state.grid[4][6].brand == models.Brand.FESTIVAL assert state.grid[4][7] == state.grid[4][6]
def start_game(): game_id = request.json['game_id'] game_state = persistance.get_game_state(game_id) if game_state.is_started: raise models.RuleViolation('Cannot start already started game!') player_count_min = int(os.environ['PLAYER_COUNT_MIN']) player_count_max = int(os.environ['PLAYER_COUNT_MAX']) tile_hand_size = int(os.environ['TILE_HAND_SIZE']) player_count = len(game_state.player_order) if not player_count_min <= player_count <= player_count_max: raise models.RuleViolation( f'Cannot start game with {player_count} players!') shuffle(game_state.player_order) starting_player = game_state.player_order[0] initial_tiles = tiles.generate_initial_tiles() board_starting_tiles = tiles.draw_tiles(initial_tiles, player_count) for tile in board_starting_tiles: grid.place_tile(game_state, tile) game_state.is_started = True game_state.current_turn_player = starting_player game_state.current_action_player = starting_player tiles_by_player_id = { player_id: tiles.draw_tiles(initial_tiles, tile_hand_size) for player_id in game_state.player_order } game_state.tiles_remaining = len(initial_tiles) persistance.initialize_global_tiles(game_id, initial_tiles) persistance.initialize_player_tiles(game_id, tiles_by_player_id) persistance.update_game_state(game_id, game_state.to_dict()) return 'OK'
def test_grow_chain_brand(state): grid.place_tile(state, models.Tile(4, 6)) grid.place_tile(state, models.Tile(4, 7), brand=models.Brand.IMPERIAL) grid.place_tile(state, models.Tile(3, 6)) assert state.grid[4][6] is not None assert state.grid[4][6].brand == models.Brand.IMPERIAL assert state.grid[4][7] == state.grid[4][6] assert state.grid[4][7] == state.grid[3][6]
def place_tile(): game_id = request.json['game_id'] id_token = request.json['id_token'] x = int(request.json['x']) y = int(request.json['y']) raw_brand = request.json['brand'] brand = None if raw_brand == '' else models.Brand(raw_brand) player_id = firebase_admin.auth.verify_id_token(id_token)['uid'] state = persistance.get_game_state(game_id) if state.current_action_player != player_id: raise models.RuleViolation( "Stop trying to take other player's turns! You cheat!") if state.current_action_type != models.ActionType.PLACE_TILE: raise models.RuleViolation( 'It is your turn, but it is not time to place a tile!') player_tiles = persistance.get_player_tiles(game_id, player_id) if not any(tile.x == x and tile.y == y for tile in player_tiles): raise models.RuleViolation( 'You do not have that tile! Stop trying to cheat!') if not state.is_started: raise models.RuleViolation('Cannot take turn until game has begun!') tile = models.Tile(x, y) place_tile_result = grid.place_tile(state, tile, brand) stock.apply_majority_bonuses(state, place_tile_result.acquired_chains) stock.award_founder_share(state, player_id, place_tile_result.new_brand) grid.set_brand_lists(state) stock.set_price_table(state) turns.transition_from_place(state, place_tile_result, game_id) persistance.delete_player_tile(game_id, player_id, models.Tile(x, y)) # this should all happen atomically, but as a stopgap make sure this happens last persistance.update_game_state(game_id, state.to_dict()) return 'OK'
def test_merge_unbranded_no_choice(state): grid.place_tile(state, models.Tile(11, 0)) grid.place_tile(state, models.Tile(11, 2)) assert state.grid[11][0] is not None assert state.grid[11][2] is not None assert state.grid[11][0] != state.grid[11][2] grid.place_tile(state, models.Tile(11, 1)) assert state.grid[11][0] is not None assert state.grid[11][1] is not None assert state.grid[11][2] is not None assert state.grid[11][0] == state.grid[11][2] assert state.grid[11][0] == state.grid[11][1]
def test_merge_unbranded_choose_brand(state): grid.place_tile(state, models.Tile(11, 0)) grid.place_tile(state, models.Tile(11, 2)) assert state.grid[11][0] is not None assert state.grid[11][2] is not None assert state.grid[11][0] != state.grid[11][2] grid.place_tile(state, models.Tile(11, 1), brand=models.Brand.AMERICAN) assert state.grid[11][0] is not None assert state.grid[11][1] is not None assert state.grid[11][2] is not None assert state.grid[11][2].brand == models.Brand.AMERICAN assert state.grid[11][0] == state.grid[11][2] assert state.grid[11][0] == state.grid[11][1]
def test_merge_locked_chains_and_unlocked_chain(state): grid.place_tile(state, models.Tile(0, 1)) grid.place_tile(state, models.Tile(1, 1), brand=models.Brand.FESTIVAL) grid.place_tile(state, models.Tile(2, 1)) grid.place_tile(state, models.Tile(3, 1)) grid.place_tile(state, models.Tile(4, 1)) grid.place_tile(state, models.Tile(5, 1)) grid.place_tile(state, models.Tile(6, 1)) grid.place_tile(state, models.Tile(7, 1)) grid.place_tile(state, models.Tile(8, 1)) grid.place_tile(state, models.Tile(9, 1)) grid.place_tile(state, models.Tile(5, 0)) grid.place_tile(state, models.Tile(0, 3)) grid.place_tile(state, models.Tile(1, 3), brand=models.Brand.LUXOR) grid.place_tile(state, models.Tile(2, 3)) grid.place_tile(state, models.Tile(3, 3)) grid.place_tile(state, models.Tile(4, 3)) grid.place_tile(state, models.Tile(5, 3)) grid.place_tile(state, models.Tile(6, 3)) grid.place_tile(state, models.Tile(7, 3)) grid.place_tile(state, models.Tile(8, 3)) grid.place_tile(state, models.Tile(9, 3)) grid.place_tile(state, models.Tile(5, 4)) grid.place_tile(state, models.Tile(10, 2)) assert state.grid[7][1].is_locked() assert state.grid[5][4].is_locked() assert not state.grid[10][2].is_locked() with pytest.raises(models.RuleViolation): grid.place_tile(state, models.Tile(9, 2))
def test_merge_multiple_branded_different_size(state): grid.place_tile(state, models.Tile(8, 5)) grid.place_tile(state, models.Tile(8, 6), brand=models.Brand.TOWER) grid.place_tile(state, models.Tile(8, 7)) grid.place_tile(state, models.Tile(6, 4)) grid.place_tile(state, models.Tile(6, 5), brand=models.Brand.AMERICAN) with pytest.raises(models.RuleViolation): grid.place_tile(state, models.Tile(7, 5), brand=models.Brand.AMERICAN) with pytest.raises(models.RuleViolation): grid.place_tile(state, models.Tile(7, 5), brand=models.Brand.LUXOR) grid.place_tile(state, models.Tile(7, 5)) assert state.grid[8][5] is not None assert state.grid[8][6] is not None assert state.grid[8][7] is not None assert state.grid[6][4] is not None assert state.grid[6][5] is not None assert state.grid[7][5] is not None assert state.grid[8][5].brand == models.Brand.TOWER assert state.grid[8][5] == state.grid[8][6] assert state.grid[8][5] == state.grid[8][7] assert state.grid[8][5] == state.grid[7][5] assert state.grid[8][5] == state.grid[6][4] assert state.grid[8][5] == state.grid[6][5]
def test_grow_chain_illegally_specify_new_brand(state): grid.place_tile(state, models.Tile(4, 6)) grid.place_tile(state, models.Tile(4, 7), brand=models.Brand.IMPERIAL) with pytest.raises(models.RuleViolation): grid.place_tile(state, models.Tile(3, 6), brand=models.Brand.WORLDWIDE)
def test_simple_placement_brand(state): with pytest.raises(models.RuleViolation): grid.place_tile(state, models.Tile(1, 3), brand=models.Brand.LUXOR)
def test_grow_locked_chain(state): grid.place_tile(state, models.Tile(0, 0)) grid.place_tile(state, models.Tile(1, 0), brand=models.Brand.FESTIVAL) grid.place_tile(state, models.Tile(2, 0)) grid.place_tile(state, models.Tile(3, 0)) grid.place_tile(state, models.Tile(4, 0)) grid.place_tile(state, models.Tile(5, 0)) grid.place_tile(state, models.Tile(6, 0)) grid.place_tile(state, models.Tile(7, 0)) grid.place_tile(state, models.Tile(8, 0)) grid.place_tile(state, models.Tile(9, 0)) grid.place_tile(state, models.Tile(10, 0)) assert state.grid[9][0] == state.grid[1][0] assert state.grid[7][0].is_locked() assert state.grid[0][0].brand == models.Brand.FESTIVAL assert state.grid[4][0].brand == models.Brand.FESTIVAL assert state.grid[5][0].brand == models.Brand.FESTIVAL grid.place_tile(state, models.Tile(2, 1)) assert len(state.grid[2][1].tiles) == 12 assert state.grid[2][1].is_locked() assert state.grid[2][1].brand == models.Brand.FESTIVAL
def test_grow_chain_no_brand(state): grid.place_tile(state, models.Tile(4, 6)) with pytest.raises(models.RuleViolation): grid.place_tile(state, models.Tile(4, 7))
def test_simple_placement_no_brand(state): grid.place_tile(state, models.Tile(1, 3)) assert state.grid[1][3] is not None assert state.grid[1][3].brand is None
def test_merge_locked_and_unlocked_chain(state): grid.place_tile(state, models.Tile(0, 0)) grid.place_tile(state, models.Tile(1, 0), brand=models.Brand.FESTIVAL) grid.place_tile(state, models.Tile(2, 0)) grid.place_tile(state, models.Tile(3, 0)) grid.place_tile(state, models.Tile(4, 0)) grid.place_tile(state, models.Tile(5, 0)) grid.place_tile(state, models.Tile(6, 0)) grid.place_tile(state, models.Tile(7, 0)) grid.place_tile(state, models.Tile(8, 0)) grid.place_tile(state, models.Tile(9, 0)) grid.place_tile(state, models.Tile(10, 0)) grid.place_tile(state, models.Tile(0, 2)) grid.place_tile(state, models.Tile(1, 2), brand=models.Brand.LUXOR) grid.place_tile(state, models.Tile(2, 2)) grid.place_tile(state, models.Tile(3, 2)) grid.place_tile(state, models.Tile(4, 2)) grid.place_tile(state, models.Tile(5, 2)) grid.place_tile(state, models.Tile(6, 2)) grid.place_tile(state, models.Tile(7, 2)) grid.place_tile(state, models.Tile(8, 2)) grid.place_tile(state, models.Tile(9, 2)) assert state.grid[7][0].is_locked() assert not state.grid[1][2].is_locked() grid.place_tile(state, models.Tile(2, 1)) assert state.grid[0][0] == state.grid[7][2] assert state.grid[2][1].brand == models.Brand.FESTIVAL
def test_already_taken_spot(state): grid.place_tile(state, models.Tile(1, 3)) with pytest.raises(models.RuleViolation): grid.place_tile(state, models.Tile(1, 3))
def test_merge_locked_chains(state): grid.place_tile(state, models.Tile(0, 0)) grid.place_tile(state, models.Tile(1, 0), brand=models.Brand.FESTIVAL) grid.place_tile(state, models.Tile(2, 0)) grid.place_tile(state, models.Tile(3, 0)) grid.place_tile(state, models.Tile(4, 0)) grid.place_tile(state, models.Tile(5, 0)) grid.place_tile(state, models.Tile(6, 0)) grid.place_tile(state, models.Tile(7, 0)) grid.place_tile(state, models.Tile(8, 0)) grid.place_tile(state, models.Tile(9, 0)) grid.place_tile(state, models.Tile(10, 0)) grid.place_tile(state, models.Tile(0, 2)) grid.place_tile(state, models.Tile(1, 2), brand=models.Brand.LUXOR) grid.place_tile(state, models.Tile(2, 2)) grid.place_tile(state, models.Tile(3, 2)) grid.place_tile(state, models.Tile(4, 2)) grid.place_tile(state, models.Tile(5, 2)) grid.place_tile(state, models.Tile(6, 2)) grid.place_tile(state, models.Tile(7, 2)) grid.place_tile(state, models.Tile(8, 2)) grid.place_tile(state, models.Tile(9, 2)) grid.place_tile(state, models.Tile(10, 2)) assert state.grid[7][0].is_locked() assert state.grid[1][2].is_locked() with pytest.raises(models.RuleViolation): grid.place_tile(state, models.Tile(2, 1))