Exemplo n.º 1
0
    def test_standard_win(self):
        game1 = Game(1, 2)
        game1.setServe(game1.player1)
        self.assertFalse(game1.getWinner())
        self.add_score(game1, game1.player1, 11)
        self.assertTrue(game1.getWinner())
        self.assertEqual(game1.getWinner(), game1.player1)

        game2 = Game(1, 2)
        game2.setServe(game2.player2)
        self.assertFalse(game2.getWinner())
        self.add_score(game2, game2.player2, 11)
        self.assertTrue(game2.getWinner())
        self.assertEqual(game2.getWinner(), game2.player2)
Exemplo n.º 2
0
 def send_game_answer(self, data):
     good_description = Game().submit_question(data)
     game_info = self.get_game_info(data.get('id_user'))
     if good_description:
         game_info[
             'good_description'] = f'Стоит поступить иначе: {good_description}'
     else:
         game_info['good_description'] = 'Хороший выбор!'
     return game_info
Exemplo n.º 3
0
    def test_points_adding(self):
        newgame = Game(1, 2)
        newgame.setServe(newgame.player1)

        self.add_score(newgame, newgame.player1, 5)
        self.assertEqual(newgame.getScore(newgame.player1), 5)

        self.add_score(newgame, newgame.player2, 5)
        self.assertEqual(newgame.getScore(newgame.player2), 5)
Exemplo n.º 4
0
    def test_tiebreak_win(self):
        game1 = Game(1, 2)
        game1.setServe(game1.player1)
        self.add_score(game1, game1.player1, 10)
        self.add_score(game1, game1.player2, 11)
        self.add_score(game1, game1.player1, 1)
        self.assertFalse(game1.getWinner())

        self.add_score(game1, game1.player2, 2)
        self.assertTrue(game1.getWinner())
        self.assertEqual(game1.getWinner(), game1.player2)
Exemplo n.º 5
0
        def inner(*args, **kwargs):
            game_id = kwargs["game_id"]
            state = db.load_game_state(game_id)
            game = Game(state)
            result = func(*args, **kwargs, game=game)

            if save:
                db.save_game_state(game_id, game.get_state(),
                                   datetime.datetime.now())

            return result
Exemplo n.º 6
0
    def test_serving_adding(self):
        newgame = Game(1, 2)
        newgame.setServe(newgame.player1)

        self.add_score(newgame, newgame.player1, 5)
        # Player1 should be serving
        self.assertEqual(newgame.getServe(), 1)

        self.add_score(newgame, newgame.player2, 5)
        # Player2 should be serving
        self.assertEqual(newgame.getServe(), 2)
Exemplo n.º 7
0
    def test_serving_subtracting(self):
        newgame = Game(1, 2)
        newgame.setServe(newgame.player1)
        self.add_score(newgame, newgame.player1, 5)  # (5)-0
        self.add_score(newgame, newgame.player2, 5)  # 5-(5)

        self.subtract_score(newgame, newgame.player1, 3)  # 2-(5)
        self.assertEqual(newgame.getServe(), 2)

        self.subtract_score(newgame, newgame.player2, 3)  # (2)-2
        self.assertEqual(newgame.getServe(), 1)
Exemplo n.º 8
0
def init_pvp():
    code = token_hex(16)
    g = Game(2, current_user.id)
    save_game(g, code)

    game_record = GameModel(code=code,
                            user_id=current_user.id,
                            mode=PVP_MODE,
                            isHost=True)
    db.session.add(game_record)
    db.session.commit()

    return redirect(url_for('game.waiting_room', code=code))
Exemplo n.º 9
0
    def test_tiebreak_serving(self):
        newgame = Game(1, 2)
        newgame.setServe(newgame.player1)
        self.add_score(newgame, newgame.player1, 10)  # 10-(0)
        self.add_score(newgame, newgame.player1, 10)  # (10)-10
        self.assertEqual(newgame.getServe(), 1)

        self.add_score(newgame, newgame.player1, 1)
        self.assertEqual(newgame.getServe(), 2)
        self.add_score(newgame, newgame.player1, 1)
        self.assertEqual(newgame.getServe(), 1)

        self.add_score(newgame, newgame.player1, 1)
        self.assertEqual(newgame.getServe(), 2)
        self.add_score(newgame, newgame.player1, 1)
        self.assertEqual(newgame.getServe(), 1)
Exemplo n.º 10
0
def create_game():
    game = Game()
    player_1 = request.form.get('player_1_name')
    player_2 = request.form.get('player_2_name')
    player_3 = request.form.get('player_3_name')
    player_4 = request.form.get('player_4_name')
    player_5 = request.form.get('player_5_name')
    player_6 = request.form.get('player_6_name')
    players = [
        i
        for i in [player_1, player_2, player_3, player_4, player_5, player_6]
        if i and i != ""
    ]
    game.start_game(players)
    game_id = db.save_game_state(None, game.get_state(),
                                 datetime.datetime.now())
    return redirect(url_for("view", game_id=game_id))
