4

There is a game that I've programmed in java. The game is simple (refer to the figure below). There are 4 birds and 1 larva. It is a 2 player game (AI vs Human).

enter image description here

  • Larva can move diagonally forward AND diagonally backward
  • Birds can ONLY move diagonally forward
  • Larva wins if it can get to line 1 (fence)
  • Larva also wins if birds have no moves left
  • Birds CANNOT "eat" the larva.
  • Birds win if Larva has NO move left (cannot move at all)

enter image description here

When the game starts, Larva begins, then ONE bird can move (any one), then Larva, etc...


I have implemented a MiniMax (Alpha Beta Pruning) and I'm using the following evaluate() function (heuristic function).

Let us give the following numbers to each square on the board.

enter image description here

Therefore, our evaluation function will be

h(n) = value of position of larva - value of position of bird 1 - value of position of bird 2 - value of position of bird 3 - value of position of bird 4

the Larva will try to MAXIMIZE the heuristic value whereas the Birds will try to MINIMIZe it

Example:

enter image description here

However, this is a simple and naive heuristic. It does not act in a smart manner. I am a beginner in AI and I would like to know what can I do to IMPROVE this heuristic function?

What would be a good/informed heuristic?

Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
Matt
  • 974
  • 1
  • 13
  • 31

3 Answers3

2

How about this :

Maximum :larva

Minimum :birds

H(t)=max_distance(larva,line_8)+Σmin_distance(bird_n,larva)

or

H(t)=Σmin_distance(bird_n,larva) - min_distance(larva,line_1)

max_distance(larva,line_8): to reflect the condition that larva is closer to the line 1.

Σmin_distance(bird_n,larva): to reflect the condition that birds are closer to the larva(to block it).

I believe there are still many thing could be considered ,for example ,the bird closest to the larva should have high priority to be chosen to move, but the direction about the function above make sense , and many details can be thought to improve it easily.

柯鴻儀
  • 613
  • 1
  • 10
  • 25
  • This is indeed a good heuristic. However, this game can be played as Larva (AI) vs Birds (Human) AND Birds (AI) vs Larva (Human) Does this evaluation function takes into account the birds side of the game? (e.g. if the birds play as AI) – Matt Nov 11 '15 at 05:08
  • Also, in this case, the evaluation function will be LOWER as the larva gets closer to line 1... Larva is trying to Maximize the value.. Or maybe I'm missing something? – Matt Nov 11 '15 at 05:12
  • I think so , in the max-min game-tree ,one must maximum the score ,the other must minimum it instead. considering the win rule of birds in your case:Birds win if Larva has NO move left, birds must try to block the larva, just by moving closely to it. – 柯鴻儀 Nov 11 '15 at 05:17
  • just changing `min_distance(larva,line_1)` to `max_distance(larva,line_8)` or `-1* min_distance(larva,line_1)` can fit the maximum requirement. – 柯鴻儀 Nov 11 '15 at 05:21
  • By `max_distance(larva, line_8)`, what do you mean exatly. Let's say Larva is at D2, then the max distance is 6 right? I mean you just count how far (vertically) the larva is from line 8? – Matt Nov 11 '15 at 05:24
  • I think both vertically distance or steps count from line 8 are fine,both of these can reflect the fact that larva is closer to the win condition. – 柯鴻儀 Nov 11 '15 at 05:28
  • Wouldn't the heuristic be smarter if I SQUARE the `dist(larva,line_8)` ? Because the closer it gets to line 1, the bigger the evaluation function gets. Also for the birds, I could say whenever a Bird is the closest to the Larva (below right OR below left), then double the value of that bird. – Matt Nov 11 '15 at 14:11
  • yes,I totally agree with you about the SQUARE ,there is no just one standard answer, but square the dist is better. – 柯鴻儀 Nov 11 '15 at 14:13
2

There is 1 simple way to improve your heuristic considerably. In your current heuristic, the values of square A1 is 8 less than the value of square A8. This makes the Birds inclined to move towards the left side of the game board, as a move to the left will always be higher than a move to the right. This is nit accurate. All squares on row 1 should have the same value. Thus assign all squares in row 1 a 1, in row 2 a 2, etc. This way the birds and larva won't be inclined to move to the left, and instead can focus on making a good move.

chessprogrammer
  • 768
  • 4
  • 15
1

You could take into account the fact that birds will have a positional advantage over the larva when the larva is on the sides of the board, so if Larva is MAX then change the side tile values of the board to be smaller.

Iche
  • 145
  • 2
  • 8
  • I did try that. Works a bit better. Thank you. But It isn't as smarter... the heuristic I've proposed is very naive.. – Matt Nov 11 '15 at 05:23