%%s 0/0/0 %%d D 1.1 25-Mar-82 12:15:52 v1.1 1 0 %%c Version 1.1 is the Spring 1982 Distribution of the LBL/Hughes release %%c of the Software Tools Virtual Operating System software and documentation. %%T %%I 1 #-h- cttt 131 asc 25-mar-82 09:00:14 v1.1 (sw-tools v1.1) ## cttt - common block for ttt common /cttt/ w(304), b(64) integer w # Table of winning positions integer b # The game board #-h- ttt.r 6014 asc 25-mar-82 09:00:17 v1.1 (sw-tools v1.1) #-h- tttsym 168 asc 25-mar-82 08:59:40 v1.1 (sw-tools v1.1) ## tttsym -- symbol definitions for tic tac toe define(EMPTY,0) define(PLAYER,1) define(BEAST,5) define(BUFSIZE,20) define(pl,call putlin($1,STDOUT);call putc('@n')) #-h- ttt 492 asc 25-mar-82 08:59:41 v1.1 (sw-tools v1.1) ## ttt - 3D Tic Tac Toe ## See the April '78 issue of Kilobaud for details. DRIVER(ttt) include cttt integer prompt character buf(BUFSIZE) call query("usage: ttt.") call tttini if( prompt( "Do you want the rules? (n) ", buf, STDIN) == EOF ) return else if( buf(1) == 'Y' | buf(1) == 'y' ) call rules if( prompt( "Do you want to go first? (n) ", buf, STDIN) == EOF ) return else if( buf(1) == 'Y' | buf(1) == 'y' ) call user repeat { call beast call user } DRETURN end #-h- tttini 1395 asc 25-mar-82 08:59:43 v1.1 (sw-tools v1.1) ## tttini -- initialize win table and game board. subroutine tttini integer i include cttt data w /01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 01, 05, 09, 13, 02, 06, 10, 14, 03, 07, 11, 15, 04, 08, 12, 16, 01, 06, 11, 16, 04, 07, 10, 13, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 17, 21, 25, 29, 18, 22, 26, 30, 19, 23, 27, 31, 20, 24, 28, 32, 17, 22, 27, 32, 20, 23, 26, 29, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 33, 37, 41, 45, 34, 38, 42, 46, 35, 39, 43, 47, 36, 40, 44, 48, 33, 38, 43, 48, 36, 39, 42, 45, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 49, 53, 57, 61, 50, 54, 58, 62, 51, 55, 59, 63, 52, 56, 60, 64, 49, 54, 59, 64, 52, 55, 58, 61, 01, 17, 33, 49, 02, 18, 34, 50, 03, 19, 35, 51, 04, 20, 36, 52, 05, 21, 37, 53, 06, 22, 38, 54, 07, 23, 39, 55, 08, 24, 40, 56, 09, 25, 41, 57, 10, 26, 42, 58, 11, 27, 43, 59, 12, 28, 44, 60, 14, 30, 46, 62, 13, 29, 45, 61, 15, 31, 47, 63, 16, 32, 48, 64, 01, 22, 43, 64, 05, 22, 39, 56, 09, 26, 43, 60, 13, 26, 39, 52, 02, 22, 42, 62, 14, 26, 38, 50, 03, 23, 43, 63, 15, 27, 39, 51, 04, 23, 42, 61, 08, 23, 38, 53, 12, 27, 42, 57, 16, 27, 38, 49, 01, 21, 41, 61, 01, 18, 35, 52, 04, 19, 34, 49, 04, 24, 44, 64, 13, 25, 37, 49, 13, 30, 47, 64, 16, 31, 46, 61, 16, 28, 40, 52/ for( i = 1 ; i <= 64 ; i = i + 1 ) b(i) = 0 return end #-h- beast 1157 asc 25-mar-82 08:59:45 v1.1 (sw-tools v1.1) ## beast -- move for the machine. exit on machine wins and draws. subroutine beast integer i, j, t integer bs, bt, s, v(76) integer weight include cttt for( i = 1 ; i <= 4 * 76 ; i = i + 4 ) { t = 0 for( j = 0 ; j < 4 ; j = j + 1 ) t = t + b( w(i+j) ) v( (i-1)/4 + 1 ) = t if( t == 3 * BEAST ) break } if( i <= 4 * 76 ) { for( j = 0 ; j < 4 ; j = j + 1 ) { if( b( w(i+j) ) == EMPTY ) { b( w(i+j) ) = BEAST break } } call board call remark( "i win.") call endst(OK) } bt = 0 for( s = 1 ; s <= 64 ; s = s + 1 ) { if( b(s) != EMPTY ) next t = 0 for( i = 1 ; i <= 4 * 76 ; i = i + 4 ) { for( j = 0 ; j < 4 ; j = j + 1 ) if( w(i+j) == s ) break if( j != 4 ) { if( v( (i-1)/4 + 1 ) == 3 * PLAYER ) { b(s) = BEAST return } t = t + weight( v( (i-1)/4 + 1 ) ) } } if( t > bt ) { bt = t bs = s } } if( bt != 0 ) b(bs) = BEAST else { for( s = 1 ; s <= 64 ; s = s + 1 ) if( b(s) == EMPTY ) break if( s > 64 ) { call remark( "draw.") call endst(OK) } b(s) = BEAST } return end #-h- board 469 asc 25-mar-82 08:59:47 v1.1 (sw-tools v1.1) ## board -- display the game board for tic tac toe. subroutine board integer i, j string sep "----------- ----------- ----------- -----------" call putc('@n') for( i = 1 ; i <= 4 ; i = i + 1 ) { if( i != 1 ) pl(sep) for( j = 0 ; j < 64 ; j = j + 4 ) { call psq(i+j) if( j == 12 | j == 28 | j == 44 ) call putlin( " ", STDOUT) else if( j >= 60 ) call putc('@n') else call putc('!') } } call putc('@n') return end #-h- psq 288 asc 25-mar-82 08:59:48 v1.1 (sw-tools v1.1) ## psq -- Output a square for tic tac toe subroutine psq(s) integer s, v include cttt string uu "UU" string cc "CC" string bb " " v = b(s) if( v == PLAYER ) call putlin( uu, STDOUT) else if( v == BEAST ) call putlin( cc, STDOUT) else call putlin( bb, STDOUT) return end #-h- rules 442 asc 25-mar-82 08:59:49 v1.1 (sw-tools v1.1) ## rules -- display tic tac toe rules subroutine rules pl(" ") pl("Three dimensional tic-tac-toe is played on a 4x4x4") pl("board. To win you must get 4 in a row. Your moves") pl("are specified as a 3 digit number; the first digit") pl("is the level, the second the row and the third the") pl("column. Levels and columns go from left to right") pl("from 0 to 3. Rows go from top to bottom with 0 on") pl("the top.") pl(" ") return end #-h- user 651 asc 25-mar-82 08:59:50 v1.1 (sw-tools v1.1) ## user -- Accept a user move. Exit if he/she wins. subroutine user include cttt integer i, j, t integer d1, d2, d3 integer prompt character buf(BUFSIZE) call board repeat { if( prompt( "Your move? ", buf, STDIN) <= 0 ) call endst(OK) d1 = buf(1) - '0' d2 = buf(2) - '0' d3 = buf(3) - '0' i = 16 * d1 + d2 + 4 * d3 + 1 if( 1 <= i & i <= 64 & b(i) == EMPTY ) # valid move break call remark("?eh?") } b(i) = PLAYER for( i = 1 ; i <= 4 * 76 ; i = i + 4 ) { t = 0 for( j = 0 ; j < 4 ; j = j + 1 ) t = t + b( w(i+j) ) if( t == 4 * PLAYER ) { call remark( "you win.") call endst(OK) } } return end #-h- weight 295 asc 25-mar-82 08:59:52 v1.1 (sw-tools v1.1) ## weight -- return weight value for total along a winning combination. integer function weight(at) integer at if( at == PLAYER ) weight = 1 else if( at == 2 * PLAYER ) weight = 4 else if( at == BEAST ) weight = 1 else if( at == 2 * BEAST ) weight = 2 else weight = 0 return end #-h- ttt.fmt 337 asc 25-mar-82 09:00:21 v1.1 (sw-tools v1.1) .so ~bin/manhdr .hd Ttt (1) 15-Nov-81 3-dimensional tic tac toe .sy ttt .ds TTT is a 3-dimensional tic tac toe game played against the computer. The program will explain the rules. .sa The UNIX ``ttt'' program. .au Original Basic version by Joseph Roehrig. .br Converted to C by Dave Conroy. .br Converted to RatFor by Dave Martin. .bu %%E 1