Monday, June 29, 2009

Teach a Dog

Summary

This is a little Java excersize I did on a simple learning AI. You train your dog by giving them commands and then rewarding or punishing him for his behavior. The commands can be anything you like, though the dog can only perform a limited set of actions. In the beginning, he responds to the commands randomly but with time he learns from your feedback. A later version also adds different visitors that enter your house. You can teach your loyal watchdog to greet your wife with a warm lick but drive burglars away with teeth and growl. Train him well enough, and you won't even need to give any commands!

Technologies I Used

  • Java

The AI Mechanic

The game is rather repetitive - you just give commands and give feedback. The interesting was to create the learning mechanic. The dog always responds to the commands in three phases, with three options each: bark/growl/be quiet, run/walk/stay put, and lick/bite/do nothing. For each phase, there's a matrix: one dimension for the three options, one for the commands the player has issued so far, and one for the different visitors. The values in this matrix represent the desirability of each action with each command/visitor combination. When a visitor arrives and a command (optional) is issued, the dog finds the action with the highest value for that combination (with some random variation added) and performs it.

If the dog is rewarded, all the desirability values related to the selected action are increased, making him more likely in general to perform that action in the future. This way you can develop you dog's general nature into a specific direction. The desirability values related to the action combined with the command or the visitor are increased more, however, making the dog more likely to respond to that command and that visitor with that action in the future. The opposite is true for punishment.

I played with the idea of making this into a more interesting game, in the spirit of the Lassie stories, but haven't got around to it yet at least.

No comments:

Post a Comment