- last = TRUE; /* enable last flag */
- prhand(ph, pnum, Playwin, FALSE);
- prhand(ch, cnum, Compwin, TRUE);
- prtable(sum);
- if (myturn) { /* my tyrn to play */
- if (!anymove(ch, cnum, sum)) { /* if no card to play */
- if (!mego && cnum) { /* go for comp? */
- msg("GO");
- mego = TRUE;
- }
- if (anymove(ph, pnum, sum)) /* can player move? */
- myturn = !myturn;
- else { /* give him his point */
- msg(quiet ? "You get one" : "You get one point");
- if (chkscr(&pscore, 1))
- return TRUE;
- sum = 0;
- mego = ugo = FALSE;
- Tcnt = 0;
- }
- }
- else {
- played = TRUE;
- j = -1;
- k = 0;
- for (i = 0; i < cnum; i++) { /* maximize score */
- l = pegscore(ch[i], Table, Tcnt, sum);
- if (l > k) {
- k = l;
- j = i;
+ last = TRUE; /* enable last flag */
+ prhand(ph, pnum, Playwin, FALSE);
+ prhand(ch, cnum, Compwin, TRUE);
+ prtable(sum);
+ if (myturn) { /* my tyrn to play */
+ if (!anymove(ch, cnum, sum)) { /* if no card to play */
+ if (!mego && cnum) { /* go for comp? */
+ msg("GO");
+ mego = TRUE;
+ }
+ /* can player move? */
+ if (anymove(ph, pnum, sum))
+ myturn = !myturn;
+ else { /* give him his point */
+ msg(quiet ? "You get one" :
+ "You get one point");
+ do_wait();
+ if (chkscr(&pscore, 1))
+ return TRUE;
+ sum = 0;
+ mego = ugo = FALSE;
+ Tcnt = 0;
+ }
+ } else {
+ played = TRUE;
+ j = -1;
+ k = 0;
+ /* maximize score */
+ for (i = 0; i < cnum; i++) {
+ l = pegscore(ch[i], Table, Tcnt, sum);
+ if (l > k) {
+ k = l;
+ j = i;
+ }
+ }
+ if (j < 0) /* if nothing scores */
+ j = cchose(ch, cnum, sum);
+ crd = ch[j];
+ cremove(crd, ch, cnum--);
+ sum += VAL(crd.rank);
+ Table[Tcnt++] = crd;
+ if (k > 0) {
+ addmsg(quiet ? "I get %d playing " :
+ "I get %d points playing ", k);
+ msgcard(crd, FALSE);
+ endmsg();
+ if (chkscr(&cscore, k))
+ return TRUE;
+ }
+ myturn = !myturn;
+ }
+ } else {
+ if (!anymove(ph, pnum, sum)) { /* can player move? */
+ if (!ugo && pnum) { /* go for player */
+ msg("You have a GO");
+ ugo = TRUE;
+ }
+ /* can computer play? */
+ if (anymove(ch, cnum, sum))
+ myturn = !myturn;
+ else {
+ msg(quiet ? "I get one" :
+ "I get one point");
+ do_wait();
+ if (chkscr(&cscore, 1))
+ return TRUE;
+ sum = 0;
+ mego = ugo = FALSE;
+ Tcnt = 0;
+ }
+ } else { /* player plays */
+ played = FALSE;
+ if (pnum == 1) {
+ crd = ph[0];
+ msg("You play your last card");
+ } else
+ for (;;) {
+ prhand(ph,
+ pnum, Playwin, FALSE);
+ crd = ph[infrom(ph,
+ pnum, "Your play: ")];
+ if (sum + VAL(crd.rank) <= 31)
+ break;
+ else
+ msg("Total > 31 -- try again");
+ }
+ makeknown(&crd, 1);
+ cremove(crd, ph, pnum--);
+ i = pegscore(crd, Table, Tcnt, sum);
+ sum += VAL(crd.rank);
+ Table[Tcnt++] = crd;
+ if (i > 0) {
+ msg(quiet ? "You got %d" :
+ "You got %d points", i);
+ if (pnum == 0)
+ do_wait();
+ if (chkscr(&pscore, i))
+ return TRUE;
+ }
+ myturn = !myturn;