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 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_continue_unfinished_list(self): LIST_NAME = "i live in a giant bucket" word_list = WordList.objects.get(name=LIST_NAME) # Continue the list. table_id = self.wwg.initialize_by_saved_list( self.lex, self.user, word_list, SavedListForm.CONTINUE_LIST_CHOICE, 240) word_list = WordList.objects.get(name=LIST_NAME) self.assert_wl(word_list, { 'numAlphagrams': 11, 'numCurAlphagrams': 11, 'numFirstMissed': 0, 'numMissed': 3, 'goneThruOnce': False, 'questionIndex': 10, 'is_temporary': False, 'name': LIST_NAME }) # Start the quiz; we should only get one question. wwg = WordwallsGame() params = wwg.start_quiz(table_id, self.user) self.assertEqual(len(params['questions']), 1) self.assertEqual(params['questions'][0]['a'], 'AEIORSTU') # Miss it. gave_up = wwg.give_up(self.user, table_id) self.assertTrue(gave_up) word_list = WordList.objects.get(name=LIST_NAME) self.assert_wl(word_list, { 'numAlphagrams': 11, 'numCurAlphagrams': 11, 'numFirstMissed': 4, 'numMissed': 4, 'goneThruOnce': True, 'questionIndex': 15, 'is_temporary': False, 'name': LIST_NAME, }) self.assertEqual(set([0, 2, 3, 10]), set(json.loads(word_list.firstMissed)))
def test_continue_unfinished_list(self): LIST_NAME = "i live in a giant bucket" word_list = WordList.objects.get(name=LIST_NAME) # Continue the list. table_id = self.wwg.initialize_by_saved_list( self.lex, self.user, word_list, SavedListForm.CONTINUE_LIST_CHOICE, 240) word_list = WordList.objects.get(name=LIST_NAME) self.assert_wl(word_list, { 'numAlphagrams': 11, 'numCurAlphagrams': 11, 'numFirstMissed': 0, 'numMissed': 3, 'goneThruOnce': False, 'questionIndex': 10, 'is_temporary': False, 'name': LIST_NAME }) # Start the quiz; we should only get one question. wwg = WordwallsGame() params = wwg.start_quiz(table_id, self.user) self.assertEqual(len(params['questions']), 1) self.assertEqual(params['questions'][0]['a'], 'AEIORSTU') # Miss it. gave_up = wwg.give_up(self.user, table_id) self.assertTrue(gave_up) word_list = WordList.objects.get(name=LIST_NAME) self.assert_wl(word_list, { 'numAlphagrams': 11, 'numCurAlphagrams': 11, 'numFirstMissed': 4, 'numMissed': 4, 'goneThruOnce': True, 'questionIndex': 15, 'is_temporary': False, 'name': LIST_NAME, }) self.assertEqual(set([0, 2, 3, 10]), set(json.loads(word_list.firstMissed)))
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 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 test_continue_gonethru_list(self): LIST_NAME = 'list the sécond' word_list = WordList.objects.get(name=LIST_NAME) table_id = self.wwg.initialize_by_saved_list( self.lex, self.user, word_list, SavedListForm.CONTINUE_LIST_CHOICE, 240) self.assertNotEqual(table_id, 0) wwg = WordwallsGame() params = wwg.start_quiz(table_id, self.user) self.assertEqual(len(params['questions']), 1) self.assertEqual(params['questions'][0]['a'], 'ADEILORT') # Miss it. gave_up = wwg.give_up(self.user, table_id) self.assertTrue(gave_up) word_list = WordList.objects.get(name=LIST_NAME) self.assert_wl(word_list, { 'numAlphagrams': 11, 'numCurAlphagrams': 6, 'numFirstMissed': 6, 'numMissed': 1, 'goneThruOnce': True, 'questionIndex': 10, 'is_temporary': False, 'name': LIST_NAME })
def test_continue_gonethru_list(self): LIST_NAME = u'list the sécond' word_list = WordList.objects.get(name=LIST_NAME) table_id = self.wwg.initialize_by_saved_list( self.lex, self.user, word_list, SavedListForm.CONTINUE_LIST_CHOICE, 240) self.assertNotEqual(table_id, 0) wwg = WordwallsGame() params = wwg.start_quiz(table_id, self.user) self.assertEqual(len(params['questions']), 1) self.assertEqual(params['questions'][0]['a'], 'ADEILORT') # Miss it. gave_up = wwg.give_up(self.user, table_id) self.assertTrue(gave_up) word_list = WordList.objects.get(name=LIST_NAME) self.assert_wl(word_list, { 'numAlphagrams': 11, 'numCurAlphagrams': 6, 'numFirstMissed': 6, 'numMissed': 1, 'goneThruOnce': True, 'questionIndex': 10, 'is_temporary': False, 'name': LIST_NAME })
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 giveup(user, tableid, params): wwg = WordwallsGame() success = wwg.give_up(user, tableid) if success is not True: raise RPCError(success) return True