Tuesday, September 14, 2010

Robocode

Robocode is an open source educational game designed to help people learn the Java programming language.  Much of the work is already done behind the scenes to provide the GUI and screen overlay.  One simply needs to refer to the API to begin coding their robot to move, use its radar, and shoot.


To learn basic movement, targeting, and firing behaviors, I programmed numerous robots to perform the following:

  • Position01: The minimal robot.  Does absolutely nothing at all. 
  • Position02: Move forward a total of 100 pixels per turn.  When you hit a wall, reverse direction.
  • Position03: Each turn, move forward a total of N pixels per turn, then turn right.  N is initialized to 15, and increases by 15 per turn.
  • Position04: Move to the center of the playing field, spin around in a circle,  and stop.
  • Position05: Move to the upper right corner.  Then move to the lower left corner.  Then move to the upper left corner. Then move to the lower right corner.
  • Position06: Move to the center, then move in a circle with a radius of approximately 100 pixels, ending up where you started.
  • Follow01: Pick one enemy and follow them.
  • Follow02: Pick one enemy and follow them, but stop if your robot gets within 50 pixels of them.
  • Follow03: Each turn, Find the closest enemy, and move in the opposite direction by 100 pixels, then stop.
  • Boom01: Sit still.  Rotate gun.  When it is pointing at an enemy, fire.
  • Boom02: Sit still.  Pick one enemy.  Only fire your gun when it is pointing at the chosen enemy.
  • Boom03:  Sit still. Rotate gun.  When it is pointing at an enemy, use bullet power proportional to the distance of the enemy from you. The farther away the enemy, the less power your bullet should use (since far targets increase the odds that the bullet will miss). 
  • Boom04: Sit still.  Pick one enemy and attempt to track it with your gun. In other words, try to have your gun always pointing at that enemy.  Don't fire (you don't want to kill it). 

I successfully coded all behaviors.  My implementations are available here.

At first, I was frustrated at the lack of a definitive guide that detailed specific robot behaviors and its code.  The wiki was not particularly helpful as the information was scattered throughout dozens of pages and mostly contained advanced behaviors.  The API became my golden guide from Position04 and onwards.

Position04 and Position05 presented the greatest challenge due to the necessity of trigonometric concepts and the awkward "compass" system that Robocode uses.  I completed Position04 by simply having the robot move in right angles until it reached the center.  In Position05, I used trigonometric functions such as arc tangent to have the robot move directly to its destination.  A problem I encountered was that the body of the robot is considered to be a square, not a single point.  Thus, my robot would occasionally run into a wall before hitting the corner of the map.

Other robots that exhibited interesting behaviors were Follow02 and Boom02.  I learned that by adjusting movement and radar rotation rates, I could affect how well the robots performed their tasks.  For example, I discovered that a radar rotation rate of 45 degrees per tick and 100 pixels per movement resulted in a potentially optimal robot that could quickly track down another robot.

Since positioning and predicting robot movements are the main strategies in Robocode, a competitive robot would strike a balance between radar rotation and movement rates.  In addition, techniques such as statistical analysis would be beneficial in predicting enemy movement patterns.

1 comment:


  1. - Xoẹt.
    đồ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
    Trong tay của Tô Hân Nhi hiện tại là một thanh kiếm màu trắng bạc, đấu khí trên thân thể của nàng vận chuyển, xung quanh liền tràn ngập, một kiếm quang cường hãn tấn công về phía thanh niên.

    - Xùy.

    Một tiếng vang lên, hán tử kia thấy thế thì thân hình nhanh chóng lùi lại về phía sau, đồng thời bay lên không trung.

    - Vạn Kiếm Quy Nhất.

    Tô Hân Nhi khẽ kêu lên một tiếng, đấu khí trên không trung bắt đầu di động, một mảng hư không xuất hiện, vô số kiếm quang hợp thành một kiếm võ thật lớn, vô cùng chói mắt.

    - Vạn Kiếm Quy Nhất, hình như đây là đấu kỹ của Nhạc gai.

    Nhạc Thành nhìn thấy Tô Hân Nhi sử dụng Vạn Kiếm quy nhất thì nhớ lại trước kia ở Nhạc gia tiểu ny tử này từng diễn qua với mình, uy lực thật bất phàm.

    ReplyDelete