public static void write_kec(String filename, KarelKECEnvironment kke) throws IOException, KarelException { BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(filename)); KarelKECEnvironment.KECTokenType token[] = KarelKECEnvironment.KECTokenType.values(); // Check all tokens for (int i = 0; i < 10; i++) { if (kke.get(token[i]).p1 != 0 && kke.get(token[i]).p1 != 1) throw new KarelException("El formato de las condiciones es incorrecto"); } if (kke.is_set(token[8]) && (kke.get(token[8]).p1 < 0 || kke.get(token[8]).p1 > 3)) // Karel orientation throw new KarelException("El formato de las condiciones es incorrecto"); if (kke.is_set(token[9]) && kke.get(token[9]).p2 != kke.beeper.length) // Beepers on the world throw new KarelException("El formato de las condiciones es incorrecto"); // No basic problemas for (int i = 0; i < 10; i++) KarelWorldManager.KarelMDOToken.write_token(kke.get(token[i]), bout); for (int i = 0, n = kke.get(token[9]).p2; i < n; i++) KarelWorldManager.KarelMDOToken.write_token(kke.beeper[i], bout); bout.close(); }