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


Python State.check方法代码示例

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


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

示例1: __init__

# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import check [as 别名]
class Game:
    def __init__(self):
        self.gameState = State(0)
        self.gameUI = GameUI(300, 300)

    def run(self, mode):
        turn = 0
        while True:
            if turn == 0:
                if mode == Mode.TwoPlayers:
                    pos = self.gameUI.GetMousePos()
                elif mode == Mode.OnePlayerFirst:
                    pos = self.gameUI.GetMousePos()
                else:
                    self.gameState.curPlayer = turn
                    pos = MiniMax.GetPosition(self.gameState)
                if pos != None:
                    pos_val = pos[0] * 3 + pos[1]
                    actionStat = self.gameState.takeAction(turn, pos_val)
                    if actionStat:
                        turn = 1
                        self.gameUI.drawO(pos)
                        if self.gameState.check() != '?':
                            break
            else:
                if mode == Mode.TwoPlayers:
                    pos = self.gameUI.GetMousePos()
                elif mode == Mode.OnePlayerFirst:
                    self.gameState.curPlayer = turn
                    pos = MiniMax.GetPosition(self.gameState)
                else:
                    pos = self.gameUI.GetMousePos()
                if pos != None:
                    pos_val = pos[0] * 3 + pos[1]
                    actionStat = self.gameState.takeAction(turn, pos_val)
                    if actionStat:
                        turn = 0
                        self.gameUI.drawX(pos)
                        if self.gameState.check() != '?':
                            break

        if self.gameState.check() == '1':
            print("Player 1 win!")
            while True:
                pass
        elif self.gameState.check() == '0':
            print("Player 0 win!")
            while True:
                pass
        else:
            print("draw!")
            while True:
                pass
开发者ID:cyj907,项目名称:TicTacToe,代码行数:55,代码来源:Game.py


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