python的for语句中i未被定义_python 报错 类名没有被定义

写了图片中一个类,脚本中声明对象没有报错,但是在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()

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值