Python - Me lanza error en mi funcion que debe retornar una isntancia de clase...AYUDA

 
Vista:

Me lanza error en mi funcion que debe retornar una isntancia de clase...AYUDA

Publicado por Minimax 3 en raya en tablero 4x4 (2 intervenciones) el 25/04/2018 00:25:04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
class AiMove:
	def __init__(self):
		self.x = -1
		self.y=-1
		self.score = 0
 
 
def Imprimir(Matriz,n):
	for i in range(n):
		linea ="|"
		for j in range(n):
			if (Matriz[i][j] == 0):
				linea+=" "
			elif (Matriz[i][j]==- 1):
				linea+="X"
			elif (Matriz[i][j]== 1):
				linea+="O"
			linea+="|"
		print linea
 
		print "---------"
 
def Gameover(Matriz,n):
	#Condicion tablero lleno
	blancos=0;
	for i in range(n):
		contJfilas = 0
		contCfilas = 0
		contJcol = 0
		contCcol = 0
		for j in range(n):
			if(Matriz[i][j]==0):
				blancos = blancos + 1
			if (Matriz[i][j]==1):
				contCfilas= contCfilas+1
			elif(Matriz[i][j]==-1):
				contJfilas = contJfilas +1
			if (Matriz[j][i]==1):
				contCcol= contCcol +1
			elif (Matriz[j][i]==-1):
				contJcol= contJcol +1
		#Condicion 3 en raya en fila o 3 en raya columna
		if (contJcol==3 or contJfilas ==3):
			return -1
		elif (contCfilas==3 or contCcol ==3):
			return 1
	if blancos == 16:
		return 2
	else:
		return 0
 
def getMejorM(Matriz, player,n):
	rv = Gameover(Matriz,n)
	if(rv== 1):
		a = AiMove()
		a.score = 10
		return a
	elif rv==-1:
		a = AiMove()
		a.score = -10
		return a
 
	elif rv ==2: #Si es empate
		a = AiMove()
		return a
 
	movimientos = []
	for i in range (n):
		for j in range (n):
			if(Matriz[i][j] == 0):
				movimiento = AiMove()
				movimiento.x = i
				movimiento.y = j
				Matriz[i][j] = player
				if (player == 1):
					movimiento.score = getMejorM(Matriz, -1,n).score
				else:
					movimiento.score = getMejorM(Matriz, 1,n).score
				movimientos.append(movimiento)
				Matriz[i][j] = 0
 
	#Escoger
	auxb = 0
	if player==1:
		mejorscore = -100000
		for i in range (len(movimientos)):
			if movimientos[i].score > mejorscore:
				auxb= i
				mejorscore = movimientos[i].score
 
	elif player==-1:
		peorscore = 100000
		for i in range (len(movimientos)):
			if movimientos[i].score < peorscore:
				auxb= i
				peorscore = movimientos[i].score
 
	#Retornar el mejor movimiento
	return movimientos[auxb]
 
 
 
n=4
Matriz = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	for j in range(n):
		Matriz[i][j] = 0
Imprimir(Matriz,n)
while True:
	fila = int(raw_input("Ingresa casilla x: "))-1
	columna = int(raw_input("Ingresa casilla y: "))-1
	if (Matriz[fila][columna] == 0):
		Matriz[fila][columna] = -1
	#Mover(Matriz,n)
	Imprimir(Matriz,n)
	bestM = AiMove()
	bestM = getMejorM(Matriz, 1, n)
	Matriz[bestM.x][bestM.y] = 1
	Imprimir(Matriz,n)
	if Gameover(Matriz,n) != 0:
		break
 
 
print "FIN"
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder