AI Challenge - Ants

Marco Leise Marco.Leise at gmx.de
Tue Nov 8 13:20:08 PST 2011


Am 08.11.2011, 21:04 Uhr, schrieb maarten van damme  
<maartenvd1994 at gmail.com>:

> I have stolen an isvisible method from the c# bot
>
> bool isVisible(Loc loc){
>  Loc[] offsets;
> int squares = cast(int)floor(sqrt(_viewradius2));
> for (int r = -1 * squares; r <= squares; ++r){
> for (int c = -1 * squares; c <= squares; ++c){
> int square = r * r + c * c;
> if (square < _viewradius2){
> Loc newLoc = {r,c};
> offsets~=newLoc;
> }
> }
> }
> foreach (ant;_myAnts)
> {
> foreach (offset;offsets)
> {
> if ((ant.col + offset.col) == loc.col &&
> (ant.row + offset.row) == loc.row)
> {
>  return true;
> }
> }
> }
> return false;
>  }

Nice theft, although 'offsets' should really be a field of the Ants class  
and not recomputed on every invocation.

> But I have also lost interest because of a couple of shortcommings, the
> hell it is to debug that thing and when it finally compiles fine on 2
> machines it gives a cryptic error about glue.c (that had something to do
> with rdmd)

I tend to use a 'general purpose' Makefile for building, that I symlink  
into new projects and wait for a bigger, better build tool. Then I use the  
'debug' target as the build command in DDT (Eclipse) and have an 'External  
Launcher' that runs gdb with the executable. The flags look like this: -w  
-unittest -debug -gc -L--export-dynamic. Still I mostly use writeln for  
debugging algorithms and in/out contracts to avoid bugs that are easy to  
catch there.
As for the Ants game, you can add a flag to the engine, I think it was -I,  
that has it save bot input in a text file. If you feed that to your bot  
via stdin, the bot will behave exactly as during the game, but this time  
you can wrap it in a call to gdb, use a special debug build or add flags  
to your bot that enables more debugging output.


More information about the Digitalmars-d-learn mailing list