当前位置: 首页>>代码示例>>Python>>正文


Python Solver.populate方法代码示例

本文整理汇总了Python中solver.Solver.populate方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.populate方法的具体用法?Python Solver.populate怎么用?Python Solver.populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在solver.Solver的用法示例。


在下文中一共展示了Solver.populate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import populate [as 别名]
def main():
    args = parse_args()
    f = open(args.puzzle)

    g = Grid()
    s = Solver(g)
    s.populate(puzzle_start_input(f.readlines()))
    print g
    s.solve()
    print g
开发者ID:dgkimura,项目名称:sudoku,代码行数:12,代码来源:sudoku.py

示例2: __init__

# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import populate [as 别名]
class Game:
    def __init__(self):
        # WINDOW SETUP
        self.window = pygame.Surface((GAME_WINDOW_WIDTH, GAME_WINDOW_HEIGHT))

        # SHADOW SETUP
        self.shadow_grid = [[Shadows(i, x) for x in range(GRID_HEIGHT)] for i in range(GRID_WIDTH)]

        # GRID SETUP
        self.populate_grid()  # fills in colors
        print "Drawing the grid"
        self.draw_grid()  # draws grey grid lines

    def draw_grid(self):
        for x in range(GRID_WIDTH):
            pygame.draw.line(self.window, COLOR_GREY, (x * TILESIZE_X, 0), (x * TILESIZE_X, GAME_WINDOW_HEIGHT))
        for y in range(GRID_HEIGHT):
            pygame.draw.line(self.window, COLOR_GREY, (0, y * TILESIZE_Y), (GAME_WINDOW_WIDTH, y * TILESIZE_Y))

    def populate_grid(self):
        """
        Draw grid squares to match grid created by solver
        """
        # SOLVER
        self.solver = Solver()
        self.solver.populate(self.solver.grid)
        for row in self.solver.grid:
            for item in row:
                square_surface = pygame.Surface((TILESIZE_X, TILESIZE_Y))
                contents_surface = pygame.Surface((TILESIZE_X / 2, TILESIZE_Y / 2))

                # print "Item", item # DEBUG
                # print "item x", item.x # DEBUG
                # print "item y", item.y # DEBUG

                element = self.solver.grid[item.x][item.y]
                element.shadow = self.shadow_grid[item.x][item.y]
                if element.is_lit:
                    element.shadow.darkness = LIGHT_MAX

                # print "Element", element # DEBUG

                if element.group == ELEMENT_WALL:
                    # Draw dark grey square
                    square_surface.fill(COLOR_DARK_GREY)
                    # print "wall element at", item.x, item.y # DEBUG
                elif element.group == ELEMENT_PATH:
                    # Draw light brown square (or nothing)
                    square_surface.fill(COLOR_LIGHT_BROWN)
                    # print "path element at", item.x, item.y # DEBUG
                    for i in element.contents:
                        if i.group == ELEMENT_START:
                            # Draw green square onto grid
                            contents_surface.fill(COLOR_GREEN)
                            # print "start element here" # DEBUG
                        elif i.group == ELEMENT_GOAL:
                            # Draw blue square onto grid
                            contents_surface.fill(COLOR_BLUE)
                            # print "goal element here" # DEBUG
                        elif i.group == ELEMENT_TREASURE:
                            # Draw gold square onto grid
                            contents_surface.fill(COLOR_GOLD)
                            # print "treasure element here" # DEBUG

                # Draw the contents onto the square
                square_surface.blit(contents_surface, (10, 10))

                # Draw the square onto the grid
                self.window.blit(square_surface, (item.x * TILESIZE_X, TILESIZE_Y * item.y))
        self.check_lighting()

    def draw(self, surface):
        """
        Draws the game window onto the specified surface
        """
        surface.blit(self.window, (GAME_WINDOW_ORIGIN_X, GAME_WINDOW_ORIGIN_Y))

    def check_lighting(self):
        print "Editing shadows"
        for row in self.solver.grid:
            for item in row:
                if item.is_lit:
                    if item.y > 0:
                        # print "editing north"
                        north = self.solver.grid[item.x][item.y - 1]
                        north.shadow.darkness = LIGHT_HI
                    if item.y < GRID_HEIGHT - 1:
                        # print "editing south"
                        south = self.solver.grid[item.x][item.y + 1]
                        south.shadow.darkness = LIGHT_HI
                    if item.x > 0:
                        # print "editing west"
                        west = self.solver.grid[item.x - 1][item.y]
                        west.shadow.darkness = LIGHT_HI
                    if item.x < GRID_WIDTH - 1:
                        # print "editing east"
                        east = self.solver.grid[item.x + 1][item.y]
                        east.shadow.darkness = LIGHT_HI

        self.update_shadows()
#.........这里部分代码省略.........
开发者ID:FOSSRIT,项目名称:pyCaveExplorer,代码行数:103,代码来源:game.py


注:本文中的solver.Solver.populate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。