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


Python Board.reset方法代码示例

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


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

示例1: test_solution

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import reset [as 别名]
def test_solution(max_touchs=6, game=None):
    b = Board(game, max_touchs)
    max_iters = 8000
    done = False
    solutions = []
    while max_iters > 0:
        touchs = []
        b.reset()
        f = random.choice(evaluatorsList)
        for i in range(0, max_touchs):
            touch = solution.getTouch(b.clone(), f)
            if not touch:
                continue
            touchs.append(touch)
            score = b.touch(touch, False)
            if score == 0:
                break
                done = True
        max_iters -= 1
        solutions.append(Ret(f, touchs, score))
        if done:
            break

    best = min(solutions, key=lambda x: x.score)
    worst = max(solutions, key=lambda x: x.score)
    print "Best -> " + str(best)
    print "Worst -> " + str(worst)
    showSolution(b, best.touchs)
开发者ID:dougcunha,项目名称:BubbleBlasterSolver,代码行数:30,代码来源:test_solution.py

示例2: Game

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import reset [as 别名]
class Game(object):
    """
    This is the main game class. It provides an interactive CLI to the
    peg-jump game.
    """

    def __init__(self, stdin=sys.stdin, stdout=sys.stdout):
        self.stdout = stdout
        self.stdin = stdin
        self.board = Board(5)
        self.board.reset()
        self.width = 80
        self.i = 0

    def welcome(self):
        """
        Just a welcome message. Nothing special.
        """
        print >>self.stdout, "Welcome to Peg Jump.".center(self.width)
        print >>self.stdout, "====================".center(self.width)
        print >>self.stdout, self.board

    def get_valid_peg_position(self):
        """
        Gets a valid peg position. Raises an InputException if it
        doesn't understand or a QuitException if 'quit' is entered.
        """

        line = self.stdin.readline()
        if "quit" in line:
            raise QuitException
        try:
            (row_str, column_str) = line.split(",")
            row, column = int(row_str), int(column_str)
            if self.board.is_within_bounds(row, column):
                return row, column
            else:
                raise InputException('Sorry, "' + line.strip() + '" is outside my boundaries.')
        except ValueError:
            raise InputException('Sorry, I do not understand "' + line.strip() + '".')

    def get_peg_position(self, populated, prompt=None):
        """
        Wrapper for get_valid_peg_position, but knows about populated and
        unpopulated positions.
        """
        amount = populated and "no" or "a"
        try:
            print >>self.stdout, prompt,
            row, column = self.get_valid_peg_position()
            if self.board.is_vacant(row, column) == populated:
                raise Exception('Sorry, there is %s peg at "%d, %d".' % (amount, row, column))
            else:
                return row, column
        except InputException, ex:
            print >>self.stdout, ex
开发者ID:pombredanne,项目名称:peg_jump,代码行数:58,代码来源:game.py

示例3: test_reset

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import reset [as 别名]
    def test_reset(self):
        flat = "RNBQKBNRPPPPPPPP....................pp...........pppp..pprnbqkbnr"
        matrix = Board.to_matrix(flat)
        b = Board()
        b.set_config(matrix=matrix)

        b.reset()

        expected = Board.to_matrix(INITIAL_BOARD)
        result = b.matrix
        self.assertEqual(expected, result)
开发者ID:cathoderay,项目名称:chess,代码行数:13,代码来源:test_board.py

示例4: reset

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import reset [as 别名]
def reset():
    global turn,powerupenable,p1p,p2p,enable,connect
    enable = ''
    powerupenable = False
    turn = 0
    length = 0
    width = 0
    os.system('clear')
    print("choose a board size. minimum: 4, maximum 30")
    while length not in available:
        length = input("board length?  ")
    while width not in available:
        width = input("board width?  ")
    print("creating board size {} x {}".format(length, width))
    size = [int(length),int(width)]
    connect = Board(size)
    time.sleep(.75)
    connect.reset()
    p1p = int(connect.area/10)
    p2p = int(connect.area/10)
开发者ID:coconut750750,项目名称:Connect4,代码行数:22,代码来源:connect1.py

