def round_1(self): table_id, user = self.setup_quiz(p_min=5, p_max=15, length=8) wwg = WordwallsGame() # Let's guess some of the words from the 5-15 range words_to_guess = [ 'ABCDEFGH', # miss AEROLITE 'IDOLATER', # miss TAILORED 'OUTRAISE', 'SAUTOIRE', 'ALIENORS', 'AILERONS', '', # miss ANEROIDS/ANODISER 'SEDATION', # miss ASTONIED 'DELATION', '', # miss all of the AEILNOST words. 'ASTEROID', 'ELATERIN', # miss ENTAILER and TREENAIL 'DETAINER', 'RETAINED' ] # Guess all the words 3 times. (5, 5 and 1) for i in range(3): params = wwg.start_quiz(table_id, user) if i != 2: self.assertEqual(len(params['questions']), 5) else: self.assertEqual(len(params['questions']), 1) for w in words_to_guess: wwg.guess(w, table_id, user) wwg.give_up(user, table_id) return table_id, user
def test_quiz_ends_after_time(self, timer_ran_out): # Mock timer running out by the time the guess comes in. timer_ran_out.return_value = True table_id, user = self.setup_quiz() wwg = WordwallsGame() wwg.start_quiz(table_id, user) guess_state = wwg.guess('CATS', table_id, user) self.assertFalse(guess_state['going']) self.assertEqual(guess_state['alphagram'], '') wgm = wwg.get_wgm(table_id) state = json.loads(wgm.currentGameState) self.assertFalse(state['quizGoing'])
def test_quiz_params_correct(self): table_id, user = self.setup_quiz() wwg = WordwallsGame() params = wwg.start_quiz(table_id, user) self.assertEqual(len(params['questions']), 50) self.assertEqual(params['time'], 240) self.assertEqual(params['gameType'], 'regular') self.assertEqual(params['serverMsg'], 'These are questions 1 through 50 of 81.') guess_state = wwg.guess('CATS', table_id, user) self.assertTrue(guess_state['going']) self.assertEqual(guess_state['alphagram'], '')
def round_2(self, table_id, user): wwg = WordwallsGame() words_to_guess = [ 'AEROLITE', 'IDOLATER', 'TAILORED', '', # miss ANEROIDS again 'ASTONIED', 'SEDATION', 'ELATIONS', 'INSOLATE', 'TOENAILS', 'ELATERIN', 'ENTAILER' # miss TREENAIL ] # Guess all the words 2 times. (5, 5 and 1) for i in range(2): params = wwg.start_quiz(table_id, user) logger.debug('params %s', params) if i == 0: self.assertEqual(len(params['questions']), 5) else: self.assertEqual(len(params['questions']), 1) for w in words_to_guess: wwg.guess(w, table_id, user) wwg.give_up(user, table_id)
def guess(user, tableid, params): g = params['guess'] wrong_answers = params.get('wrongAnswers', 0) wwg = WordwallsGame() state = wwg.guess(g.strip(), tableid, user, wrong_answers=wrong_answers) if state is None: raise RPCError('Quiz is already over.') game_packet = { 'g': state['going'], 'C': state['alphagram'], 'w': state['word'], 'a': state['already_solved'], 's': state['solver'] } # If this is a multiplayer game, should broadcast to group. # if wwg.is_multiplayer(tableid): # broadcast_to_table(tableid, BroadcastTypes.GUESS_RESPONSE, game_packet) return game_packet
def table(request, id): if request.method == 'POST': action = request.POST['action'] logger.debug(u'user=%s, action=%s, table=%s', request.user, action, id) if action == "start": return start_game(request, id) elif action == "guess": logger.debug(u'guess=%s', request.POST['guess']) wwg = WordwallsGame() state = wwg.guess(request.POST['guess'].strip(), id, request.user) if state is None: return response(_('Quiz is already over.'), status=StatusCode.BAD_REQUEST) logger.debug(u'table=%s Returning %s', id, state) return response({'g': state['going'], 'C': state['alphagram'], 'w': state['word'], 'a': state['already_solved']}) elif action == "gameEnded": wwg = WordwallsGame() ret = wwg.check_game_ended(id) # 'going' is the opposite of 'game ended' return response({'g': not ret}) elif action == "giveUp": wwg = WordwallsGame() ret = wwg.give_up(request.user, id) return response({'g': not ret}) elif action == "save": wwg = WordwallsGame() ret = wwg.save(request.user, id, request.POST['listname']) return response(ret) elif action == "giveUpAndSave": wwg = WordwallsGame() ret = wwg.give_up_and_save(request.user, id, request.POST['listname']) # this shouldn't return a response, because it's not going to be # caught by the javascript logger.debug("Give up and saving returned: %s" % ret) return response(ret) elif action == "savePrefs": profile = request.user.aerolithprofile profile.customWordwallsStyle = request.POST['prefs'] profile.save() return response({'success': True}) elif action == "getDcData": wwg = WordwallsGame() dcId = wwg.get_dc_id(id) if dcId > 0: leaderboardData = getLeaderboardDataDcInstance( DailyChallenge.objects.get(pk=dcId)) return response(leaderboardData) else: return response({'success': False}, status=StatusCode.BAD_REQUEST) else: # it's a GET wwg = WordwallsGame() permitted = wwg.permit(request.user, id) if gargoyle.is_active('disable_games', request): permitted = False if not permitted: return render(request, 'wordwalls/notPermitted.html', {'tablenum': id}) params = wwg.get_add_params(id) # Add styling params from user's profile (for styling table # tiles, backgrounds, etc) profile = request.user.aerolithprofile style = profile.customWordwallsStyle if style != "": params['style'] = style return render(request, 'wordwalls/table.html', {'tablenum': id, 'username': request.user.username, 'addParams': json.dumps(params), 'avatarUrl': profile.avatarUrl, 'CURRENT_VERSION': CURRENT_VERSION, 'lexicon': wwg.get_wgm(id).lexicon })
def round_3(self, table_id, user): wwg = WordwallsGame() params = wwg.start_quiz(table_id, user) self.assertEqual(len(params['questions']), 2) for w in ['ANEROIDS', 'ANODISER', 'ELATERIN', 'ENTAILER', 'TREENAIL']: wwg.guess(w, table_id, user)
def table(request, id): logger.info("request: %s", request.method) if request.method == 'POST': action = request.POST['action'] logger.info('action %s', action) if action == "start": return start_game(request, id) elif action == "guess": logger.info('%s: guess %s, table %s', request.user.username, request.POST['guess'], id) wwg = WordwallsGame() state = wwg.guess(request.POST['guess'].strip(), id, request.user) return response({'g': state[0], 'C': state[1]}) elif action == "gameEnded": wwg = WordwallsGame() ret = wwg.checkGameEnded(id) # 'going' is the opposite of 'game ended' return response({'g': not ret}) elif action == "giveUp": wwg = WordwallsGame() ret = wwg.giveUp(request.user, id) return response({'g': not ret}) elif action == "save": wwg = WordwallsGame() ret = wwg.save(request.user, id, request.POST['listname']) return response(ret) elif action == "giveUpAndSave": wwg = WordwallsGame() ret = wwg.giveUpAndSave(request.user, id, request.POST['listname']) # this shouldn't return a response, because it's not going to be # caught by the javascript logger.debug("Give up and saving returned: %s" % ret) return response(ret) elif action == "savePrefs": profile = request.user.get_profile() profile.customWordwallsStyle = request.POST['prefs'] profile.save() return response({'success': True}) elif action == "getDcData": wwg = WordwallsGame() dcId = wwg.getDcId(id) if dcId > 0: leaderboardData = getLeaderboardDataDcInstance( DailyChallenge.objects.get(pk=dcId)) return response(leaderboardData) else: # it's a GET wwg = WordwallsGame() permitted = wwg.permit(request.user, id) if gargoyle.is_active('disable_games', request): permitted = False if permitted: params = wwg.getAddParams(id) # Add styling params from user's profile (for styling table # tiles, backgrounds, etc) try: profile = request.user.get_profile() style = profile.customWordwallsStyle if style != "": params['style'] = style except: pass return render( request, 'wordwalls/table.html', { 'tablenum': id, 'username': request.user.username, 'addParams': json.dumps(params), 'avatarUrl': profile.avatarUrl, 'CURRENT_VERSION': CURRENT_VERSION }) else: return render(request, 'wordwalls/notPermitted.html', {'tablenum': id})
def table(request, id): logger.info("request: %s", request.method) if request.method == 'POST': action = request.POST['action'] logger.info('action %s', action) if action == "start": return start_game(request, id) elif action == "guess": logger.info('%s: guess %s, table %s', request.user.username, request.POST['guess'], id) wwg = WordwallsGame() state = wwg.guess(request.POST['guess'].strip(), id, request.user) return response({'g': state[0], 'C': state[1]}) elif action == "gameEnded": wwg = WordwallsGame() ret = wwg.checkGameEnded(id) # 'going' is the opposite of 'game ended' return response({'g': not ret}) elif action == "giveUp": wwg = WordwallsGame() ret = wwg.giveUp(request.user, id) return response({'g': not ret}) elif action == "save": wwg = WordwallsGame() ret = wwg.save(request.user, id, request.POST['listname']) return response(ret) elif action == "giveUpAndSave": wwg = WordwallsGame() ret = wwg.giveUpAndSave(request.user, id, request.POST['listname']) # this shouldn't return a response, because it's not going to be # caught by the javascript logger.debug("Give up and saving returned: %s" % ret) return response(ret) elif action == "savePrefs": profile = request.user.get_profile() profile.customWordwallsStyle = request.POST['prefs'] profile.save() return response({'success': True}) elif action == "getDcData": wwg = WordwallsGame() dcId = wwg.getDcId(id) if dcId > 0: leaderboardData = getLeaderboardDataDcInstance( DailyChallenge.objects.get(pk=dcId)) return response(leaderboardData) else: # it's a GET wwg = WordwallsGame() permitted = wwg.permit(request.user, id) if gargoyle.is_active('disable_games', request): permitted = False if permitted: params = wwg.getAddParams(id) # Add styling params from user's profile (for styling table # tiles, backgrounds, etc) try: profile = request.user.get_profile() style = profile.customWordwallsStyle if style != "": params['style'] = style except: pass return render_to_response('wordwalls/table.html', {'tablenum': id, 'username': request.user.username, 'addParams': json.dumps(params), 'avatarUrl': profile.avatarUrl, 'CURRENT_VERSION': CURRENT_VERSION }, context_instance=RequestContext(request)) else: return render_to_response('wordwalls/notPermitted.html', {'tablenum': id}, context_instance=RequestContext(request))