What is the purpose of Bayesian networks? I have seen a lot of explanations of what Bayesian networks are, but I simply cannot wrap my head around their use in code. So here is my three part question. 


Am I right in my definition of Bayes nets? Bayesian networks are a way to (visually) portray how variables/events are linked and how they will affect each other. Probabilities can be added to each node to give you a greater sense of what will happen. In conjunction with an acting AI, Bayes nets are used to predict the AI's actions and inform what it should be doing, i.e. giving minimax a better prediction.
Can you give a pseudo code representation of a Bayes net? 
Let's get a little more specific. I have a creature simulator, the creature has a home where he sleeps and, there are patches of grass where he eats. There are other creatures out there that he wants to avoid because they will fight him. So his action -> reaction set is: 

{hungry->find food -> eat food
tiered -> go to shelter -> sleep
in danger -> avoid other creature
under attack -> run to shelter}


I am trying to express this as an mdp so that it will learn what actions are best when; and what are the best spots (most prosperous &amp; least dangerous) on the map.

How, if at all, am I supposed to use a Bayes net? If the situation requires probabilities feel free to add your own, pseudo code also appreciated.
I am trying to state a possible bayes net:
What the creature wants to know is what to do next. So the root node is 'ACTION'. Possible actions are (let's say field 1 = home): [move to field 1, move to field 2, ... move to field n, sleep, eat] or [go north, go south, go east, go west, eat, sleep]. 'ACTION' depends on the creature's 'STATE', that can be [afraid(by another creature), under attack, hungry, tired]. 'STATE' depends on 'ANOTHER CREATURE' and 'FOOD AVAILABLE'. The latter two nodes can be [yes,no] and both depend on the current 'FIELD', [field 1, ..., field n].

'FIELD' -&gt; 'ANOTHER CREATURE'

'FIELD' -&gt; 'FOOD AVAILABLE'

'ANOTHER CRATURE' -&gt; 'STATE'

'FOOD AVAILABLE' -&gt; 'STATE'

'FIELD' -&gt; 'ACTION'

'STATE' -&gt; 'ACTION'


Each node has a table containing the probabilities p(value|value of dependency1, value dependency2,...). For example the 'ACTION' table holds the probabilities for each combination of p(action to take | value of 'STATE', value of 'FIELD').

I think suitable methods to estimate the model's probabilities are Q-learning or SARSA-learning.