[m-users.] Mercury for Game AI

David Epstein davideps at umich.edu
Thu Jan 20 00:02:33 AEDT 2022


I'm designing a turn-based text game similar to the detective puzzle
problems
<https://github.com/Anniepoo/prolog-examples/blob/master/newdetective.pl>
that people sometimes write in Prolog. The difference is that the player
must solve the mystery (not Prolog) and that the suspects continue to act,
e.g. lie to the player, kill again, flee, etc. I'd welcome suggestions on
how to approach the subsystems described below in a manner that leverages
Mercury's strengths. I'd also welcome references to academic journal
articles that might be helpful.

I'm hoping that Mercury will provide a common approach to maintaining game
state, character knowledge, action planning, and parsing and generating
dialogue. In the past, these have been completely separate systems that I
needed to convert between, which became very difficult to maintain. C# will
provide and manage all the GUI elements and act as a container for Mercury
to run on Android and iOs devices.

The pseudocode below is probably more like PDDL
<https://en.wikipedia.org/wiki/Planning_Domain_Definition_Language> than
Prolog, but hopefully my intentions are clear.

*Game State*
*% Create characters*
person(adam)
person(bob)
person(carl)
person(dan)
*% Assign character status*
dead(dan)
*% Define the world*
room(salon)
room(bedroom)
room(hallway)
*% Place characters*
location(adam,salon)
location(bob,salon)
location(carl,hallway)
location(dan,bedroom)
*% Define network for navigation*
connected(salon,hallway)
connected(bedroom,hallway)
connected(X,Y) :- connected(Y,X)
*% Define some past events (things that actually occurred, regardless if
anyone saw them)*
attack(bob,dan,bedroom)


*Character Knowledge*
*% bob knows what he did*
saw(bob,attack(bob,dan,bedroom)
heard(bob,attack(bob,dan,bedroom)
*% adam heard what dan did*
heard(adam,attack(bob,dan,bedroom))


*Action Planning*
I'm familiar with planners like Fast Downward
<https://www.fast-downward.org/>, which given a current state, a goal
state, and a set of possible actions very quickly string together the
necessary actions to get from the current to the goal state. Ivan
Bratko's *Programming
for Artificial Intelligence* describes Prolog programs with this
functionality. Each action is defined with a set of prerequisites (what
must be already true to apply the action) and effects (what will be true
after the action occurs). Is there a more Mercury specific implementation,
maybe something that involves constraint programming? Eventually, I'd like
to add temporality/scheduling and beliefs (e.g. adam may have heard bob
attack dan, but he erroneously believes that he heard carl).

move(Person,Room1,Room2)
     preq: location(Person,Room1), connected(Room1,Room2)
     effect: not(location(Person,Room1), location(Person,Room2)


*Parsing and Generating Dialogue *
The GUI will offer the user a set of words that can be translated into a
Mercury query, for example "What did you hear" asked to bob, would become
"heard(bob,X)." Additional code would prevent bob from implicating himself
in a crime. Perhaps DCG would be helpful in translating query results back
into plain English?


I'm definitely open to ideas and advice. Thanks for reading.

-david
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20220119/1582bf0b/attachment-0001.html>


More information about the users mailing list