/ Superply Web Edition
/ Code author: Dennis Shasha, 2002
/ Here is the activity we want. Display a choice of boards.
/ Once a board is chosen, display it with blanks and with the
/ row and column headers showing.
/ Then put up the header that says: Red (horizontal) moves first.
/ Show a hint card.
/ When a player clicks the first one, see whether the hint matches.
/ If so, then fill that space with color (showing the answer)
/ and see whether that player wins. If correct but player doesn't win
/ then the player goes into addmove mode where there is a contiguity
/ requirement.
/ When a player's move does not satisfy the requirement, then play
/ continues with the other player.
/ Must have the ability to match a hint to a choice.
/
/ New interface: go to attbroker at port 2000 and attman at port 2120 etc.
/ attbroker gives a session id and a port as before, but there can
/ be many sessions on a given port. The session id should be part
/ of the command:
/ each command should have the intended command then colon then a session id,
/ e.g. sendtables:31
/ Guangwei: set the m h to 2120, 2121 etc.
/ Set the m i 1000 higher.
\m h 2226
webaddress: ""
/ STRING PROCESSING
/ parses a field based on vertical bars
getfields:{[line]
i: line = "|"
j1: &i
j2: &~i
line @:j2
size: #j1
:(0,(j1 - !size)) _ line
}
/ get rid of blanks at either end of the string
delendblanks:{[string]
if[0 = #string; :""]
if[string ~ ,"" ; :""]
i: & ~ string = " "
if[(#string) = (#i); :string]
if[0 = (#i); :""]
string: (- ((#string) - (1 + *|i))) _ string
:(*i) _ string
}
/ HTMLIZE
printheader:{[atts]
out: "
"
j: 0
while[j < #atts
out,: " "
out,: ($atts[j]), (" | ")
j+: 1
]
out,: "
"
:out
}
/ spit out a table of tables and attributes
tabatttable:{[timestamp; val]
j: 0
out: ""
while[j < #val
out,: ""
v: val[j]
w: $v
type: :[j = 0; "table:"; "attribute:"]
if[(j=0) & (v = disptable); w: ("*_"), w]
out,: ,/(" "
""
$w
""
" | ")
j+: 1
]
out,: "
"
:out
}
/ print out tables and attributes as a table
tabatt:{[timestamp]
tabs: disptable..o
atts: listofatts
max: (#tabs) | (#atts)
if[max > (#tabs)
tabs,: (max - (#tabs)) # `
]
if[max > (#atts)
atts,: (max - (#atts)) # `
]
pairs: tabs ,' atts
x :(printheader[`Tables `Attributes])
: x, (,/ (tabatttable[timestamp]' pairs)), ("
")
}
/ spit out a table of values
tablehtmlize:{[type; timestamp; textcols; vals;i]
val: vals[i], ()
j: 0
out: ""
while[j < #val
out,: ""
v: val[j]
out,: ,/(" "
""
$v
""
" | ")
j+: 1
]
out,: "
"
if[i = ((#vals) - 1)
/ last one
out,: ""
]
:out
}
/ val may be a singleton or a pair, triplet, ...
valhtmlize:{[timestamp; textcols; vals;i]
val: vals[i], ()
j: 0
out: ()
while[j < #val
v: val[j]
if[j _in textcols / send back row
out,: ,/(" "
" ")
]
if[~ j _in textcols
out,: ,/(" "
""
$v
""
" ")
]
j+: 1
]
out,: "
"
:out
}
/ given table, attribute or value as a symbol, spit out the appropriate href
htmlize:{[timestamp; type; name]
: ,/(" "
""
$name
""
" ")
}
/ END HTMLIZE
\l webkid
/ BROWSER INTERFACE
forlog: ()
/ .m.h receives inputs from the web
/ input part is in common. Processing of xweb string is different
/ depending on whether it is native or not.
.m.h:{[xweb]
webstring,: ,xweb
forlog,: ,xweb
xweb: convertweb[xweb]
getflag: xweb[!3] ~ "GET"
if[getflag / get operation e.g. .m.h[attribute:foo]
if[0 = # xweb _ss ".m.h"; :xweb] / we used to stop here
iii: * xweb _ss ".m.h"
xweb: iii _ xweb
j: xweb ? "]"
xweb@: !j
xweb: 5 _ xweb / to get rid of .m.h
]
if[~getflag / post operation, e.g. filling in blanks for ordering stuff
!-14 / should never have a post
/ This can only have to do with values.
i: xweb _ss "Text"
j: (*i) + 4
/ find out which column was modified
rowmodified: ()
while[xweb[j] _in "0123456789"
rowmodified,: xweb[j]
j+: 1
]
rowmodified: 0 $ rowmodified
xweb: (*i) _ xweb
i: 1 + *| & xweb = "="
flag: 1
while[ flag
if[(i = #xweb)
flag: 0
]
if[flag = 1
if[(~xweb[i] _in "0123456789")
flag:0
]
]
i+: 1
]
xweb@: !(i-1)
/ xweb: convertweb[xweb]
j: & ~ xweb = " "
xweb@: j
starts: 1 + & xweb = "="
ends: & xweb = "&"
ends,: #xweb / final &
yy: xweb[starts + !:'(ends - starts)] / assemble answers
myval[rowmodified]:: yy
/ causing the myval trigger to fire
]
xweb: convertweb[xweb] / this results in exactly what's in .m.h brackets
/ Believe above is unnecessary
if[lastinput ~ xweb; :lastoutput]
zz: _ltime _t
forlog,: ,("Timestamp: "),($zz[0]),(" "),($zz[1])
forlog,: ,xweb
if[xweb _sm "*tart*"
y:processxwebministart[xweb]
]
if[xweb _sm "*click*"
y:processxwebminiclick[xweb]
]
/ savesession[currentsessionid]
lastinput:: xweb
lastoutput:: y
"log6" 0: forlog
"screen" 0: y
:y
}
/ gets rid of strange web stuff (written by Mike Rosenberg)
convertweb:{[x]
,/@[(0,,/+(a;a+3))_ x;&(!2*#a)!2;:
_ci+/'16 1*/:"0123456789ABCDEF"?/:/:x@(a:&x="%")+\:1 2]}
/ process a start game request
processxwebministart: {[xweb]
cardindex:: 0
out: "