Example #1
0
 def test_evaluate(self):
     """Processes a combination of operands and operators"""
     challenge = Challenge('2 3 1 5')
     operands = ['2', '3', '1']
     operators = ['+', '*']
     result = challenge.evaluate(operands, operators)
     assert_equals(result, 5)
Example #2
0
    def play_challenge(self, **args):
        """ Ask to challenge to organised
    
        @param **args: Dictionnary of parameters the challenge.
        Should contain the parameter "game_name"
        @return: results
                
        """
        game_name = args.pop('game_name')
        if game_name in self.games:
            bots = self.games[game_name]['bots']
        else:
            raise ValueError("{game}: unknown game".format(game = game_name))

        challenge = Challenge(game_name, bots)
        try:
            chall_type = args.pop('chall_type')
        except KeyError:
            chall_type = 'championship'
        finally:
            if  chall_type in challenge.avialable_challenge:
                getattr(challenge, chall_type)(**args)
            else:
                raise ValueError('{chal} is an unknown challenge type'.format(chal = chall_type))

        return challenge.give_res_champ()
Example #3
0
    def play_challenge(self, **args):
        """ Ask to challenge to organised
    
        @param **args: Dictionnary of parameters the challenge.
        Should contain the parameter "game_name"
        @return: results
                
        """
        game_name = args.pop('game_name')
        if game_name in self.games:
            bots = self.games[game_name]['bots']
        else:
            raise ValueError("{game}: unknown game".format(game = game_name))

        challenge = Challenge(game_name, bots)
        try:
            chall_type = args.pop('chall_type')
        except KeyError:
            chall_type = 'championship'
        finally:
            if  chall_type in challenge.avialable_challenge:
                getattr(challenge, chall_type)(**args)
            else:
                raise ValueError('{chal} is an unknown challenge type'.format(chal = chall_type))

        return challenge.give_res_champ()
Example #4
0
 def test_format_output(self):
     """Test that formatting the output works as expected"""
     challenge = Challenge('1 2 3 0')
     operands = ('1', '2', '3',)
     operators = ('+', '-',)
     result = challenge.format_output(operands, operators)
     expected = '1 + 2 - 3'
     assert_equals(result, expected)
Example #5
0
def get_challenge_info():
    try:
        data = request.args
        if {'challenge_id'} != set(list(data.keys())):
            raise Exception('ApiException', 'Invalid arguments are provided')
        print(Challenge(data['challenge_id']).get_challenge_info())
        return {'result': Challenge(data['challenge_id']).get_challenge_info()}
    except Exception as e:
        return {'error': str(e)}
Example #6
0
    def test_example_six_num(self):
        """Handles '1 2 3 4 5 6 3'"""
        challenge = Challenge('1 2 3 4 5 6 3')
        result = challenge.run()
        possible_results = [
            '1 + 2 + 3 + 6 - 4 - 5',
            '1 + 2 + 3 - 4 - 5 + 6',
        ]

        assert_in(result, possible_results)
Example #7
0
    def test_example_five_num(self):
        """Handles '6 7 1 2 5 8'"""
        challenge = Challenge('6 7 1 2 5 8')
        result = challenge.run()
        possible_results = [
            '6 + 5 - 7 * 1 * 2',
            '6 * 7 * 1 - 2 / 5',
        ]

        assert_in(result, possible_results)
Example #8
0
    def test_example_three_num_two(self):
        """Handles '4 6 3 2'"""
        challenge = Challenge('4 6 3 2')
        result = challenge.run()
        possible_results = [
            '4 * 3 / 6',
            '4 / 6 * 3',
        ]

        assert_in(result, possible_results)
Example #9
0
    def test_example_three_num_one(self):
        """Handles '1 2 3 5'"""
        challenge = Challenge('1 2 3 5')
        result = challenge.run()
        possible_results = [
            '2 + 3 * 1',
            '3 + 2 * 1',
            '1 * 2 + 3'
        ]

        assert_in(result, possible_results)
