[CONTEST] Official "CASCON I Have a Code" discussion

Go down

[CONTEST] Official "CASCON I Have a Code" discussion

Post  Eddie on Sat Sep 13, 2008 11:39 am

CASCON I Have A Code
Wednesday, October 29, 2008 8:30 am to 4:00 pm

This is a fairly entertaining contest. It's similar to robocode if you have done that before. Basically, you write an AI to take over the entire map with your cells. Your cells start as stem cells, and later can specialize into attacking cells, defending cells, growing cells, etc. You earn points by occupying space or killing others. There are up to 4 other colonies of cells (other AIs) in the same map battling you, and there's a time limit (<1 minute?). This whole thing reminds me of starcraft. Looks fun, check it out.

If you are confused with the installation, read here.

Feel free to share your AIs here. I played around it this morning and made this noob AI, it implements a basic strategy and is partially based on chance. Though it pwns "random colony" 100% of the time, it fails against everyone else.

Spoiler:

Code:

import com.ibm.jc.JavaChallenge;
import com.ibm.colony.*;

import com.ibm.colony.Const;
import com.ibm.colony.IStemCell;

/**
 * Swarms up toward the top, then attacks down
 * Owns "random colony", gets owned by everyone else
 */
@JavaChallenge(name = "N00bZerg", organization = "Betelgeuse")
public class MyColony extends Colony {

      /* DIRECTIONS */
      final int N = 1;
      final int NE = 2;
      final int E = 3;
      final int SE = 4;
      final int S = 5;
      final int SW = 6;
      final int W = 7;
      final int NW = 8;
      
      int myDir [] = {N,W,E,NE,E,W,NW};
      int atkDir [] = {S,SW,SE,E,W};
      
      double n;   // random number
      int cnt;   // count
      
      
      public void initialize() {
         // put implementation here
      }

      public void orderSubjects(int lastMoveTime) {
         cnt ++;

         if (cnt < 200) {
            for (IStemCell stemcell : getStemCells()) {
               n = Math.random();
               if (n < 0.6) {
                  if (stemcell.getSplitTime() <= 0)
                     split (stemcell);
                  else
                     grow (stemcell);
//               } else if (n < 0.6) {
//                  if (stemcell.getHP() >= Const.MACRO_PRE_HP)
//                     specializeTCell(stemcell);
//                  else
//                     grow (stemcell);
               } else {
                  move (stemcell, myDir [(int) (Math.random() * 6) + 1] );
               }
            }
         } else {
            for (IStemCell stemcell : getStemCells()) {
               if (stemcell.getHP() >= Const.MACRO_PRE_HP)
                  specializeTCell(stemcell);
               else
                  grow (stemcell);
            }
         }
         
         for (ITCell t : getTCells()) {
            if (Math.random() < 0.25) {
               move (t, atkDir  [(int) (Math.random() * 4) + 1]);
            } else if (t.getAP () <= 5 || t.getHP() <= 20)
               grow(t);
            else if (t.getSplitTime() <= 0)
               split(t);
            else
               //attack (t, atkDir  [(int) (Math.random() * 4) + 1]);
               attack (t,S);
         }
         
      }
      
      
      /* JUNK BELOW */
      public String getSchoolName () {
         return "RHHS";
      }
      
      public String getColonyName () {
         return "Zerg";
      }
}

Eddie
Admin
Admin

Number of posts : 65
Location : Canada
Grade : 12
L337ness :
0 / 1000 / 100

Registration date : 2008-08-27

View user profile http://rhhscs.clubdiscussion.net

Back to top Go down

Re: [CONTEST] Official "CASCON I Have a Code" discussion

Post  a13x on Mon Sep 15, 2008 8:10 pm

Is this an individual thing? Or are we all just representing our school.

Edit: Never mind, I rtfm'ed

a13x
Alumni
Alumni

Number of posts : 299
Grade : >12
L337ness :
0 / 1000 / 100

Registration date : 2008-09-11

View user profile

Back to top Go down

Re: [CONTEST] Official "CASCON I Have a Code" discussion

Post  Dan on Tue Sep 16, 2008 12:35 am

Wow this is actually really fun : p. It's really easy to ^^ (just read the manual thing). I'll work on some pro colonies tomorrow.

