/* CCCC H H EEEEE SSSS SSSS 3333 DDDD CCCC ** C H H E S S 3 D D C ** C HHHHH EEEE SSS SSS 333 D D C ** C H H E S S 3 D D .. C ** CCCC H H EEEEE SSSS SSSS 3333 DDDD .. CCCC ** ** c h e s s 3 d . c dennette@wiz-worx.com ** ** test of C compiler on various platforms ** ... draws a chessboard ** ** 29-jun-76 FORTRAN - XDS Sigma 9 - original version ** 27-oct-79 FORTRAN - PDP 11/70 ** 08-jul-82 C - VAX 780 ** 01-apr-83 Pascal - IBM PC ** 04-dec-83 C - DEC Rainbow (Aztec CII) ** 22-dec-83 - modified to read data from a file ** 30-may-84 C - SAGE-IV (DRI CP/M-68K) ** 09-sep-84 C - DEC Rainbow (CI-C86) ** 23-aug-93 C - Microsoft (ANSI) Visual C++ ** 01-aug-95 C - changed default board ** 1997-03-17 C - outputs "small" board ** 1997-03-17 C - outputs 3D board for DKBtrace ** ** usage: A>CHESS3D filename ** ** reads data from named file to display chessboard - see files ** CHESS*.DAT for examples */ #include #include #define DARK '*' #define LIGHT '.' #define BLACK 'B' #define WHITE 'W' FILE *in_fcb; char board[8][16], pcolor, sqcolor; char *mask[7] = { " ", "Pawn ", "Bishop", "Knight", "Rook ", "Queen ", "King " }; long buffer; int bcol, brow, col, re, row, ua, sq[8][8] = { /* default values */ { 0, 0, 0, -4, 0, 0, -6, -4 }, /* . * .-R . *-K-R */ { -1, -1, -1, 0, 0, -3, 0, -1 }, /* -P-P-P . *-N *-P */ { 0, 0, 0, 0, 0, 0, 0, 2 }, /* . * . * . * . B */ { 0, 0, 0, 0, 0, -5, 0, 3 }, /* * . * . *-Q * N */ { 0, -2, -1, 0, 0, 0, 0, 0 }, /* .-B-P * . * . * */ { 0, 0, 1, -1, 0, 0, 0, 0 }, /* * . P-P * . * . */ { 1, 1, 0, 0, 4, 1, 1, 1 }, /* P P . * R P P P */ { 4, 0, 0, 5, 0, 0, 6, 0 } /* R . * Q * . K . */ }; /* "SHANNON'S SACRIFICE" - SCIENTIFIC AMERICAN, FEB'50 */ void main( int argc, char **argv ) { /* read chessboard data from named file ... or use default if no file named */ if ((in_fcb = fopen(argv[1],"r")) == NULL) { /* barf on open error */ if (argc>1) fprintf(stderr, "\007\nCannot open data file '%s'\007\n", argv[1]); } else { for (ua=0 ; ua<8 ; ua++) /* for each row ... */ for (re=0 ; re<8 ; re++) /* for each column ... */ fscanf(in_fcb, "%d", &sq[ua][re]); /* ... get value */ fclose(in_fcb); } /* ** for each sq[ua][re] determine the the color of the piece ('pcolor') */ for (ua=0 ; ua<8 ; ua++) { printf("{ rank #%d }\n", 8-ua); for (re=0 ; re<8 ; re++) { pcolor = (sq[ua][re]<0 ? BLACK : WHITE); /* ** now that you've got it, output 'x' and 'z' coordinates ** if the sq[ua][re] is not empty (value 0), put the kind of piece ('mask') */ if (sq[ua][re]) printf("\tOBJECT %c%s TRANSLATE <%d 0 %d> END_OBJECT\t{ %c%d }\n", pcolor, mask[abs(sq[ua][re])], -28+(re*8), 28-(ua*8), (char)('a'+re), 8-ua); } } }