示例5: __init__

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import reset [as 别名]
class Player:

    def __init__(self, size=4):
        self._size = size
        self._board = Board(size)

    def reset(self):
        self._board.reset()

    def on_key_press(self, symbol, modifiers):
        mapper = {
            key.LEFT: (-1, 0),
            key.RIGHT: (1, 0),
            key.UP: (0, 1),
            key.DOWN: (0, -1)
        }
        if symbol in mapper.keys():
            delta = mapper[symbol]
            self._board.push_delta(delta)

    def draw(self):
        self._board.draw()
开发者ID:chongkong,项目名称:2048,代码行数:24,代码来源:player.py

示例6: __init__

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import reset [as 别名]

#.........这里部分代码省略.........
        accelerator='Ctrl+Y')
    edit_menu.add_command(label='Delete selected',
        command=self.board._delete_selected_items, accelerator='Delete')
    edit_menu.add_command(label='Rotate selected',
        command=self.board._rotate_selected_item, accelerator='r')
    edit_menu.add_command(label='Toggle cursor', command=self._toggle_cursor,
        accelerator='D')
    self._menu.add_cascade(label='Edit', menu=edit_menu)
    self._root.config(menu=self._menu)
  def _setup_shortcuts(self):
    """
    Adds basic shortcuts.
    """
    self.board.parent.bind('<Control-n>', lambda event: self._new_file())
    self.board.parent.bind('<Control-N>', lambda event: self._new_file())
    self.board.parent.bind('<Control-o>', lambda event: self._open_file())
    self.board.parent.bind('<Control-O>', lambda event: self._open_file())
    self.board.parent.bind('<Control-q>', lambda event: self.board.quit())
    self.board.parent.bind('<Control-Q>', lambda event: self.board.quit())
    self.board.parent.bind('<Control-s>', lambda event: self._save_file())
    self.board.parent.bind('<Control-S>', lambda event: self._save_file())
    self.board.parent.bind('<Control-y>', lambda event: self.board.redo())
    self.board.parent.bind('<Control-Y>', lambda event: self.board.redo())
    self.board.parent.bind('<Control-z>', lambda event: self.board.undo())
    self.board.parent.bind('<Control-Z>', lambda event: self.board.undo())
    self.board.add_key_binding('d', self._toggle_cursor)
  def _init_board(self):
    """
    (Re)Initializes the board based on this app's specific needs, as per
        self._on_init.
    """
    self.board.clear()
    self._on_init(self.board)
    self.board.reset()
  def _on_changed(self, board_changed):
    """
    Callback for when the board is changed. Updates the title of the app window
        to indicate whether we need to save the file.
    """
    self._root.title('%s (%s) %s %s' % (self._app_name, self._dev_stage,
        strip_file_name(self._file_name), '*' if board_changed else ''))
  def _save_as(self, file_name=None):
    """
    Saves the current state of the app with the given |file_name|.
    """
    saved_file_name = save_board(self.board, file_name, self._app_name,
        self._file_extension)
    if saved_file_name:
      self._file_name = saved_file_name
      self.board.set_changed(False)
  def _save_file(self):
    """
    Saves the current state of the app with its current file name (asks for a
        a file path if it currently does not have one).
    """
    self._save_as(self._file_name)
  def _request_save(self):
    """
    Requests for a file save if necessary. Returns True if there isn't anything
        to save or, in the case that there is something to save, if the user
        either decides to save the file (will be presented with a dialog to do
        so) or decides not to save the file. Returns False if the user cancels
        the request for save (i.e. does neither).
    """
    if self.board.changed():
      save = request_save_board()
开发者ID:Edward-Wei,项目名称:mit-courses,代码行数:70,代码来源:app_runner.py

