Beispiel #1
0
 def make_saved_game_model (self):
     # Description, Image, Last-Access time (for sorting), Puzzle (jar)
     self.saved_game_model = gtk.ListStore(str, gtk.gdk.Pixbuf, int, gobject.TYPE_PYOBJECT)
     for g in self.saved_games:
         game = g['game'].split('\n')[0]
         grid = sudoku.sudoku_grid_from_string(game)
         sr = sudoku.SudokuRater(grid.grid)
         sdifficulty = sr.difficulty()
         lastPlayedText = _("Last Played %(timeAgo)s") % {'timeAgo': format_friendly_date(g['saved_at'])}
         levelText =  _("%(level)s puzzle") % {'level': sdifficulty.value_string()}
         durationText = _("Played for %(duration)s") % {
                 'duration': format_time(g['timer.active_time'], round_at = 15, friendly = True)}
         desc = "<b><i>%s</i></b>\n<span size='small'><i>%s</i>\n<i>%s.</i></span>" % (
             levelText,
             lastPlayedText,
             durationText,
             )
         self.saved_game_model.append((
             desc,
             sudoku_thumber.make_pixbuf(grid.grid,
                                        sudoku.sudoku_grid_from_string(g['game'].split('\n')[1].replace(' ', '')).grid,
                                        color_from_difficulty(sdifficulty.value)
                                        ),
             g['saved_at'],
             g
             ))
Beispiel #2
0
def generateSolutions(page, puzzles, showFooter=True):
    col = row = 0
    i = 0
    for puz, d in puzzles:
        i += 1
        page.setFont('Times-Bold', 8)
        page.drawString(
            36 + col * 72 * 2.5, PAGE_HEIGHT - 72 - row * 72 * 2.5 + 6,
            "Puzzle %d (%s, difficulty rating %.02f)" %
            (i, d.value_string(), d.value))
        solver = sudoku.SudokuRater(puz.grid,
                                    verbose=False,
                                    group_size=puz.group_size)
        solver.solve()
        renderPuzzle(page,
                     solver,
                     PAGE_HEIGHT - 72 - row * 72 * 2.5,
                     36 + col * 72 * 2.5,
                     72 * 2,
                     fontSize=10,
                     thickLine=2)
        col += 1
        if col == 3:
            col = 0
            row += 1
            if row == 4:
                col = row = 0
                if showFooter:
                    generateFooter(page)
                page.showPage()
    if showFooter:
        generateFooter(page)
    def is_unique (self, sudoku_grid):
        """If puzzle is unique, return its difficulty.

        Otherwise, return None."""
        solver = sudoku.SudokuRater(sudoku_grid,verbose=False,group_size=self.group_size)
        if solver.has_unique_solution():
            return solver.difficulty()
        else:
            return None
 def assess_difficulty (self, sudoku_grid):
     solver = None
     try:
         solver = sudoku.SudokuRater(sudoku_grid,verbose=False,group_size=self.group_size)
         d = solver.difficulty()
         self.rated_puzzles.append((sudoku_grid,d))
         return d
     except:
         print 'Impossible!'
         print 'Puzzle was:'
         if solver:
             print solver.virgin
         print 'Solution: ',
         print self.start_grid
         print 'Puzzle foobared in following state:',
         if solver:
             print solver
         raise
 def get_difficulty (self, game):
     if not self.sudoku_maker.all_puzzles.has_key(game):
         self.sudoku_maker.all_puzzles[game]=sudoku.SudokuRater(game).difficulty()
     return self.sudoku_maker.all_puzzles[game]