Scribd Robot Fruit Hunt Game

October is going to shape up to be a weird month if this is any indication.  Yesterday, 10/1, I stumbled across an eBook I wanted to check out, and so I went to Scribd (really awesome and large online library).  Somehow I came across this hilarious and terrificly simple bot game.

I didn’t have much time last night (about 45 minutes…worked all day, work out until 6:30, dinner/kids, excuses, excuses)…but I was intrigued and wanted to see if I could get a relatively unintelligent robot working real quick.  I think this game has been out there a while, but it was still on github and looked fun.

First things first, go git it (2 minutes, if that – gotta log in!):

git clone https://github.com/scribd/robot-fruit-hunt.git

This is probably more Javascript (33 minutes) than I’ve ever written before. Here’s the gist of it, I grabbed this piece of fruit I’m standing on if it’s worth taking. Otherwise, I ignore it and fan out looking for other relevant fruit (Function goGetRelevantFruitAroundMe(board)).

   trace("Looking for fruit at my position: " + get_my_x() + "," + get_my_y());
   if (board[get_my_x()][get_my_y()] > 0) {
	   typeOfFruit = board[get_my_x()][get_my_y()];
	   howManyOfFruit = get_total_item_count(typeOfFruit);
	   howManyOfFruitOpponentHas = get_opponent_item_count(typeOfFruit);
	   howManyOfFruitIHave = get_my_item_count(typeOfFruit);
	   if ((howManyOfFruitOpponentHas <= (howManyOfFruit / 2)) && (howManyOfFruitIHave <= (howManyOfFruit / 2))) {
		   trace("Found fruit at my position worth taking");
		   return TAKE;
	   } else {
		   trace("Found fruit at my position, but ignoring, already lost category " + typeOfFruit);
	   }
   } else {
	   trace("Didn't find anything at my position, will look immediately around me.");
   }

   //Where's the nearest fruit worth taking (will ignore losing categories)
   return goGetRelevantFruitAroundMe(board);

I can imagine how much you could learn by looking at other things (all doing this under 10 seconds of course):

– keeping track of where your opponent has gone and what they have eaten
– probabilities of each square, likelihood it will do you any good to go after it
– where you started on board and what is most densely populated quandrant in your favor to go after
– picking up nearby categories that can win or halve before opponent does

All kinds of game theory and what not here I’m sure.  But I went ahead and uploaded the bot after adding in some tracing (10 minutes).

Ideally, I’d get more time to come back and really write a bang up bot (with some actual intelligence behind it), more than just a bunch of quick if/else blocks.  But I think I’m supposed to be writing an Android app for SitterSat.

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: