Moje zdjęcie
Software Craftsman's Blog by Marcin Pieciukiewicz
Java and Scala development

Wednesday, April 3, 2013

Bot for Scalatron – great way to practice Scala

Recently I was pointed to project Scalatron which is a programming game, where bots are fighting in simple arena. The main goal is to capture as many energy points as possible, or at least more than your opponents.


Your goal, as a developer is to write a function in Scala programming language that controls your Bot. In brief your function will be called by the Scalatron server with passed parameters such as the map of area that is visible to your bot. And your function should return a commands that will be passed to your bot. This is very simple mechanism that allows you to control your bot in easy way.

I consider the Scalatron project to be very enjoyable way to learn or practice the Scala language and trying to develop some interesting decisions algorithms.

Scalatron Bot Mars to score 1 000 000 energy points!

My idea to write a Scalatron bot was to equip it with a number of competitive senses and passions. One, to force bot to look after food, other to fear of the enemies and even a sense to fear of small rooms. Here are the list of those senses:

Hunger – looks after eatable beasts and plants
Fear – tries to run away from opponents bots and hostile beasts
Explorer – tries not to stay in one place for too long
CabinFever – tries to avoid small rooms with, in some possibilities, no easy exit

Those senses are used to calculate preferences for direction that bot should move. Most important characteristic of them is that they are exponentially decaying when the distance from interesting object is growing. That way bot will react mostly for the objects that are nearest to him.

Also, to be more efficient, my bot will simultaneously spawn child bots that might have one of two roles (that might be switched during lifetime of spawned bot):

Missile – to track down enemy bots or hostile beasts and blow up when they are near
Hunter – to capture eatable beasts and plants

Those bots, especially those in hunter role have additional senses besides those introduced earlier:

Loner – to avoid being in the same area with other friendly bots
GoHome – to get back to my master bot to be absorbed by it

Those are to summarise main ideas that I have come up with, that allowed me to develop a Mars bot that achieved more than 1 000 000 points in standard scalatron benchmark.

I you are interested in more details how I've implemented that bot, you can find my bot’s source code on github's ScalaBotMars project.

1 comment:

  1. Wow! Such an amazing and helpful post this is. I really really love it. I hope that you continue to do your work like this in the future also.

    Best Apache Spark Online Course
    Apache Spark and Scala Online Training

    ReplyDelete