EDIT: My Growth Cell Colony pwns all colonies except for the growth attack colony XD. It's not quite done yet, so hopefully with a few more extra AI features it'll beat the other growth one.
avatar
Dan
Alumni
Alumni

Number of posts : 73
Age : 26
Location : Waterloo, Ontario
Grade : >12
L337ness :
69 / 10069 / 100

Registration date : 2008-08-27

View user profile

Back to top Go down

Re: [CONTEST] Official "CASCON I Have a Code" discussion

Post  Jamie(); on Wed Oct 15, 2008 7:52 am

Here is what I made so far, it's pretty good, can usually beat everything, all depends on where it starts. Take from it what you will. It has an interesting growth pattern, and relitavely tough cells. I also added specific specialization depending on how far away the closest enemy cell is. BTW, I have too many imports, but that's okay (I guess).

Edit: Where I say "play" I mean that you'll need to fool around with it for it to be good. (I think its good, but could be more refined/tested).

Spoiler:

Code:
import com.ibm.jc.JavaChallenge;
import com.ibm.colony.*;
import java.awt.Point;
import com.ibm.colony.Const;
import com.ibm.colony.IGrowthCell;
import com.ibm.colony.IKamikazeCell;
import com.ibm.colony.IMacrophage;
import com.ibm.colony.IStemCell;

/** Spreads, specializes into TCells if enemy is near, and growth otherwise
 *    excellent growing pattern
 * @author Jamie Langille
 * @version Date: October 12/08
 * @defeats Random, Scorched, MacroAttack, TAttack, (Phase), (GrowthAttack)
 */
@SuppressWarnings("unused")
@JavaChallenge(name = "Expander", organization = "Simic")
public class MyColony extends Colony
{
   boolean [] walls = {false, false, false, false, false, false, false, false, false};
   public void initialize()
   {
      System.out.println("\u00a7!");
   }


