int main(int argc, const char * argv[]) { char* input = (char*)malloc(sizeof(char) * 10); char** gameboard = newboard(); int gameplayer = 1; if (argc == 2) { if (load(gameboard, argv[1], &gameplayer)) printf("Hra byla uspesne nactena.\n"); } if (colors == 0) { printf("Chcete zapnout barvy? (jen pro Unix)\n> "); scanf("%s", input); if (strcmp(input, "ano") == 0) colors = 1; } while (1) { printboard(gameboard); printf("Na rade je hrac %i (%s)\n", gameplayer, (gameplayer - 1) ? "kolecka" : "krizky"); printf("> "); scanf("%s", input); if (strcmp(input, "konec") == 0) { printf("Konec hry.\n"); break; } else if (strcmp(input, "uloz") == 0) { if (save(gameboard, "piskvorky.txt", gameplayer)) { printf("Hra byla uspesne ulozena. Konec hry.\n"); break; } } else if (strcmp(input, "novy") == 0) { gameboard = newboard(); gameplayer = 1; printf("\nVitej v nove hre.\n"); } else if (strcmp(input, "?") == 0) printf("Napoveda:\n \"a1\" az \"c3\" pro zadavani souradnic\n \"novy\" pro novou hru\n \"konec\" pro ukonceni hry\n \"uloz\" pro ulozeni hry\n"); else if (turn(gameboard, input, gameplayer)) { if (win(gameboard, gameplayer)) { printboard(gameboard); printf("Vyhral hrac %i (%s). Konec hry.\n", gameplayer, (gameplayer - 1) ? "kolecka" : "krizky"); break; } else if (full(gameboard)) { printf("Remiza, vsechny policka jsou zaplneny. Konec hry.\n"); break; } gameplayer = (gameplayer == 1) ? 2 : 1; } } return 0; }
//Test if the piece/square is threatened after a simulated move //NOTE: The threatened status should be checked after the move, as pawn moves depend on // what is surrounding them. That's why both start and destination are needed by the function bool isThreatenedAfter(const std::vector<int>& board, int start, int destination){ std::vector<int> newboard(board); //Simulate the move //NOTE: it's possible that start==destination, // so the start must be emptied first! // Otherwise, the destination would be empty when start==dest newboard[start] = 0; newboard[destination] = board[start]; std::pair<int,int> dummyMove = std::make_pair(0, 0); std::vector<int> testvector; //Check possible moves of all pieces for (unsigned int i=0; i < newboard.size(); i++) { //Do not check "none" pieces (empty square) and friendly pieces if (newboard[i] != 0 && newboard[i]%2 != newboard[destination]%2 ) { //NOTE: 1) Do not take the forward move of pawns into accout, it cannot capture or check // 2) En passant is not needed, dummy move can be used. if (newboard[i]==W_PAWN) { testvector = whitePawnMoveForwardLeft(newboard, i, dummyMove); testvector = join(testvector, whitePawnMoveForwardRight(newboard, i, dummyMove) ); } else if (newboard[i]==B_PAWN) { testvector = blackPawnMoveForwardLeft(newboard, i, dummyMove); testvector = join(testvector, blackPawnMoveForwardRight(newboard, i, dummyMove) ); } else if (newboard[i]==W_KNIGHT || newboard[i]==B_KNIGHT) testvector = knightMove(newboard, i); else if (newboard[i]==W_ROOK || newboard[i]==B_ROOK) testvector = rookMove(newboard, i); else if (newboard[i]==W_BISHOP || newboard[i]==B_BISHOP) testvector = bishopMove(newboard, i); else if (newboard[i]==W_QUEEN || newboard[i]==B_QUEEN) testvector = queenMove(newboard, i); //NOTE: Be careful with kings and don't end up in infinite recursion... else if (newboard[i]==W_KING || newboard[i]==B_KING) testvector = kingMove(newboard, i, false); //NOTE the 3rd argument } //The destination is a possible move of one of the enemy pieces // -> the moving piece will be under attack if ( std::find(testvector.begin(), testvector.end(), destination) != testvector.end() ) return true; } return false; }
newwave() { register monster *mptr; addscore(FLUSHSCORE); Wave++; mvprintf(WAVEROW,WAVECOL+10,"%D",Wave); if ( Wave&1 ) { for ( mptr=Monster ; mptr < &Monster[MAXMONSTER] ; mptr++ ) if ( mptr->time > MINMONTIME ) mptr->time = max(mptr->time-MONDELTA,MINMONTIME); if ( Pacman.time > MINPACTIME ) Pacman.time = max(Pacman.time-PACDELTA,MINPACTIME); } newboard(); drawboard(); Dotsrem = DOTS; Seekprob += Seekinc; elinit(); pacinit(); moninit(); fruitinit(TRUE); }
int CBwfind::findlast(int tb[][8], int &step, int &flag, int cut) { int value=0,max=-100000,min=100000,k=0,i,j; int temp[8][8]; if(step==64){ if(ComChoice==1) return(black(tb)-white(tb)); else return(white(tb)-black(tb)); } for(i=0;i<8;i++)for(j=0;j<8;j++) temp[i][j]=tb[i][j]; for(i=0;i<8;i++)for(j=0;j<8;j++){ if(judge(tb,i,j,flag)){ int ii,jj; k=1;//存在合理的步子 newboard(tb,i,j,flag); flag=-flag; step++; if(-flag==ComChoice){ value=findlast(tb,step,flag,max); } if(-flag==ManChoice){ value=findlast(tb,step,flag,min); } step--; flag=-flag; //恢复棋盘 for(ii=0;ii<8;ii++)for(jj=0;jj<8;jj++) tb[ii][jj]=temp[ii][jj]; if(flag-ManChoice==0&&value<cut) return value; if(flag-ComChoice==0&&value>cut) return value; if(flag-ManChoice==0){ if(value<min){ min=value; } } if(flag-ComChoice==0){ if(value>max){ max=value; if(step==CountNum()){ stepx=i; stepy=j; } } } }//if }//for //当前没有步可走 if(k==0){ flag=-flag; if(search(tb,flag)){ value=findlast(tb,step,flag,cut); flag=-flag; return value; } else{ flag=-flag; if(ComChoice==1) return(black(tb)-white(tb)); else return(white(tb)-black(tb)); } } //存在合理步 else{ if(flag-ManChoice==0) return min; if(flag-ComChoice==0){ return max; } } }
int CBwfind::findfirst(int tb[][8] , int &step, int &flag, int cut) { int value=0,max=-100000,min=100000,k=0,i,j; int temp[8][8]; if(step==depth){ return valuefirst(tb); } for(i=0;i<8;i++)for(j=0;j<8;j++) temp[i][j]=tb[i][j]; for(i=0;i<8;i++)for(j=0;j<8;j++){ if(judge(tb,i,j,flag)){ int ii,jj; value=0; k=1;//存在合理的步子 newboard(tb,i,j,flag); flag=-flag; step++; if(-flag==ComChoice){ LineSense(tb,i,j,value); Corner(tb,i,j,value); value+=findfirst(tb,step,flag,max); } if(-flag==ManChoice){ Corner(tb,i,j,value); LineSense(tb,i,j,value); value+=findfirst(tb,step,flag,min); } step--; flag=-flag; //恢复棋盘 for(ii=0;ii<8;ii++) for(jj=0;jj<8;jj++) tb[ii][jj]=temp[ii][jj]; if(flag-ManChoice==0&&value<cut) return value; if(flag-ComChoice==0&&value>cut) return value; if(flag-ManChoice==0){ if(value<min){ min=value; } } if(flag-ComChoice==0){ if(value>max){ max=value; if(step==0){ stepx=i; stepy=j; } } } }//if }//for //当前没有步可走 if(k==0){ flag=-flag; if(search(tb,flag)){ value=findfirst(tb,step,flag,cut); flag=-flag; return value; } else{ flag=-flag; return valuefirst(tb); } } //存在合理步 else{ if(flag-ManChoice==0) return min; else if(flag-ComChoice==0){ //if return max; }//if }//else }
int main(int ac, char *av[]) { bool restore; /* Revoke setgid privileges */ setgid(getgid()); if (strcmp(av[0], "a.out") == 0) { outf = fopen("q", "w"); setbuf(outf, NULL); Debug = TRUE; } restore = FALSE; switch (ac) { case 2: rest_f(av[1]); restore = TRUE; case 1: break; default: usage(); /* NOTREACHED */ } Play = PLAYER; initscr(); delwin(stdscr); stdscr = Board = newwin(BOARD_Y, BOARD_X, 0, 0); Score = newwin(SCORE_Y, SCORE_X, 0, 40); Miles = newwin(MILES_Y, MILES_X, 17, 0); #ifdef attron idlok(Board, TRUE); idlok(Score, TRUE); idlok(Miles, TRUE); #endif leaveok(Score, TRUE); leaveok(Miles, TRUE); clearok(curscr, TRUE); srandomdev(); cbreak(); noecho(); signal(SIGINT, rub); for (;;) { if (!restore || (Player[PLAYER].total >= 5000 || Player[COMP].total >= 5000)) { if (Player[COMP].total < Player[PLAYER].total) Player[PLAYER].games++; else if (Player[COMP].total > Player[PLAYER].total) Player[COMP].games++; Player[COMP].total = 0; Player[PLAYER].total = 0; } do { if (!restore) Handstart = Play = other(Handstart); if (!restore || On_exit) { shuffle(); init(); } newboard(); if (restore) mvwaddstr(Score, ERR_Y, ERR_X, Initstr); prboard(); do { domove(); if (Finished) newscore(); prboard(); } while (!Finished); check_more(); restore = On_exit = FALSE; } while (Player[COMP].total < 5000 && Player[PLAYER].total < 5000); } }
static void initBoards() { FILE *fp = fopen(".BRD", "w"); boardheader_t b; if(fp) { memset(&b, 0, sizeof(b)); strcpy(b.brdname, "SYSOP"); strcpy(b.title, "嘰哩 ◎站長好!"); b.brdattr = BRD_POSTMASK | BRD_NOTRAN; b.level = 0; b.gid = 2; newboard(fp, &b); strcpy(b.brdname, "1..........."); strcpy(b.title, ".... Σ中央政府 《高壓危險,非人可敵》"); b.brdattr = BRD_GROUPBOARD; b.level = PERM_SYSOP; b.gid = 1; newboard(fp, &b); strcpy(b.brdname, "junk"); strcpy(b.title, "發電 ◎雜七雜八的垃圾"); b.brdattr = BRD_NOTRAN; b.level = PERM_SYSOP; b.gid = 2; newboard(fp, &b); strcpy(b.brdname, "Security"); strcpy(b.title, "發電 ◎站內系統安全"); b.brdattr = BRD_NOTRAN; b.level = PERM_SYSOP; b.gid = 2; newboard(fp, &b); strcpy(b.brdname, "2..........."); strcpy(b.title, ".... Σ市民廣場 報告 站長 ㄜ!"); b.brdattr = BRD_GROUPBOARD; b.level = 0; b.gid = 1; newboard(fp, &b); strcpy(b.brdname, BN_ALLPOST); strcpy(b.title, "嘰哩 ◎跨板式LOCAL新文章"); b.brdattr = BRD_POSTMASK | BRD_NOTRAN; b.level = PERM_SYSOP; b.gid = 5; newboard(fp, &b); strcpy(b.brdname, "deleted"); strcpy(b.title, "嘰哩 ◎資源回收筒"); b.brdattr = BRD_NOTRAN; b.level = PERM_BM; b.gid = 5; newboard(fp, &b); strcpy(b.brdname, "Note"); strcpy(b.title, "嘰哩 ◎動態看板及歌曲投稿"); b.brdattr = BRD_NOTRAN; b.level = 0; b.gid = 5; newboard(fp, &b); strcpy(b.brdname, "Record"); strcpy(b.title, "嘰哩 ◎我們的成果"); b.brdattr = BRD_NOTRAN | BRD_POSTMASK; b.level = 0; b.gid = 5; newboard(fp, &b); strcpy(b.brdname, "WhoAmI"); strcpy(b.title, "嘰哩 ◎呵呵,猜猜我是誰!"); b.brdattr = BRD_NOTRAN; b.level = 0; b.gid = 5; newboard(fp, &b); strcpy(b.brdname, "EditExp"); strcpy(b.title, "嘰哩 ◎範本精靈投稿區"); b.brdattr = BRD_NOTRAN; b.level = 0; b.gid = 5; newboard(fp, &b); strcpy(b.brdname, "ALLHIDPOST"); strcpy(b.title, "嘰哩 ◎跨板式LOCAL新文章(隱板)"); b.brdattr = BRD_POSTMASK | BRD_HIDE; b.level = PERM_SYSOP; b.gid = 5; newboard(fp, &b); #ifdef BN_DIGEST strcpy(b.brdname, BN_DIGEST); strcpy(b.title, "文摘 ◎" BBSNAME "文摘 好文的收集地"); b.brdattr = BRD_NOTRAN | BRD_POSTMASK; b.level = PERM_SYSOP; b.gid = 5; newboard(fp, &b); #endif #ifdef BN_FIVECHESS_LOG strcpy(b.brdname, BN_FIVECHESS_LOG); strcpy(b.title, "棋藝 ◎" BBSNAME "五子棋譜 站上對局全紀錄"); b.brdattr = BRD_NOTRAN | BRD_POSTMASK; b.level = PERM_SYSOP; b.gid = 5; newboard(fp, &b); #endif fclose(fp); } }