Thursday, September 16, 2010

Competitive Robocode Robot

In this next segment of my experience with Robocode, I developed a competitive robot called RobotFighter that could reliably beat most non-advanced robots.  Secondary objectives were to improve my Java and Eclipse skills, and also to improve my ability to write code that adhered to standards.

The main feature of this bot is its random movement system.  First, RobotFighter calculates the distance between itself and the enemy bot.  If this distance is over 150 pixels, RobotFighter turns at a seemingly random angle and rushes toward the enemy bot.  If the distance is less than 150 pixels, RobotFighter turns at a random angle and retreats up to 450 pixels away from the enemy bot.  By introducing randomness into its movements, RobotFighter is able to evade enemy bot fire while closing in for short-distance attacks or retreating from ram-style attacks.

RobotFighter scans in a right-ward direction at 45 degrees per tick and with a wide arc.  Upon detection of an enemy bot, it fires a bullet and moves in a random direction.  Due to the limitations of Robot class, all actions are performed in serial, and thus, RobotFighter cannot maintain a perfect lock on the enemy bot.

Since RobotFighter uses a linear firing system, it only fires when it is within 500 pixels of an enemy bot.  It also varies the power behind its shots in proportion to the distance to the enemy bot.  The strength of its bullets are 0.9 at a distance of 500 pixels, and 3.0 (the maximum) at distances of less than 150 pixels.

RobotFighter was tested against 8 different sample robots in 100 rounds each.

Walls     Win: 64%     Loss: 36%

The movement system worked nicely in this match-up.  RobotFighter evaded most of Wall's bullets until it wore itself down to 0 energy.

RamFire     Win: 62%     Loss: 38%

The movement system overwhelmed RamFire's slow rotation rate.  RobotFighter backed away from RamFire in sharp angles, leaving it vulnerable to fire while it rotated.

SpinBot     Win: 21%     Loss: 79%

RobotFighter's linear firing system does not work well against bots that do not stop.  It is also inaccurate against circular movements.  If this robot were to be redesigned, it would have a pattern-finding system to predict the enemy's next movements.

Crazy     Win: 97%     Loss: 3%

Similar to the match-up against Walls, RobotFighter evaded most of Crazy's bullets until it wore itself down to 0 energy.

Fire     Win: 100%     Loss: 0%

RobotFighter is extremely effective against opponents that remain still for long periods of time.

Corners     Win: 82%     Loss: 18%

Like Fire, Corners remained still in a corner of the map, leaving it completely vulnerable to all bullets.

Tracker     Win: 76%     Loss: 24%

Tracker and RobotFighter used very similar movement systems.  The difference was that RobotFighter evaded more bullets by moving in non-right angles and it fired more powerful bullets up close.

SittingDuck     Win: 100%     Loss: 0%

SittingDuck literally did nothing but sit, so a 100% win percentage was expected.

Lessons Learned:
  1. From a documentation perspective, I learned that ALL methods need to be documented regardless of how trivial and straightforward they may seem.  To another developer, any missing documentation is far from trivial or straightforward.
  2. Eclipse provides a bunch of useful tools that make development times much quicker.  Some of these tools include automatic import statements, code formatting according to a standards template, refactoring, and built-in Javadocs.
  3. Every developer can learn to "listen" better.  In my previous experience with Robocode, I failed to "listen" when I did not notice the link to ICS 413 Robocode Standards.  This time around, I made sure to "listen" by double-checking that all requirements have been met.
A packaged version of RobotFighter is available here.

1 comment:

  1. Thác Ni Tư hiện tại đã đột phá tới cảnh giới ma pháp sư cấp sáu, mặc dù là mới đột phá nhưng đối với nhất tinh nhị tinhđồng tâm
    game mu
    cho thuê phòng trọ
    cho thuê phòng trọ
    nhac san cuc manh
    tư vấn pháp luật qua điện thoại
    văn phòng luật
    số điện thoại tư vấn luật
    dịch vụ thành lập doanh nghiệp đấu hoàng y hoàn toàn có thể chống lại được. Về phần Trần Bưu, hắn cũng đã đột phá tới ngũ phẩm sơ giai luyện dược sư.

    Nhạc Thành dự định có thời gian sẽ đưa cho Thác Ni Tư và Trần Bưu luyện chế một số đan dược, về phần Khiếu Thiên Hổ và Tử Điện Mãng, Nhạc Thành cũng nghĩ cách khiến cho bọn nó tiên giai.

    - Thác Ni Tư, ta dự định để cho ngươi và Trần Bưu đến Quỷ Uyên để hỗ trợ Đổng Đại Ngưu, các ngươi thấy thế nào?

    Nhạc Thành nói với Thác Ni Tư và Trần Ni Tư và Trần Bưu nhìn nhau, sau đó Trần Bưu nói:

    - Đại nhân, tại hạ muốn ở cạnh người.

    - Đại nhân, chúng ta cũng muốn ở bên cạnh người.

    Hai người bọn họ cũng biết ở cạnh đại nhân tốt hơn rất nhiều, ít ra là tốt hơn đi lưu đày bên ngoài.