0

I just finished creating a game in Prolog using Sicstus.

During the game I use assert's and retract's to update the values of some variables I use.

When the game finishes, if I don't reconsult the source files, and re-run the game, those variables have the same content of the past game, which makes sense.

So what I am asking is if exists some sort of built-in predicate that I can call at the end of the game so it reconsults the source files, establishing the original data of the game. (I know it is a lazy way to do it.)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Pedro Pereira
  • 312
  • 5
  • 21
  • 1
    Are all the facts that you assert during the operation of the game new, or are there defaults for them when you start? If they're new when you run the game, you could just retract all of them (`retractall`) when done. If not, you could refactor your code so that your dynamic facts are new when you start and can just all be retracted when you want to reset the game. – lurker Nov 06 '15 at 21:10
  • They all have default values. I am running on scarce time and a good refactor to the code would take more time than I have right now ( my management of time was not the greatest ), so could I not use the predicate reconsult/1 ? And if so, how do I get the path of the file I originally consulted? – Pedro Pereira Nov 06 '15 at 21:19
  • Is the path of the original file fixed? Why wouldn't your program know where it is? – lurker Nov 06 '15 at 21:21
  • Is not fixed. The `reconsult/1` uses an absolute path, and I need to be a relative path to the main file so I can reconsult the configs – Pedro Pereira Nov 06 '15 at 21:25
  • Perhaps you can remove the default facts from the file and write an initializer predicate that asserts them instead. Then you could retract all of them on a restart and rerun your initializer to set the defaults – lurker Nov 06 '15 at 21:27
  • 1
    Oh I see! Why did I not think of that?! Thank you @lurker for helping me these past days! – Pedro Pereira Nov 06 '15 at 21:28

1 Answers1

0

Perhaps you can remove the default facts from the file and write an initializer predicate that asserts them instead. Then you could retract all of them on a restart and rerun your initializer to set the defaults

– lurker

This was the answer. Thank you Lurker.

Pedro Pereira
  • 312
  • 5
  • 21