Exemplo n.º 11
0
def vs_ai(code=None):
    payload = {
        'buy':
        bool(int(request.form.get('buy')))
        if request.form.get('buy') else None,
        'build':
        request.form.get('build').split(';')[0:-1]
        if request.form.get('build') else None
    }
    if code:
        if request.form.get('next_turn'):
            g = load_game(code)
            g.next_turn(payload)
            ai_payload = ai_move(g)
            g.next_turn(ai_payload)
            if g.winner:
                game_record = GameModel.query.filter_by(code=code).first()
                game_record.status = STATUS_FINISHED
                db.session.commit()
                delete_game(code)
                flash('player {} have won!!'.format(g.winner.id), 'success')
                return redirect(url_for('game.home'))
            save_game(g, code)
        else:
            g = load_game(code)
    else:
        code = token_hex(16)
        g = Game(2)
        g.next_turn(payload)
        save_game(g, code)

        game_in_db = GameModel(code=code,
                               user_id=current_user.id,
                               mode=PVAI_MODE,
                               status=STATUS_ACTIVE)
        db.session.add(game_in_db)
        db.session.commit()

    return render_template('game/board/board.html', game=g, code=code)
Exemplo n.º 12
0
def select_sport_instance(config_dict, number_of_teams=2):
    """
	Returns an object from the *Game* module based on the sport passed.
	"""
    if config_dict['sport'] == 'MPMULTISPORT1-baseball' and config_dict[
            'MPLX3450Flag']:
        config_dict['sport'] = 'MPLX3450-baseball'
    elif config_dict['sport'] == 'MPMULTISPORT1-football' and config_dict[
            'MPLX3450Flag']:
        config_dict['sport'] = 'MPLX3450-football'

    # TODO: Move this out into Console function?
    # Write sport change from mp_lx3450_flag to config file
    import app.config_default_settings
    c = app.config_default_settings.Config()
    c.write_sport(config_dict['sport'])
    del c

    choice = SPORT_LIST.index(config_dict['sport']) + 1

    # 'MMBASEBALL3'#'MPBASEBALL1'#'MMBASEBALL4'
    # 'MPMULTISPORT1-baseball'#'MPLX3450-baseball'
    # 'MPLINESCORE4'#'MPLINESCORE5'#'MPMP-15X1'#'MPMP-14X1'
    if (1 <= choice <= 8) or choice == 20:
        from app.game.game import Baseball
        game = Baseball(config_dict, number_of_teams)

    # 'MPMULTISPORT1-football'#'MPFOOTBALL1'#'MMFOOTBALL4'
    # 'MPSOCCER_LX1-football'#'MPLX3450-football'
    elif (9 <= choice <= 11) or choice == 14 or choice == 21:
        from app.game.game import Football
        game = Football(config_dict, number_of_teams)

    elif choice == 12:  # 'MPBASKETBALL1'
        from app.game.game import Basketball
        game = Basketball(config_dict, number_of_teams)

    elif choice == 13 or choice == 15:  # 'MPSOCCER_LX1-soccer'#'MPSOCCER1'
        from app.game.game import Soccer
        game = Soccer(config_dict, number_of_teams)

    elif choice == 16 or choice == 17:  # 'MPHOCKEY_LX1'#'MPHOCKEY1'
        from app.game.game import Hockey
        game = Hockey(config_dict, number_of_teams)

    elif choice == 18:  # 'MPCRICKET1'
        from app.game.game import Cricket
        game = Cricket(config_dict, number_of_teams)

    elif choice == 19:  # 'MPRACETRACK1'
        from app.game.game import Racetrack
        game = Racetrack(config_dict, number_of_teams)
    elif choice == 23:  # 'STAT'
        from app.game.game import Stat
        game = Stat(config_dict, number_of_teams)
    elif choice == 22:  # 'GENERIC'
        from app.game.game import Game
        game = Game(config_dict, number_of_teams)
    else:
        print 'sport not in list'
        raise Exception
    return game
Exemplo n.º 13
0
 def test_serve_setting(self):
     newgame = Game(1, 2)
     newgame.setServe(newgame.player1)
     self.assertEqual(newgame.getServe(), 1)
     self.assertNotEqual(newgame.getServe(), 2)
Exemplo n.º 14
0
 def test_game_creation(self):
     newgame = Game(1, 2)
     self.assertEqual(newgame.player1.user, 1)
     self.assertEqual(newgame.player2.user, 2)
     self.assertEqual(newgame.pointsServed, 0)
Exemplo n.º 15
0
 def test_session_id(self):
     game = Game(1, 2)
     session.setSessionId(5)
     session.setSession(game)
     self.assertEqual(session.getSessionId(), 6)
Exemplo n.º 16
0
 def test_session_end(self):
     game = Game(1, 2)
     session.setSession(game)
     session.endSession()
     self.assertFalse(session.getSession())
Exemplo n.º 17
0
 def test_start(self):
     Game().start_game({'id_user': 1, 'id_person': 1})
Exemplo n.º 18
0
 def start_new_game(self, data):
     self.provider.end_game(data.get('id_user'))
     Game().start_game(data)
     return self.get_game_info(data.get('id_user'))
Exemplo n.º 19
0
def start():
    game = Game()
    game.get_a_random_fruit()
    game.mount_tip()
    game.start_game()
Exemplo n.º 20
0
 def test_submit_question(self):
     Game().submit_question({'answer': 0, 'id_user': 1})
Exemplo n.º 21
0
 def test_session_create(self):
     game = Game(1, 2)
     session.setSession(game)
     self.assertEqual(session.getSession(), game)