Esempio n. 1
0
/*
 * dble()
 *	Have the current player double and ask opponent to accept.
 */
void
dble ()
{
	register int	resp;			/* response to y/n */

	for (;;)  {
		writel (" doubles.");		/* indicate double */

		if (cturn == -pnum)  {		/* see if computer accepts */
			if (dblgood())  {	    /* guess not */
				writel ("  Declined.\n");
				nexturn();
				cturn *= -2;	    /* indicate loss */
				return;
			} else  {		    /* computer accepts */
				writel ("  Accepted.\n");
				gvalue *= 2;	    /* double game value */
				dlast = cturn;
				if (tflag)
					gwrite();
				return;
			}
		}

						/* ask if player accepts */
		writel ("  Does ");
		writel (cturn == 1? color[2]: color[3]);
		writel (" accept?");

						/* get response from yorn,
						 * a "2" means he said "p"
						 * for print board. */
		if ((resp = yorn ('R')) == 2)  {
			writel ("  Reprint.\n");
			buflush();
			wrboard();
			writel (*Colorptr);
			continue;
		}

						/* check response */
		if (resp)  {
						    /* accepted */
			gvalue *= 2;
			dlast = cturn;
			if (tflag)
				gwrite();
			return;
		}

		nexturn ();			/* declined */
		cturn *= -2;
		return;
	}
}
Esempio n. 2
0
void
dble()
{
	int     resp;		/* response to y/n */

	for (;;) {
		addstr(" doubles.");	/* indicate double */

		if (cturn == -pnum) {	/* see if computer accepts */
			if (dblgood()) {	/* guess not */
				addstr("  Declined.\n");
				nexturn();
				cturn *= -2;	/* indicate loss */
				return;
			} else {/* computer accepts */
				addstr("  Accepted.\n");
				gvalue *= 2;	/* double game value */
				dlast = cturn;
				gwrite();
				return;
			}
		}
		/* ask if player accepts */
		printw("  Does %s accept?", cturn == 1 ? color[2] : color[3]);

		/* get response from yorn; a "2" means he said "p" to print board. */
		if ((resp = yorn ('r')) == 2) {
			addstr("  Reprint.\n");
			moveplayers();
			wrboard();
			addstr(*Colorptr);
			continue;
		}
		/* check response */
		if (resp) {
			/* accepted */
			gvalue *= 2;
			dlast = cturn;
			gwrite();
			return;
		}
		nexturn();	/* declined */
		cturn *= -2;
		return;
	}
}
Esempio n. 3
0
File: dark.c Progetto: yrchen/Athena
/* move chess 就等於吃棋子 */
move_chess(char y, char x, char yy, char xx, char *mark, char *turn)
{
 chess[y][x]=chess[yy][xx];
 chess[yy][xx]=0;
 show_chess(y, x, chess[y][x], 0);
 show_chess(yy, xx, 0, 0);
 *mark=0;
 *turn=nexturn(*turn);
}
Esempio n. 4
0
void
getmove()
{
	int     i, c;

	c = 0;
	for (;;) {
		i = checkmove(c);

		switch (i) {
		case -1:
			if (movokay(mvlim)) {
				move(20, 0);
				for (i = 0; i < mvlim; i++)
					if (h[i])
						wrhit(g[i]);
				nexturn();
				if (*offopp == 15)
					cturn *= -2;
				return;
			}
		case -4:
		case 0:
			refresh();
			if (i != 0 && i != -4)
				break;
			mvaddstr(20, 0, *Colorptr);
			if (i == -4)
				addstr(" must make ");
			else
				addstr(" can only make ");
			printw("%d move%s.\n", mvlim, mvlim > 1 ? "s":"");
			break;

		case -3:
			if (quit())
				return;
		}

		move(cturn == -1 ? 18 : 19, 39);
		clrtoeol();
		c = -1;
	}
}
Esempio n. 5
0
int
main (int argc, char **argv)
{
	int     i,l;		/* non-descript indices */
	char    c;		/* non-descript character storage */

	if (pledge("stdio rpath wpath cpath tty exec", NULL) == -1)
		err(1, "pledge");

	signal(SIGINT, getout);	/* trap interrupts */

	/* use whole screen for text */
	begscr = 0;

	getarg(argc, argv);

	initcurses();

	/* check if restored game and save flag for later */
	if ((rfl = rflag)) {
		if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
			err(1, "pledge");

		wrboard();	/* print board */
		/* if new game, pretend to be a non-restored game */
		if (cturn == 0)
			rflag = 0;
	} else {
		rscore = wscore = 0;	/* zero score */

		if (aflag) {	/* print rules */
			addstr(rules);
			if (yorn(0)) {
				endwin();
				execl(TEACH, "teachgammon", (char *)NULL);

				err(1, "%s", noteach);
			} else {/* if not rules, then instructions */
				addstr(need);
				if (yorn(0)) {	/* print instructions */
					clear();
					text(instruct);
				}
			}
		}

		if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
			err(1, "pledge");

		init();		/* initialize board */

		if (pnum == 2) {/* ask for color(s) */
			printw("\n%s", askcol);
			while (pnum == 2) {
				c = readc();
				switch (c) {

				case 'R':	/* red */
					pnum = -1;
					break;

				case 'W':	/* white */
					pnum = 1;
					break;

				case 'B':	/* both */
					pnum = 0;
					break;

				case 'P':	/* Control the dice */
					iroll = 1;
					addstr("\nDice controlled!\n");
					addstr(askcol);
					break;

				default:	/* error */
					beep();
				}
			}
		}

		wrboard();		/* print board */

		move(18, 0);
	}
	/* limit text to bottom of screen */
	begscr = 17;

	for (;;)  {			/* begin game! */
		/* initial roll if needed */
		if ((!rflag) || raflag)
			roll();

		/* perform ritual of first roll */
		if (!rflag) {
			move(17, 0);
			while (D0 == D1)	/* no doubles */
				roll();

			/* print rolls */
			printw("%s%d%s%d", rollr, D0, rollw, D1);

			/* winner goes first */
			if (D0 > D1) {
				addstr(rstart);
				cturn = 1;
			} else {
				addstr(wstart);
				cturn = -1;
			}
		}
		/* initialize variables according to whose turn it is */

		if (cturn == 1) {	/* red */
			home = 25;
			bar = 0;
			inptr = &in[1];
			inopp = &in[0];
			offptr = &off[1];
			offopp = &off[0];
			Colorptr = &color[1];
			colorptr = &color[3];
			colen = 3;
		} else {		/* white */
			home = 0;
			bar = 25;
			inptr = &in[0];
			inopp = &in[1];
			offptr = &off[0];
			offopp = &off[1];
			Colorptr = &color[0];
			colorptr = &color[2];
			colen = 5;
		}

		/* do first move (special case) */
		if (!(rflag && raflag)) {
			if (cturn == pnum)	/* computer's move */
				domove(0);
			else {	/* player's move */
				mvlim = movallow();
				/* reprint roll */
				move(cturn == -1 ? 18 : 19, 0);
				proll();
				getmove();	/* get player's move */
			}
		}
		move(17, 0);
		clrtoeol();
		begscr = 18;
		/* no longer any difference between normal and recovered game. */
		rflag = 0;

		/* move as long as it's someone's turn */
		while (cturn == 1 || cturn == -1) {

			/* board maintainence */
			moveplayers();	/* fix board */

			/* do computer's move */
			if (cturn == pnum) {
				domove(1);

				/* see if double refused */
				if (cturn == -2 || cturn == 2)
					break;

				/* check for winning move */
				if (*offopp == 15) {
					cturn *= -2;
					break;
				}
				continue;

			}
			/* (player's move) */

			/* clean screen if safe */
			if (hflag) {
				move(20, 0);
				clrtobot();
				hflag = 1;
			}
			/* if allowed, give him a chance to double */
			if (dflag && dlast != cturn && gvalue < 64) {
				move(cturn == -1 ? 18: 19, 0);
				addstr(*Colorptr);
				c = readc();

				/* character cases */
				switch (c) {

				case 'R':		/* reprint board */
					wrboard();
					break;

				case 'S':		/* save game */
					raflag = 1;
					save(1);
					break;

				case 'Q':		/* quit */
					quit();
					break;

				case 'D':		/* double */
					dble();
					break;

				case ' ':		/* roll */
				case '\n':
					roll();
					printw(" rolls %d %d.  ", D0, D1);

					/* see if he can move */
					if ((mvlim = movallow()) == 0) {

						/* can't move */
						printw("%s%s%s", toobad1, *colorptr, unable);
						if (pnum) {
							moveplayers();
							sleep(MVPAUSE);
						}
						nexturn();
						break;
					}

					getmove();

					/* okay to clean screen */
					hflag = 1;
					break;

				default:		/* invalid character */

					/* print help message */
					move(20, 0);
					text(helpm);
					move(cturn == -1 ? 18 : 19, 0);

					/* don't erase */
					hflag = 0;
				}
			} else {/* couldn't double */

				/* print roll */
				roll();
				move(cturn == -1 ? 18: 19, 0);
				proll();

				/* can he move? */
				if ((mvlim = movallow()) == 0) {

					/* he can't */
					printw("%s%s%s", toobad2, *colorptr, cantmv);
					moveplayers();
					sleep(MVPAUSE);
					nexturn();
					continue;
				}

				getmove();
			}
		}

		/* don't worry about who won if quit */
		if (cturn == 0)
			break;

		/* fix cturn = winner */
		cturn /= -2;

		/* final board pos. */
		moveplayers();

		/* backgammon? */
		mflag = 0;
		l = bar + 7 * cturn;
		for (i = bar; i != l; i += cturn)
			if (board[i] * cturn)
				mflag++;

		/* compute game value */
		move(20, 0);
		if (*offopp == 15) {
			if (mflag) {
				addstr(bgammon);
				gvalue *= 3;
			}
			else if (*offptr <= 0) {
				addstr(gammon);
				gvalue *= 2;
			}
		}
		/* report situation */
		if (cturn == -1) {
			addstr("Red wins ");
			rscore += gvalue;
		} else {
			addstr("White wins ");
			wscore += gvalue;
		}
		printw("%d point%s.\n", gvalue, (gvalue > 1) ? "s":"");

		/* write score */
		wrscore();

		/* see if he wants another game */
		addstr(again);
		if ((i = yorn('S')) == 0)
			break;

		init();
		if (i == 2) {
			addstr("  Save.\n");
			cturn = 0;
			save(0);
		}
		/* yes, reset game */
		wrboard();
	}

	/* give him a chance to save if game was recovered */
	if (rfl && cturn) {
		addstr(svpromt);
		if (yorn(0)) {
			/* re-initialize for recovery */
			init();
			cturn = 0;
			save(0);
		}
	}
	/* leave peacefully */
	getout(0);
	/* NOT REACHED */
}
Esempio n. 6
0
tutor ()  {
	register int	i, j;

	i = 0;
	begscr = 18;
	cturn = -1;
	home = 0;
	bar = 25;
	inptr = &in[0];
	inopp = &in[1];
	offptr = &off[0];
	offopp = &off[1];
	Colorptr = &color[0];
	colorptr = &color[2];
	colen = 5;
	wrboard();

	while (1)  {
		if (! brdeq(test[i].brd,board))  {
			if (tflag && curr == 23)
				curmove (18,0);
			writel (better);
			nexturn();
			movback (mvlim);
			if (tflag)  {
				refresh();
				clrest ();
			}
			if ((! tflag) || curr == 19)  {
				proll();
				writec ('\t');
			}
			else
				curmove (curr > 19? curr-2: curr+4,25);
			getmove();
			if (cturn == 0)
				leave();
			continue;
		}
		if (tflag)
			curmove (18,0);
		text (*test[i].com);
		if (! tflag)
			writec ('\n');
		if (i == maxmoves)
			break;
		D0 = test[i].roll1;
		D1 = test[i].roll2;
		d0 = 0;
		mvlim = 0;
		for (j = 0; j < 4; j++)  {
			if (test[i].mp[j] == test[i].mg[j])
				break;
			p[j] = test[i].mp[j];
			g[j] = test[i].mg[j];
			mvlim++;
		}
		if (mvlim)
			for (j = 0; j < mvlim; j++)
				if (makmove(j))
					writel ("AARGH!!!\n");
		if (tflag)
			refresh();
		nexturn();
		D0 = test[i].new1;
		D1 = test[i].new2;
		d0 = 0;
		i++;
		mvlim = movallow();
		if (mvlim)  {
			if (tflag)
				clrest();
			proll();
			writec('\t');
			getmove();
			if (tflag)
				refresh();
			if (cturn == 0)
				leave();
		}
	}
	leave();
}
Esempio n. 7
0
getmove ()  {
	register int	i, c;

	c = 0;
	for (;;)  {
		i = checkmove(c);

		switch (i)  {
		case -1:
			if (movokay(mvlim))  {
				if (tflag)
					curmove (20,0);
				else
					writec ('\n');
				for (i = 0; i < mvlim; i++)
					if (h[i])
						wrhit(g[i]);
				nexturn();
				if (*offopp == 15)
					cturn *= -2;
				if (tflag && pnum)
					bflag = pnum;
				return;
			}

		case -4:
		case 0:
			if (tflag)
				refresh();
			if (i != 0 && i != -4)
				break;
			if (tflag)
				curmove (20,0);
			else
				writec ('\n');
			writel (*Colorptr);
			if (i == -4)
				writel (" must make ");
			else
				writel (" can only make ");
			writec (mvlim+'0');
			writel (" move");
			if (mvlim > 1)
				writec ('s');
			writec ('.');
			writec ('\n');
			break;

		case -3:
			if (quit())
				return;
		}

		if (! tflag)
			proll ();
		else  {
			curmove (cturn == -1? 18: 19,39);
			cline ();
			c = -1;
		}
	}
}
Esempio n. 8
0
File: dark.c Progetto: yrchen/Athena
int
dark(int fd, user_info *uin, int t)
                                      {
 char x=0,y=0,turn=0,xx,yy,mark=0,color=-1;
 char data[100],shown[2]={0,0},result=0,peace=0;
 time_t rest,init=time(0);
 int key,datac;
//       screenline *screen; //for save the scre
 
 data[0]=0;
 start(uin);
 add_io(fd, 0);
 t=t?1:0;
 
 if(!t) { /* 兩邊棋盤資料同步 */
  for(yy=0; yy<8; yy++)
   strncat(data, chess[yy], 4);
  do {
   datac=send(fd, data, strlen(data), 0);
  } while(datac<0);
 }
 else {
  do {
   key=igetkey();
   if (key == I_OTHERDATA) {
     datac= recv(fd, data, sizeof(data), 0);
     if(datac<=0) {add_io(0, 0); return;}
     for(yy=0; yy<8; yy++)
      strncpy(chess[yy], data+yy*4, 4);
   }
  } while(key != I_OTHERDATA);
 }
 move(18,0); clrtoeol();
 
 do {
  printtt(19, 56, "%s",t==turn?"自己":"對方"); 
  refresh();
  rest=time(0);
  
  do {
    if(t==turn) {
      show_cursor(y, x, 1);
      move(18, 0);
    }
    key=time(0)-init;
    datac=ttt+rest-time(0);

    if(datac<1 && turn==t) {
      change_record(1);
      add_io(0,0); bell();
      pressanykey("時間到囉!!..這局輸囉.. :~(");
      return 0;
    }
    else if(datac<1) {
      change_record(0);
      add_io(0,0); bell();
      pressanykey("對方可能睡著啦~ so算你贏了!! ^^Y");
      return 0;
    }
    
    move(22,34); 
    prints("%2d:%2d:%2d",key/3600,(key%3600)/60,key%60);
    printtt(21,47,"4%d;1m  %d:%2d",datac<30?1:4,datac/60,datac%60);
    move(b_lines,0); clrtoeol();
    prints(" 說明  [←↑↓→/jikl]移動 \
[Enter/Space]確定 [w]傳訊 [p]和棋 [q]\
投降 [h]Help ");
    refresh();
    key=igetkey();
    peace=0;

     if(key==I_OTHERDATA) {
       bell();
       datac= recv(fd, data, sizeof(data), 0);
       if(datac<=0) {add_io(0, 0); return;}
       
       if(*data=='P') {
         getdata(18, 0, "對方提出和棋的要求..答應和棋嗎?? (y/n) [n]", data, 4, LCECHO, 0);
         move(18,0); clrtoeol();
         do {
          datac=send(fd, data, 1, 0);
         } while(datac<0);
         if(*data=='y') {
           change_record(2);
           add_io(0, 0);
           pressanykey("雙方握手言和 :)");
           return 0;
         }
         key=0;
       }
       else if(*data=='Q') {
         change_record(0);
         add_io(0, 0);
         pressanykey("耶耶耶..對方投降了.. ^^Y");
         return 0;
       }
       else {
         yy=data[0]-1; xx=data[1]-1;
         y=data[2]-1; x=data[3]-1;

         if(darked(chess[y][x])) { /* 對方翻棋 */
           if(color<0) {
             color=nexturn(red(chess[y][x]));
             show_color(color);
           }
           show_chess(y, x, chess[y][x], 0);
           chess[y][x]--;
           turn=nexturn(turn);
         }
         else {
           if(chess[y][x]) 
             result=show_eaten(chess[y][x],shown[t]++,0);
           move_chess(y,x,yy,xx,&mark,&turn);
         }
       }
     }

   switch(key) {
     case 'h':
      {
       extern screenline* big_picture;
       screenline* screen0 = calloc(t_lines, sizeof(screenline));
       memcpy(screen0, big_picture, t_lines * sizeof(screenline));
       more("game/dark.help",YEA); //* 改成自己的路徑
       memcpy(big_picture, screen0, t_lines * sizeof(screenline));
       free(screen0);
       redoscr();
      }
       break;
     case 'w':
      {
       extern screenline* big_picture;
       screenline* screen0 = calloc(2, sizeof(screenline));
       memcpy(screen0, big_picture, 2 * sizeof(screenline));
       my_write(uin->pid, "傳訊息: ");
       memcpy(big_picture, screen0, 2 * sizeof(screenline));
       free(screen0);
       redoscr();
      }
       break;
     case 'p':
       if(t==turn) {
         int keyy;
         if(peace) break;
         bell();
         getdata(18, 0, "真的要和棋嗎?? (y/n) [n]", data, 4, LCECHO, 0);
         move(18, 0); clrtoeol(); 
         if(*data!='y') break;
         prints("詢問對手是否同意和棋..請稍後... :)"); refresh();
         peace=1;
         do {
          datac=send(fd, "P", 1, 0);
         } while(datac<0);

         do {
           keyy=igetkey();
           if(keyy==I_OTHERDATA) {
             datac= recv(fd, data, sizeof(data), 0);
             if(datac<=0) {add_io(0, 0); return 0;}
             move(18, 0); clrtoeol(); 
             if(*data=='y') {
               change_record(2);
               add_io(0, 0);
               pressanykey("雙方握手言和 :)");
               return 0;
             }
             else 
               pressanykey("對方不同意和棋.. :~");
           }
         } while (keyy!=I_OTHERDATA);
       }
       break;
     case 'q':
       if(t==turn) {
         bell();
         getdata(18, 0, "真的要投降嗎?? (y/n) [n]", data, 4, LCECHO, 0);
         move(18,0); clrtoeol();
         if(*data!='y') break;
         do {
          datac=send(fd, "Q", 1, 0);
         } while(datac<0);
         change_record(1);
         add_io(0, 0);
         pressanykey("啊啊啊..我不行了..投降~ ^^;");
         return 0;
       }
       break;
     default:
      if(t!=turn) key=0;
      break;
   }

   if(t!=turn) continue;
   switch(key) {
    case ' ':
    case 13:
     if(!mark && darked(chess[y][x])) { /* 翻棋 */
       if(color<0) {
        color=red(chess[y][x]);
        show_color(color);
       }
       show_chess(y, x, chess[y][x], 0);
       chess[y][x]--;
       turn=nexturn(turn);
     }
     
     else if(mark) { /* 已 mark 的處理 */
       if(!chess[y][x] && nexto(x-xx,y-yy)) /* 移動 */
        move_chess(y,x,yy,xx,&mark,&turn);
       else if(!mychess(y,x,color) && !darked(chess[y][x])) { /* 吃對方的棋子 */
         if(nexto2(x-xx,y-yy) && mark==6) { /* mark 起來的棋子不在隔壁(炮) */
          char i,tmp=0;
          if(x==xx)
           for(i=min(y,yy)+1; i<max(y,yy); i++)
            tmp+=(chess[i][x]!=0);  
          else
           for(i=min(x,xx)+1; i<max(x,xx); i++)
            tmp+=(chess[y][i]!=0);  
          if(tmp==1 && chess[y][x]) {
            result=show_eaten(chess[y][x],shown[nexturn(t)]++,1);
            move_chess(y,x,yy,xx,&mark,&turn);
          }
          else cancel_mark(yy,xx,&mark,&key);
         }
         else { /* mark 起來的棋子在隔壁 */
           if( nexto(x-xx,y-yy) &&
              ((mark==7 && rank(chess[y][x])==1) || /* 小兵立大功 */
               ( mark<=rank(chess[y][x]) &&
                 rank(chess[y][x])-mark!=6  ))  ) { /* 將軍怕小兵 */
             result=show_eaten(chess[y][x],shown[nexturn(t)]++,1);
             move_chess(y,x,yy,xx,&mark,&turn);
           }
           else cancel_mark(yy,xx,&mark,&key);
         }
       }
       else cancel_mark(yy,xx,&mark,&key); /* 不能移不能吃 */
     }
     
     /* mark 起來 */     
     else if(!mark && chess[y][x] && mychess(y,x,color)) { /* mark 起來 */
       show_chess(y, x, chess[y][x], 1);
       mark=rank(chess[y][x]);
       xx=x; yy=y;
       key=0;
     }
     else key=0;
     break;
     
    case 'u':
     if(mark) cancel_mark(yy, xx, &mark, &key);
     break;
    case KEY_LEFT:
    case 'j':
     show_cursor(y, x, 0);
     y=y==0?7:y-1;
     break;
    case KEY_RIGHT:
    case 'l':
     show_cursor(y, x, 0);
     y=y==7?0:y+1;
     break;
    case KEY_UP:
    case 'i':
     show_cursor(y, x, 0);
     x=x==0?3:x-1;
     break;
    case KEY_DOWN:
    case 'k':
     show_cursor(y, x, 0);
     x=x==3?0:x+1;
     break;
   } 
   
  } while(key!=' ' && key!=13 && key!=I_OTHERDATA);
  
  show_cursor(y, x, 0);
  
  if(t==turn) continue; /* turn已經動過..so是相反的值 */
  data[0]=yy+1; data[1]=xx+1; 
  data[2]=y+1; data[3]=x+1;
  do {
    datac=send(fd, data, 4, 0);
  } while(datac<0);
  
 } while(!result);
 add_io(0, 0);  
 if(!turn) 
 {
   FILE *fs;
   init=time(0)-init;
   if(fs=fopen("log/dark.log","a+")) //* 可改成自己想要的路徑
   {
     fprintf(fs,"%s win %s %d:%d\n",currutmp->userid,uin->userid,init/60,init%60);
     fclose(fs); 
   }
 }
 change_record(1);
 pressanykey("恭禧你%s了 ^^Y",t==turn?"輸":"贏");
}
Esempio n. 9
0
/* zero if first move */
void
move(int okay)
{
    int i;			/* index */
    int l;			/* last man */

    l = 0;
    if (okay) {
        /* see if comp should double */
        if (gvalue < 64 && dlast != cturn && dblgood()) {
            writel(*Colorptr);
            dble();		/* double */
            /* return if declined */
            if (cturn != 1 && cturn != -1)
                return;
        }
        roll();
    }

    race = 0;
    for (i = 0; i < 26; i++) {
        if (board[i] < 0)
            l = i;
    }
    for (i = 0; i < l; i++) {
        if (board[i] > 0)
            break;
    }
    if (i == l)
        race = 1;

    /* print roll */
    if (tflag)
        curmove(cturn == -1 ? 18 : 19, 0);
    writel(*Colorptr);
    writel(" rolls ");
    writec(D0 + '0');
    writec(' ');
    writec(D1 + '0');
    /* make tty interruptable while thinking */
    if (tflag)
        cline();
    fixtty(noech);

    /* find out how many moves */
    mvlim = movallow();
    if (mvlim == 0) {
        writel(" but cannot use it.\n");
        nexturn();
        fixtty(raw);
        return;
    }

    /* initialize */
    for (i = 0; i < 4; i++)
        cp[i] = cg[i] = 0;

    /* strategize */
    trymove(0, 0);
    pickmove();

    /* print move */
    writel(" and moves ");
    for (i = 0; i < mvlim; i++) {
        if (i > 0)
            writec(',');
        wrint(p[i] = cp[i]);
        writec('-');
        wrint(g[i] = cg[i]);
        makmove(i);
    }
    writec('.');

    /* print blots hit */
    if (tflag)
        curmove(20, 0);
    else
        writec('\n');
    for (i = 0; i < mvlim; i++)
        if (h[i])
            wrhit(g[i]);
    /* get ready for next move */
    nexturn();
    if (!okay) {
        buflush();
        sleep(3);
    }
    fixtty(raw);		/* no more tty interrupt */
}
Esempio n. 10
0
void
domove(int okay)
{
	int     i;		/* index */
	int     l = 0;		/* last man */

	bestmove = -9999999.;
	if (okay) {
	    	/* see if comp should double */
		if (dflag && gvalue < 64 && dlast != cturn && dblgood()) {
			addstr(*Colorptr);
			dble();	/* double */
			/* return if declined */
			if (cturn != 1 && cturn != -1)
				return;
		}
		roll();
	}
	race = 0;
	for (i = 0; i < 26; i++) {
		if (board[i] < 0)
			l = i;
	}
	for (i = 0; i < l; i++) {
		if (board[i] > 0)
			break;
	}
	if (i == l)
		race = 1;

	/* print roll */
	move(cturn == -1 ? 18 : 19, 0);
	printw("%s rolls %d %d", *Colorptr, D0, D1);
	clrtoeol();

	/* find out how many moves */
	mvlim = movallow();
	if (mvlim == 0) {
		addstr(" but cannot use it.\n");
		nexturn();
		return;
	}

	/* initialize */
	for (i = 0; i < 4; i++)
		cp[i] = cg[i] = 0;

	/* strategize */
	trymove(0, 0);
	pickmove();

	/* print move */
	addstr(" and moves ");
	for (i = 0; i < mvlim; i++) {
		if (i > 0)
			addch(',');
		printw("%d-%d", p[i] = cp[i], g[i] = cg[i]);
		makmove(i);
	}
	addch('.');

	/* print blots hit */
	move(20, 0);
	for (i = 0; i < mvlim; i++)
		if (h[i])
			wrhit(g[i]);
	/* get ready for next move */
	nexturn();
	if (!okay) {
		refresh();
		sleep(3);
	}
}
Esempio n. 11
0
void
tutor(void)
{
	int     i, j, k;
	int     wrongans;

	wrongans = 0;
	i = 0;
	begscr = 18;
	cturn = -1;
	home = 0;
	bar = 25;
	inptr = &in[0];
	inopp = &in[1];
	offptr = &off[0];
	offopp = &off[1];
	Colorptr = &color[0];
	colorptr = &color[2];
	colen = 5;
	wrboard();

	while (1) {
		if (!brdeq(test[i].brd, board)) {
			wrongans++;
			move(18, 0);
			if (wrongans >= 3) {
				wrongans = 0;
				text(*test[i].ans);
				memcpy(board,test[i].brd,26*sizeof(int));
				/* and have to fix *inptr, *offptr; player is red (+ve) */
				k = 0;
				for (j = 19; j < 26; j++)
					k += (board[j] > 0 ? board[j] : 0);
				*inopp = k;
				for (j = 0; j < 19; j++)
					k += (board[j] > 0 ? board[j] : 0);
				*offopp = k - 30;  /* -15 at start */
				moveplayers();
				clrest();
			} else {
				addstr(better);
				nexturn();
				movback(mvlim);
				moveplayers();
				clrest();
				getyx(stdscr, j, k);
				if (j == 19) {
					proll();
					addch('\t');
				} else
					move(j > 19 ? j - 2 : j + 4, 25);
				getmove();
				if (cturn == 0)
					leave();
				continue;
			}
		} else
			wrongans = 0;
		move(18, 0);
		text(*test[i].com);
		move(19, 0);
		if (i == maxmoves)
			break;
		D0 = test[i].roll1;
		D1 = test[i].roll2;
		d0 = 0;
		mvlim = 0;
		for (j = 0; j < 4; j++) {
			if (test[i].mp[j] == test[i].mg[j])
				break;
			p[j] = test[i].mp[j];
			g[j] = test[i].mg[j];
			mvlim++;
		}
		if (mvlim)
			for (j = 0; j < mvlim; j++)
				if (makmove(j))
					addstr("AARGH!!!\n");
		moveplayers();
		nexturn();
		D0 = test[i].new1;
		D1 = test[i].new2;
		d0 = 0;
		i++;
		mvlim = movallow();
		if (mvlim) {
			clrest();
			proll();
			addch('\t');
			getmove();
			moveplayers();
			if (cturn == 0)
				leave();
		}
	}
	leave();
}
Esempio n. 12
0
/* zero if first move */
void
move(struct move *mm, int okay)
{
	int     i;		/* index */
	int     l;		/* last man */

	l = 0;
	if (okay) {
		/* see if comp should double */
		if (gvalue < 64 && dlast != cturn && dblgood()) {
			writel(*Colorptr);
			dble();	/* double */
			/* return if declined */
			if (cturn != 1 && cturn != -1)
				return;
		}
		roll(mm);
	}
	race = 0;
	for (i = 0; i < 26; i++) {
		if (board[i] < 0)
			l = i;
	}
	for (i = 0; i < l; i++) {
		if (board[i] > 0)
			break;
	}
	if (i == l)
		race = 1;

	/* print roll */
	if (tflag)
		curmove(cturn == -1 ? 18 : 19, 0);
	writel(*Colorptr);
	writel(" rolls ");
	writec(mm->D0 + '0');
	writec(' ');
	writec(mm->D1 + '0');
	/* make tty interruptable while thinking */
	if (tflag)
		cline();
	fixtty(&noech);

	/* find out how many moves */
	mm->mvlim = movallow(mm);
	if (mm->mvlim == 0) {
		writel(" but cannot use it.\n");
		nexturn();
		fixtty(&raw);
		return;
	}
	/* initialize */
	for (i = 0; i < 4; i++)
		cp[i] = cg[i] = 0;

	/* strategize */
	trymove(mm, 0, 0);
	pickmove(mm);

	/* print move */
	writel(" and moves ");
	for (i = 0; i < mm->mvlim; i++) {
		if (i > 0)
			writec(',');
		wrint(mm->p[i] = cp[i]);
		writec('-');
		wrint(mm->g[i] = cg[i]);
		makmove(mm, i);

		/*
		 * This assertion persuades gcc 4.5 that the loop
		 * doesn't result in signed overflow of i. mvlim
		 * isn't, or at least shouldn't be, changed by makmove
		 * at all.
		 */
		assert(mm->mvlim >= 0 && mm->mvlim <= 5);
	}
	writec('.');

	/* print blots hit */
	if (tflag)
		curmove(20, 0);
	else
		writec('\n');
	for (i = 0; i < mm->mvlim; i++)
		if (mm->h[i])
			wrhit(mm->g[i]);
	/* get ready for next move */
	nexturn();
	if (!okay) {
		buflush();
		sleep(3);
	}
	fixtty(&raw);		/* no more tty interrupt */
}