#include #include #include #include #include #include #include #include "game.h" #include "bastet.h" #include "bast.h" #define WELL_POS(y,x) (*yx2pointer(y,x)) #define WPOS(w,y,x) (*wyx2pointer(w,y,x)) extern const DOT block_data[BLOCK_TYPES][BLOCK_ORIENTS][BLOCK_DOTS]; extern int bl_next; extern unsigned char *well_data; extern WINDOW *well_win; unsigned char *well_tmp=NULL; int *col_hei; long *bl_scores; char debug_buf[100]; void bast_init() { well_tmp=(unsigned char *)malloc(WELL_WIDTH*WELL_HEIGHT); if(well_tmp==NULL) assert(FALSE); col_hei= (int *)malloc(WELL_WIDTH*sizeof(int)); if(col_hei==NULL) assert(FALSE); bl_scores=(long *)malloc(BLOCK_TYPES*sizeof(long)); if(bl_scores==NULL) assert(FALSE); } void bast_clear() { free(well_tmp); free(col_hei); free(bl_scores); } inline unsigned char *wyx2pointer(char *well, int y, int x) { return well + (y * WELL_WIDTH) + x; } long eval_pos(char *well) //the higher, the better your block is { int i,j; long pos=0; //checks for completed lines for(i=0;i WELL_HEIGHT - 1) || (x + dot.x < 0) || (x + dot.x > WELL_WIDTH - 1) || (WPOS(well_data,y + dot.y, x + dot.x) > 0)) return 0; } return 1; } /* Put the points a block occupies into well */ void wset_block(char *well, int y, int x, int type, int orient) { int i; DOT dot; for (i = 0; i < BLOCK_DOTS; i++) { dot = block_data[type][orient][i]; WPOS(well, y + dot.y, x + dot.x) = dot.color; } //DBG: //draw_block(well_win,y,x,type,orient,0); //usleep(5000); //draw_block(well_win,y,x,type,orient,1); } #define MIN(a,b) (a