PySwip is a Python - SWI-Prolog bridge enabling to query SWI-Prolog in your Python programs. It features an (incomplete) SWI-Prolog foreign language interface, a utility class that makes it easy querying with Prolog and also a Pythonic interface.
Hi, I'm trying to use pyswip as a reasoner for games. It requires frequent operations adding and removing facts from the prolog database. I want to do the following 2 types of operations: (1) add facts of format "does(player, M)" to the database, (2) remove facts of format "does(player, M)" from the database.
By reading the examples, I tried the following:
prolog = Prolog()
When the game start, I load the game rules as follows:
prolog.consult('game_description.pl')
While playing the game, I keeps calling:
prolog.assertz('does(player, M)') when making a move
and
prolog.retractall('does(player, M)') when undoing a move.
However, my observation is as the game continues (with the call to assertz and retractall increases), the program gets slower and slower. Am I doing something wrong here? Or is there a better way of adding and removing facts from the database?
Hi, I'm trying to use pyswip as a reasoner for games. It requires frequent operations adding and removing facts from the prolog database. I want to do the following 2 types of operations: (1) add facts of format "does(player, M)" to the database, (2) remove facts of format "does(player, M)" from the database. By reading the examples, I tried the following:
prolog = Prolog()
When the game start, I load the game rules as follows:prolog.consult('game_description.pl')
While playing the game, I keeps calling:prolog.assertz('does(player, M)')
when making a move andprolog.retractall('does(player, M)')
when undoing a move.However, my observation is as the game continues (with the call to assertz and retractall increases), the program gets slower and slower. Am I doing something wrong here? Or is there a better way of adding and removing facts from the database?
Thanks.