   public void orderSubjects(int lastMoveTime)
   {

      /** Wall procedures
       *    If colony has found all walls, corners become false
       *    If colony has found all corners, walls become false
       */
      if (walls [2] && walls [4] && walls [6] && walls [8])
      {
         walls [1] = false;
         walls [3] = false;
         walls [5] = false;
         walls [7] = false;
      }
      else if (walls [1] && walls [3] && walls [5] && walls [7])
      {
         walls [2] = false;
         walls [4] = false;
         walls [6] = false;
         walls [8] = false;
      }


      /** Orders Stems
       *    moves toward walls,
       *    specializes into growth
       *    Add advanced specialization
       */
      for (IStemCell stem : getStemCells())
      {
         Point[] locations = World.getValidAdjacentLocations(stem.getX(), stem.getY());
         if (stem.getSplitTime() == 0)
            split (stem);
         else if (locations.length == 0)
            if (stem.getHP() >= 120)
               specializeGrowthCell (stem);
            else
               grow (stem);
         else
         {
            IObject enemy = locateEnemyCell (stem);
            if (enemy != null && stem.getDistanceTo(enemy.getX(), enemy.getY()) == 1)
               attack (stem, stem.getDirectionTo(enemy.getX(), enemy.getY()));
            else if (enemy != null && stem.getDistanceTo(enemy.getX(), enemy.getY()) <= 7 && stem.getHP() >= 75) // Play with this
               specializeTCell (stem);
            else if (locations.length <= 3)
               if (stem.getHP() >= 120) // Play
                  specializeGrowthCell (stem);
               else
                  grow(stem);
            else if (stem.getHP() >= 90)
               move (stem, locateWall(stem));
            else
               grow(stem);
         }
         // Sensors

         // Corners
         if (stem.getY() == 0 && stem.getX() == 71)
            walls [2] = true;
         else if (stem.getX() == 71 && stem.getY() == 63)
            walls [4] = true;
         else if (stem.getY() == 63 && stem.getX() == 0)
            walls [6] = true;
         else if (stem.getX() == 0 && stem.getY() == 0)
            walls [8] = true;

         // Walls
         else if (stem.getY() == 0)
            walls [1] = true;
         else if (stem.getX() == 71)
            walls [3] = true;
         else if (stem.getY() == 63)
            walls [5] = true;
         else if (stem.getX() == 0)
            walls [7] = true;
      }



      /** Orders growth
       *  moves toward opponent & grows
       */
      for (IGrowthCell grow : getGrowthCells())
      {
         Point[] locations = World.getValidAdjacentLocations(grow.getX(), grow.getY());
         if (grow.getSplitTime() == 0 && locations.length != 0)
            split (grow);
         else if (locations.length == 0)
            grow (grow);
         else
         {
            IObject enemy =  locateEnemyCell (grow);
            if (enemy != null && grow.getDistanceTo(enemy.getX(), enemy.getY()) == 1)
               attack (grow, grow.getDirectionTo(enemy.getX(), enemy.getY()));
            else if (locations.length <= 3)
               grow(grow);
            else if (grow.getHP() >= 250)
               move (grow, locateWall(grow));
            else
               grow(grow);
         }
         // Sensors

         // Corners
         if (grow.getY() == 0 && grow.getX() == 71)
            walls [2] = true;
         else if (grow.getX() == 71 && grow.getY() == 63)
            walls [4] = true;
         else if (grow.getY() == 63 && grow.getX() == 0)
            walls [6] = true;
         else if (grow.getX() == 0 && grow.getY() == 0)
            walls [8] = true;

         // Walls
         else if (grow.getY() == 0)
            walls [1] = true;
         else if (grow.getX() == 71)
            walls [3] = true;
         else if (grow.getY() == 63)
            walls [5] = true;
         else if (grow.getX() == 0)
            walls [7] = true;
      }

      /** Orders Ts
       *  moves toward opponent & grows
       */
      for (ITCell tcell : getTCells())
      {
         Point[] locations = World.getValidAdjacentLocations(tcell.getX(), tcell.getY());
         if (tcell.getSplitTime() == 0 && locations.length != 0)
            split (tcell);
         else if (locations.length == 0)
            grow (tcell);
         else
         {
            IObject enemy = locateEnemyCell (tcell);
            if (enemy != null && tcell.getDistanceTo(enemy.getX(), enemy.getY()) == 1)
               attack (tcell, tcell.getDirectionTo(enemy.getX(), enemy.getY()));
            else if (locations.length <= 3)
               grow(tcell);
            else if (enemy != null && tcell.getHP() >= 150) //
               if (tcell.getDistanceTo(enemy.getX(), enemy.getY()) <= 7)
                  move (tcell, tcell.getDirectionTo(enemy.getX(), enemy.getY()));
               else
                  move (tcell, locateWall (tcell));
            else if (enemy == null && tcell.getHP() >= 3)
               move (tcell, locateWall (tcell));
            else
               grow(tcell);
         }
      }
   }
   /** Finds the closest enemy cell from the given cell,
    *   and returns the direction that it should move.
    *    Could possibly be shortened (embed, etc., maybie not)
    *    @param cell - the cell to move
    *    @return  the closest enemy cell - null if there are no enemy cells
    *           Direction to it can be found by:
    *           cell.getDistanceTo(locateEnemyCell (cell).getX(), locateEnemyCell (cell).getY())
    */
   private ICell locateEnemyCell (ICell cell)
   {
      int minDistance = Integer.MAX_VALUE; // Or someting, doesn't matter
      ICell cellToAttack = null;
      if (World.getOtherStemCells() != null)
      {
         for (IStemCell enemy : World.getOtherStemCells())
         {
            if (minDistance > cell.getDistanceTo (enemy.getX(), enemy.getY())) // Preferred not to do calc in if
            {
               minDistance = cell.getDistanceTo (enemy.getX(), enemy.getY());
               cellToAttack = enemy;
            }
         }
      }
      if (World.getOtherTCells() != null)
      {
         for (ITCell enemy : World.getOtherTCells())
         {
            if (minDistance > cell.getDistanceTo (enemy.getX(), enemy.getY()))
            {
               minDistance = cell.getDistanceTo (enemy.getX(), enemy.getY());
               cellToAttack = enemy;
            }
         }
      }
      if (World.getOtherGrowthCells() != null)
      {
         for (IGrowthCell enemy : World.getOtherGrowthCells())
         {
            if (minDistance > cell.getDistanceTo (enemy.getX(), enemy.getY()))
            {
               minDistance = cell.getDistanceTo (enemy.getX(), enemy.getY());
               cellToAttack = enemy;
            }
         }
      }
      if (World.getOtherMacrophages() != null)
      {
         for (IMacrophage enemy : World.getOtherMacrophages())
         {
            if (minDistance > cell.getDistanceTo (enemy.getX(), enemy.getY()))
            {
               minDistance = cell.getDistanceTo (enemy.getX(), enemy.getY());
               cellToAttack = enemy;
            }
         }
      }
      if (World.getOtherKamikazeCells() != null)
      {
         for (IKamikazeCell enemy : World.getOtherKamikazeCells())
         {
            if (minDistance > cell.getDistanceTo (enemy.getX(), enemy.getY()))
            {
               minDistance = cell.getDistanceTo (enemy.getX(), enemy.getY());
               cellToAttack = enemy;
            }
         }
      }
      return cellToAttack;
   }