示例7: Minesweeper

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import reset [as 别名]
class Minesweeper(object):
    """
    Main game application
    """
    def __init__(self, difficulty, use_ai, total_games):

        # read settings file
        with open('settings.yaml', 'r') as f:
            settings = yaml.load(f)            
            self.rows = settings[difficulty]["rows"]
            self.cols = settings[difficulty]["columns"]
            self.mines = settings[difficulty]["mines"]
            self.width = settings[difficulty]["width"]
            self.height = settings[difficulty]["height"]
            self.size = self.width, self.height
        
        # pygame setup
        self._running = True # used to stop game loop        
        self.screen = self.setup_screen()

        # scorekeeping
        self.start_time = time.time()
        self.time_elapsed = 0        
        self.score = 0
        self.lost_game = False
        self.won_game = False

        # game board setup        


        # AI / autoplay
        self.use_ai = use_ai        

        # create board and gui 
        self.board = Board(self.width, self.height, self.rows, self.cols, self.mines, self.screen, 36)    
        self.gui = Gui(self.board, self)

        # autoplay or enter event loop        
        if self.use_ai:
            self.autoplay(total_games)
        self.loop()



    def autoplay(self, times_to_play):
        """
        Automatically play minesweeper a certain number of times.        
        :param times_to_play: int
        """
        for i in range(times_to_play):
            print "\n### Playthrough", i

            # draw the starting board; also draws scores
            self.draw()

            # play 1 game

            solver.Solver.play_best_guess(self)            
            
            # reset board
            self.reset_game()


    def game_over(self):
        # unflag and reveal all cells
        for i in xrange(self.rows):
            for j in xrange(self.cols):
                self.board.cells[i][j].revealed = True


    def reset_game(self):
        # reset score and draw new board
        self.lost_game = False
        self.won_game = False
        self.score = 0
        self.start_time = time.time()
        self.time_elapsed = 0
        self.board.reset()
        self.draw()


    def flag_cell(self, i, j):
        """
        Flags cell and redraws board when user right-clicks or control-clicks cell
        :param i: cell row
        :param j: cell column
        """
        # do not flag revealed squares
        if not self.board.cells[i][j].revealed:
            if self.board.cells[i][j].flagged == True:
                self.board.cells[i][j].flagged = False
            else:
                self.board.cells[i][j].flagged = True
        if self.test_did_win():
            self.game_over()


    def reveal_cell(self, row, col):
        """
        Mark a cell as revealed and if it's not a mine 
#.........这里部分代码省略.........
开发者ID:ashleyrevlett,项目名称:minesweeper,代码行数:103,代码来源:minesweeper.py

示例8:

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import reset [as 别名]
 while True:
     screen.fill(BLACK)
     board.draw()
     for event in pygame.event.get():
         if event.type == pygame.QUIT:
             pygame.quit()
         if event.type == pygame.MOUSEBUTTONDOWN:
             row, line = pygame.mouse.get_pos()
             line //= 200
             row //= 200
             if board.check(row, line) == 'can be placed here':
                 if player == 1:
                     player = 2
                 elif player == 2:
                     player = 1
                 board.color(player, line, row)
                 moves -= 1
     if board.check_win(1) == 'win':
         screen.fill(BLUE)
         pygame.display.flip()
         pygame.time.wait(1000)
         board.reset()
     elif board.check_win(2) == 'win':
         screen.fill(GREEN)
         pygame.display.flip()
         pygame.time.wait(1000)
         board.reset()
     if moves == 0:
         moves = 9
         board.reset()
     pygame.display.flip()
开发者ID:Blake11,项目名称:X-si-0,代码行数:33,代码来源:main.py

示例9: Game

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import reset [as 别名]
class Game():
    def __init__(self):
        pygame.init()
        self.surface = pygame.display.set_mode(screen_size, DOUBLEBUF)
        pygame.display.set_caption('Tetris by wukat')
        self.startScreen = StartScreen(self.surface)
        self.gamestate = self.startScreen.loop()  # 1 - run, 0 - exit, -1 - pause
        self.overScreen = GameOverScreen(self.surface)
        self.board = Board(self.surface)  # games board
        
        self.quit = Button(self.surface, "QUIT", screen_size[0] - 60, screen_size[1] - 30, 25)
        self.pause = Button(self.surface, "PAUSE", screen_size[0] - 76, screen_size[1] - 65, 25)
        self.gameOverText = Text(self.surface, "GAME OVER", True, 70, WHITE, backgroundcolor, screen_size[0] // 2, screen_size[1] * 3 / 8)
        
        if self.gamestate == 1:  
            while self.loop():  # loop returns 1 - play again, 0 - quit
                pass
        self.game_exit()

    def game_exit(self):
        pygame.quit()
                 
    def loop(self):
        self.board.reset()  # initialization of everything 
        self.pause.draw()
        self.quit.draw()
        self.acttime = 0
        self.checktime = 0
        self.hideMouse()
        pygame.key.set_repeat(80, 80)
        
        while self.gamestate:  # main loop
            if not self.readEvents() and self.gamestate == 1:
                temp = pygame.time.get_ticks()  # get time
                if -(self.acttime - temp) > self.board.time:  # time
                    self.board.block.moveDown()
                    self.checktime = temp + 100
                    self.acttime = temp
                    
                if -(self.checktime - temp) > 150:  # time
                    self.checktime = temp
                    self.board.checkBlock()  # check if blocks lays

                self.board.draw()
                
                if self.board.isGameOver():  # when the game is over gameoverscreen runs
                    self.gameOverText.show()
                    pygame.display.update()
                    pygame.time.wait(1000)
                    self.overScreen.show(self.board.point)
                    return self.overScreen.loop()  # loop return 1 or 0 - restart or quit
        return 0
        
    def hideMouse(self):  # if mouse under the board, hide
        x, y = pygame.mouse.get_pos()
        if x >= 0 and x <= NCOLS * size + 5 and y >= 0 and y <= NROWS * size + 5:
            pygame.mouse.set_visible(False)
        else:
            pygame.mouse.set_visible(True)
            
    def readEvents(self):  # events
        flag = 0
        for event in pygame.event.get():
            if (event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE)) or (event.type == MOUSEBUTTONDOWN and self.quit.checkIfHover(pygame.mouse.get_pos())):
                self.gamestate = 0
                flag = 1
            elif (event.type == KEYDOWN and event.key == K_SPACE) or (event.type == MOUSEBUTTONDOWN and self.pause.checkIfHover(pygame.mouse.get_pos())):
                self.gamestate *= -1
                flag = 1
            elif (event.type == KEYDOWN and (event.key == K_w or event.key == K_UP)) and self.gamestate == 1:
                self.board.block.rotate()
                flag = 1
            elif (event.type == KEYDOWN and (event.key == K_s or event.key == K_DOWN)) and self.gamestate == 1:
                self.board.block.moveDown()
                flag = 1
            elif (event.type == KEYDOWN and (event.key == K_d or event.key == K_RIGHT)) and self.gamestate == 1:
                self.board.block.move(1, 0)
                flag = 1
            elif (event.type == KEYDOWN and (event.key == K_a or event.key == K_LEFT)) and self.gamestate == 1:
                self.board.block.move(-1, 0)
                flag = 1
            elif event.type == MOUSEMOTION:  # check if buttons are howered
                pos = pygame.mouse.get_pos()
                if self.quit.checkIfHover(pos):
                    self.quit.hover = 1
                else:
                    self.quit.hover = 0
                if self.pause.checkIfHover(pos):
                    self.pause.hover = 1
                else:
                    self.pause.hover = 0
                self.pause.drawBorder()
                self.quit.drawBorder()
                self.hideMouse()
        self.board.actualize(self.board.check())  # actualization of the game (check if any rows are full)
        if flag:
            self.checktime += 150
        return flag
开发者ID:wukat,项目名称:Tetris,代码行数:100,代码来源:game.py

示例10: len

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import reset [as 别名]
if len(sys.argv) > 1:
    depth = int(sys.argv[1])
    assert 0 < depth < 7


board = Board()
debugger = Debugger(board, quiet=True)


def parse_perftsuite():
    with open('test/perftsuite.epd', 'rb') as csvfile:
        reader = csv.reader(csvfile, delimiter=';')
        for row in reader:
            parsed = [c.strip() for c in row]
            fen, results = parsed[0], [r.split() for r in parsed[1:]]
            yield fen, {k: int(v) for k, v in results}


l = 0
for fen, results in parse_perftsuite():
    l += 1
    board.reset(fen)
    if not 'D%i' % depth in results: continue
    try:
        assert debugger.divide(depth) == results['D%i' % depth]
    except AssertionError as e:
        print "Error\n====="
        print l, fen
        import pdb; pdb.set_trace()

print "OK"
开发者ID:martinogden,项目名称:chessval,代码行数:33,代码来源:__main__.py


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