home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
138.lha
/
Cycle
/
NotsoDizzy.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-20
|
2KB
|
109 lines
/*
"Not so Dizzy" is a middleweight player who evaluates the scores around
him in the manner of "Round the CLock" and "Keep 'em Flying", but with a
more sophisticated evaluation algorithm. Notice that, for speed, the arena
memory is searched directly instead of on a cell-by-cell basis via the
Inquire() function: a local copy of the board is made so that it may be
searched and modified withoug affecting the actual arena. The
strategy_init and strategy_finish functions allocate and free the
required memory.
*/
#include "cycles.h"
char player_name[] = "Not so Dizzy";
long xdir[] = {0,1,0,-1};
long ydir[] = {-1,0,1,0};
static IMAGE myTable;
static nbytes;
static IMAGE *table = 0;
static x_bytes;
void mySet(),myClr(),*malloc();
IMAGE *GetScreenMem();
strategy_init()
{
table = GetScreenMem();
myTable.x = table->x;
myTable.y = table->y;
x_bytes = (myTable.x>>3)+(!!(myTable.x&7));
nbytes = myTable.y * x_bytes;
myTable.buf = (BYTE *)malloc(nbytes);
if (!myTable.buf) {
printf("Error, can't get memory for my copy of the board\n");
return(-1);
}
return(0);
}
strategy_finish()
{
free(myTable.buf);
}
strategy()
{
long x,y,dir;
long score,best;
long i,j,d;
GetInfo(&x,&y,&dir);
best = 0;
copyBoard();
for(d=TURN_RIGHT(dir), i=0; i<4; i++,d=TURN_RIGHT(d)) {
score = value(x + xdir[d],y + ydir[d],2);
if (score > best) {
dir = d;
best = score;
}
}
return(dir);
}
value(x,y,d)
{
long i,best,v;
if (myInquire(x,y)) return(0);
if (d > 0) {
mySet(x,y);
best = 0;
for (i=0; i<4; i++) {
v = value(x + xdir[i], y+ ydir[i], d-1);
if (v>best) best = v;
}
myClr(x,y);
return(1 + best);
}
return(1);
}
copyBoard()
{
register i;
register char *p,*q;
q = myTable.buf;
p = table->buf;
for (i = nbytes; --i>=0; )
*q++ = *p++;
}
static power[] = {1,2,4,8,16,32,64,128};
/* return the sttaus of the pixel @ x,y */
myInquire(x,y)
{
if (x<0 || y<0 || x>=myTable.x || y>=myTable.y) return(1);
return((myTable.buf[(x>>3)+y*x_bytes]&power[x&7]) != 0);
}
/* return the status of the pixel @ x,y */
void mySet(x,y)
{
if (x<0 || y<0 || x>=myTable.x || y>=myTable.y) return;
myTable.buf[(x>>3)+y*x_bytes] |= power[x&7];
}
/* return the status of the pixel @ x,y */
void myClr(x,y)
{
if (x<0 || y<0 || x>=myTable.x || y>=myTable.y) return;
myTable.buf[(x>>3)+y*x_bytes] &= ~power[x&7];
}