Example #10
0
def challengeAnswer(link):
    challenge = ProblemDb.query.filter_by(link=link).first()
    if challenge == None:
        return err(400, "Wrong questions")
    data = request.json
    if data == None:
        return err(400, "No json data")
    try:
        user = data['user']
        answers = data['answer']
        if len(user) == 0:
            return err(400, "请输入用户名")
    except:
        return err(400, "Wrong parameters")

    if len(answers) > 1000000:
        return err(400, "Answer is too long")

    questions = challenge.questions

    try:
        c = Challenge()
        score, results, err_msg = c.evaluate(link, questions, answers)
        if score == None:
            return err(400, err_msg)
    except Exception as e:
        print(e)
        return err(400, "Something is wrong but I don't know why")

    s = SolutionDb.query.filter_by(user=user,
                                   ques_id=challenge.id,
                                   version=challenge.version).first()
    if s == None:
        s = SolutionDb()
    elif s.score > score:
        return success({"msg": "success", "score": score})

    s.ques_id = challenge.id
    s.ques_title = challenge.title
    s.user = user
    s.answers = answers
    s.version = challenge.version
    s.score = score
    s.results = results
    db.session.add(s)
    db.session.commit()

    return success({"msg": "success", "score": score})
Example #11
0
def start_challenge(request):
    user_id = request['userId']
    image_width = int(request['imageWidth'])
    image_height = int(request['imageHeight'])
    challenge = vars(Challenge(user_id, image_width, image_height, token_secret))
    table.put_item(Item=challenge)
    return 200, challenge
Example #12
0
def start_challenge():
    try:
        data = eval(request.data.decode())
        if {'challenge_id'} != set(list(data.keys())):
            raise Exception('ApiException', 'Invalid arguments are provided')
        return {'result': {'challenge_id': Challenge(data['challenge_id']).start()}}
    except Exception as e:
        return {'error': str(e)}
 def counteract_assassin(blocker,player,deck):
     print(f'{player.name} your assassination was counteracted by Contessa')
     opt=str(input(f'Do you want to challenge {blocker.name}? Options: yes / no: '))
     if opt=='yes':
         valid,deck =Challenge.challenge_counteraction(player, blocker,'Contessa',deck)
         return valid,deck
     else:
         return 'Not_Today',deck
Example #14
0
def edit_challenge():
    try:
        data = eval(request.data.decode('utf-8'))
        print(data)
        if {'challenge_id', 'kwargs'} != set(list(data.keys())):
            raise Exception('ApiException', 'Invalid arguments are provided')
        return {'result': Challenge(data['challenge_id']).edit(data['kwargs'])}
    except Exception as e:
        return {'error': str(e)}
Example #15
0
def game_loop(game_state: str, act_tournament: Tournament):
    """

    :param game_state: Actual game state
    :param act_tournament: The tournament to play
    """
    displaying_leader_board = False
    keep_displaying_leaderborad = False
    ask_for_lb = False
    actual_challengers = act_tournament.get_next_group()
    loops_in_this_screen = 0
    points_given = 0

    act_test = Challenge(3)
    o, genre, game = act_test.get_next_test()
    display_genre_game_animation(genre, game)
    display_act_challenge(actual_challengers, act_test.act_test[0])

    while game_state != "gameover":
        if displaying_leader_board:
            keep_displaying_leaderborad = handle_events_leaderboard()
            loops_in_this_screen += 3
        else:
            actual_challengers, act_test, act_tournament, points_given, game_state, ask_for_lb \
                = handle_events_standard_mode(actual_challengers, act_test, act_tournament, points_given, game_state)

        if loops_in_this_screen == 600 or (not keep_displaying_leaderborad and displaying_leader_board) or ask_for_lb:
            loops_in_this_screen = 0
            displaying_leader_board = not displaying_leader_board
            if not displaying_leader_board:
                reset_display()
                display_act_challenge(actual_challengers, act_test.act_test[0])
            else:
                display_leader_board(act_tournament)
            sleep(1)

        pygame.time.delay(100)
        loops_in_this_screen += 1
    display_winner(act_tournament)
    try:
        os.remove("savegame")
    except:
        print("And no need to erase the saved game!")
    sleep(300)
