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


Python Board.check_win方法代码示例

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


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

示例1: min_val

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import check_win [as 别名]
		def min_val(board, node, y, z, score, depth):
			#initialize temporary board for checking the moves
			b_buf = Board()
			b_buf = board.copy_temp()
			m_buf = b_buf.empty_moves()

			all_val = [] #list of tuples: (succ, score)
			for succ in m_buf:
				b_buf.temp_move(y, succ)
				if b_buf.check_win(y):
					score = depth - 10
					val = (succ, score)
					all_val.append(val)
					b_buf.del_move(y,succ)
				elif b_buf.check_draw(y,z):					
					val =(succ, 0)
					all_val.append(val)
					b_buf.del_move(y,succ)
				else:
					depth = depth + 1
					buf = max_val(b_buf, succ, y, z, score, depth) #(succ, score)
					val = (succ, buf[1]) #succ : the next node, buf[1] : max score generated by max_val
					all_val.append(val)

			minscore = getminscore(all_val)

			return minscore #tuple with minimum score : (next node, minimum score)
开发者ID:jessicaprt,项目名称:c275,代码行数:29,代码来源:tictactoe.py

示例2: main

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import check_win [as 别名]
def main():
    board = Board()
    board.lastmove = 'x'
    turn = 'o'
    while not board.check_win(board.lastmove):
        board.display()
        got_move = False
        print("It's " + turn + "'s turn.")
        while not got_move:
            movex = raw_input("     Enter row number (0-2): ")
            movey = raw_input("  Enter column number (0-2): ")
            try:
                movex = int(movex)
                movey = int(movey)
                got_move = True
            except ValueError:
                got_move = False
        board.move(movex, movey, turn)
        if board.lastmove == 'o':
            turn = 'x'
        elif board.lastmove == 'x':
            turn = 'o'
        print('')
    # For posterity.
    board.display()
开发者ID:pontillo,项目名称:pytictactoe,代码行数:27,代码来源:loop.py

示例3: max_val

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import check_win [as 别名]
		def max_val(board, node, y, z, score, depth):
			b_buf = Board()
			b_buf = board.copy_temp()
			m_buf = b_buf.empty_moves()

			all_val = []
			for succ in m_buf:
				b_buf.temp_move(z, succ)
				if b_buf.check_win(z):
					score = 10-depth
					val = (succ, score)
					all_val.append(val)
					b_buf.del_move(z,succ)

				elif b_buf.check_draw(y,z):
					val = (succ, 0)
					all_val.append(val)
					b_buf.del_move(z,succ)

				else:
					depth = depth + 1
					buf = min_val(b_buf, succ, y, z, score, depth)
					val = (succ, buf[1])
					all_val.append(val)
					b_buf.del_move(z,succ)

			maxscore = getmaxscore(all_val)


			return maxscore
开发者ID:jessicaprt,项目名称:c275,代码行数:32,代码来源:tictactoe.py

示例4: test_check_win_no_win

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import check_win [as 别名]
 def test_check_win_no_win(self):
     # Arrange
     position = [0]*12
     board = Board(position, '', '')
     # Act
     win = board.check_win(board.position)
     # Assert
     self.assertEquals(False,win)
开发者ID:chaowarat,项目名称:zumo-game,代码行数:10,代码来源:test_board.py

示例5: test_check_win_p1_win

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import check_win [as 别名]
 def test_check_win_p1_win(self):
     # Arrange
     position = [0]*12
     board = Board(position, '', '')
     for i in range (0,len(board.position)):
     	board.position[i] = 1
     # Act
     win = board.check_win(board.position)
     # Assert
     self.assertEquals(1,win)
开发者ID:chaowarat,项目名称:zumo-game,代码行数:12,代码来源:test_board.py

示例6: tic_tac_toe

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import check_win [as 别名]
def  tic_tac_toe():
    pX = select_player(X)
    pO = select_player(O)

    board = Board()
    winner = None
    print board
    for player in itertools.cycle( (pX, pO) ):
        player.move(board)
        print board
        winner = board.check_win()
        if winner:
            break
    if winner == STALEMATE:
        print "Stale Mate"
        print "A curious game."
        print "The only way to win is not to play."
        print "How about a nice game of Global Thermonuclear Warfare?"
        print ""
    else:
        print "%s Wins!" % winner
开发者ID:mscout1,项目名称:Tic-Tac-Toe,代码行数:23,代码来源:tictactoe.py

示例7:

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import check_win [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

示例8: play_game

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import check_win [as 别名]
def play_game(game):
    """plays a game of tic tac toe with humans and/or AI"""

    # first game or a restart
    setPlayers = True
    # whether or not to list paths that can be reached
    paths = False

    donePlaying = False
    # loops through games until the user is done playing
    while not donePlaying:

        if setPlayers:
            setPlayers = False
            players = set_players()
            # whether paths will be shown or not
            if get_input("Do you want to show game path solutions? (Y)es or (N)o", ['Y', 'N']) == 'Y':
                paths = True

        # the game currently in play
        gameState = Board('         ', 1)
        gameState.paths = game[0][0].paths
        turnNum = 0

        # loops until the game is won
        while not gameState.check_win()[0] and gameState.what_turn() != 9:

            print gameState.make_board(paths)

            # gets the character for the current player
            if turnNum % 2 == 0:
                player = 'X'
            else:
                player = 'O'
            # human move
            if players[turnNum % 2] == 'H':
                move = human_turn(player, gameState)
            # AI controlled move
            else:
                move = ai_turn(gameState)
                raw_input("\nComputer player %s has made their move. Press enter to see it.\n" % player)

            # re-makes the board with new information
            gameState = Board(gameState[0:move] + player + gameState[move + 1:9])

            for layout in game[gameState.what_turn()]:
                if layout.matches(gameState):
                    gameState.pattern = layout.pattern

                    # won't continue if there are no paths to show
                    if len(layout.paths) == 9:

                        l = Board(layout, layout.pattern, layout.paths)

                        # goes through every possible rotation of the board to correctly set the paths
                        for rots in range(8):
                            if l.make_board(False) == gameState.make_board(False):
                                gameState.paths = l.paths
                                break

                            p = l.paths
                            # rotates the board and the paths
                            l = Board(l.rotate(), l.pattern, 
                                      [p[6], p[3], p[0], p[7], p[4], p[1], p[8], p[5], p[2]])
                            if rots == 3:
                                p = l.paths
                                # mirrors the board and the paths
                                l = Board(l.mirror(), l.pattern, 
                                          [p[2], p[1], p[0], p[5], p[4], p[3], p[8], p[7], p[6]])

            turnNum += 1

        # prints the winning or tied board
        print gameState.make_board(showWin = True)

        again = get_input("\n(R)ematch, (C)hange players / toggle paths display, or go (B)ack?", 'R C B'.split())
        if again == 'B':
            donePlaying = True
        elif again == 'C':
            setPlayers = True
开发者ID:nikkisquared,项目名称:tic-tac-toe-analyzer,代码行数:82,代码来源:game.py


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