   /** Finds the closest wall from a
    *    particular cell.
    * @param cell
    * @return direction to wall, 0 if the cell is there.
    */

   private int locateWall (ICell cell)
   {
      int minDistance = Integer.MAX_VALUE;
      int pointX = 0;
      int pointY = 0;
      if (minDistance > cell.getDistanceTo (36, 0) && !walls [1])
      {
         minDistance = cell.getDistanceTo(36, 0);
         pointX = 36;
         pointY = 0;
      }
      if (minDistance > cell.getDistanceTo (71, 0) && !walls [2])
      {
         minDistance = cell.getDistanceTo(71, 0);
         pointX = 71;
         pointY = 0;
      }
      if (minDistance > cell.getDistanceTo (71, 32) && !walls [3])
      {
         minDistance = cell.getDistanceTo(71, 32);
         pointX = 71;
         pointY = 32;
      }
      if (minDistance > cell.getDistanceTo (71, 63) && !walls [4])
      {
         minDistance = cell.getDistanceTo(71, 63);
         pointX = 71;
         pointY = 63;
      }
      if (minDistance > cell.getDistanceTo (36, 63) && !walls [5])
      {
         minDistance = cell.getDistanceTo(36, 63);
         pointX = 36;
         pointY = 63;
      }
      if (minDistance > cell.getDistanceTo (0, 63) && !walls [6])
      {
         minDistance = cell.getDistanceTo(0, 63);
         pointX = 0;
         pointY = 63;
      }
      if (minDistance > cell.getDistanceTo (0, 32) && !walls [7])
      {
         minDistance = cell.getDistanceTo(0, 32);
         pointX = 0;
         pointY = 32;
      }
      if (minDistance > cell.getDistanceTo (0, 0) && !walls [8])
      {
         minDistance = cell.getDistanceTo(0, 0);
         pointX = 0;
         pointY = 0;
      }
      if (cell.getX() == pointX && cell.getY() == pointY)
         return (int)(Math.random () * 8) + 1;
      else
         return cell.getDirectionTo(pointX, pointY);
   }

   public String getSchoolName () {
      return "RHHS";
   }

   public String getColonyName () {
      return "Expander";
   }
}
avatar
Jamie();
Admin
Admin

Number of posts : 43
Age : 25
Location : Canada
Grade : 11
L337ness :
0 / 1000 / 100

Registration date : 2008-09-06

View user profile

Back to top Go down

Re: [CONTEST] Official "CASCON I Have a Code" discussion

Post  Dan on Wed Oct 29, 2008 11:19 pm

For those who are interested Tyson and I got 4th place (out of 36 teams I believe).
It was pretty lol, 2/3 games Tyson and I played our cells covered the ENTIRE MAP at the end of the round (only one other team managed to do this, and they only did it once). Pretty lol cuz it turns out it's better not to finish off your enemies, but let them stay alive so you can feed off of them (the game was scored on points, not wins).

Alex and Eddy got in the top 10 as well Smile.
avatar
Dan
Alumni
Alumni

Number of posts : 73
Age : 26
Location : Waterloo, Ontario
Grade : >12
L337ness :
69 / 10069 / 100

Registration date : 2008-08-27

View user profile

Back to top Go down

Re: [CONTEST] Official "CASCON I Have a Code" discussion

Post  a13x on Sat Nov 08, 2008 8:02 pm

we got ninth *sadface*, meaning we lost the game.

a13x
Alumni
Alumni

Number of posts : 299
Grade : >12
L337ness :
0 / 1000 / 100

Registration date : 2008-09-11

View user profile

Back to top Go down

Re: [CONTEST] Official "CASCON I Have a Code" discussion

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum