在设计整个程序之前,先设计好数据结构:
数据结构根据用途划分:
临时步结构,用于存储程序计算出的临时的下棋位置
ji
class Step:
point = None
游戏状态类,用于记录围棋的状态
class GameStatus(object):
"""
记录游戏状态的类
ourColor:我方颜色
opponentColor:对方颜色
curColor: 当前执棋者的颜色
ourStep:我方下棋的步数
oppoentStep:对方下棋的步数
round:回合数
isGuessMode:设置是否为猜棋模式
komi:中国规则:黑胜0.5目,贴目:6.5目
koPoints:劫点的元组列表
blackCaptured: 黑棋被吃掉的棋子数目
whiteCaptured: 白棋被吃掉的棋子数目
recent: 最近一次行棋的坐标
"""
komi = 6.5
ourColor = Chess.EMPTY
opponentColor = Chess.EMPTY
curColor = Chess.EMPTY
ourStep = 0
opponentStep = 0
round = 0
isGuessMode = False
koPoint = (-1, -1)
koTimes = 0
blackCaputured = 0
whiteCaputured = 0
recent = tuple()
refused = False
guessNum = 5
@staticmethod
def resetGameStatus(gameStatus):
"""
复盘游戏状态专用方法
:param gameStatus:
:return:
"""
GameStatus.komi = gameStatus.komi
GameStatus.ourStep = gameStatus.ourStep
GameStatus.opponentStep = gameStatus.opponentStep
GameStatus.round = gameStatus.round
GameStatus.isGuessMode = gameStatus.isGuessMode
GameStatus.koTimes = gameStatus.koTimes
GameStatus.koPoint = gameStatus.koPoint
GameStatus.blackCaputured = gameStatus.blackCaputured
GameStatus.whiteCaputured = gameStatus.whiteCaputured
GameStatus.recent = gameStatus.recent
GameStatus.refused = gameStatus.refused
GameStatus.ourColor = gameStatus.ourColor
GameStatus.curColor = gameStatus.curColor
GameStatus.opponentColor = gameStatus.opponentColor
GameStatus.guessNum = gameStatus.guessNum
def reset(self, gameStatus):
self.ourStep = 0
self.opponentStep = 0
self.round = 0
self.isGuessMode = False
self.koTimes = 0
self.koPoint = (-1, -1)
self.blackCaputured = 0
self.whiteCaputured = 0
self.recent = tuple()
self.refused = False
self.guessNum = 3
def __init__(self):
self.komi = copy.copy(GameStatus.komi)
self.ourColor = copy.copy(GameStatus.ourColor)
self.opponentColor = copy.copy(GameStatus.opponentColor)
self.curColor = copy.copy(GameStatus