@@ -227,6 +227,7 @@ public Nar() throws IOException, InstantiationException, InvocationTargetExcepti
227
227
* Reset the system with an empty memory and reset clock. Called locally.
228
228
*/
229
229
public void reset () {
230
+ cycle = (long ) 0 ;
230
231
memory .reset ();
231
232
}
232
233
@@ -380,12 +381,31 @@ public void addInputFile(final String s) {
380
381
String line ;
381
382
while ((line = br .readLine ()) != null ) {
382
383
if (!line .isEmpty ()) {
383
- this .addInput (line );
384
+ //Loading experience file lines, or else just normal input lines
385
+ if (line .matches ("([A-Za-z])+:(.*)" )) {
386
+ //Extract creation time:
387
+ if (!line .startsWith ("IN:" )) {
388
+ continue ; //ignore
389
+ }
390
+ String [] spl = line .replace ("IN:" , "" ).split ("\\ {" );
391
+ int creationTime = Integer .parseInt (spl [spl .length -1 ].split (" :" )[0 ].split ("\\ |" )[0 ]);
392
+ while (this .time () < creationTime ) {
393
+ this .cycles (1 );
394
+ }
395
+ String lineReconstructed = "" ; //the line but without the stamp info at the end
396
+ for (int i =0 ; i <spl .length -1 ; i ++) {
397
+ lineReconstructed += spl [i ] + "{" ;
398
+ }
399
+ lineReconstructed = lineReconstructed .substring (0 , lineReconstructed .length ()-1 );
400
+ this .addInput (lineReconstructed .trim ());
401
+ } else {
402
+ this .addInput (line );
403
+ }
384
404
}
385
405
}
386
- } catch (final IOException ex ) {
406
+ } catch (final Exception ex ) {
387
407
Logger .getLogger (Nar .class .getName ()).log (Level .SEVERE , null , ex );
388
- throw new IllegalStateException ("Could not open specified file " , ex );
408
+ throw new IllegalStateException ("Loading experience file failed " , ex );
389
409
}
390
410
}
391
411
0 commit comments