var curb=""
var whiteturn = ">"
var blackturn = "<"
var blackbottom = "bb"
var whitebottom = "wb"
var bottomcolor = whitebottom
function forsythtoplain(aa) {
// e.g. aa = "r1bqkbnr;pppp1ppp;2n5;1B2p4;4P3;5N2;PPPP1PPP;RNBQKB1R;>"
aa = new String (aa)
res=""
thelen=aa.length
for (i=0;i"
return res
}
function forsythtoplain1char(cc) {
// e.g. cc = "r", "n", "b", "3"
res=""
if (cc=="<") {return cc}
if (cc==">") {return cc}
if (cc==".") {return cc}
if (cc=="x") {return cc}
if (cc=="m") {return cc}
if (cc=="r") {return cc}
if (cc=="n") {return cc}
if (cc=="b") {return cc}
if (cc=="q") {return cc}
if (cc=="k") {return cc}
if (cc=="p") {return cc}
if (cc=="R") {return cc}
if (cc=="N") {return cc}
if (cc=="B") {return cc}
if (cc=="Q") {return cc}
if (cc=="K") {return cc}
if (cc=="P") {return cc}
if (cc=="1") {return "x"}
if (cc=="2") {return "xx"}
if (cc=="3") {return "xxx"}
if (cc=="4") {return "xxxx"}
if (cc=="5") {return "xxxxx"}
if (cc=="6") {return "xxxxxx"}
if (cc=="7") {return "xxxxxxx"}
if (cc=="8") {return "xxxxxxxx"}
return ""
}
function putpiece (i,cc) {
// e.g. putpiece (5,"k") {
// alert ( 'putpiece ' + i + ' = ' + cc )
res = ""
if (false) {
} else if (cc==">") { res += "wk"
} else if (cc=="<") { res += "bk"
} else if (cc=="x") { res += "mt"
} else if (cc=="m") { res += "mt"
} else if (cc==".") { res += "mt"
} else if (cc=="r") { res += "br"
} else if (cc=="n") { res += "bn"
} else if (cc=="b") { res += "bb"
} else if (cc=="q") { res += "bq"
} else if (cc=="k") { res += "bk"
} else if (cc=="p") { res += "bp"
} else if (cc=="R") { res += "wr"
} else if (cc=="N") { res += "wn"
} else if (cc=="B") { res += "wb"
} else if (cc=="Q") { res += "wq"
} else if (cc=="K") { res += "wk"
} else if (cc=="P") { res += "wp"
} else {}
if (false) {
} else if (i==64 && cc==">") {
res += "_l"
} else if (i==64 && cc=="<") {
res += "_d"
} else if (iswhite(i)) {
res += "_l"
} else {
res += "_d"
}
document.images[i].src=giffile(res)
return true
}
function iswhite(i) {
rowstart = (mydiv(i,8) % 2)
field = i % 2
return (rowstart == field)
}
function mydiv(i,x) {
iclean = i - (i%x)
idivx = iclean / x
return idivx
}
function domakemove( fromftof , updatecurb ) {
// ---------------------------------------------
// -- curb: the board
// -- fromftof: "d2d4"
// ---------------------------------------------
fromf = ""
fromf += fromftof.charAt(0)
fromf += fromftof.charAt(1)
tof = ""
tof += fromftof.charAt(2)
tof += fromftof.charAt(3)
return makemove(curb,fromf,tof,updatecurb)
}
function makemove( bb, fromf, tof , updatecurb ) {
// ---------------------------------------------
// -- bb: the board
// -- fromf: move from field (number 0-63)
// -- tof: move to field
// ---------------------------------------------
// alert ( 'makemove ' + bb + "\n" + fromf + ", " + tof )
turnnumber = 64
turn = bb.charAt(turnnumber)
fromf = fieldtonumber(fromf)
tof = fieldtonumber(tof)
piece = bb.charAt(fromf)
// alert ( bb + "\n char " + fromf + " = " + piece)
bb = replacepiece ( bb, tof, piece )
bb = replacepiece ( bb, fromf, "x" )
bb = replacepiece ( bb, turnnumber, switchturn(turn) )
// alert ( "makemove res = " + bb )
if (updatecurb) {curb = bb}
return bb
}
function fieldtonumber ( ff ) {
// ---------------------------------------------
// -- ff: "e2" (e.g.)
// ---------------------------------------------
//alert ( 'fieldtonumber: ' + ff )
theline = ff.charAt(0)
therow = ff.charAt(1)
// alert ( 'line ' + theline + " row " + therow )
if (therow=="8") {res = 0}
if (therow=="7") {res = 8}
if (therow=="6") {res = 16}
if (therow=="5") {res = 24}
if (therow=="4") {res = 32}
if (therow=="3") {res = 40}
if (therow=="2") {res = 48}
if (therow=="1") {res = 56}
if (theline=="a") {res += 0}
if (theline=="b") {res += 1}
if (theline=="c") {res += 2}
if (theline=="d") {res += 3}
if (theline=="e") {res += 4}
if (theline=="f") {res += 5}
if (theline=="g") {res += 6}
if (theline=="h") {res += 7}
//alert ( 'fieldtonumber-res: ' + res )
return res
}
function replacepiece ( bb, ii, piece ) {
// ---------------------------------------------
// -- bb: the board
// -- ff: field (number 0-63)
// -- piece: e.g. "r" = rook
// ---------------------------------------------
// alert ( "replacepiece: " + piece )
res = replacestringpos(bb,ii,ii+1,piece)
// alert ( "replacepiece res = " + res )
return res
}
function switchturn ( turn ) {
// ---------------------------------------------
// -- turn = blackturn/whiteturn
// ---------------------------------------------
if (turn==whiteturn) {
return blackturn
} else {
return whiteturn
}
}
function replacestringpos ( ss, ii, jj, tt ) {
// ---------------------------------------------
// -- bb: the string
// -- ii: start of substring to be replaced
// -- jj: first char after substring to be replaced
// -- tt: replace string
// ---------------------------------------------
// alert ( "replacestringpos: " + ss + "\n" + ii + ", " + jj + ", " + tt )
res = ""
res += ss.substring(0,ii)
res += tt
res += ss.substring(jj,ss.length)
// alert ( 'result: ' + res )
return res
}
function initpos() {
return (
"rnbqkbnr;"
+ "pppppppp;"
+ "8;"
+ "8;"
+ "8;"
+ "8;"
+ "PPPPPPPP;"
+ "RNBQKBNR;>"
)
}
var curb=forsythtoplain(initpos())