写了图片中一个类,脚本中声明对象没有报错,但是在console中声明时却报错类名不存在。很疑惑,望能解答,各位大佬补上代码:#!/usr/bin/envpython#-*-coding:utf-8-*-classOthelloSt...
写了图片中一个类,脚本中声明对象没有报错,但是在console中声明时却报错 类名不存在。很疑惑,望能解答,各位大佬
补上代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class OthelloState:
def __init__(self,sz = 8):
""" czhhbp: bulld game board,sz display the board size:sz*sz square
"""
self.playerJustMoved = 2 # At the root pretend the player just moved is p2 - p1 has the first move
self.board = [] # 0 = empty, 1 = player 1, 2 = player 2
self.size = sz
assert sz == int(sz) and sz % 2 == 0 # size must be integral and even
for y in range(sz):
self.board.append([0]*sz)
tmp=int(sz/2)
self.board[tmp][tmp] = self.board[tmp-1][tmp-1] = 1
self.board[tmp][tmp-1] = self.board[tmp-1][tmp] = 2
def Clone(self):
""" Create a deep clone of this game state.
"""
st = OthelloState()
# st.playerJustMoved = self.playerJustMoved
st.board = [self.board[i][:] for i in range(self.size)]
st.size = self.size
return st
b=OthelloState()
展开