You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constUtilityAi=require("utility-ai")utility_ai=newUtilityAi// define your actions e.g "Move to Enemy", "Fire at Enemy", "Move to Cover", "Reload Gun"utility_ai.addAction("Move to Enemy",action=>{// pre-conditions for actions, if not fulfilled all actions will be skippedaction.condition(({ player })=>{if(player.isStuck()){returnfalse}// explicit return of true needed to fulfill conditionreturntrue})// each score expects a number as return value, the higher the better the action will be weightedaction.score("Distance to Enemy",({ player, enemy })=>{returnplayer.distanceTo(enemy)})action.score("Gun is not loaded",({ player })=>{returnplayer.gunEmpty()&&-100})})utility_ai.addAction("Fire at Enemy",action=>{action.score("Proximity to Enemy < 50",({ player, enemy })=>{returnplayer.distanceTo(enemy)<50&&75})action.score("Cannot make it to cover",({ player })=>{returnplayer.nextCoverDistance()>25&&50})action.score("Gun is not loaded",({ player })=>{returnplayer.gunEmpty()&&-125})})utility_ai.addAction("Move to Cover",action=>{action.score("Is not in cover",({ player })=>{return!player.isInCover()&&50})action.score("Proximity to Cover < 50",({ player })=>{returnplayer.nextCoverDistance()<50&&50})})utility_ai.addAction("Reload Gun",action=>{action.score("Gun is not loaded",({ player })=>{returnplayer.gunEmpty()&&75})action.score("Is in Cover",({ player })=>{returnplayer.isInCover()&&50})action.score("Gun is loaded",({ player })=>{return!player.gunEmpty()&&-125})})constdata={player: {...},enemy: {...}}// starts the evaluation of a given world state and returns its best actionconstresult=utility_ai.evaluate(data)// e.g. result = { action: "Move to Cover", score: 100 }