def start_game(): board_model: Board = Board() player_1: Player = Player(Order.FIRST) player_2: Player = Player(Order.SECOND) game = Hex(board_model, PlayersController(player_1, player_2)) game.on_execute()
def test_determine_player__should_return_p2(): turn_count = 2 P1 = Player() P2 = Player() starting_player = P1 players = [P1, P2] actual = utilities.determine_player(turn_count, starting_player, players) assert actual is P2
def __init__(self): self.pool = Pool(load_champ_data()) self.rankings = [] self.round = 0 self.players = [ Player(i, f"Player #{i}", self.pool) for i in range(NUM_PLAYERS) ]
def get_rostered_players(owners: List[Owner], current_week: int, soup_kitchen: SoupKitchen) -> List[Player]: print('\nLoading rosters...') players: List[Player] = [] weeks = range(current_week + 1, num_weeks + 1) for owner, week in tqdm(list(product(owners, weeks))): soup = soup_kitchen.get('/f1/%s/%s?week=%s&stat1=P&stat2=PW' % (league_id, owner.id, week)) for table_id in ['statTable0', 'statTable1', 'statTable2']: table = soup.find('table', id=table_id) for tr in table.find('tbody').findAll('tr'): info = tr.find('div', {'class': 'ysf-player-name'}) _id = [ t for t in info.find('a')['href'].split('/') if t != '' ][-1] player = next((p for p in players if p.id == _id), None) if not player: name = info.find('a').text team, position = [ token.strip() for token in info.find('span').text.split('-') ] players.append(Player(_id, name, team, position, owner.id)) bolded_trs = tr.findAll('span', {'class': 'Fw-b'}) projection = int(float( bolded_trs[-1].text.strip())) if bolded_trs else 0 next(p for p in players if p.id == _id).set_weekly_projection(week, projection) return players
async def _store(self, ctx): """View store information and inventory.""" player = Player(ctx.message.author.id) location = Location(player.current_location) store_ids = self.stores.list_id() for store_id in store_ids: store = Store(store_id) prices = store.settings['prices'] if store.location.location_id == player.current_location: embed = discord.Embed( title=location.name, color=discord.Color.green(), description='Welcome to **' + store.name + '**, ' + ctx.message.author.display_name + '!') items = self.items.list() embed.add_field(name='Items for Sale', value='The following are available for sale.\n', inline=False) for item in items: if item['id'] in store.available_items: embed.add_field( name=item['emoji'] + ' ' + str(item['id']) + '. ' + item['name'], value='Price: ' + str(prices[str(item['id'])]) ) embed.set_footer(text='Requested by '+ctx.message.author.display_name + '. Prices updated: ' + str(prices['date']), icon_url=ctx.message.author.avatar_url) if hasattr(store, 'thumbnail'): embed.set_thumbnail(url=store.thumbnail) await ctx.send(embed=embed)
def test_place_card__should_place_card_in_mid_center(): game = Board() player = Player() card = all_cards.BLOBRA position = 'mid_center' actual = utilities.place_card(game, player, card, position) assert actual['mid_center']['card'] == all_cards.BLOBRA
def register(): if current_user.is_authenticated: return redirect(url_for('index')) form = RegistrationForm() if form.validate_on_submit(): user = Player(username=form.username.data, password=form.password.data) user.save_to_db() flash('Congratulations, you are now a registered user!') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
async def _add_item_to_inventory(self, ctx, item_id: int = 0, count: int = 0): """Add any item to inventory""" player = Player(ctx.message.author.id) player.add_to_inventory(item_id, count) item_object = Item(item_id) await ctx.send( str(count) + ' of ' + item_object.name + ' added to inventory')
def test_has_card_in_hand__should_return_true(): player = Player() player.hand = [ all_cards.COCKATRICE, all_cards.COCKATRICE, all_cards.COCKATRICE, all_cards.COCKATRICE, all_cards.BLOBRA ] card = 'Blobra' actual = utilities.has_card_in_hand(player, card) assert actual is True
def test_has_card_in_hand__should_return_false(): player = Player() player.hand = [ all_cards.COCKATRICE, all_cards.COCKATRICE, all_cards.COCKATRICE, all_cards.COCKATRICE, all_cards.BLOBRA ] card = 'Zell' actual = utilities.has_card_in_hand(player, card) assert actual is False
async def _buy_item(self, ctx, item_id: int = 0, count: int = 0): """Buy an item from the store.""" item_object = Item(item_id) cost = item_object.get_price() * count player = Player(ctx.message.author.id) balance = player.get_balance() wallet = balance['wallet'] if cost > wallet: return await ctx.send("Not enough cash. Need: " + str(cost)) else: player.add_balance('wallet', -cost) player.add_to_inventory(item_id, count) return await ctx.send("Successfully purchased.")
async def _subway(self, ctx, location_id: int = 0): """Use map to view station map, or an id to move to another station.""" await ctx.trigger_typing() if not location_id: return await ctx.send('Try either map or a valid location id.') player = Player(ctx.message.author.id) if player.current_location == location_id: return await ctx.send('You are already there.') distance = abs(location_id - player.current_location) current_location = Location(player.current_location) await ctx.send(':train: ' + ctx.message.author.display_name + ' is now leaving: **' + current_location.name + '** :train:') player.move_to(location_id) location = Location(location_id) time.sleep(distance) return await ctx.send(':train: ' + ctx.message.author.display_name + ' is now arriving at: **' + location.name + '** :train:')
def get_or_create_player(headers: dict, color: str = "White"): name = headers.get(color) # surname, given_name if not name: LOGGER.error("Name was empty %s" % headers) fide_id_str = f"{color}FideId" fide_id = headers.get(fide_id_str) given_name = name[name.find(",") + 2:] surname = name[:name.find(",")] LOGGER.debug(f"given_name: {given_name}, surname: {surname}, fide_id: {fide_id}") try: player = Player.query.filter( or_(Player.fide_id.is_(None), Player.fide_id == fide_id), Player.given_name == given_name, Player.surname == surname ).one_or_none() except MultipleResultsFound as e: LOGGER.error("Multiple results found for combination: %s, %s fide_id: %s" % (surname, given_name, fide_id)) player = None if not player: player = Player(given_name=given_name, surname=surname, fide_id=fide_id) player.store() return player
async def _subway_maps(self, ctx): """View a map of this system's stations.""" await ctx.trigger_typing() player = Player(ctx.message.author.id) current_location = Location(player.current_location) locations = self.locations.list() stops_str = '' for location in locations: if location['id'] == player.current_location: stops_str = stops_str + ':small_orange_diamond: ' else: stops_str = stops_str + ':small_blue_diamond: ' stops_str = stops_str + str( location['id']) + '. ' + location['name'] stores = self.stores.at_location(location['id']) if len(stores) > 0: stores_str = ' (' for store in stores: stores_str = stores_str + store.name if store != stores[-1]: stores_str = stores_str + ', ' stops_str = stops_str + stores_str stops_str = stops_str + ')' stops_str = stops_str + '\n' guild = ctx.message.guild.name embed = discord.Embed(title='Subway Stops', color=discord.Color.blurple(), description='Map of ' + guild + '\nYou are currently in ' + current_location.name) embed.set_footer(text='Queried by ' + ctx.message.author.display_name, icon_url=ctx.message.author.avatar_url) embed.add_field(name='Stops', value=stops_str) embed.set_thumbnail( url= 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/64/MBTA.svg/1200px-MBTA.svg.png' ) return await ctx.send(embed=embed)
async def _get_profile(self, ctx): """See your player profile, balances, current location and inventory.""" player = Player(ctx.message.author.id) inventory_list = player.get_inventory() balances = player.get_balance() location = Location(player.current_location) stores = self.stores.at_location(player.current_location) stores_str = '' for store in stores: if store.location.location_id == player.current_location: if store != stores[-1]: stores_str = stores_str + store.name + ', ' else: stores_str = stores_str + store.name embed = discord.Embed(title='Profile', description='Current Location: ' + location.name, colour=discord.Colour.gold()) if stores_str != '': embed.add_field(name='Stores:', value=stores_str, inline=False) inventory_str = '' if len(inventory_list) > 0: for inventory in inventory_list: item_object = Item(inventory['id']) inventory_str = inventory_str + item_object.emoji + '(' + str( inventory['count']) + ') ' + ' ' + item_object.name + '\n' else: inventory_str = 'Empty Inventory' embed.add_field(name='Bank Balance:', value=':moneybag:' + '{:20,.0f}'.format(balances['bank'])) embed.add_field(name='Cash Balance:', value=':moneybag:' + '{:20,.0f}'.format(balances['wallet'])) embed.add_field(name='Inventory', value=inventory_str, inline=False) embed.set_author(name=ctx.message.author.display_name, icon_url=ctx.message.author.avatar_url) embed.set_thumbnail(url=ctx.message.author.avatar_url) return await ctx.send(embed=embed)
import random from src.models.board import Board from src.models.player import Player from src.models.challenges import challenges from src.services import utilities game = Board() turn_count = 1 P1 = Player() P2 = Player() P1.name = input('What is Player 1\'s name? ') P2.name = input('What is Player 2\'s name? ') players = [P1, P2] starting_player = random.choice(players) while turn_count < 10: print(f'The current turn is {turn_count}') current_player = utilities.determine_player(turn_count, starting_player, players) print(f'The current player is {current_player.name}.') print(f'{P1.name} has {P1.cards}') print(f'{P2.name} has {P2.cards}') selected_card = input('Choose a card from your hand ... ') while not utilities.has_card_in_hand(current_player, selected_card): selected_card = input('That card is not in your hand. Try again ... ') played_card = [ item for item in current_player.hand if item['name'] == selected_card ][0]
async def _add_bank(self, ctx, money: int = 0): """Add money to bank""" player = Player(ctx.message.author.id) player.add_balance('bank', money) return await ctx.send(str(money) + ' added to bank.')
async def _add_wallet(self, ctx, money: int = 0): """Add money to wallet.""" player = Player(ctx.message.author.id) player.add_balance('wallet', money) return await ctx.send(str(money) + ' added to wallet.')
def test_generate_hand__should_generate_hand_of_five_cards(): # no arrange actual = Player().generate_hand() assert len(actual) == 5
def test_generate_deck__should_generate_full_deck(): # no arrange actual = Player() assert len(actual.deck) == 110
def setUp(self): self.p1 = Player() self.p2 = Player()
def new_player(name, room_id): name = name.upper() player = Player(name, 0, 0, 0, 0, 0, 0, room_id) player_all = Player_All(name, 0, 0, 0, 0, 0, 0, room_id, player._id) player.save_to_mongo() player_all.save_to_mongo()
def player1(): p1 = Player(id=1, name="player1") p1.board.add_champ(Champion.from_name("Veigar"), Offset(0, 0)) return p1
def get_or_create_lichess_player(lichess_username: str): player = Player.query.filter_by(lichess_username=lichess_username).one_or_none() if not player: player = Player(lichess_username=lichess_username) player.store() return player