flagcapper / GoogleAI-Ants-Starter-Pack

C starter pack for the ants google ai contest.
5 stars 2 forks source link

Hills implementation #3

Open kuashio opened 12 years ago

kuashio commented 12 years ago

Does the "Hills not implemented yet" comment on the starter packages page mean that the code doesn't register hills in the local map representation?

I made my own implementation and it has worked fine. I just added a new case into the switch in the __initmap function in ants.c Here it is:

// Updates the map.
//
//    %   = Walls       (the official spec calls this water,
//                      in either case it's simply space that is occupied)
//    .   = Land        (territory that you can walk on)
//    a   = Your Ant
// [b..z] = Enemy Ants
// [A..Z] = Dead Ants   (disappear after one turn)
//    *   = Food
//    ?   = Unknown     (not used in latest engine version, unknowns are assumed to be land)
//    @   = Enemy Hill
//    +   = Your Hill

...

        switch (*data) {
            case 'w':
                game_info->map[offset] = '%';
                break;
            case 'a':
                game_info->map[offset] = var3 + 49;
                break;
            case 'd':
                game_info->map[offset] = var3 + 27;
                break;
            case 'f':
                game_info->map[offset] = '*';
                break;
            case 'h':                                           // hills, by kuashio
                game_info->map[offset] = (var3=='0')?'+':'@';   //    @   = Enemy Hill
                break;                                          //    +   = Your Hill
        }

Is this enough to say hills are implemented in C?

flagcapper commented 12 years ago

There are a few issues with this:

  1. It doesn't create a structure that lets you iterate through the hills as you can for ants, food, etc.
  2. It also doesn't handle the special case of when there is both an ant and a hill at the same location.
  3. There is no difference between enemy hills that belong to different players.

The way I've done it in my bot (which I probably should add to the starter pack at some point) is to add another structure to ants.h, allocate it the same way as the others are done in _init_game(), and set the square that a hill occupies to a number between '0' and '9'. If both an ant and a hill occupy the same square I set the square to the letter that represents that player and also set the most significant bit of that byte to a 1.

amstan commented 12 years ago

Please re-post this issue in the main aichallenge/aichallenge repo