// NEWLIB var curb="" var emptyf = "_" 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 officer if (ispawn(piece)) { if (tof.charAt(1)=="8" || tof.charAt(1)=="1") { if (false) { } else if (piece=="p"){ piece = "z" } else if (piece=="P"){ piece = "Z" } } } bb = replacepiece ( bb, tofnum, piece ) bb = replacepiece ( bb, fromfnum, emptyf ) bb = replacepiece ( bb, turnnumber, switchturn(turn) ) // alert ( "makemove res = " + bb ) if (updatecurb) {curb = bb} return bb } // makemove function fieldtonumber ( ff ) { // --------------------------------------------- // -- ff: "e2" (e.g.) // --------------------------------------------- //alert ( 'fieldtonumber: ' + ff ) theline = ff.charAt(0) therow = ff.charAt(1) // alert ( 'line ' + theline + " row " + therow ) res = 8 * rowtonumber(therow) + linetonumber(theline) //alert ( 'fieldtonumber-res: ' + res ) return res } function numbertofield ( ff ) { // --------------------------------------------- // -- ff: 17 (e.g.) // --------------------------------------------- //alert ( 'numbertofield: ' + ff ) linenum = ff % 8 rownum = mydiv(ff,8) res = "" // alert ( 'line ' + linenum + " row " + rownum ) res += numbertoline(linenum) res += numbertoline(rownum) //alert ( 'numbertofield-res: ' + res ) return res } function linetonumber(theline) { if (theline=="a") {return 0} if (theline=="b") {return 1} if (theline=="c") {return 2} if (theline=="d") {return 3} if (theline=="e") {return 4} if (theline=="f") {return 5} if (theline=="g") {return 6} if (theline=="h") {return 7} } function numbertoline(linenumber) { if (linenumber==0) {return "a"} if (linenumber==1) {return "b"} if (linenumber==2) {return "c"} if (linenumber==3) {return "d"} if (linenumber==4) {return "e"} if (linenumber==5) {return "f"} if (linenumber==6) {return "g"} if (linenumber==7) {return "h"} } function rowtonumber(therow) { if (therow=="8") {return 0} if (therow=="7") {return 1} if (therow=="6") {return 2} if (therow=="5") {return 3} if (therow=="4") {return 4} if (therow=="3") {return 5} if (therow=="2") {return 6} if (therow=="1") {return 7} } function numbertorow(rownumber) { if (rownumber==0) {return "8"} if (rownumber==1) {return "7"} if (rownumber==2) {return "6"} if (rownumber==3) {return "5"} if (rownumber==4) {return "4"} if (rownumber==5) {return "3"} if (rownumber==6) {return "2"} if (rownumber==7) {return "1"} } 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()) 1