Gamemaster
General
Game
Playing
besttictactoe
Description
Two boards of Tic Tac Toe.
Rulesheet
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% besttictactoe %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% metadata %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% role(x) role(o) base(cell(B,M,N,x)) :- board(B) & index(M) & index(N) base(cell(B,M,N,o)) :- board(B) & index(M) & index(N) base(cell(B,M,N,b)) :- board(B) & index(M) & index(N) base(control(R)) :- role(R) action(mark(B,M,N)) :- board(B) & index(M) & index(N) board(al) board(be) index(1) index(2) index(3) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% init %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% init(cell(B,M,N,b)) :- board(B) & index(M) & index(N) init(cell(al,1,1,b)) init(control(x)) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% legal %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% legal(mark(B,M,N)) :- cell(B,M,N,b) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% operations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mark(B,M,N) :: control(R) ==> cell(B,M,N,R) & ~cell(B,M,N,b) mark(B,M,N) :: control(x) ==> ~control(x) & control(o) mark(B,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(B,M,X) :- cell(B,M,1,X) & cell(B,M,2,X) & cell(B,M,3,X) col(B,N,X) :- cell(B,1,N,X) & cell(B,2,N,X) & cell(B,3,N,X) diag(B,X) :- cell(B,1,1,X) & cell(B,2,2,X) & cell(B,3,3,X) diag(B,X) :- cell(B,1,3,X) & cell(B,2,2,X) & cell(B,3,1,X) line(X) :- row(al,M,X) | row(be,M,X) line(X) :- col(al,N,X) | col(be,M,X) line(X) :- diag(al,X) | diag(be,X) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% terminal %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% terminal :- line(x) terminal :- line(o) terminal :- ~open open :- cell(B,M,N,b) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Stylesheet
//============================================================================== // besttictactoe //============================================================================== 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('bgcolor','white'); table.setAttribute('border','10'); var row = table.insertRow(0); var cell = row.insertCell(0); cell.appendChild(render('al', state)) var row = table.insertRow(1); var cell = row.insertCell(0); cell.appendChild(render('be',state)) return table} function render(game, state) { var table = document.createElement('table'); table.setAttribute('cellspacing','0'); table.setAttribute('bgcolor','white'); table.setAttribute('border','10'); makerow(table, 0, state, game) makerow(table, 1, state, game) makerow(table, 2, state, game) return table } function makerow (table,rownum,state, game) {var row =table.insertRow(rownum); makecell(row,rownum,0,state, game); makecell(row,rownum,1,state, game); makecell(row,rownum,2,state, game); return row} function makecell (row,rownum,colnum,state, game) {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',game,rownum,colnum,'Z'),state,seq()); if (mark && mark != 'b') {cell.innerHTML = mark} else {cell.innerHTML = ' '}; return cell} //============================================================================== //============================================================================== //==============================================================================
Ownership