Ofcourse, if I were to make a hive containing a whole bunch of Tamagotchis, I wasn't going to take care of them myself: I have better things to do. As a well-trained lazy programmer, I wrote a program to do that for me: an artificial intelligence that could keep the Tamagotchis happy and fed.
For an artificial intelligence, there are a few options. With Google and other big players doing awesome things with neural networks, you may be tempted to think that this would also be the best option for a Tamagotchi. Unfortunately, the Tamagotchis aren't really easy to be controlled using a vanilla neural network: the dependencies between what's on screen and the sequence of buttons to press combined with the hidden variables in the Tamagotchi would make it a pretty daunting task for a neural network, potentially leaving many malnourished and unhappy Tamagotchis in its wake.
Another option, not usually seen as an artificial intelligence, would be symbolic execution. This would mean writing an emulator that has symbolic values for some inputs, instead of 'real' values. It will emulate its way to a certain 'goal' (for example, a routine that makes the Tamagotchi happier) and then deduce from the code path the values the symbolic inputs should have to get to that goal.
I unfortunately have little experience with symbolic execution, so I have no idea how doable this is. Also, as far as I know there aren't any symbolic execution engines for the 6502 available yet. While I'm intrigued by this idea and would love to hear about someone else implementing it, for the Tamagotchi AI I'd have to go with something else.
The most boring way to implement AI to keep the Tamagotchi happy is just a simple state machine that uses data from the LCD to take a certain action. That would mean I would have to code all the code that takes care of a Tamagotchi myself. With the Tamagotchis being as simple as they are, luckily that doesn't necessarily take up much time. Also, Natalie found out that the Tamagotchi itself is mainly run as a big state machine. It makes sense to make the AI to take care of it a state machine too.
In the end, the state machine looks a bit like this:
The state machine gets its inputs purely from the LCD, and it does this by matching the LCDs image with a bunch of predefined images. It's a crude mechanism, but it works well for this purpose. It can actually play the games the Tamagotchi has halfway well. Here's an example: this Tamagotchi needs some food and some love. The AI will first feed it, then play a game with it in order to make it more happy: