def build_game(): content = request.get_json() player1_name = content.get('player1Name', 'Player 1') player2_name = content.get('player2Name', 'Player 2') decks = content.get('decks', ['Codenames']) bystanders = content.get('bystanders', 9) game = make_game(player1_name, player2_name, bystanders, decks) db_game = Game(token=id_generator(size=30), game_details=json.dumps(game)) db.session.add(db_game) db.session.commit() # Create 2 attendees to be used later player1 = db_game.add_pending_attendee(name=player1_name, index=1) player2 = db_game.add_pending_attendee(name=player2_name, index=2) game = safe_game(game, db_game.token) return { 'gameUrlPlayer1': url_for('start_game_split', game_id=db_game.token, player_token=player1.token, token=make_login_token(signer, db_game.token, 1)), 'gameUrlPlayer2': url_for('start_game_split', game_id=db_game.token, player_token=player2.token, token=make_login_token(signer, db_game.token, 2)), }
def start_new_game(game_id, db_game, game, **kwargs): new_game = make_game(game['player1']['name'], game['player2']['name'], game['initialBystanders'], decks=game['decks']) update_game_details(new_game, game_id) for channel in build_channels(db_game): app.logger.info(f'Triggering update on socket channels {channel}') pusher_client.trigger(channel, 'game_update', {}) pusher_client.trigger(channel, 'key_update', {}) game = safe_game(game, game_id) return {'result': 1, 'game': game}
def test_should_have_correct_commonality(): """Per the rules, one common black, one black is green, one black is yellow and three common greens""" game = make_game('Bob', 'Diane', 12, ['Codenames']) player1 = game['player1'] player2 = game['player2'] common_black = [word for word in player1['black'] if word in player2['black']] common_green = [word for word in player1['green'] if word in player2['green']] black_green_common_1 = [word for word in player1['black'] if word in player2['green']] black_green_common_2 = [word for word in player2['black'] if word in player1['green']] assert_that(common_black).is_length(1) assert_that(common_green).is_length(3) assert_that(black_green_common_1).is_length(1) assert_that(black_green_common_2).is_length(1) assert_that(player1['green']).is_length(9) assert_that(player2['green']).is_length(9) assert_that(player1['black']).is_length(3) assert_that(player2['black']).is_length(3) assert_that(game['lost']).is_false() assert_that(game['next_up']).is_none()
def main(): """The main method containing the main loop.""" rows = int(input()) cols = int(input()) start = input() if (start == "EMPTY"): game = game_py.make_game(rows, cols) elif (start == "CONTENTS"): requested_array = [] for i in range(rows): requested_array.append(list(input())) translated_array = [[(ord(char) - 64) for char in row] for row in requested_array] game = game_py.Game(translated_array) while (1): print(game_to_str(game)) if (game.state == game_py.Game_State.OVER): print("GAME OVER") break input_str = input() if (input_str == ""): game.tick() elif (input_str == "<"): game.move_col_left() elif (input_str == ">"): game.move_col_right() elif (input_str == "Q"): break elif (input_str == "R"): game.rotate() elif (re.match(r"F \d [A-J] [A-J] [A-J]", input_str)): game.make_column([ ord(input_str[4]) - 64, ord(input_str[6]) - 64, ord(input_str[8]) - 64 ], int(input_str[2]) - 1)
def test_read_decks_from_string(): """Decks will be passed as string, transformed to enum""" game = make_game('Bob', 'Diane', 12, [Decks.Codenames.value, Decks.Duet_2.value]) assert_that(game['decks']).is_equal_to(['Codenames', 'Duet #2'])