void writec(int c) { if (tflag) fancyc(c); else addbuf(c); }
/* * bsect (b,rpos,cpos,cnext) * Print the contents of a board position. "b" has the value of the * position, "rpos" is the row to start printing, "cpos" is the column to * start printing, and "cnext" is positive if the position starts at the top * and negative if it starts at the bottom. The value of "cpos" is checked * to see if the position is a player's home, since those are printed * differently. */ static void bsect(int b, int rpos, int cpos, int cnext) { int j; /* index */ int n; /* number of men on position */ int bct; /* counter */ int k; /* index */ char pc; /* color of men on position */ bct = 0; n = abs(b); /* initialize n and pc */ pc = (b > 0 ? 'r' : 'w'); if (n < 6 && cpos < 54) /* position cursor at start */ curmove(rpos, cpos + 1); else curmove(rpos, cpos); for (j = 0; j < 5; j++) { /* print position row by row */ for (k = 0; k < 15; k += 5) /* print men */ if (n > j + k) fancyc(pc); if (j < 4) { /* figure how far to back up for next row */ if (n < 6) { /* stop if none left */ if (j + 1 == n) break; bct = 1; /* single column */ } else { if (n < 11) { /* two columns */ if (cpos == 54) { /* home pos */ if (j + 5 >= n) bct = 1; else bct = 2; } if (cpos < 54) { /* not home */ if (j + 6 >= n) bct = 1; else bct = 2; } } else { /* three columns */ if (j + 10 >= n) bct = 2; else bct = 3; } } /* reposition cursor */ curmove(curr + cnext, curc - bct); } } }
fboard () { register int i, j, l; curmove (0,0); /* do top line */ for (i = 0; i < 53; i++) fancyc ('_'); curmove (15,0); /* do botttom line */ for (i = 0; i < 53; i++) fancyc ('_'); l = 1; /* do vertical lines */ for (i = 52; i > -1; i -= 28) { curmove ( (l == 1? 1: 15) ,i); fancyc ('|'); for (j = 0; j < 14; j++) { curmove (curr+l,curc-1); fancyc ('|'); } if (i == 24) i += 32; l = -l; /* alternate directions */ } curmove (2,1); /* label positions 13-18 */ for (i = 13; i < 18; i++) { fancyc ('1'); fancyc ((i % 10)+'0'); curmove (curr,curc+2); } fancyc ('1'); fancyc ('8'); curmove (2,29); /* label positions 19-24 */ fancyc ('1'); fancyc ('9'); for (i = 20; i < 25; i++) { curmove (curr,curc+2); fancyc ('2'); fancyc ((i % 10)+'0'); } curmove (14,1); /* label positions 12-7 */ fancyc ('1'); fancyc ('2'); for (i = 11; i > 6; i--) { curmove (curr,curc+2); fancyc (i > 9? '1': ' '); fancyc ((i % 10)+'0'); } curmove (14,30); /* label positions 6-1 */ fancyc ('6'); for (i = 5; i > 0; i--) { curmove (curr,curc+3); fancyc (i+'0'); } for (i = 12; i > 6; i--) /* print positions 12-7 */ if (board[i]) bsect (board[i],13,1+4*(12-i),-1); if (board[0]) /* print red men on bar */ bsect (board[0],13,25,-1); for (i = 6; i > 0; i--) /* print positions 6-1 */ if (board[i]) bsect (board[i],13,29+4*(6-i),-1); l = (off[1] < 0? off[1]+15: off[1]); /* print white's home */ bsect (l,3,54,1); curmove (8,25); /* print the word BAR */ fancyc ('B'); fancyc ('A'); fancyc ('R'); for (i = 13; i < 19; i++) /* print positions 13-18 */ if (board[i]) bsect (board[i],3,1+4*(i-13),1); if (board[25]) /* print white's men on bar */ bsect (board[25],3,25,1); for (i = 19; i < 25; i++) /* print positions 19-24 */ if (board[i]) bsect (board[i],3,29+4*(i-19),1); l = (off[0] < 0? off[0]+15: off[0]); /* print red's home */ bsect (-l,13,54,-1); for (i = 0; i < 26; i++) /* save board position * for refresh later */ oldb[i] = board[i]; oldr = (off[1] < 0? off[1]+15: off[1]); oldw = -(off[0] < 0? off[0]+15: off[0]); }