void main() { int i; clrscr(); puts(" This program is to execute Bit Shift Operation."); puts(" >> Now reading datas from file......Succeeded!"); puts(" >> Calculating......Completed!"); puts(" >> Results are:"); for(i=0;i<MAXNUM;i++) xx[i]=0; if(readdat()) { printf(" Can't open the data file in188.dat!\007\n"); return; } calvalue(); printf(" >> The total number of data in the file is %d.\n",totnum); printf(" >> The even number of data after bit shift is %d.\n",totcnt); printf(" >> The variance of these even numbers is %.2lf\n",totpjz); writedat(); PressKeyToQuit(); }
int five_pk(int fd,int first) { int cx, ch, cy,datac,fdone,x /* ,y */; char genbuf[100],data[90],xy_po[5],genbuf1[20] /* ,x1[1],y1[1],done[1] */; /* struct user_info *opponent; */ /* char fname[50]; */ int i,j /* ,k */,fway,banf,idone; /* * Ôö¼ÓÁÄÌ칦ÄÜ. Added by satan. 99.04.02 */ #define START 17 #define END 21 #define PROMPT 23 #undef MAX #define MAX (END - START) #define BSIZE 60 char chatbuf[80], *cbuf; int ptr = 0, chating = 0 /*, over = 0 */; setutmpmode(FIVE); /*Óû§×´Ì¬ÉèÖÃ*/ clear (); InitScreen(); five_chat (NULL, 1); cbuf = chatbuf + 19; chatbuf[0] = '\0'; chatbuf[79] = '\0'; cbuf[0] = '\0'; sprintf (chatbuf + 1, "%-16s: ", cuser.username); add_io(fd, 0); begin: for(i=0; i<=14; i++) for(j=0; j<=14; j++) playboard[i][j]=0; hand=1; winner=0; quitf=0; px=14; py=7; fway = 1; banf = 1; idone = 0; sprintf(genbuf, "%s (%s)", cuser.userid, cuser.username); if(first) { move(1,33); prints("ºÚ¡ñÏÈÊÖ %s ",genbuf); move(2,33); prints("°×¡ðºóÊÖ %s ",save_page_requestor); } else { move(1,33); prints("°×¡ðºóÊÖ %s ",genbuf); move(2,33); prints("ºÚ¡ñÏÈÊÖ %s ",save_page_requestor); } move(15,35); if(first) outs("¡ïµÈ´ý¶Ô·½ÏÂ×Ó¡ï"); else outs("¡ôÏÖÔÚ¸Ã×Ô¼ºÏ¡ô"); move(7,14); outs("¡ñ"); player=white; playboard[7][7]=black; chess[1][0]=14; /*¼Í¼ËùÏÂλַ*/ chess[1][1]=7; move(4,35); outs("µÚ 1ÊÖ ¡ñH 8"); if(!first) { /*³¬¹Ö!*/ move (7, 14); fdone=1; } else fdone=0; /*¶ÔÊÖÍê³É*/ while (1) { ch=igetkey(); if (ch == I_OTHERDATA) { datac = recv(fd, data, sizeof(data), 0); if (datac <= 0) { move(17,30); outs("[47m[31;47m ¶Ô·½Í¶½µÁË...@_@ [m"); break; } if (data[0] == '\0') { five_chat (data + 1, 0); if (chating) move (PROMPT, ptr + 6); else move (py, px); continue; } else if (data[0] == '\1') { bell (); RMSG = YEA; saveline (PROMPT, 0); sprintf (genbuf, "%s ˵: ÖØÀ´Ò»Å̺ÃÂð? (Y/N)[Y]:", save_page_requestor); getdata (PROMPT, 0, genbuf, genbuf1, 2, LCECHO, YEA); RMSG = NA; if (genbuf1[0] == 'n' || genbuf1[0] == 'N') { saveline (PROMPT, 1); send (fd, "\3", 1, 0); continue; } else { saveline (PROMPT, 1); InitScreen (); first = 0; send (fd, "\2", 1, 0); goto begin; } } else if (data[0] == '\2') { bell (); saveline (PROMPT, 0); move (PROMPT, 0); clrtoeol (); prints ("%s ½ÓÊÜÁËÄãµÄÇëÇó :-)", save_page_requestor); refresh (); sleep (1); saveline (PROMPT, 1); InitScreen (); first = 1; goto begin; } else if (data[0] == '\3') { bell (); saveline (PROMPT, 0); move (PROMPT, 0); clrtoeol (); prints ("%s ¾Ü¾øÁËÄãµÄÇëÇó :-(", save_page_requestor); refresh (); sleep (1); saveline (PROMPT, 1); if (chating) move (PROMPT, ptr + 6); else move (py, px); continue; } else if (data[0] == '\xff') { move (PROMPT, 0); quit (); break; } i=atoi(data); cx=i/1000; /*½âÒëdata³ÉÆåÅÌ×ÊÁÏ*/ cy=(i%1000)/10; fdone=i%10; hand+=1; if(hand%2==0) move(((hand-1)%20)/2+4,48); else move(((hand-1)%19)/2+4,35); prints("µÚ%2dÊÖ %s%c%2d",hand, (player==black)?"¡ñ":"¡ð",abcd[cx/2],15-cy); move(cy,cx); x=cx/2; playboard[x][cy]=player; if(player==black) { outs("¡ñ"); player=white; } else { outs("¡ð"); player=black; } move (cy, cx); refresh (); bell (); move(15,35); outs("¡ôÏÖÔÚ¸Ã×Ô¼ºÏ¡ô"); haha (5); tdeadf=tlivef=livethree=threefour=0; for(j=0; j<=10; j++) calvalue(cx/2,j,cx/2,j+1,cx/2,j+2,cx/2,j+3,cx/2,j+4); for(i=0; i<=10; i++) /*ºáÏò*/ calvalue(i,cy,i+1,cy,i+2,cy,i+3,cy,i+4,cy); for(i=-4; i<=0; i++) /*бÓÒÏÂ*/ calvalue(cx/2+i,cy+i,cx/2+i+1,cy+i+1,cx/2+i+2,cy+i+2, cx/2+i+3,cy+i+3,cx/2+i+4,cy+i+4); for(i=-4; i<=0; i++) /*б×óÏÂ*/ calvalue(cx/2-i,cy+i,cx/2-i-1,cy+i+1,cx/2-i-2,cy+i+2,cx/2-i-3, cy+i+3,cx/2-i-4,cy+i+4); for(j=0; j<=9; j++) callfour(cx/2,j,cx/2,j+1,cx/2,j+2,cx/2,j+3,cx/2,j+4,cx/2,j+5); for(i=0; i<=9; i++) /*ËĺáÏò*/ callfour(i,cy,i+1,cy,i+2,cy,i+3,cy,i+4,cy,i+5,cy); for(i=-5; i<=0; i++) { /*ËÄбÓÒÏÂ*/ callfour(cx/2+i,cy+i,cx/2+i+1,cy+i+1,cx/2+i+2,cy+i+2, cx/2+i+3,cy+i+3,cx/2+i+4,cy+i+4,cx/2+i+5,cy+i+5); /*ËÄб×óÏÂ*/ callfour(cx/2-i,cy+i,cx/2-i-1,cy+i+1,cx/2-i-2,cy+i+2,cx/2-i-3, cy+i+3,cx/2-i-4,cy+i+4,cx/2-i-5,cy+i+5); } py = cy; px = cx; if(tlivef>=2 && winner==0) bandhand(4); if(livethree>=2 && tlivef ==0) bandhand(3); if(threefour==black) haha(1); else if(threefour==white) haha(1); if (chating) { sleep (1); move (PROMPT, ptr + 6); } else move (py, px); if (winner) { InitScreen (); goto begin; } } else { if (ch == Ctrl('X')) { quitf = 1; } else if (ch==Ctrl('C') || ((ch=='Q' || ch=='q') && !chating)) { RMSG = YEA; saveline (PROMPT, 0); getdata(PROMPT, 0, "ÄúÈ·¶¨ÒªÀ뿪Âð? (Y/N)?[N] ", genbuf1, 2, LCECHO, YEA); if (genbuf1[0] == 'Y' || genbuf1[0] == 'y') quitf = 1; else quitf = 0; saveline (PROMPT, 1); RMSG = NA; } else if (ch==Ctrl('N') || ((ch=='N' || ch=='n') && !chating)) { saveline (PROMPT, 0); RMSG = YEA; getdata(PROMPT,0,"ÄúÈ·¶¨ÒªÖØпªÊ¼Âð? (Y/N)?[N] ",genbuf1,2,LCECHO, YEA); if (genbuf1[0] == 'Y' || genbuf1[0] == 'y') { send (fd, "\1", 1, 0); move (PROMPT, 0); bell (); clrtoeol (); move (PROMPT, 0); outs ("ÒѾÒѾÌæÄú·¢³öÇëÇóÁË"); refresh (); sleep (1); } RMSG = NA; saveline (PROMPT, 1); if (chating) move (PROMPT, ptr + 6); else move (py, px); continue; } else if (ch == '\t') { if (chating) { chating = 0; move (py, px); } else { chating = 1; move (PROMPT, 6 + ptr); } continue; } else if (ch == '\0') continue; else if (chating) { if (ch == '\n' || ch == '\r') { if (!cbuf[0]) continue; ptr = 0; five_chat (chatbuf + 1, 0); send (fd, chatbuf, strlen (chatbuf + 1) + 2, 0); cbuf[0] = '\0'; move (PROMPT, 6); clrtoeol (); } else if (ch == KEY_LEFT) { if (ptr) ptr --; } else if (ch == KEY_RIGHT) { if (cbuf[ptr]) ptr ++; } else if (ch == Ctrl ('H') || ch == '\177') { if (ptr) { ptr --; memcpy (&cbuf[ptr], &cbuf[ptr+1], BSIZE-ptr); move (PROMPT, ptr+6); clrtoeol (); prints ("%s",&cbuf[ptr]); } } else if (ch == KEY_DEL) { if (cbuf[ptr]) { memcpy (&cbuf[ptr], &cbuf[ptr+1], BSIZE-ptr); clrtoeol (); prints ("%s",&cbuf[ptr]); } } else if (ch == Ctrl ('A')) { ptr = 0; } else if (ch == Ctrl ('E')) { while (cbuf[++ptr]) ; } else if (ch == Ctrl ('K')) { ptr = 0; cbuf[ptr] = '\0'; move (PROMPT, ptr+6); clrtoeol (); } else if (ch == Ctrl ('U')) { memmove (cbuf, &cbuf[ptr], BSIZE - ptr + 1); ptr = 0; move (PROMPT, ptr+6); clrtoeol (); prints ("%s",cbuf); } else if (ch == Ctrl ('W')) { if (ptr) { int optr; optr = ptr; ptr --; do { if (cbuf[ptr] != ' ') break; } while (-- ptr); do { if (cbuf[ptr] == ' ') { if (cbuf[ptr+1] != ' ') ptr ++; break; } } while (-- ptr); memcpy (&cbuf[ptr], &cbuf[optr], BSIZE-optr+1); move (PROMPT, ptr+6); clrtoeol (); prints ("%s",&cbuf[ptr]); } } else if (isprint2 (ch)) { if (ptr == BSIZE) continue; if (!cbuf[ptr]) { cbuf[ptr] = ch; move (PROMPT, 6 + ptr); outc (ch); cbuf[++ptr] = 0; } else { memmove (&cbuf[ptr+1], &cbuf[ptr], BSIZE-ptr+1); cbuf[ptr] = ch; move (PROMPT, 6 + ptr); prints ("%s",&cbuf[ptr]); ptr ++; } } move (PROMPT, 6 + ptr); continue; } } if(fdone==1 && !chating && ch != I_OTHERDATA)/*»»ÎÒ*/ { move(py,px); switch (ch) { case KEY_DOWN: case 'j': case 'J': py=py+1; if(py>14) py=0; break; case KEY_UP: case 'k': case 'K': py=py-1; if(py<0) py=14; break; case KEY_LEFT: case 'h': case 'H': px=px-1; if(px<0) px=28; break; case KEY_RIGHT: case 'l': case 'L': px=px+1; if(px>28) { px=0; px=px-1; } /*»áÌø¸ñßÖ*/ break; case ' ': if(banf==1) break; if((px%2)==1) px=px-1; /*½â¾önetterm²»ºÏÎÊÌâ*/ move(py,px); hand+=1; playboard[x][py]=player; if(player==black) { outs("¡ñ"); player=white; } else { outs("¡ð"); player=black; } chess[hand][0]=px; chess[hand][1]=py; if(hand%2==0) move(((hand-1)%20)/2+4,48); else move(((hand-1)%19)/2+4,35); prints("µÚ%2dÊÖ %s%c%2d",hand, (hand%2==1)?"¡ñ":"¡ð",abcd[px/2],15-py); idone=1; move (py, px); refresh (); break; default: break; } move(py,px); x=px/2; if(playboard[x][py]!=0) banf=1; else banf=0; if(idone==1) { xy_po[0] = px/10 + '0'; xy_po[1] = px%10 + '0'; xy_po[2] = py/10 + '0'; xy_po[3] = py%10 + '0'; fdone=0; xy_po[4]='1'; if(send(fd,xy_po,sizeof(xy_po),0)==-1) break; move(15,35); outs("¡ïµÈ´ý¶Ô·½ÏÂ×Ó¡ï"); haha (5); tdeadf=tlivef=livethree=threefour=0; for(j=0; j<=10; j++) calvalue(px/2,j,px/2,j+1,px/2,j+2,px/2,j+3,px/2,j+4); for(i=0; i<=10; i++) /*ºáÏò*/ calvalue(i,py,i+1,py,i+2,py,i+3,py,i+4,py); for(i=-4; i<=0; i++) /*бÓÒÏÂ*/ calvalue(px/2+i,py+i,px/2+i+1,py+i+1,px/2+i+2,py+i+2, px/2+i+3,py+i+3,px/2+i+4,py+i+4); for(i=-4; i<=0; i++) /*б×óÏÂ*/ calvalue(px/2-i,py+i,px/2-i-1,py+i+1,px/2-i-2,py+i+2,px/2-i-3, py+i+3,px/2-i-4,py+i+4); for(j=0; j<=9; j++) callfour(px/2,j,px/2,j+1,px/2,j+2,px/2,j+3,px/2,j+4,px/2,j+5); for(i=0; i<=9; i++) /*ËĺáÏò*/ callfour(i,py,i+1,py,i+2,py,i+3,py,i+4,py,i+5,py); for(i=-5; i<=0; i++) { /*ËÄбÓÒÏÂ*/ callfour(px/2+i,py+i,px/2+i+1,py+i+1,px/2+i+2,py+i+2, px/2+i+3,py+i+3,px/2+i+4,py+i+4,px/2+i+5,py+i+5); /*ËÄб×óÏÂ*/ callfour(px/2-i,py+i,px/2-i-1,py+i+1,px/2-i-2,py+i+2,px/2-i-3, py+i+3,px/2-i-4,py+i+4,px/2-i-5,py+i+5); } if(tlivef>=2 && winner==0) bandhand(4); if(livethree>=2 && tlivef ==0) bandhand(3); if(threefour==black) haha(1); else if(threefour==white) haha(1); } idone=0; } if (quitf) { genbuf1[0] = '\xff'; send (fd, genbuf1, 1, 0); press (); break; } if (winner) { InitScreen (); goto begin; } } add_io(0, 0); close(fd); return; }