/* * pexeso - multiplayer Pexeso game for MS-Dos/Win32/SVGAlib/X11 * * pexeso.c - main game file * ____________________________________________________________ * * Developed by Ondrej Jombik * Copyright (c) 1997-2000 Condy software inc. * Copyright (c) 2001-2004 Platon SDG, http://platon.sk/ * All rights reserved. * * See README file for more information about this software. * See COPYING file for license information. * * Download the latest version from * http://platon.sk/projects/games/ */ /* $Platon: games/pexeso/pexeso.c,v 1.15 2004/04/06 09:04:09 nepto Exp $ */ #define EXESIZE/* or pexeso.exe EOF pointer */ 43985L /* LANGUAGE */ #define LANG_ENGLISH_NEW 0 #define LANG_ENGLISH_OLD 1 #define LANG_SLOVAK 2 #define LANG_ENGLISH LANG_ENGLISH_NEW #define LANGUAGE LANG_ENGLISH /* alter this to change language */ /* VERSION: 0=English, 1=Slovak */ #define SLOVAK (LANGUAGE == LANG_SLOVAK) /* COMPLAY: 0=vypnuty, 1=zapnuty */ #define COMPUTER_PLAY 1 /* Forcing final end screen */ #define FORCE_END_SCREEN 0 /* ///////////////////////////////////////////////////////////////////////// */ #define PICTURE_SIZE 1318 #if COMPUTER_PLAY # define MAXPLAYERS 9 # define COMPUTERS 6 # define MOUSE_STEPS 20 # define STEPS_DELAY (0.05) #else # define MAXPLAYERS 10 #endif enum computers { COMP_NONE, COMP_SILLY, COMP_POOR, COMP_NORMAL, COMP_GOOD, COMP_GURU }; #if SLOVAK # define EXENAME "pexeso.exe" # define ERR_ARGC "Pr¡lis vela argumentov v pr¡kazovom riadku." # define ERR_EXEC "Nem“zem spustit" # define ERR_MOUSE "Tento program potrebuje mys." # define ERR_DATFILE "Nedostatok volnej pam„te." # define ERR_WRITE "Chyba pri z pise. Plny disk?" # define ERR_GRAPH "Chyba grafiky:" # define STR_WINNER "V I T A Z" # define STR_MAIN "Start Hry","Pocet Hr cov:?","Poc¡tac:xxxxxxx","Inform cie","Odchod do DOSu" # define STR_INFO "P E X E S O","","Naprogramoval","Ondrej Jomb¡k","","Grafika","Stefan Soun","","Specialne podakovanie","Michal Koc¡","","(c) Copyright 1997","Condy software inc.","Vsetky pr va vyhraden‚." # define STR_COMP "Vypnuty","Hlupy", "Slaby", "Normal", "Dobry", "Guru" # define STR_YESNO "Ano","Nie" # define STR_MENU_TITLE_1 "P E X E S O" # define STR_MENU_TITLE_2 "by Ondrej Jomb¡k" #elif (LANGUAGE == LANG_ENGLISH_OLD) # define EXENAME "pexeso.exe" /* "pex_eng.exe" */ # define ERR_ARGC "Too many arguments in command line." # define ERR_EXEC "Can't run" # define ERR_MOUSE "This program requires mouse." # define ERR_DATFILE "Not enough memory or DATfile (pexeso.dat) not found." # define ERR_WRITE "Can't write. Disk full?" # define ERR_GRAPH "Graphics error:" # define STR_WINNER "W I N N E R" # define STR_MAIN "Start Game","Players:?","Computer:xxxxxx","Information","Exit to DOS" # define STR_INFO "P E X E S O","","Programmed by","Ondrej Jomb¡k","","Graphics by","Stefan Soun","","Especially thanks to","Michal Koc¡","","(c) Copyright 1997","Condy software inc.","All rights reserved." # define STR_COMP "Off","Silly", "Poor", "Normal", "Good", "Guru" # define STR_YESNO "Yes","No" # define STR_MENU_TITLE_1 "P E X E S O" # define STR_MENU_TITLE_2 "by Ondrej Jomb¡k" #else # define EXENAME "N/A" # define ERR_ARGC "Too many arguments in command line." # define ERR_EXEC "Can't run" # define ERR_MOUSE "This program requires mouse." # define ERR_DATFILE "Not enough memory or data file 'pexeso.dat' was not found." # define ERR_WRITE "Can't write. Disk full?" # define ERR_GRAPH "Graphics error: " # define STR_WINNER "W I N N E R" # define STR_MAIN "Start Game","Players:?","Computer:xxxxxx","Information","Exit to OS" # define STR_INFO "P E X E S O","","Programmed by","Ondrej Jombik","","Graphics by","Stefan Soun","","Especially thanks to","Michal Koci","","(c) 1997-2000 Condy software", "(c) 2001-2004 Platon SDG","All rights reserved." # define STR_COMP "Off","Silly","Poor","Normal","Good","Guru" # define STR_YESNO "Yes","No" # define STR_MENU_TITLE_1 "P E X E S O" # define STR_MENU_TITLE_2 "by Ondrej Jombik" #endif #include #include #include #include #include #include /* target operating system type */ #if PLATON_SYSTEM_SVGALIB || PLATON_SYSTEM_X11 # include # include # define CLOCK_FNC times(NULL) # define CLOCK_DIV sysconf(_SC_CLK_TCK) #endif #if PLATON_SYSTEM_MSDOS || PLATON_SYSTEM_WIN32 # include # include # define CLOCK_FNC clock() # define CLOCK_DIV CLOCKS_PER_SEC #endif #if PLATON_SYSTEM_WIN32 # include # include #endif #if PLATON_SYSTEM_MSDOS # include #endif #include #include #include #include #include #include "data.h" #include "cursors.h" #if PLATON_SYSTEM_MSDOS || PLATON_SYSTEM_WIN32 # define RAND_INT(__lo, __hi) (__lo + random(__hi - __lo + 1)) #endif #if PLATON_SYSTEM_SVGALIB || PLATON_SYSTEM_X11 # define RAND_INT(__lo, __hi) (__lo + (random() % (__hi - __lo + 1))) #endif int brkfnc(void); void koniec(void); void grcprintfxy(WORD x,WORD y,const char*format,...); void draw_picture(BYTE x,BYTE y,BYTE n,void*pic); void downbar(BYTE fillcolor,BYTE fontcolor,BYTE n,BYTE players,BYTE score); WORD mainmenu(void); BYTE move_mouse(WORD *x, WORD *y, WORD setx, WORD sety); void choose_max_field(BYTE computer, BYTE *setx, BYTE *sety, BYTE cardsx[2][32], BYTE cardsy[2][32], BYTE xpic, BYTE ypic); void choose_min_field(BYTE computer, BYTE *setx, BYTE *sety, BYTE cardsx[2][32], BYTE cardsy[2][32], BYTE pex[8][8], BYTE xpic, BYTE ypic); int main(void) { register char c; register WORD k, l; register void *pic; WORD x, y; BYTE pex[8][8],score[MAXPLAYERS],xpic[2],ypic[2]; #if COMPUTER_PLAY /* COMPUTER PLAY DATA */ BYTE computer, played_card = 0xff; BYTE cardsx[2][32]; BYTE cardsy[2][32]; #endif register BYTE go,but,players,chksum; clock_t clck = CLOCK_FNC; gotoxy(1,25); textattr(0x07); for (k=0;k<80;k++) putch('_'); /* putch('Ä'); */ putch('\n'); setcbrk(1); ctrlbrk(brkfnc); atexit(koniec); #if 0 #if PLATON_SYSTEM_MSDOS if (argc>1) { puts(ERR_ARGC); exit(1); } { char exename[]=EXENAME; if (strcmpi(exename,argv[0]+strlen(argv[0])-strlen(exename))) { printf("\n%s %s\n",ERR_EXEC,strupr(exename)); return 1; } } #endif #endif if (!initmouse()) { puts(ERR_MOUSE); return 1; } /* LOADING */ #if 0 void*pic=fileloadfrom(EXENAME,EXESIZE); if (pic==NULL) {puts(ERR_DATFILE);exit(1);} #else pic = (void *) pexeso_data; #endif /* GRAPHICS INITIALIZATION */ #if 0 int gdriver=9,gmode=2,errorcode; if (set_egavga_bgi()!=1) {puts(ERR_WRITE);exit(1);} initgraph(&gdriver,&gmode,""); if ((errorcode=graphresult())!=grOk) {printf("\n%s %s\n",ERR_GRAPH,grapherrormsg(errorcode));exit(1);} remove("eGaVgA.bGI"); #else if (my_graph_init(0) < 0) { return 1; } #endif showmouse(); /* // PROGRAM ///////////////////////////////////////////////////////// */ while (1) { /* Printout playground */ setcolor(WHITE); hidemouse(); for (k=0;k<8;k++) for (l=0;l<8;l++) draw_picture(k,l,0,pic); rectangle(0, 0, getmaxx(), getmaxy()); line(0, getmaxy() - 30, getmaxx(), getmaxy() - 30); showmouse(); /* Main menu call */ if ((k = mainmenu()) == 0xffffU) { break; } #if COMPUTER_PLAY computer=k/0xff; #endif players=k%0xff; #if 0 if (computer) players--; /* TODO: remove me */ #endif xpic[0] = ypic[0] = 0xff; xpic[1] = ypic[1] = 0xff; randomize(); { register BYTE m,n; for (k=0;k<8;k++) for (l=0;l<8;l++) pex[k][l]=0xff; for (k=0;k<32;k++) { while (pex[m=RAND_INT(0,7)][n=RAND_INT(0,7)]!=0xff); pex[m][n] = k; while (pex[m=RAND_INT(0,7)][n=RAND_INT(0,7)]!=0xff); pex[m][n] = k; #if COMPUTER_PLAY if (computer) { cardsx[0][k] = 0xff; cardsy[0][k] = 0xff; cardsx[1][k] = 0xff; cardsy[1][k] = 0xff; } #endif } } go=0; c=0; chksum=0; for (k=0;k .5) { clck = CLOCK_FNC; l = !l; downbar(l ? go + 1 : 0, l ? 0 : go + 9, go, players, score[go]); } if (kbhit()) c = getch(); #if COMPUTER_PLAY /* It's a computer turn! */ /* {{{ */ if (go == players - 1 && computer) { BYTE setx = 0xff; BYTE sety = 0xff; if (computer > COMP_SILLY) { if (played_card != 0xff) { setx = cardsx[1][played_card]; sety = cardsy[1][played_card]; #if 0 if (setx == 0xff && sety == 0xff) { setx = cardsx[0][played_card]; sety = cardsy[0][played_card]; } #else if (setx == 0xff) setx = cardsx[0][played_card]; if (sety == 0xff) sety = cardsy[0][played_card]; #endif if (k == 1 && ((setx == 0xff && sety == 0xff) || (setx == xpic[0] && sety == ypic[0]))) { played_card = 0xff; } } if (played_card == 0xff) { choose_max_field(computer, &setx, &sety, cardsx, cardsy, (k == 1 ? xpic[0] : 0xff), (k == 1 ? ypic[0] : 0xff)); if (setx == 0xff && sety == 0xff) { choose_min_field(computer, &setx, &sety, cardsx, cardsy, pex, (k == 1 ? xpic[0] : 0xff), (k == 1 ? ypic[0] : 0xff)); } } } while (setx == 0xff || sety == 0xff || pex[setx][sety] == 0xff) { if (setx == 0xff) setx = RAND_INT(0, 7); if (sety == 0xff) sety = RAND_INT(0, 7); if (pex[setx][sety] != 0xff) break; switch (RAND_INT(0, 2)) { case 1: setx = 0xff; break; case 2: sety = 0xff; break; default: setx = sety = 0xff; break; } } played_card = pex[setx][sety]; if (played_card == 0xff) { /* Reaching this is not very good... How did we select field to play?! */ but = 0; } else { but = move_mouse(&x, &y, setx, sety); } } #endif /* }}} */ else { but = releasebutton(0, &x, &y); } if (but) { xpic[k]=(x)/80;ypic[k]=(y)/55; if ((x>10+xpic[k]*80)&&(x<10+xpic[k]*80+60)&&(y>10+ypic[k]*55)&&(y<10+ypic[k]*55+40)&&(pex[xpic[k]][ypic[k]]!=0xff)) { if (k==1&&xpic[1]==xpic[0]&&ypic[1]==ypic[0]); else{ hidemouse(); draw_picture(xpic[k], ypic[k], pex[xpic[k]][ypic[k]] + 1, pic); showmouse(); break; } } } } if (c==ESC) break; }/* end of double 'k' for */ if (c == ESC) { continue; } wait(2); #if defined(FORCE_END_SCREEN) && FORCE_END_SCREEN do { register BYTE card1, card2; do { card1 = RAND_INT(1, 64 - chksum); card2 = RAND_INT(1, 64 - chksum); } while (card1 == card2); for (xpic[0]=0;xpic[0]<8 && card1 > 0;xpic[0]++) for (ypic[0]=0;ypic[0]<8 && card1 > 0;ypic[0]++) if (pex[xpic[0]][ypic[0]]!=0xff) card1--; for (xpic[1]=0;xpic[1]<8 && card2 > 0;xpic[1]++) for (ypic[1]=0;ypic[1]<8 && card2 > 0;ypic[1]++) if (pex[xpic[1]][ypic[1]]!=0xff) card2--; xpic[0]--; ypic[0]--; xpic[1]--; ypic[1]--; #endif /* Sussessfull hit */ if (pex[xpic[0]][ypic[0]] == pex[xpic[1]][ypic[1]]) { #if COMPUTER_PLAY /* Erasing computer buffer of revealed card */ { register BYTE card_found = pex[xpic[0]][ypic[0]]; cardsx[0][card_found] = 0xff; cardsy[0][card_found] = 0xff; cardsx[1][card_found] = 0xff; cardsy[1][card_found] = 0xff; played_card = 0xff; } #endif pex[xpic[0]][ypic[0]] = pex[xpic[1]][ypic[1]] = 0xff; score[go]++; chksum++; chksum++; hidemouse(); draw_picture(xpic[0],ypic[0],0xff,pic); draw_picture(xpic[1],ypic[1],0xff,pic); showmouse(); wait(0.1); #if defined(FORCE_END_SCREEN) && FORCE_END_SCREEN } else { go++; if (go >= players) go = 0; } } while (chksum < 64); if (chksum == 64) { /* always true */ #endif if (chksum == 64) { /* END OF GAME */ /* {{{ */ register WORD size; register BYTE maxscore=0; for (k=0;kmaxscore) maxscore=score[k]; size=((getmaxy()-30)-(((getmaxy()-130)/maxscore)*maxscore))/2; hidemouse(); setfillstyle(1,0); bar(1,1,getmaxx()-1,getmaxy()-31); settextstyle(0,0,1); settextjustify(CENTER_TEXT,CENTER_TEXT); setcolor(WHITE); for (k=0;k<=maxscore;k++) grcprintfxy(89,1+size+((getmaxy()-130)/maxscore)*k, "%2u-",maxscore-k); line(100,size,100,(getmaxy()-30)-size-1); for (k=0;kyy) ||(textheight(_winner)>xx)) break; } setcolor(WHITE); settextstyle(0,1,l-1); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(100+(k*xx)+(xx/2),size+(yy/2),_winner); } } cursor_click_enable(); showmouse(); while (!getmousepos(&x,&y)); cursor_click_disable(); hidemouse(); setfillstyle(1,0); bar(1,1,getmaxx()-1,getmaxy()-31); showmouse(); wait(.125); c=ESC; } /* }}} */ } else { /* Hit failure */ /* {{{ */ downbar(go+1,0,go,players,score[go]); hidemouse(); draw_picture(xpic[0],ypic[0],0,pic); draw_picture(xpic[1],ypic[1],0,pic); showmouse(); go++; if (go >= players) go = 0; } /* }}} */ #if COMPUTER_PLAY /* COMPUTER BUFFER RE-LOADING */ /* {{{ */ if (computer > COMP_SILLY) { played_card = 0xff; if (pex[xpic[0]][ypic[0]] != 0xff) { for (k = 0; k < 2; k++) { register int store, card; store = 0; card = pex[xpic[k]][ypic[k]]; if (cardsx[0][card] != 0xff && cardsy[0][card] != 0xff && (cardsx[0][card] != xpic[k] || cardsy[0][card] != ypic[k])) store = 1; switch (computer) { case COMP_SILLY: /* what are you doing here? :) */ store = -store; break; case COMP_POOR: /* remember a little */ store = RAND_INT(0, 5) ? -store : store; break; case COMP_NORMAL: /* remember one half */ store = RAND_INT(0, 1) ? store : -store; break; case COMP_GOOD: /* remember 2/3 */ store = RAND_INT(0, 2) ? store : -store; break; case COMP_GURU: /* remember everything */ store = store; break; } if (store < 0) { switch (RAND_INT(0, 2)) { case 1: cardsx[-store][card] = xpic[k]; break; case 2: cardsy[-store][card] = ypic[k]; break; default: /* forgot everything */ break; } continue; } /* remember everything */ cardsx[store][pex[xpic[k]][ypic[k]]] = xpic[k]; cardsy[store][pex[xpic[k]][ypic[k]]] = ypic[k]; } } } #endif /* }}} */ } } /* my_graph_close(); */ /* REMOVE ME! */ #if 0 free(pic); #endif return 0; } /* MAIN */ /* /////////////////////////////////////////////////////////////////////// */ int brkfnc(void) /* {{{ */ { gotoxy(1,1); return(1); } /* }}} */ void koniec(void) /* {{{ */ { my_graph_close(); fcloseall(); endstring("PEXESO"); #if (LANGUAGE == LANG_ENGLISH) epilogue(); #else randomize(); switch (RAND_INT(0,3)) { case 0: textattr(0x04);cputs("\n\r Full version contains:"); textattr(0x0c);cputs("\n\n\r þ NEW COLORFUL IMAGES\n\r þ INCREDIBLE SOUND EFFECTS\n\r þ MORE POWERFUL COMPUTER PLAY"); textattr(0x04+128);cputs("\n\n\r Please register!\n\r"); break; default: textattr(LIGHTMAGENTA);cputs("\n\r e-mail"); textattr(128+LIGHTMAGENTA);cputs(":"); textattr(WHITE); cputs(" Jombik@pobox.sk"); textattr(LIGHTMAGENTA);cputs("\n\r homepage"); textattr(128+LIGHTMAGENTA);cputs(":"); textattr(WHITE); cputs(" http://Jombik.w3.to"); if (!RAND_INT(0,2)) { textattr(0x02); cputs("\n\n\n\rSo doN'T foRgeT To ViSit ouR inCreDibLe _talker_ "); textattr(WHITE); cputs("telnet://atlantis.sk:7000\n"); } else{ textattr(LIGHTMAGENTA);cputs("\n\r talker"); textattr(128+LIGHTMAGENTA);cputs(":"); textattr(WHITE); cputs(" telnet://atlantis.sk:7000"); } textattr(GREEN);cputs("\n\n\rThis is an "); textattr(LIGHTCYAN);cputs("eXtreme & precizion "); textattr(LIGHTGREEN);cputs("Neptun "); textattr(GREEN);cputs("software production."); textattr(GREEN);cputs("\n\rEspecially thanx 2 "); textattr(LIGHTCYAN);cputs("neverending "); textattr(LIGHTGREEN);cputs("Wolcaan "); textattr(GREEN);cputs("bug reporting."); break; } textattr(0x07);cputs("\n\r"); #endif } /* }}} */ void grcprintfxy(WORD x,WORD y,const char *format,...) /* {{{ */ { char s[255]; va_list ag; va_start(ag,format); vsprintf(s,format,ag); va_end(ag); outtextxy(x,y,s); } /* }}} */ void draw_picture(BYTE x,BYTE y,BYTE n,void*pic) /* {{{ */ { if (n == 0xff) { setfillstyle(1, BLACK); bar(10+x*80,10+y*55,70+x*80,50+y*55); } else { putimage_BGI_cached(10 + x * 80, 10 + y * 55, (BYTE *) pic + n * PICTURE_SIZE, COPY_PUT); } } /* }}} */ void downbar(BYTE fillcolor,BYTE fontcolor,BYTE n,BYTE players,BYTE score) /* {{{ */ { setfillstyle(1,fillcolor); bar(getmaxx()/players*n+1,getmaxy()-29,n==players-1?getmaxx()-1:getmaxx()/players*(n+1),getmaxy()-1); setcolor(fontcolor); settextstyle(0,0,2); settextjustify(CENTER_TEXT,CENTER_TEXT); grcprintfxy(getmaxx()/players*n+((getmaxx()/players)/2),getmaxy()-14,"%u",score); } /* }}} */ WORD mainmenu(void) /* {{{ */ { char*maintxt[]={STR_MAIN,NULL}; char*infotxt[]={STR_INFO,NULL}; char*yesnotxt[]={STR_YESNO,NULL}; char*comptxt[]={STR_COMP,NULL}; static BYTE players=1,computer=0; register int i; register int successfully_allocated = 1, runned_first = 1; register WORD ret = 0; #if PLATON_SYSTEM_SVGALIB || PLATON_SYSTEM_X11 for (i = 0; maintxt[i] != NULL; i++) { if (strchr(maintxt[i], ':') != NULL) { register char *tmp_ptr; if ((tmp_ptr = strdup(maintxt[i])) == NULL) { successfully_allocated = 0; break; } else maintxt[i] = tmp_ptr; } } #endif rangex(196,getmaxx()-199); rangey(149,getmaxy()-185); /* setmousepos(getmaxx()/2,168); */ while (1) { if (ret > 0) { hidemouse(); setfillstyle(1, BLACK); bar(192,145,getmaxx()-194,getmaxy()-180); showmouse(); break; } setcolor(BLACK); setfillstyle(1, DARKGRAY); settextstyle(0,0,1); settextjustify(CENTER_TEXT,CENTER_TEXT); hidemouse(); bar(192,145,getmaxx()-194,getmaxy()-180); rectangle(195,148,getmaxx()-197,getmaxy()-183); setcolor(WHITE); outtextxy(getmaxx() / 2, 165, STR_MENU_TITLE_1); outtextxy(getmaxx() / 2, 175, STR_MENU_TITLE_2); for (i=0;iMAXPLAYERS-(computer==0?1:0)) players=1+(computer!=0?1:0); break; case 2: #if COMPUTER_PLAY computer++; if (computer >= COMPUTERS) computer = 0; if (computer == 1) players++; if (! computer) players--; #endif break; case 3: setcolor(2); setfillstyle(1,DARKGRAY); settextstyle(0,0,1); settextjustify(CENTER_TEXT,CENTER_TEXT); hidemouse(); bar(192,145,getmaxx()-194,getmaxy()-180); rectangle(195,148,getmaxx()-197,getmaxy()-183); showmouse(); if (menu(infotxt,getmaxx()/2,154,0,1,10,2,10)==0xff) ret = 0xffff; break; case 4: setcolor(GREEN); setfillstyle(1,DARKGRAY); hidemouse(); bar(192,145,getmaxx()-194,getmaxy()-180); for (i=0;i<28;i++) rectangle(195+i*3,148+i*2, getmaxx()-197-i*3,getmaxy()-183-i*2); showmouse(); if (!menu(yesnotxt,getmaxx()/2,206,0,2,20,BLACK,LIGHTRED)) ret = 0xffff; break; default: break; }; } #if PLATON_SYSTEM_SVGALIB || PLATON_SYSTEM_X11 if (successfully_allocated) for (i = 0; maintxt[i] != NULL; i++) if (strchr(maintxt[i], ':') != NULL) free(maintxt[i]); #endif return ret; } /* }}} */ BYTE move_mouse(WORD *x, WORD *y, WORD setx, WORD sety) /* {{{ */ { register BYTE i; WORD setmousex, setmousey; setmousex = 40 + setx * 80; setmousey = 30 + sety * 55; (void)getmousepos(x, y); for (i = 0; i <= MOUSE_STEPS; i++) { setmousepos( setmousex > *x ? *x+((double)(setmousex-*x)/MOUSE_STEPS)*i : setmousex + ((double)(*x-setmousex)/MOUSE_STEPS)*(MOUSE_STEPS-i), setmousey > *y ? *y+((double)(setmousey-*y)/MOUSE_STEPS)*i : setmousey + ((double)(*y-setmousey)/MOUSE_STEPS)*(MOUSE_STEPS-i) ); wait(STEPS_DELAY); } setmousepos(setmousex, setmousey); (void)getmousepos(x,y); *x = setmousex; /* just for sure */ *y = setmousey; return 1; } /* }}} */ void choose_max_field(BYTE computer, BYTE *setx, BYTE *sety, /* ...) {{{ */ BYTE cardsx[2][32], BYTE cardsy[2][32], BYTE xpic, BYTE ypic) { register BYTE k, cur_issues = 0, idx = 0; BYTE min_issues = 9, max_issues = 0; BYTE min_card = 0xff, max_card = 0xff, played_card; computer = computer; /* TODO: remove */ for (k = 0; k < 32; k++) { cur_issues = (cardsx[0][k] != 0xff ? 1 : 0) + (cardsy[0][k] != 0xff ? 1 : 0) + (cardsx[1][k] != 0xff ? 3 : 0) + (cardsy[1][k] != 0xff ? 3 : 0); if (cur_issues > max_issues) { max_card = k; max_issues = cur_issues; } if (cur_issues < min_issues) { min_card = k; min_issues = cur_issues; } if (cur_issues == max_issues && ! RAND_INT(0, 2)) max_card = k; if (cur_issues == min_issues && ! RAND_INT(0, 2)) min_card = k; } switch (max_issues) { case 8: idx = 0; played_card = max_card; break; case 7: idx = 0; played_card = max_card; break; case 6: idx = 0; played_card = max_card; break; case 5: idx = 1; played_card = max_card; break; case 4: idx = 0; played_card = max_card; break; default: idx = 0; played_card = min_card; break; } *setx = cardsx[idx][played_card]; *sety = cardsy[idx][played_card]; if (*setx == xpic && *sety == ypic) { *setx = cardsx[idx ? 0 : 1][played_card]; *sety = cardsy[idx ? 0 : 1][played_card]; } if (*setx == xpic && *sety == ypic) { *setx = 0xff; *sety = 0xff; } #if 0 fprintf(stderr, "choose_max_field(): returning [%d, %d] (max_issues=%d)\n", *setx, *sety, max_issues); #endif } /* }}} */ void choose_min_field(BYTE computer, BYTE *setx, BYTE *sety, /* ...) {{{ */ BYTE cardsx[2][32], BYTE cardsy[2][32], BYTE pex[8][8], BYTE xpic, BYTE ypic) { register int k2, l2, i2; BYTE curref, minref = 0xff; for (l2 = 0; l2 < 8; l2++) { for (k2 = 0; k2 < 8; k2++) { if (pex[k2][l2] == 0xff) continue; curref = 0; for (i2 = 0; i2 < 32; i2++) { if (cardsx[0][i2] == k2 && cardsy[0][i2] == l2) curref++; if (cardsx[1][i2] == k2 && cardsy[1][i2] == l2) curref++; } if (curref > minref) continue; if (curref == minref) { if (computer == COMP_GURU) continue; if (RAND_INT(0, 60)) continue; } /* Potencial field */ if (k2 == xpic && l2 == ypic) { } else { *setx = k2; *sety = l2; minref = curref; } } } #if 0 fprintf(stderr, "choose_min_field(): returning [%d, %d]\n", *setx, *sety); #endif } /* }}} */ /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=0: * }}} */