Gamemaster
General
Game
Playing
nineboardtictactoe
Description
In nine board tic-tac-toe, nine tic-tac-toe boards are themselves arranged in a 3x3 grid. The first player's move must go on the middle board; all moves afterwards are placed in the empty spaces on the board corresponding to the square of the previous move (that is, if a move were in the upper-left square of a board, the next move would take place on the upper-left board). If a player cannot move because the indicated board is full, the game ends in a draw. Victory is attained by getting three in a row on any board. This makes the game considerably longer and more involved than tic-tac-toe, with a definite opening, middle game, and endgame.
Rulesheet
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% nineboardtictactoe %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% metadata %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% role(x) role(o) base(cell(I,J,K,L,x)) :- index(I) & index(J) & index(K) & index(L) base(cell(I,J,K,L,o)) :- index(I) & index(J) & index(K) & index(L) base(cell(I,J,K,L,b)) :- index(I) & index(J) & index(K) & index(L) base(current(I,J)) :- index(I) & index(J) base(control(R)) :- role(R) action(mark(I,J,K,L)) :- index(I) & index(J) & index(K) & index(L) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% init %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% init(cell(I,J,K,L,b)) :- index(I) & index(J) & index(K) & index(L) init(current(2,2)) init(control(x)) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% legal %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% legal(mark(I,J,K,L)) :- control(R) & current(I,J) & cell(I,J,K,L,b) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% operations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mark(I,J,M,N) :: control(R) ==> cell(I,J,M,N,R) & ~cell(I,J,M,N,b) mark(I,J,M,N) :: ~current(I,J) & current(M,N) mark(I,J,M,N) :: control(x) ==> ~control(x) & control(o) mark(I,J,M,N) :: control(o) ==> ~control(o) & control(x) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% goal %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% goal(x,100) :- line(x) & ~line(o) goal(x,50) :- line(x) & line(o) goal(x,50) :- ~line(x) & ~line(o) goal(x,0) :- ~line(x) & line(o) goal(o,100) :- ~line(x) & line(o) goal(o,50) :- line(x) & line(o) goal(o,50) :- ~line(x) & ~line(o) goal(o,0) :- line(x) & ~line(o) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% terminal %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% terminal :- line(x) terminal :- line(o) terminal :- current(I,J) & ~open(I,J) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Views %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% row(I,J,M,X) :- cell(I,J,M,1,X) & cell(I,J,M,2,X) & cell(I,J,M,3,X) col(I,J,N,X) :- cell(I,J,1,N,X) & cell(I,J,2,N,X) & cell(I,J,3,N,X) diag(I,J,X) :- cell(I,J,1,1,X) & cell(I,J,2,2,X) & cell(I,J,3,3,X) diag(I,J,X) :- cell(I,J,1,3,X) & cell(I,J,2,2,X) & cell(I,J,3,1,X) line(X) :- row(I,J,M,X) line(X) :- col(I,J,N,X) line(X) :- diag(I,J,X) open(I,J) :- cell(I,J,M,N,b) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% index(1) index(2) index(3) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Stylesheet
//------------------------------------------------------------------------------ // nineboardtictactoe //------------------------------------------------------------------------------ function renderstate (state) {var role = compfindx('R',seq('control','R'),state,library); var table = document.createElement('table'); table.setAttribute('border','0'); var row = table.insertRow(table.rows.length); var cell = row.insertCell(0); var board = renderboard(state); cell.appendChild(board); row = table.insertRow(table.rows.length); var cell = row.insertCell(0); cell.setAttribute('align','center'); cell.setAttribute('style','font-size:20px'); if (compfindp('terminal',state,library)) {cell.innerHTML = 'Game over'} else {cell.innerHTML = 'Control: ' + role}; return table} function renderboard (state) {var table = document.createElement('table'); table.setAttribute('cellspacing','0'); table.setAttribute('border','0'); var row = table.insertRow(0); var cell = row.insertCell(0); cell.appendChild(maketable('1','1',state)); cell = row.insertCell(1); cell.appendChild(maketable('1','2',state)); cell = row.insertCell(2); cell.appendChild(maketable('1','3',state)); row = table.insertRow(1); cell = row.insertCell(0); cell.appendChild(maketable('2','1',state)); cell = row.insertCell(1); cell.appendChild(maketable('2','2',state)); cell = row.insertCell(2); cell.appendChild(maketable('2','3',state)); row = table.insertRow(2); cell = row.insertCell(0); cell.appendChild(maketable('3','1',state)); cell = row.insertCell(1); cell.appendChild(maketable('3','2',state)); cell = row.insertCell(2); cell.appendChild(maketable('3','3',state)); return table} function maketable (boardrow,boardcol,state) {var table = document.createElement('table'); table.setAttribute('cellspacing','0'); var current = compfindp(seq('current',boardrow,boardcol),state,seq()); if (current) {table.setAttribute('bgcolor','#ffeeee')} else {table.setAttribute('bgcolor','#eeeeee')}; table.setAttribute('border','10'); makerow(table,boardrow,boardcol,0,state); makerow(table,boardrow,boardcol,1,state); makerow(table,boardrow,boardcol,2,state); return table} function makerow (table,boardrow,boardcol,rownum,state) {var row =table.insertRow(rownum); makecell(row,boardrow,boardcol,rownum,0,state); makecell(row,boardrow,boardcol,rownum,1,state); makecell(row,boardrow,boardcol,rownum,2,state); return row} function makecell (row,boardrow,boardcol,rownum,colnum,state) {var cell = row.insertCell(colnum); cell.setAttribute('width','40'); cell.setAttribute('height','40'); cell.setAttribute('align','center'); cell.setAttribute('valign','center'); cell.setAttribute('style','font-family:helvetica;font-size:18pt'); rownum = (rownum+1).toString(); colnum = (colnum+1).toString(); var mark = compfindx('Z',seq('cell',boardrow,boardcol,rownum,colnum,'Z'),state,seq()); if (mark && mark != 'b') {cell.innerHTML = mark} else {cell.innerHTML = ' '}; return cell} //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Ownership