def gen_seq(self,status,turn): #根据状态和turn来产生序列 import copy if turn not in (1,2): return None tmp={} tmp[1]=copy.deepcopy(status) tmp[2]=copy.deepcopy(status) #if turn=1 则 tmp2全颠倒1和2, 否则tmp1颠倒. 暂时只有开始状态,所以不用处理 op=Optimal() seq=[] while self.check(tmp[turn]): next=op.optimal(tmp[turn]) if not next: break #没的下了也结束 seq.append(next) tmp[turn][next[0]][next[1]] = 1 #表示走了一步棋 tmp[3-turn][next[0]][next[1]] = 2 #对方看起来的效果 3-turn表示另一家 turn = 3-turn #换边 return seq
def test_optimal(): op= Optimal() status=[[1, 0, 1], [0, 0, 2], [0, 0, 0]] print op.optimal(status) return op.optimal(status)