LuaFuligni(lua.fulignistudio.unibo.it), AndreaFranzon
(andrea.franzonstudio.unibo.it),OrfeoCiano(orfeo.ianostudio.unibo.it)
AlmaMaterStudiorum-UniversitàdiBologna
Abstrat. Ourgoalistoreateanappliationthatusesartiialplay-
ersforthegameofRisk!.SomeoftheexistingimplementationsofRisk!
present ustomizable artiial players but their behavior seems to be
neithertoosmartnornaiveandthisantireoutthehumanplayer.We
intent to ahieve the goal ina dierent way: we hose to use Prolog,
adelarativelanguage,inontrastwiththeexistingopen-soureimple-
mentations.WelearntthattheusageofPrologreduesthedevelopment
timeandeortsbyoeringagoodabstration.
Keywords:artiialintelligene,Prolog,Risk,game,dies.
1 Introdution
Ourgoal isto reate anappliation that usesartiial playersforthegame of
Risk!TheontextistheusageoftheArtiialIntelligenesonthisgamethatis
astrategy,turn-based,multiplayergame andontainssomerandomnessdue to
thethrowingofdies.MoreexatlyweuseA.I.forthegamestrategy.Wehoose
risk! beauseunlikegamesin the theory'sgamesit presentsmany problemati
for example the hoie of the attaking territories or the predition of whih
territorytheenemywillattak.
Usuallytheexistingopen-soureimplementationsofthisgameusesimpera-
tivelanguagestodesribetheA.I.strategy.We,instead,proposetoseparatethe
A.I.aspetfrom theprogrambyusing adelarativelogi language.Wehoose
Prolog beauseit inludes the rst-order logi and bakwardhaining meha-
nismnatively.Moreoverwedon'thooseanimperativelanguage,likeJava,for
theA.I. aspetbeauseall thetreesearhand inferenefuntionalityinluded
in somelibrariesarelesseientthanthePrologengine.
As adelarativelanguagewehooseProloginstead of otherlanguageslike
Lispbeausewehavetoinfermoreonreordsthanonlists.Ourintentistouse
theProloglanguagefordesribingtheartiialplayer'sdeisions.
Theabilityofeahartiialplayer(andsothediultyforahumanplayer)is
haraterizedbythesetofrulesthatdenetheinfereneengineofeahartiial
player.The partiularity ofour solutionisthe onnetionbetweenprolog that
Risk! is aturn-based strategi board game for twoto six playersin whih the
goalisindiatedbyanobjetiveard.Thegameisplayedonaboarddepitinga
politialmapoftheEarththatontains42territoriesdistributedin6ontinents.
Thereareseveralgoalsbutinourappliation,forsimpliityandforageneral
purpose,weonsider onlytheaimto own24territories.
Atthestart-upeahplayerdistributesaxednumberofarmiesontheboard.
Ineahturntherearethreephases:plaingarmies,attaking,fortifying. Inthe
rstphasetheplayerputs newarmiesintotheownedterritories.Intheseond
the player attak a nearby enemy territory, the suess or fail of an attak is
deided by the throw of dies. In the third phase the player an move some
armiesbetweentwoowned nearbyterritoriesonlyone. Thephaseswill repeat
themselvesuntilaplayerreaheshis goal.
3 Related works
Thisapproahanbeusedingameswhihpresentrandomnessandmultiplayer
issuesoringameswheretheartiialplayer'sbehaviorisstritlyonnetedwith
logialdesriptionlikeRisk!.
Nowadays there are several implementations of Risk!. The most famous is
Risk Digital of Hasbro but there are alot of Risk! lones like Lux for Linux,
DominionformobilephonesorotherashgamesanbefoundovertheInternet.
Someofthose implementationspresentustomizableartiialplayersbuttheir
behaviorseemstobeneithertoosmartnornaiveandthisantireoutthehuman
player.
Ourapproah,besidesfousingoneieny,hallengesthelogialaspetin
adierentandmoresuitablewayin ordertoimprovethegame-play.
4 Methodology
OurrstimplementationisaJavamodelaptto representthe gameboard and
alltheinformationsthat itontains(territoryborders,neighborhoodrelations,
ontinents,territoryownership, ...).WealsodenethePrologknowledge-base
struturepayingattentionondataonsistenywiththeJavamodel.
WeproposethreedierentA.I.diultylevels:easy,mediumandhard.The
easylevelperformsrandomations.Insteadthehardlevelwillbeanextension
of themedium levelthat is anintelligent implementation ofthesameProlog
prediates. Eah skill that distinguish medium and hard diulty is mapped
into Prolog prediates. We use GNU Prolog for Java to embed the Prolog
interpreterintoourJavaappliationbeauseitrespetstheISOstandards.
Weassumethattheaimistoonquer24territoriesto simplifythestudyof
thegame. We hoose toguide theA.I. throughsomewell-knownasesin eah
The Risk! Map an be onsidered as a set of ountries (territories). For eah
territorywedene:
arelationofneighborhoodbetweenterritories;
theterritory'sownership;
thenumberofarmiesaterritoryholds;
WerepresentedthisknowledgeinPrologbydeningthefollowingsetoffats:
player/1 represents a player, identied by his olor (blue, red, green, pink,
blak,yellow).
territory/1 representsaterritory,identiedbyhisname.
owner/2 represents the ownership of a territory identied by the denoted
player.
neighbor/2 representstherelationoftheneighborhoodbetweentwoterritories.
army/2 representsthearmynumberforeahterritory.
Sothisisthesimplestknowledgebaseweanhave:
player(red).
player(green).
territory(siberia).
territory(jauzia).
territory(ita).
owner(siberia ,red).
owner(jauzia, red).
owner(ita ,green).
neighbor(siberia ,jauzia).
neighbor(siberia ,ita).
neighbor(jauzia ,ita).
neighbor(jauzia ,siberia).
neighbor(ita ,jauzia).
neighbor(ita ,siberia).
army(siberia ,3).
army(jauzia ,4).
army(ita ,2).
4.2 Moves
armyshouldbeplaed.
attak/3 Givenaplayer'solor,itgivesbaktwoterritories:anattaksoure
(territoryownedbytheplayer),andanattakdestination(territory
ownedbyanenemyplayer).
move/3 Given a player's olor,it gives bak two territories: the territory-
soure from whih the armies should be moved, and the territory-
destinationtowhihthearmiesshould bemoved.
Herearesomesamplequeries:
?
−
plae_army(red,Destination).Yes, Destination=siberia.
?
−
attak(red,Soure,Destination).Yes, Soure= yauzia, Destination=ita.
?
−
move(red,Soure,Destination).Yes, Soure=siberia ,Destination =jauzia.
TheimplementationofthoseprediateswillvaryaordingtoA.I.diulty.
InthiswaytheresponsibilityoftheJavaengineistoupdatetheknowledgebase
andperformthemovesuggestedbytheprologengine.
4.3 Randomnessrepresentation in Prolog
Beause of randomness omponentof thegame, exploring adeisional tree to
hoosewhihterritorytoattak, ouldleadto agenerallow-responsivity.This
is beausewe'dhaveto inserttworandomnesslevel (attakand defensedies)
into thedeisiontreeinreasingexponentiallythenumberofthenodes in that
level.
Thereforewedeideto representtherandomnessomponentsusing atable
thatontains,giventhenumerofattakeranddefenderarmy,theprobabilityto
winanattak.InsidetheKnowledgeBaseinPrologwerepresentthisinformation
withvitory/3:
vitory(Attak#Army, Defense#Army, Probability).
Sothattheprediateattak,givenaxedthresholdvalue,knewtheong-
urationattakerarmy/defenderarmythattwoterritoriesmusthavetoperform
anattak.
4.4 FromJava to Prolog
Javahastheresponsibilityofgeneratingtheknowledgebase.Inordertoaom-
2 for(Continent ontinent:ontinents)
3 {
4 for(Territory territory:ontinent.getTerritories())
5 visitor.visit(territory);
6 }
Onetheknowledgebaseisupdated,itisloadedbythePrologengine:
1 Environment env = new Environment();
2 //Loading the knowledge base file and A.I. implementation
3 env.ensureLoaded(AtomTerm.get("knowledge.pl"));
4 env.ensureLoaded(AtomTerm.get("easy.pl"));
5 interpreter = env.reateInterpreter();
6 env. runInitialization(interpreter );
Theexeutionofaquery:
1 //Calling the query: ?
−
plae_army(red,Territory).2 VariableTerm answerTerm = new VariableTerm("Territory");
3 Term[℄ args = {AtomTerm.get(playerColor),answerTerm};
4 CompoundTerm goalTerm = new CompoundTerm(AtomTerm.get("
plae_army"), args);
5
6 //Exeuting the query and testing if sueded
7 int r = interpreter.runOne(goalTerm);
8 if(r==PrologCode.SUCCESS || r==PrologCode.SUCCESS_LAST)
9 {
10
11 //Getting the Prolog indiated territory from the
game table
12 Term value = answerTerm.dereferene();
13 String n a m e = TermWriter.toString(value);
14 Territory destination = table.getTerritory(n a m e);
15 }
TheresultofthisquerywillbeusedbytheRiskgameenginethatperforms
theorrespondingmove.
5 Case-study
During an attak,to handle the randomnessof the dies, wegenerate a table
(based onMarkov hains)whih ontainstheprobabilityof winning anattak
bythenumberofattakanddefensearmies.
Eahplayer'sdiultyisharaterizedbyathresholdvalue,onlyiftheprob-
movesarmiesbetweentheterritories.Tobreakthedeadlokweneedtohardode
somespei Prologonditions.
Afterthitweagaintestedthesystembyletting twoplayers,withthe same
A.I. diulty level, ght eah-other.Otherwise, if there is at least oneplayer
with adierent diulty level,then the spei onditionsare notso evident,
sotheTuringtestispassed.
Tooverometheseproblemsanersolutionouldbetorepresentthemodel
asaConstraintLinearProgrammingprobleminwhiheverydeisionisdrivenby
anobjetivefuntion thatwilleitherbeminimizedormaximized,dependingon
theationthattheplayerhasperformed.Theobjetivefuntionvariesaording
totheevaluationofdierentvariables.Thisevaluationiseitherroughorrened
dependingontheplayer'sdiultylevel.
6 Conlusions
Our implementation grants a good level of playing for every kind of player.
OtherwisetheCPLsolutionwouldrequireanetuningoftheobjetivefuntion
for eah diulty in order to meet the optimal value for eah A.I. level. This
will produe an unnatural playing style. The Prolog interpreter is an optimal
solutionforthesekindsofproblems.ByusingPrologitiseasiertoswithbetween
dierentA.I.logis(andapproahes)leavingtheoreappliation unhanged.
Referenes
1. Osborne,JasonA.April 2003:"MarkovChains for theRISKBoardGameRevis-
ited",MathematisMagazine76
2. S.RusselleP.Norvig,2005:"Intelligenzaartiiale.Unapproiomoderno"volume
1SeondaEdizione.
3. L.Console,E.Lamma,P.Mello,M.Milano,1997:"ProgrammazioneLogiaePro-log"
SeondaEdizioneUTET.