I am designing an AI for mouse and cat. So they have HP, and cat will chase and eat mouse, mouse will eat cheese. This eating action will help them to gain HP. If they can't eat food, they will die if they use up all the HP.
So I searched through books and I have a basic algorithm for this.
def chooseAction(actions, goals): # Go through each action, and calculate the # discontentment. bestAction = actions bestValue = calculateDiscontentment(actions, goals) for action in actions: thisValue = calculateDiscontentment(action, goals) if thisValue < bestValue: bestValue = thisValue bestAction = action # return the best action return bestAction def calculateDiscontentment(action, goals): # Keep a running total discontentment = 0 # Loop through each goal for goal in action: # Calculate the new value after the action newValue = goal.value + action.getGoalChange(goal) # Get the discontentment of this value discontentment += goal.getDiscontentment(value) struct Goal: value def getDiscontentment(newValue): return newValue * newValue
This algorithm is quite easy to understand, and quite easy to implement.
So I have to determine Goal and goal value for each action they take.
Let say a mouse, He may want to move, eat.
So I have to come up with a value(wiliness) for these values.
What is a good way to determine these values?
My approach is here.
Ley say my mouse have a view range of 3 cells and it can only walk in four directions up down left and right.
The goal eat value may determine by its MAX_ENERGY and NOW_ENERGY and I come out a formula eatValue = MAX_ENERGY - NOW_ENERGY. This make sense because, it NOW_ENERGY is equal to MAX_ENERGY, my mouse has a wiliness 0 to eat.
What is a good way of come out this simple formulations? What will be the good heriustic for my mouse to move?