def AnalizadorCodigo(self): """Analizador del código Analiza el código para llevar a cabo los comandos Parameter --------- None Returns ------- Nothing """ self.SourceFile = Reader.openFile(self.SourceCode) line = Reader.readLine(self.SourceFile) if (line != 'ARGENTOS\n'): print "\n\nMal pibe, no hiciste bien la apertura del archivo. Ponele ARGENTOS en el primer renglón" exit else: line = Reader.readLine(self.SourceFile) while (line != "ARGENTOS\n"): line = string.split(line, "%")[0] line = string.split(string.split(line, "\n")[0], " ") #line = string.split(string.split(Reader.readLine(self.SourceFile), "\n")[0], " ") i = 0 while i < len(line): #Verifico si viene un comando de cambio de posición del caballo if line[i] == "argento": y = list(line[i + 1])[0] x = list(line[i + 1])[1] #Verifico si es legal el movimiento del caballo if self.caballo.isCorrectMove(y, x) == -1: print "\n\nError Chabon: Moviste mal el caballo \n\n" exit(-1) #El movimiento del caballo es ok, por lo tanto continúo self.caballo.mover(y, x) i = i + 2 #Aumento el índice if (y == 't' and x == 'a'): #Ingreso al campo de caracteres self.estado = 1 elif (line[i] == 'ge' and self.geFin == 0): #Se necesita imprimir line = Reader.readLine(self.SourceFile) line = string.split(line, "%")[0] line = string.split(string.split(line, "\n")[0], " ") while (line[0] != 'ge'): j = 0 while j < len(line): #Me encuentro en el campo principal if line[0] == '' and len(line) == 1: line = Reader.readLine(self.SourceFile) line = string.split(line, "%")[0] line = string.split( string.split(line, "\n")[0], " ") if self.estado == 0: if line[j] == "argento": y = list(line[j + 1])[0] x = list(line[j + 1])[1] #Verifico si es legal el movimiento del caballo if self.caballo.isCorrectMove(y, x) == -1: print "\n\nError Chabon: Moviste mal el caballo \n\n" exit(-1) #El movimiento del caballo es ok, por lo tanto continúo self.caballo.mover(y, x) j = j + 2 #Aumento el índice if (line[j] == "aaa"): y = list(line[j - 1])[0] x = list(line[j - 1])[1] if (y == 'T' and x == 'A'): #Ingreso al campo de caracteres self.estado = 1 if (y == 'N' and x == 'A'): self.sParaMostrarEnPantallita += ' ' break #Me encuentro en el campo de caracteres elif self.estado == 1: if line[j] == "argento": y = list(line[j + 1])[0] x = list(line[j + 1])[1] #Verifico si es legal el movimiento del caballo if self.caballo.isCorrectMove(y, x) == -1: print "\n\nError Chabon: Moviste mal el caballo \n\n" exit(-1) #El movimiento del caballo es ok, por lo tanto continúo self.caballo.mover(y, x) j = j + 2 #Aumento el índice elif (line[j] == "aaa"): y = list(line[j - 1])[0] x = list(line[j - 1])[1] #Aquí leo en el campo de caracteres self.sParaMostrarEnPantallita += self.cCaracter.DameCaracter( y, x, self.caballo) j += 1 elif (line[j] == "oo"): self.estado = 0 break elif (line[j] != "argento" and line[j] != "aaa" and line[j] != "oo"): j += 1 line = Reader.readLine(self.SourceFile) line = string.split(line, "%")[0] line = string.split( string.split(line, "\n")[0], " ") #Para dar por finalizado el printeo if (line[0] == 'ge'): print self.sParaMostrarEnPantallita self.sParaMostrarEnPantallita = "" self.geFin = 1 j += 1 i += 1 line = Reader.readLine(self.SourceFile)