Gamemaster
General
Game
Playing
tictactoe
Description
Tic Tac Toe (or Noughts and Crosses, Xs and Os) is a game for two players who take turns placing their marks in a 3x3 grid. The first player to place three of his marks in a horizontal, vertical, or diagonal row wins the game.
Rulesheet
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% tictactoe %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% metadata %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% role(x) role(o) base(cell(M,N,x)) :- index(M) & index(N) base(cell(M,N,o)) :- index(M) & index(N) base(cell(M,N,b)) :- index(M) & index(N) base(control(R)) :- role(R) action(mark(M,N)) :- index(M) & index(N) index(1) index(2) index(3) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% init %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% init(cell(M,N,b)) :- index(M) & index(N) init(control(x)) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% legal %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% legal(mark(M,N)) :- cell(M,N,b) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% operations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mark(M,N) :: control(R) ==> cell(M,N,R) & ~cell(M,N,b) mark(M,N) :: control(x) ==> ~control(x) & control(o) mark(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) row(M,X) :- cell(M,1,X) & cell(M,2,X) & cell(M,3,X) col(N,X) :- cell(1,N,X) & cell(2,N,X) & cell(3,N,X) diag(X) :- cell(1,1,X) & cell(2,2,X) & cell(3,3,X) diag(X) :- cell(1,3,X) & cell(2,2,X) & cell(3,1,X) line(X) :- row(M,X) line(X) :- col(N,X) line(X) :- diag(X) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% terminal %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% terminal :- line(x) terminal :- line(o) terminal :- ~open open :- cell(M,N,b) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Stylesheet
//============================================================================== // tictactoe //============================================================================== function rendersituation (state) {var role = findcontrol(state,library); var table = document.createElement('table'); table.setAttribute('border','0'); var row = table.insertRow(table.rows.length); var cell = row.insertCell(0); cell.setAttribute('align','center'); cell.setAttribute('style',"font-size:14px;font-family:arial;color:#888888"); cell.innerHTML = "Click a cell to mark that cell."; var row = table.insertRow(table.rows.length); var cell = row.insertCell(0); cell.setAttribute('align','center'); cell.appendChild(renderactiveboard(state)); row = table.insertRow(table.rows.length); var cell = row.insertCell(0); cell.setAttribute('align','center'); cell.setAttribute('style','font-size:20px'); if (findterminalp(state,library)) {cell.innerHTML = 'Game over'} else {cell.innerHTML = 'Control: ' + role}; return table} function renderactiveboard (state) {var table = document.createElement('table'); table.setAttribute('cellspacing','0'); table.setAttribute('bgcolor','white'); table.setAttribute('border','10'); makeactiverow(table,0,state); makeactiverow(table,1,state); makeactiverow(table,2,state); return table} function makeactiverow (table,rownum,state) {var row =table.insertRow(rownum); makeactivecell(row,rownum,0,state); makeactivecell(row,rownum,1,state); makeactivecell(row,rownum,2,state); return row} function makeactivecell (row,rownum,colnum,state) {var cell = row.insertCell(colnum); cell.setAttribute('width','60'); cell.setAttribute('height','60'); cell.setAttribute('align','center'); cell.setAttribute('valign','center'); cell.setAttribute('style','font-family:helvetica;font-size:28pt'); rownum = (rownum+1).toString(); colnum = (colnum+1).toString(); var mark = compfindx('Z',seq('cell',rownum,colnum,'Z'),state,seq()); if (mark && mark != 'b') {cell.innerHTML = mark} else {cell.innerHTML = ' '; cell.id = grind(seq('mark',rownum,colnum)); if (findterminalp(state,library)) {return cell}; cell.setAttribute("onclick","perform(read(this.id))"); cell.style.cursor = "pointer"}; return cell} //============================================================================== 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 (findterminalp(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('bgcolor','white'); table.setAttribute('border','10'); makerow(table,0,state); makerow(table,1,state); makerow(table,2,state); return table} function makerow (table,rownum,state) {var row =table.insertRow(rownum); makecell(row,rownum,0,state); makecell(row,rownum,1,state); makecell(row,rownum,2,state); return row} function makecell (row,rownum,colnum,state) {var cell = row.insertCell(colnum); cell.setAttribute('width','60'); cell.setAttribute('height','60'); cell.setAttribute('align','center'); cell.setAttribute('valign','center'); cell.setAttribute('style','font-family:helvetica;font-size:28pt'); rownum = (rownum+1).toString(); colnum = (colnum+1).toString(); var mark = compfindx('Z',seq('cell',rownum,colnum,'Z'),state,seq()); if (mark && mark != 'b') {cell.innerHTML = mark} else {cell.innerHTML = ' '}; return cell} //============================================================================== function renderactions (state) {return document.createTextNode("")} //============================================================================== //============================================================================== //==============================================================================
Ownership
genesereth