Example #16
0
def challenge_won4():
    prompt = ('''Sir, the ROCKET is READY. WE WILL SPREAD OUR JOY THROUGHOUT THE EARTH''')
    choices = ('HIt thE BUTToN', 'I\m having second thoughts', '', '')
    ans_vals = (1001,1010,1001,1001)
    ans_expl =  (
        '3... 2... 1... Isn\'t it beautiful, sir?', 
        'WE HAVE COME TOO FAR. THERE IS NO BACKING OUT NOW!!\n\n*hits button for you',
        '',
        ''
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #17
0
def challenge_won3():
    prompt = ('''BUT HOw CaN WE GIVE OuR gIFT?''')
    choices = ('USE THE SKY', 'A ROCKET OF GOOD TIDINGS', 'VIRUS OF JOY', '')
    ans_vals = (89764,89764,89764,89764)
    ans_expl =  (
        'YES, OF COURSE, WE cAN SpREAD THE JOY THROUGH THE hEAVENS', 
        'bOMBs HAvE DeSTRoYED BUt OURs CAN GIVE LIFE!',
        'HAPPINESS GOES VIRAL',
        '.'
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #18
0
def challenge_won1():
    prompt = ('''BuT LOOK AT THEM, UNHAPPY mAsseS. ''')
    choices = ('', '', 'SOMEthing must be DONE!', '')
    ans_vals = (0,0,1324,1000)
    ans_expl =  (
        '', 
        '',
        'WhY DO YOU nOT SeE WHAT HAPpYS ARe FOR YOUR TAKINg, PEOpLES OF THE WORLD?!',
        '.'
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #19
0
def challenge_won0():
    prompt = ('''You HaVE DONE IT!  YOu HAvE REACHED PeaK hAPPINESS! HWAAHHAHA ''')
    choices = ('', '', '', 'I am the best.')
    ans_vals = (0,0,0,1000)
    ans_expl =  (
        '', 
        '',
        '',
        'Yes, our jolly monarch, you are.'
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #20
0
def challenge_lost0():
    prompt = ('''Congratulations. You lost.''')
    choices = ('', '', '', 'I want to try again.')
    ans_vals = (0,0,0,0)
    ans_expl =  (
        '', 
        '',
        '',
        'What about "you lost" was hard to understand?'
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #21
0
def challenge_t0():
    prompt = ('''H  A  P  P  Y \n\nP  L  A  N  E  T''')
    choices = ('', '', '', 'continue')
    ans_vals = (0,0,0,0)
    ans_expl =  (
        '', 
        '',
        '',
        'by palinnilap and dragongirl'
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #22
0
def challenge13():
    prompt1 = 'Time to pick a name for your new band.'
    choices1 = ('Shredder Kitties', 'AC/Defroster', 'Shotguns and Petunias', 'Steel Dirgible')
    ans_vals1 = (5,3,-5,1)
    ans_expl1 =  (
        'Solid choice.\n\nYou captured both your unbridled rage and cuddly inner soul.', 
        'Familiar but catchy.',
        'Your first single: "Welcome to the Forest"\n\n was not a hit',
        'Definitely better than your runner up choice:\n\n "The Stink Beatles"'
    ) 
    return Challenge(prompt1, choices1, ans_vals1, ans_expl1)
Example #23
0
def challenge12():
    prompt1 = 'I KNOW. Let\'s do something for four hours straight!'
    choices1 = ('Ski', 'Scream', 'Video Games', 'Read a biography, help orphans, and write well-informed letters to congress')
    ans_vals1 = (-5,7,-10,-1)
    ans_expl1 =  (
        "You had fun for 3 hours and 15 minutes. At 3 hours and 16 minutes you swerved to avoid a moose, went off a ledge, and landed on top of a CIA operative, thus blowing his cover. Oh. And you broke your collar bone.", 
        'Your shrieks were heard by a famous metal band. They offer you a lucrative contract.',
        'You won the MMORPG battle, but lost the afternoon',
        'No points awarded to the brown-noser.\n\nAnd, minus 1 points for lying.'
    ) 
    return Challenge(prompt1, choices1, ans_vals1, ans_expl1)
Example #24
0
def challenge11():
    prompt1 = 'What a nice day!\n\nWhat would you like to do?'
    choices1 = ('Smile', 'Laugh', 'Hugs', 'Cry')
    ans_vals1 = (3,5,-10,-5)
    ans_expl1 =  (
        "Show them pearls!", 
        'The best medicine!\n\n(this statement has not been approved by the FDA)',
        'You chose a bear.\nFrom now on, your hugs will all be one-armed.',
        'Well, you haven\'t quite gotten the hang of this game yet...'
    ) 
    return Challenge(prompt1, choices1, ans_vals1, ans_expl1)
Example #25
0
def challenge31():
    prompt = ('''ARE. YOU. HAPPY. YET?!''')
    choices = ('Yes', 'YHEEESSSS', 'No', 'I\'m only getting started')
    ans_vals = (1,-10,5,-5)
    ans_expl =  (
        'WHERE IS THE PASSION?', 
        'CAN YOU EVEN SPELL?!',
        'THAT\'S RIGHT. NEVER BE CONTENT! Compared to how happy you GONNA BE, THIS IS NOTHING YET!!!!!',
        'THEN START FOR REAL, BRO.'
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #26
0
def challenge_won10():
    prompt = ('''GAME OVER''')
    choices = ('', '', '', '')
    ans_vals = (1000,9999,100000,1000)
    ans_expl =  (
        '', 
        '',
        '',
        ''
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #27
0
def challenge_won2():
    prompt = ('''SHOULDN\'T YoU DO SOmEtHING ABOUT THEM? theIR MISERy MUsTN\'T ToUCh YOu! ''')
    choices = ('YES!', 'No', '', '')
    ans_vals = (9999,9999,1000,0)
    ans_expl =  (
        'OF COURSE WE SHOULD! WHY WOULDN\'T WE?!', 
        'THAT IS CRAZY TALK MY FRIEND, WE MUST GIVE THEM OUR GIFT',
        '',
        '.'
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #28
0
def challenge_won9():
    prompt = ('''HAHAHAH hahaha h...''')
    choices = ('', '', 'ha ... ha .... h', '')
    ans_vals = (1000,9999,100000,1000)
    ans_expl =  (
        '', 
        '',
        'h',
        ''
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #29
0
def challenge_won8():
    prompt = ('''Sir, you haven't slept or ate for days!!!''')
    choices = ('', 'HAHAHAHAH!!!!!', '', '')
    ans_vals = (1000,9999,100000,1000)
    ans_expl =  (
        '', 
        'Sir, you should.... heh.. ha... HAHAHAHA!!',
        '',
        ''
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #30
0
def challenge_won6():
    prompt = ('''It\'s working! The initial shock has washed off and people push themselves off the ground and back to their feet.
    And they are... happy.. smiling... laughing ''')
    choices = ('', 'This laughter is truly inFECTIous!', '', '')
    ans_vals = (1000,9999,1000,1000)
    ans_expl =  (
        '', 
        'IT WORKED! UtOPIA HAs cOME!!!!!',
        '',
        ''
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #31
0
def challenge_won7():
    prompt = ('''bUT WAIT. PeOPLE can\'t stop laughing. They can't talk. They can\'t eat.\n
    The uproar of the city takes on an ominous tone.''')
    choices = ('', '', '', 'HAHAHAHA!!')
    ans_vals = (1000,9999,100000,1000)
    ans_expl =  (
        '', 
        '',
        '',
        'Sir?'
    ) 
    return Challenge(prompt, choices, ans_vals, ans_expl)
Example #32
0
 def testChallengeComplete(self):
     my_challenge = Challenge()
     #TODO test real condition against activity challenge
     self.assertTrue(my_challenge.complete())