//starting of tic tac toe void play_tic_tac_toe() { int won=0; int i; for(i=0;i<9;i++) { //printf("%d",i); if(i%2==0) { if(i==0) { int row=rand()%3; int col=rand()%3; board[row][col]='C'; } else{ //printf("!!!!"); bot_play();} printf("\nAfter Bot Play\n"); display_board(); } else { player_play(); } won=check_if_win(); //printf("\n\n %d %c\n\n",won,win_char); if(won==1) { if(win_char=='0') { printf("\nPlayer Win!!!"); return; } else if(win_char=='C') { printf("\nBot Wins\nYou Loose!"); return; } } } if(i==9) { printf("\nMATCH DRAW"); } }
int main(int n, char *cmd[]) { int c, m, i; int dx, dy; telnet_init(); if (map_init() == 0) printf("map.dat error\n"); if (n >= 2) { char buf[40]; strsncpy(userid, cmd[1], sizeof (userid)); readuservalue(userid, "worker.laststage", buf, sizeof (buf)); lastMaxStage = atoi(buf); if (lastMaxStage >= map_total) lastMaxStage = map_total - 1; stage = lastMaxStage; } if (n >= 3) strsncpy(fromhost, cmd[2], sizeof (fromhost)); if (stage == 0) { clear(); printf("»¶Ó¹âÁÙ[1;32mÍÆÏä×Ó[mÓÎÏ·¡£\r\n"); printf ("¹æÔòºÜ¼òµ¥£¬Ö»Ðè°ÑËùÓеÄ'¡õ'¶¼ÍƵ½'¡¤'ÉÏÃæÈ¥(»á±ä³ÉÂÌÉ«)¾Í¹ý¹ØÁË¡£\r\n"); printf("µ«ÍæÆðÀ´ÄѶȿÉÊÇÏ൱´óµÄ£¬²»ÒªÇáÊÓม£\r\n"); pressanykey(); goto start; } win_showrec(); clear(); printf("ÇëÓ÷½Ïò¼üÑ¡¹Ø, »Ø³µ¼üÈ·ÈÏ: %d ", stage); move(0, 14); while (1) { c = inkey(); if ((c == KEY_LEFT || c == KEY_UP) && stage > 0) stage--; if ((c == KEY_RIGHT || c == KEY_DOWN) && stage < lastMaxStage) stage++; if (c == 10 || c == 13) break; if (c == 3 || c == 4 || c == 32) quit(); move(0, 14); printf("%d ", stage); move(0, 14); } start: if (stage < 0 || stage >= map_total) stage = 0; clear(); printf("ÍÆÏä×Ó: µÚ [1;32m%d[m ¹Ø:\033[m", stage); move(20, 0); refresh(); sleep(1); start2: for (n = 0; n < 20; n++) for (m = 0; m < 30; m++) map_now[n][m] = map_data[stage][n][m]; if (!find_y_x(&now_y, &now_x)) printf("stage error\n"); map_show(); bzero(&my_history, sizeof (my_history)); while (1) { c = inkey(); if (my_history.max >= 1999) { move(21, 0); printf("ÄãÓÃÁË2000²½»¹Ã»Óйý¹Ø! GAME OVER."); quit(); } dx = 0; dy = 0; if (c == 8 && my_history.max > 0) { my_history.max--; i = my_history.max; map_move(my_history.y1[i], my_history.x1[i], my_history.y0[i], my_history.x0[i]); find_y_x(&now_y, &now_x); move(now_y, now_x); continue; } if (c == ' ') quit(); if (c == '') map_show(); if (c == 9) goto start2; if (c == KEY_UP) dy = -1; if (c == KEY_DOWN) dy = 1; if (c == KEY_LEFT) dx = -1; if (c == KEY_RIGHT) dx = 1; if (dx == 0 && dy == 0) continue; if (map_now[now_y + dy][now_x + dx] & 4) if (map_now[now_y + dy * 2][now_x + dx * 2] < 2) { map_move(now_y + dy, now_x + dx, now_y + dy * 2, now_x + dx * 2); i = my_history.max; my_history.y0[i] = now_y + dy; my_history.x0[i] = now_x + dx; my_history.y1[i] = now_y + dy * 2; my_history.x1[i] = now_x + dx * 2; my_history.max++; } if (map_now[now_y + dy][now_x + dx] < 2) { map_move(now_y, now_x, now_y + dy, now_x + dx); i = my_history.max; my_history.y0[i] = now_y; my_history.x0[i] = now_x; my_history.y1[i] = now_y + dy; my_history.x1[i] = now_x + dx; my_history.max++; } if (check_if_win()) break; find_y_x(&now_y, &now_x); move(now_y, now_x); } move(19, 0); printf("×£ºØÄã, Äã³É¹¦ÁË£¡"); steps = my_history.max; win_checkrec(); stage++; if (stage > lastMaxStage) { lastMaxStage = stage; if (strcmp(userid, "null.")) { char buf[30]; sprintf(buf, "%d", lastMaxStage); saveuservalue(userid, "worker.laststage", buf); } } goto start; }