Esempio n. 1
0
    def testBestCrossword(self, num_test):
        print('Running testBestCrossword()...')
        print('Randomly picking 6 - 10 words...')
        print('Generating crossword', num_test, 'times...')
        count_times, count_fewwords, count_allplaced = 0, 0, 0
        MIN_WORD_NUM = 5  # 一个填词游戏中最少几个词
        myGame = gameSystem(self.WORD_DICT)
        start_time = time.time()
        for i in range(num_test):
            num_word = choice(range(6, 11))
            wordList = myGame.getWordListFromAllWithInfo(num_word)
            cw = myGame.getBestCrossword(wordList)  # 根据要求生成较优的填词游戏

            # 循环直到生成符合要求的填词游戏
            okay = False
            while not okay:
                if cw.placed.__len__() >= MIN_WORD_NUM:
                    okay = True
                else:
                    wordList = myGame.getWordListFromAllWithInfo(num_word)
                    cw = myGame.getBestCrossword(wordList)

            if not cw.crossword:
                print('生成失败!')
            elif cw.crossword and cw.placed.__len__() < MIN_WORD_NUM:
                print('单词少于', str(MIN_WORD_NUM), '个!')
                count_fewwords += 1
            else:
                count_times += 1
                if cw.placed.__len__() == num_word:
                    count_allplaced += 1

        print(count_times, 'test passed! Time lapsed:', time.time() - start_time)
        print(count_fewwords, 'crosswords have less than', MIN_WORD_NUM, 'words')
        print(count_allplaced, 'crosswords placed all words in the list')
Esempio n. 2
0
    def checkAnswer(self):
        '''
        检查并显示答案,更新单词测试的历史正确率
        '''
        if self.testMode: print('检查答案!')
        cw_height = self.cw.nRow
        cw_width = self.cw.nCol
        self.checkAns.setEnabled(False)

        for i_row in range(cw_height):
            for i_col in range(cw_width):
                # 逐个生成格子
                if self.textbox_map[i_row][i_col]:
                    word_id = self.textbox_map[i_row][i_col][0]
                    i = self.textbox_map[i_row][i_col][1]
                    ans = self.cw.crossword[i_row][i_col]
                    usr_input = self.textbox[word_id][i].text()
                    self.textbox[word_id][i].setStyleSheet("color:black; ")
                    if usr_input.upper() != ans.upper():
                        for word in self.textbox_map[i_row][i_col][2]:
                            self.wordAccuracy[word] = False
                        self.textbox[word_id][i].setStyleSheet(
                            "border: 0.5px solid %s; "
                            "color:red; "
                            "background-color:rgba(255,225,225);" %
                            self.tbEdgeColor)

                    self.textbox[word_id][i].setText(
                        self.cw.crossword[i_row][i_col])
                    self.textbox[word_id][i].setEnabled(False)

        myGame = gameSystem(self.WORD_DICT)
        myGame.updateGameHist(self.wordAccuracy)
Esempio n. 3
0
 def game_window(self):
     self.myGame = gameSystem(self.WORD_DICT)
     cw = self.myGame.createGameFromStudy(self.WORD_DICT, self.errorWin)
     self.ui_game = gameWindow()
     self.ui_game.initUI(cw, self.WORD_DICT, self.errorWin)
     self.ui_game.setStyleSheet("#MainWindow{border-image:url(bak1.jpg)}")
     # self.ui_game.setWindowFlag(QtCore.Qt.FramelessWindowHint)  # 隐藏边框
     self.ui_game.show()
     pass
Esempio n. 4
0
 def getNextGame(self):
     '''
     加载下一轮游戏
     '''
     self.clearAll()
     myGame = gameSystem(self.WORD_DICT)
     cw = myGame.createGameFromStudy(self.WORD_DICT, self.errorWin)
     # cw = createGameFromAllWord()
     self.cw = cw
     self.close()
     self.initUI(cw, self.WORD_DICT, self.errorWin)
     self.show()
Esempio n. 5
0
    def testGenerateCrossword(self, num_word):
        print('Running testGenerateCrossword()...')

        myGame = gameSystem(self.WORD_DICT)
        start_time = time.time()
        wordList = myGame.getWordListFromAllWithInfo(num_word)

        cw = MyCrossword()
        cw.generateCrossword(wordList)
        cw.display()

        print('Crossword generated!')
        if cw.crossword:
            print('Test passed! Time lapsed:', time.time() - start_time)