Thread: [Toss-devel-svn] SF.net SVN: toss:[1440] trunk/Toss (Page 7)
Status: Beta
Brought to you by:
lukaszkaiser
From: <luk...@us...> - 2011-05-13 23:34:02
|
Revision: 1440 http://toss.svn.sourceforge.net/toss/?rev=1440&view=rev Author: lukaszkaiser Date: 2011-05-13 23:33:56 +0000 (Fri, 13 May 2011) Log Message: ----------- Add cache expiration to http GET answers. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Connect.js Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-05-13 23:17:33 UTC (rev 1439) +++ trunk/Toss/Server/ReqHandler.ml 2011-05-13 23:33:56 UTC (rev 1440) @@ -353,7 +353,7 @@ (* ------------ Http Handlers ------------ *) -let http_msg code mimetp cookies s = +let http_msg get code mimetp cookies s = let get_tm s = let t = Unix.gmtime (Unix.gettimeofday() +. s) in let day = match t.Unix.tm_wday with @@ -371,7 +371,12 @@ | None -> c ^ "httponly" | Some t -> c ^ "Expires=" ^ (get_tm t) ^ "; httponly" in let cookies_s = String.concat "\n" (List.map ck_str cookies) in - "HTTP/1.1 " ^ code ^ "\r\n" ^ + let expires_str = if not get then "" else + "Expires: " ^ (get_tm (float (40 * 24 * 3600))) ^ "\r\n" in + "HTTP/1.1 " ^ code ^ "\r\n" ^ + "Date: " ^ (get_tm 0.) ^ "\r\n" ^ + "Server: Toss\r\n" ^ + expires_str ^ "Content-Type: " ^ mimetp ^ "\r\n" ^ (if cookies = [] then "" else cookies_s ^ "\r\n") ^ "Content-length: " ^ (string_of_int (String.length s)) ^ "\r\n\r\n" ^ s @@ -399,8 +404,8 @@ | "js" -> "text/javascript" | "sv" -> "image/svg+xml" | _ -> "text/html charset=utf-8" in - http_msg "200 OK" tp [] content - ) else http_msg "404 NOT FOUND" "text/html charset=utf-8" [] + http_msg true "200 OK" tp [] content + ) else http_msg true "404 NOT FOUND" "text/html charset=utf-8" [] ("<html>\n<head><title>Toss: Page Not Found</title></head>\n" ^ "<body><p>Not found: " ^ fname_in ^ "</p></body>\n</html>") @@ -606,7 +611,7 @@ move_play tp a.(0) a.(1) a.(2) a.(3) a.(4), [] | _ -> "MOD_PYTHON ERROR ; Traceback: Unknown Toss Command! \n " ^ tcmd, [] in - http_msg "200 OK" "text/html charset=utf-8" new_cookies resp + http_msg false "200 OK" "text/html charset=utf-8" new_cookies resp let handle_http_msg rstate cmd head msg ck = Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-05-13 23:17:33 UTC (rev 1439) +++ trunk/Toss/WebClient/Connect.js 2011-05-13 23:33:56 UTC (rev 1440) @@ -65,7 +65,7 @@ // Send [msg] to server and return response text. function sync_server_msg (msg) { var xml_request = new XMLHttpRequest (); - xml_request.open ('POST', 'Handler.py', false); + xml_request.open ('POST', 'Handler', false); xml_request.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); xml_request.send (msg); @@ -80,7 +80,7 @@ // Send [msg] to server asynchronously, ignore response text. function async_server_msg (msg, f) { var xml_request = new XMLHttpRequest (); - xml_request.open ('POST', 'Handler.py', true); + xml_request.open ('POST', 'Handler', true); xml_request.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); xml_request.onreadystatechange = function () { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-15 22:48:59
|
Revision: 1442 http://toss.svn.sourceforge.net/toss/?rev=1442&view=rev Author: lukaszkaiser Date: 2011-05-15 22:48:50 +0000 (Sun, 15 May 2011) Log Message: ----------- Web user interface improvements. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/Server/ReqHandler.mli trunk/Toss/Server/Server.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/DefaultStyle.js trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html trunk/Toss/WebClient/pics/Breakthrough.png trunk/Toss/WebClient/pics/Checkers.png trunk/Toss/WebClient/pics/Chess.png trunk/Toss/WebClient/pics/Connect4.png trunk/Toss/WebClient/pics/Connect4.svg trunk/Toss/WebClient/pics/Entanglement.png trunk/Toss/WebClient/pics/Gomoku.png trunk/Toss/WebClient/pics/Gomoku.svg trunk/Toss/WebClient/pics/Pawn-Whopping.png trunk/Toss/WebClient/pics/Style.css trunk/Toss/WebClient/pics/Style2.css trunk/Toss/WebClient/pics/Tic-Tac-Toe.png trunk/Toss/WebClient/pics/Tic-Tac-Toe.svg trunk/Toss/WebClient/pics/convert_all.sh Added Paths: ----------- trunk/Toss/WebClient/pics/Style3.css Removed Paths: ------------- trunk/Toss/WebClient/contact.html Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-05-14 14:30:21 UTC (rev 1441) +++ trunk/Toss/Server/ReqHandler.ml 2011-05-15 22:48:50 UTC (rev 1442) @@ -6,7 +6,9 @@ let html_dir_path = ref (if Sys.file_exists "/usr/share/toss" then "/usr/share/toss/html" else "WebClient/") +let quit_on_eof = ref true; + (* ---------- Basic request type and internal handler ---------- *) type req_state = @@ -55,12 +57,15 @@ let heur = match game_modified, g_heur with | false, Some h -> Some h | true, _ | _, None -> Some (compute_heuristic advr state) in - let (move, _) = - Aux.random_elem (Play.maximax_unfold_choose effort - (fst state) (snd state) (Aux.unsome heur)) in - Play.cancel_timeout (); - (heur, game_modified, state, gdl_transl, playclock), - Move.move_gs_str state move + try + let (move, _) = + Aux.random_elem (Play.maximax_unfold_choose effort + (fst state) (snd state) (Aux.unsome heur)) in + Play.cancel_timeout (); + (heur, game_modified, state, gdl_transl, playclock), + Move.move_gs_str state move + with Not_found -> (heur, game_modified, state, gdl_transl, playclock), + "ERR: suggest called but no possible moves!" ) | Aux.Left(Arena.ApplyRule (r_name, mtch, t, p) as req) -> @@ -399,7 +404,7 @@ let content = Aux.input_file f in close_in f; let tp = match String.sub fname ((String.index fname '.') + 1) 2 with - | "ht" -> "text/html charset=utf-8" + | "ht" -> "text/html; charset=utf-8" | "ic" -> "image/x-icon" | "pn" -> "image/png" | "cs" -> "text/css" @@ -707,14 +712,15 @@ output_string out_ch ("ERR could not parse\n"); flush out_ch; rstate, true - | End_of_file -> + | End_of_file when !quit_on_eof -> output_string out_ch ("ERR processing completed -- EOF\n"); flush out_ch; - raise End_of_file + raise End_of_file | exn -> Printf.printf "Toss Server: error -- exception %s\n%!" (Printexc.to_string exn); Printf.printf "Exception backtrace: %s\n%!" (Printexc.get_backtrace ()); output_string out_ch ("ERR internal error -- see server stdout\n"); + flush out_ch; rstate, true Modified: trunk/Toss/Server/ReqHandler.mli =================================================================== --- trunk/Toss/Server/ReqHandler.mli 2011-05-14 14:30:21 UTC (rev 1441) +++ trunk/Toss/Server/ReqHandler.mli 2011-05-15 22:48:50 UTC (rev 1442) @@ -5,6 +5,7 @@ (** Set debugging level. *) val set_debug_level : int -> unit +val quit_on_eof : bool ref (** {2 Request Handling Functions} *) Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-05-14 14:30:21 UTC (rev 1441) +++ trunk/Toss/Server/Server.ml 2011-05-15 22:48:50 UTC (rev 1442) @@ -169,6 +169,8 @@ ("-nm", Arg.Unit (fun () -> Heuristic.use_monotonic := false), " monotonicity off"); ("-p", Arg.Int (fun i -> (port := i)), " port number (default: 8110)"); + ("-eof", Arg.Unit (fun () -> ReqHandler.quit_on_eof := false), + "do not quit server on end of file of requests"); ("-html", Arg.String (fun s -> ReqHandler.html_dir_path := s), "set path to directory with html files for the web-based client"); ("-db", Arg.String (fun s -> (DB.dbFILE := s)), "use specified DB file"); Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-05-14 14:30:21 UTC (rev 1441) +++ trunk/Toss/WebClient/Connect.js 2011-05-15 22:48:50 UTC (rev 1442) @@ -28,7 +28,8 @@ var PAYOFF_STR = "" var PLAYER_STR = "" -var ASYNC_REQ_PENDING = 0; +var ASYNC_ALL_REQ_PENDING = 0; +var ASYNC_CMD_REQ_PENDING = {}; // Helper function: sign of a number. function sign (x) { @@ -78,21 +79,32 @@ } // Send [msg] to server asynchronously, ignore response text. -function async_server_msg (msg, f) { +function async_server_msg (msg, count, f) { var xml_request = new XMLHttpRequest (); xml_request.open ('POST', 'Handler', true); xml_request.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); - xml_request.onreadystatechange = function () { - if (xml_request.readyState == 4) { - ASYNC_REQ_PENDING -= 1; - resp = xml_request.responseText; - if (resp.indexOf ("MOD_PYTHON ERROR") > -1) { - alert (resp.substring(resp.indexOf("Traceback"))); - } else { f(resp) }; + if (count) { + xml_request.onreadystatechange = function () { + if (xml_request.readyState == 4) { + ASYNC_ALL_REQ_PENDING -= 1; + resp = xml_request.responseText; + if (resp.indexOf ("MOD_PYTHON ERROR") > -1) { + alert (resp.substring(resp.indexOf("Traceback"))); + } else { f(resp) }; + } } + } else { + xml_request.onreadystatechange = function () { + if (xml_request.readyState == 4) { + resp = xml_request.responseText; + if (resp.indexOf ("MOD_PYTHON ERROR") > -1) { + alert (resp.substring(resp.indexOf("Traceback"))); + } else { f(resp) }; + } + } }; - ASYNC_REQ_PENDING += 1; + if (count) { ASYNC_ALL_REQ_PENDING += 1; } xml_request.send (msg); } @@ -103,12 +115,19 @@ // Send [msg] to server attaching prefix '[cmd]#' async., ignore response. function async_srv_ignore (cmd, msg) { - return (async_server_msg (cmd + '#' + msg, function(x) { } )); + return (async_server_msg (cmd + '#' + msg, false, function(x) { } )); } // Send [msg] to server attaching prefix '[cmd]#' async., run f on return. function async_srv (cmd, msg, f) { - return (async_server_msg (cmd + '#' + msg, f )); + if (ASYNC_CMD_REQ_PENDING[cmd]) { + ASYNC_CMD_REQ_PENDING[cmd] += 1; + } else { ASYNC_CMD_REQ_PENDING[cmd] = 1; }; + var fm = function (m) { + ASYNC_CMD_REQ_PENDING[cmd] -= 1; + f (); + }; + return (async_server_msg (cmd + '#' + msg, true, f)); } // Strip [c1] and [c2] from beginning and end of [str]. @@ -174,9 +193,9 @@ function translate_pos (pos) { var x = ((pos[0] - MODEL_MINX) * SVG_WIDTH) / MODEL_WIDTH; if (VIEW_MIRROR == 0) { - var y = ((pos[1] - MODEL_MINY) * SVG_HEIGHT) / MODEL_HEIGHT; + var y = ((pos[1] - MODEL_MINY) * SVG_HEIGHT) / MODEL_HEIGHT; } else { - var y = ((MODEL_HEIGHT - (pos[1] - MODEL_MINY)) * SVG_WIDTH) / MODEL_HEIGHT; + var y = ((MODEL_HEIGHT - (pos[1] - MODEL_MINY))*SVG_WIDTH)/MODEL_HEIGHT; } return ([x + SVG_MARGINX, y + SVG_MARGINY]) } @@ -209,26 +228,37 @@ SVG_MARGINY = margx; var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg.setAttribute('id', 'svg'); - var wx = SVG_WIDTH + 2*SVG_MARGINX; - var wy = SVG_HEIGHT + 2*SVG_MARGINY; - svg.setAttribute('viewBox', '0 0 ' + wx + " " + wy); + var wx = SVG_WIDTH + 2*SVG_MARGINX + 20; + var wy = SVG_HEIGHT + 2*SVG_MARGINY + 20; + svg.setAttribute('viewBox', '-10 -10 ' + wx + " " + wy); document.getElementById(parent_id).appendChild(svg); } -// Create new svg element [elem], child of svg, with [attributes]. -function svg_from_string (x, y, sizex, sizey, s) { +// Just make an svg elem from string +function bare_svg_from_string (s) { var parser = new DOMParser (); var svgs = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg">'; + var doc = parser.parseFromString(svgs + s + '</svg>', "text/xml"); + return (document.adoptNode(doc.childNodes[0]).childNodes[0]); +} + +// Create new svg element [elem], child of svg, set attributes, scale. +function svg_from_string (x, y, sizex, sizey, s, attributes) { + var parser = new DOMParser (); + var svgs = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg">'; var scfx = (SUGGESTED_ELEM_SIZEX - 10) / sizex; var scfy = (SUGGESTED_ELEM_SIZEY - 10) / sizey; var sc = "scale(" + scfx + "," + scfy + ")"; var gs = '<g transform="translate(' + x + "," + y + ") " + sc + '">'; - var doc = parser.parseFromString(svgs+ gs+ s + ' </g> </svg>', "text/xml"); - var elem = document.adoptNode(doc.childNodes[0]); - return(elem.childNodes[0]); + var doc = parser.parseFromString(svgs+ gs+ s + '</g></svg>', "text/xml"); + var elem = document.adoptNode(doc.childNodes[0]).childNodes[0]; + var elem_in = elem.childNodes[0]; + for (var i = 0; i < attributes.length; i++) { + elem_in.setAttribute (attributes[i][0], attributes[i][1].toString()); + } + return (elem); } - // Create new svg element [elem], child of svg, with [attributes]. function add_svg (elem, attributes) { var elem = document.createElementNS("http://www.w3.org/2000/svg", elem); Modified: trunk/Toss/WebClient/DefaultStyle.js =================================================================== --- trunk/Toss/WebClient/DefaultStyle.js 2011-05-14 14:30:21 UTC (rev 1441) +++ trunk/Toss/WebClient/DefaultStyle.js 2011-05-15 22:48:50 UTC (rev 1442) @@ -2,10 +2,11 @@ // This module implements default drawing style for games. // Functions expected from this module: -// - draw_elem (elem) +// - draw_background (game) +// - draw_elem (game, elem) // - highlight_elem (elem) // - unhighlight_elem (elem) -// - draw_rel (rel_name, args) +// - draw_rel (game, rel_name, args) var DEFpawn = '<g transform="translate(-22.5,-22.5)"> \ @@ -140,6 +141,19 @@ return (parseInt(s).toString() == s) } +// Mostly we skip background drawings, but when needed, they are here. +function draw_background (game) { + if (game == "Connect4") { + var x = SVG_MARGINX; + var y = SVG_MARGINY; + var w = SVG_WIDTH + 2 * x; + var h = SVG_HEIGHT + 2 * x; + var b = '<rect x="' + 0 + '" y="' + 0 + '" width="' + w + '" height="' + + h + '" stroke-width="5" rx="5" ry="5" id="board_connect4" />'; + document.getElementById("svg").appendChild(bare_svg_from_string (b)); + } +} + // To draw chess board we distinguish even/odd placed elements. function elem_class (elem) { var elem_cl = "model-elem"; @@ -151,17 +165,25 @@ } // Draw the element [elem]. -function draw_elem (elem) { +function draw_elem (game, elem) { var pos = ELEM_POS[elem]; - add_svg ("rect", - [["x", pos[0] - SUGGESTED_ELEM_SIZEX], - ["y", pos[1] - SUGGESTED_ELEM_SIZEY], - ["width", 2 * SUGGESTED_ELEM_SIZEX], - ["height", 2 * SUGGESTED_ELEM_SIZEX], - ["id", "elem_" + elem], - ["class", elem_class(elem)], - ["onclick", ("handle_elem_click('" + elem + "')")]] - ); + if (game != "Connect4") { + add_svg ("rect", + [["x", pos[0] - SUGGESTED_ELEM_SIZEX], + ["y", pos[1] - SUGGESTED_ELEM_SIZEY], + ["width", 2 * SUGGESTED_ELEM_SIZEX], + ["height", 2 * SUGGESTED_ELEM_SIZEY], + ["id", "elem_" + elem], + ["class", elem_class(elem)], + ["onclick", ("handle_elem_click('" + elem + "')")]] + ); + } else { + var circ = svg_from_string + (pos[0], pos[1], 10, 10, '<circle cx="0" cy="0" r="20" />', + [["id", "elem_" + elem], ["class", elem_class(elem)], + ["onclick", "handle_elem_click('" + elem + "')"]]) + document.getElementById("svg").appendChild(circ); + } } // Highlight the element [elem]. @@ -177,18 +199,45 @@ } // Draw relation [rel_name] between elements [args]. -function draw_rel (rel_name, args) { +function draw_rel (game, rel_name, args) { if (args.length == 1) { var is = 'id="' + "pred_" + args[0] + "_" + rel_name + '" '; var hs = 'onclick="' + "handle_elem_click('" + args[0] + "')" + '" '; var pos = ELEM_POS[args[0]]; if (rel_name == "P") { // Tic-tac-toe cross - var cs = 'class="' + "model-pred-" + rel_name + '" '; - var ls1 = '<line x1="-10" y1="-10" x2="10" y2="10" />'; - var ls2 = '<line x1="10" y1="-10" x2="-10" y2="10" />'; - var cr = svg_from_string (pos[0], pos[1], 12, 12, - '<g ' + cs + is + hs + '>' + ls1 + ls2 + '</g>'); - document.getElementById("svg").appendChild(cr); + if (game != "Connect4") { + var cs = 'class="' + "model-pred-" + rel_name + '" '; + var ls1 = '<line x1="-10" y1="-10" x2="10" y2="10" />'; + var ls2 = '<line x1="10" y1="-10" x2="-10" y2="10" />'; + var cr = svg_from_string + (pos[0], pos[1], 12, 12, + '<g ' + cs + is + hs + '>' + ls1 + ls2 + '</g>', []); + document.getElementById("svg").appendChild(cr); + } else { + var cls = "model-pred-" + rel_name; + var ids = "pred_" + args[0] + "_" + rel_name; + var circ = svg_from_string + (pos[0], pos[1], 10, 10, + '<circle cx="0" cy="0" r="20" />', + [["id", ids], ["class", cls], + ["onclick", "handle_elem_click('" + args[0] + "')"]]); + document.getElementById("svg").appendChild(circ); + } + } else if (rel_name == "Q") { // Tic-tac-toe Circle + var clp = ["class", "model-pred-" + rel_name]; + var idp = ["id", "pred_" + args[0] + "_" + rel_name]; + var hdp = ["onclick", ("handle_elem_click('" + args[0] + "')")]; + if (game != "Connect4") { + var circ = svg_from_string (pos[0], pos[1], 10, 10, + '<circle cx="0" cy="0" r="8" />', + [idp, clp, hdp]); + document.getElementById("svg").appendChild(circ); + } else { + var circ = svg_from_string (pos[0], pos[1], 10, 10, + '<circle cx="0" cy="0" r="20" />', + [idp, clp, hdp]); + document.getElementById("svg").appendChild(circ); + } } else if (rel_name == "R") { // Robber in Entanglement add_svg ("circle", [["cx", pos[0]], ["cy", pos[1]], ["r", SUGGESTED_ELEM_SIZEX - 5], @@ -197,53 +246,53 @@ ["onclick", ("handle_elem_click('" + args[0] + "')")]]); } else if (rel_name == "wP") { // Chess Figure: white pawn var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessW" ' + is + hs + '>' + DEFpawn + '</g>'); + '<g class="chessW" ' + is + hs + '>' + DEFpawn + '</g>', []); document.getElementById("svg").appendChild(f); } else if (rel_name == "bP") { // Chess Figure: black pawn var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessB" ' + is + hs + '>' + DEFpawn + '</g>'); + '<g class="chessB" ' + is + hs + '>' + DEFpawn + '</g>', []); document.getElementById("svg").appendChild(f); } else if (rel_name == "wN") { // Chess Figure: white knight var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessW" ' + is + hs + '>' + DEFknight + '</g>'); + '<g class="chessW" ' + is + hs + '>' + DEFknight + '</g>', []); document.getElementById("svg").appendChild(f); } else if (rel_name == "bN") { // Chess Figure: black knight var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessB" ' + is + hs + '>' + DEFknight + '</g>'); + '<g class="chessB" ' + is + hs + '>' + DEFknight + '</g>', []); document.getElementById("svg").appendChild(f); } else if (rel_name == "wB") { // Chess Figure: white bishop var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessW" ' + is + hs + '>' + DEFbishop + '</g>'); + '<g class="chessW" ' + is + hs + '>' + DEFbishop + '</g>', []); document.getElementById("svg").appendChild(f); } else if (rel_name == "bB") { // Chess Figure: black bishop var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessB" ' + is + hs + '>' + DEFbishop + '</g>'); + '<g class="chessB" ' + is + hs + '>' + DEFbishop + '</g>', []); document.getElementById("svg").appendChild(f); } else if (rel_name == "wR") { // Chess Figure: white rook var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessW" ' + is + hs + '>' + DEFrook + '</g>'); + '<g class="chessW" ' + is + hs + '>' + DEFrook + '</g>', []); document.getElementById("svg").appendChild(f); } else if (rel_name == "bR") { // Chess Figure: black rook var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessB" ' + is + hs + '>' + DEFrook + '</g>'); + '<g class="chessB" ' + is + hs + '>' + DEFrook + '</g>', []); document.getElementById("svg").appendChild(f); } else if (rel_name == "wQ" || rel_name == "Wq") { // Chess Figure: white queen or Checkers: white queen var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessW" ' + is + hs + '>' + DEFqueen + '</g>'); + '<g class="chessW" ' + is + hs + '>' + DEFqueen + '</g>', []); document.getElementById("svg").appendChild(f); } else if (rel_name == "bQ" || rel_name == "Bq") { // Chess Figure: black queen or Checkers: black queen var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessB" ' + is + hs + '>' + DEFqueen + '</g>'); + '<g class="chessB" ' + is + hs + '>' + DEFqueen + '</g>', []); document.getElementById("svg").appendChild(f); } else if (rel_name == "wK") { // Chess Figure: white king var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessW" ' + is + hs + '>' + DEFking + '</g>'); + '<g class="chessW" ' + is + hs + '>' + DEFking + '</g>', []); document.getElementById("svg").appendChild(f); } else if (rel_name == "bK") { // Chess Figure: black king var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessB" ' + is + hs + '>' + DEFking + '</g>'); + '<g class="chessB" ' + is + hs + '>' + DEFking + '</g>', []); document.getElementById("svg").appendChild(f); } else { add_svg ("circle", Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-05-14 14:30:21 UTC (rev 1441) +++ trunk/Toss/WebClient/Login.js 2011-05-15 22:48:50 UTC (rev 1442) @@ -54,6 +54,10 @@ var udata = srv("USERPLAYS", "user"); if (udata != "") { setup_user (udata.split("$")) }; } + if (window.location.href.indexOf("?simple=true") > 0) { + document.getElementById("loginform").style.display = "none"; + document.getElementById("topright-register").style.display = "none"; + }; cur_game = ""; if (game) { var cur_game = game; } var gindex = window.location.href.indexOf("?game=") @@ -235,9 +239,10 @@ function begin_mailto (name, domain, title) { var address = name + '@' + domain; if(title) { - document.write("<a class='mail' href='mailto:" + address + "'>" + "<span>"); + document.write("<a class='contact' href='mailto:" + address + "'>" + + title + "<span style='display: none;'>"); } else { - document.write("<a class='mail' href='mailto:" + address + "'>" + + document.write("<a class='contact' href='mailto:" + address + "'>" + address + "<span style='display: none;'>"); } } Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-05-14 14:30:21 UTC (rev 1441) +++ trunk/Toss/WebClient/Main.js 2011-05-15 22:48:50 UTC (rev 1442) @@ -16,6 +16,8 @@ var LAST_CLICKED_ELEM = ""; +var SIMPLE_MOVES = true; + // Get model information from server. function get_model_info () { get_elems_with_pos (); @@ -35,12 +37,13 @@ // Draw the model using function from Toss[X]Style.js. // WARNING: must call get_model_info first! -function draw_model () { +function draw_model (game) { + draw_background (game); for (var i = 0; i < ELEMS.length; i++) { - draw_elem (ELEMS[i]); + draw_elem (game, ELEMS[i]); } for (var i = 0; i < RELS.length; i++) { - draw_rel (RELS[i][0], RELS[i][1]); + draw_rel (game, RELS[i][0], RELS[i][1]); } } @@ -55,8 +58,17 @@ svg_e.parentNode.removeChild (svg_e); } +function win_s (i) { + var pl = PLAYS[CUR_PLAY_I][i]; + if (pl == UNAME) { return ("You Win!"); } + return (disp_name(pl) + " Wins"); +} + // Substitute players for 0 and 1 in a payoff string. function subst_pl (s) { + if (s == "0: 1., 1: -1.") { return (win_s (0)); } + if (s == "0: -1., 1: 1.") { return (win_s (1)); } + if (s == "0: 0., 1: 0.") { return ("Tie"); } var s1 = s.replace (/0:/g, disp_name(PLAYS[CUR_PLAY_I][0]) + ":"); var s2 = s1.replace (/1:/g, disp_name(PLAYS[CUR_PLAY_I][1]) + ":"); var s3 = s2.replace (/1.,/g, "1,"); @@ -68,16 +80,24 @@ // Full redraw. function full_redraw () { clear_svg (); - document.getElementById("working").style.display = "block"; + if (! SIMPLE_MOVES) { + document.getElementById("working").style.display = "block"; + } get_model_info (); create_svg_box (SVG_MARGINX, SVG_MARGINY, "board"); - draw_model (); + draw_model (GAME_NAME); if (PAYOFF_STR == "") { document.getElementById('movebt').innerHTML = "Make move:"; document.getElementById('cur-move').innerHTML = "none"; } else { - document.getElementById('movebt').innerHTML = "Payoffs:"; - document.getElementById('cur-move').innerHTML = subst_pl(PAYOFF_STR); + if (SIMPLE_MOVES) { + document.getElementById("board").style.paddingTop = "0em"; + } + document.getElementById("move-info-par").style.display = "none"; + document.getElementById('payoffs').innerHTML = + "Result: " + subst_pl(PAYOFF_STR); + document.getElementById('payoffs').style.display = "inline"; + document.getElementById('new-play-par').style.display = "block"; } document.getElementById("working").style.display = "none"; } @@ -120,13 +140,34 @@ // Handler for clicks on elements. function handle_elem_click (elem) { - if (ASYNC_REQ_PENDING != 0) { return; } + if (ASYNC_ALL_REQ_PENDING != 0) { return; } var moves = get_moves (elem, LAST_CLICKED_ELEM); if (moves.length == 0) { LAST_CLICKED_ELEM = ""; moves = get_moves (elem, LAST_CLICKED_ELEM); }; - if (moves.length > ELEM_COUNTERS[elem]) { + if (moves.length == 0) { // still no moves, unhighlight + for (var i = 0; i < CUR_ELEMS.length; i++) { + unhighlight_elem (CUR_ELEMS[i]); + } + CUR_ELEMS = []; + CUR_MOVE = ""; + LAST_CLICKED_ELEM = ""; + } else if (moves.length == 1) { + show_move (moves[0]); + ELEM_COUNTERS[elem] = 1; + if (SIMPLE_MOVES) { make_move (); }; + } else if (LAST_CLICKED_ELEM != "" && LAST_CLICKED_ELEM != elem //move fast + && moves.length == 2 && moves[0].length > moves[1].length + 2) { + show_move (moves[1]); + ELEM_COUNTERS[elem] = 2; + if (SIMPLE_MOVES) { make_move (); }; + } else if (LAST_CLICKED_ELEM != "" && LAST_CLICKED_ELEM != elem //move fast + && moves.length == 2 && moves[1].length > moves[0].length + 2) { + show_move (moves[0]); + ELEM_COUNTERS[elem] = 1; + if (SIMPLE_MOVES) { make_move (); }; + } else if (moves.length > ELEM_COUNTERS[elem]) { show_move (moves[ELEM_COUNTERS[elem]]); ELEM_COUNTERS[elem] += 1; } else if (moves.length > 0) { @@ -151,7 +192,7 @@ } function disp_name (uname) { - if (uname == "guest") { return ("Guest"); } + if (uname == "guest") { return ("You"); } if (UNAME_TO_NAME_MAP[uname]) { return (UNAME_TO_NAME_MAP[uname]); } name = srv ("GET_NAME", uname); UNAME_TO_NAME_MAP[uname] = name; @@ -219,7 +260,9 @@ document.getElementById("game-disp").style.display = "block"; document.getElementById("play-number").innerHTML = "" + play_id; CUR_PLAY_I = pi; - VIEW_MIRROR = (PLAYS[CUR_PLAY_I][0] == UNAME) ? 0 : 1; + if (game == "Connect4") { VIEW_MIRROR = 0; } else { + VIEW_MIRROR = (PLAYS[CUR_PLAY_I][0] == UNAME) ? 0 : 1; + } document.getElementById("cur-player").innerHTML = disp_name(PLAYS[CUR_PLAY_I][PLAYS[CUR_PLAY_I][3]]); toss_open_db (play_py_id(pi)); @@ -229,14 +272,16 @@ // Apply current move. function make_move () { - if (ASYNC_REQ_PENDING != 0) return; + if (ASYNC_ALL_REQ_PENDING != 0) { alert ("async"); return; } if (CUR_MOVE == "") return; var m = PLAYS[CUR_PLAY_I][3]; if (PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer") { alert ("It is your Opponent's turn"); return; } - document.getElementById("working").style.display = "block"; + if (! SIMPLE_MOVES) { + document.getElementById("working").style.display = "block"; + } async_srv("MOVE_PLAY", 'c, '+ CUR_MOVE +', '+ play_py_id (CUR_PLAY_I), make_move_continue); } @@ -257,7 +302,8 @@ var li = new_play_item (GAME_NAME, CUR_PLAY_I); old_li.parentNode.replaceChild (li, old_li); if (PLAYS[CUR_PLAY_I][PLAYER_STR] == "computer") { - suggest_move_async (make_move); + var mv_time = document.getElementById("speed").value; + suggest_move_async (mv_time, make_move); } } @@ -271,7 +317,7 @@ li.setAttribute ("class", "opponents-list-elem"); li.setAttribute ("id", "opponent-" + uid); // + "-" + index li.innerHTML = - '<button class="dbt" onclick="new_play_do(' + "'" + uid + "'" + ')">' + + '<button class="dbt" onclick="new_play_do('+ "'" + uid + "', 0"+ ')">'+ disp_name(uid) + ' (' + uid + ') </button>'; return (li); } @@ -293,7 +339,7 @@ var zeroli = document.createElement('li'); zeroli.setAttribute ("class", "opponents-list-elem"); zeroli.setAttribute ("id", "opponent-" + "-0"); - zeroli.innerHTML = '<button class="dbt" onclick="new_play_do(-1)">' + + zeroli.innerHTML = '<button class="dbt" onclick="new_play_do(-1, 0)">' + 'Play against Yourself</button>'; o.appendChild (zeroli); for (var i = 0; i < FRIENDS.length; i++) { @@ -307,6 +353,8 @@ function new_play (game) { if (UNAME == "") { alert ("Please log in to create plays"); return; } GAME_NAME = game; + var olist = document.getElementById("opponents-list"); + while (olist.childNodes.length > 0) { olist.removeChild(olist.firstChild); } make_opnt_list (); } @@ -352,10 +400,16 @@ function new_play_guest (game) { GAME_NAME = game; UNAME = "guest"; - new_play_do ("computer"); + document.getElementById("topuser").innerHTML = "Welcome!"; + document.getElementById("loginform").style.display = "none"; + document.getElementById("topright-register").style.display = "none"; + document.getElementById("topright").style.display = "inline"; + document.getElementById("logoutbt").style.display = "none"; + document.getElementById("welcome").style.display = "none"; + new_play_do ("computer", 0); } -function new_play_do (opp_uid) { +function new_play_do (opp_uid, vm) { list_plays (GAME_NAME) game_click (GAME_NAME) document.getElementById ("game-title").innerHTML = GAME_NAME; @@ -373,7 +427,7 @@ FREE_PLAY_NO = parseInt(info_nbr.substring(0, info_idx)); document.getElementById("play-number").innerHTML = "" + FREE_PLAY_NO; CUR_PLAY_I = PLAYS.length; - VIEW_MIRROR = 0; + VIEW_MIRROR = vm; document.getElementById("cur-player").innerHTML = disp_name(UNAME); document.getElementById("game-disp").style.display = "block"; document.getElementById("plays").style.left = "30em"; @@ -391,6 +445,32 @@ FRIENDS = convert_python_list (',', lst); } +function play_anew (me_starts) { + document.getElementById('payoffs').innerHTML = "Not Finished Yet"; + document.getElementById('payoffs').style.display = "none"; + document.getElementById('new-play-par').style.display = "none"; + toggle_suggestions (); + toggle_suggestions (); + clear_svg (); + if (me_starts) { + var opp = PLAYS[CUR_PLAY_I][1]; + if (PLAYS[CUR_PLAY_I][0] != UNAME) { opp = PLAYS[CUR_PLAY_I][0]; } + new_play_do (opp, 0); + } else { + var opp = PLAYS[CUR_PLAY_I][1]; + if (PLAYS[CUR_PLAY_I][0] != UNAME) { opp = PLAYS[CUR_PLAY_I][0]; } + var me = UNAME; + UNAME = opp; + var vm = (GAME_NAME == "Connect4") ? 0 : 1; + new_play_do (me, vm); + UNAME = me; + if (opp == "computer") { + var mv_time = document.getElementById("speed").value; + suggest_move_async (mv_time, make_move); + } + } +} + function decrease_moving (n) { document.getElementById("working").innerHTML = "Moving in " + n + "s ..."; if (n > 0) { @@ -398,43 +478,44 @@ } } -function suggest_move_async (f) { - document.getElementById("working").innerHTML = "Moving in 5s ..."; - document.getElementById("working").style.display = "block"; - setTimeout("decrease_moving(4)", 1000) +function show_moving_msg (n) { + if (n > 1) { + document.getElementById("working").innerHTML = "Moving in "+ n+ "s ..."; + document.getElementById("working").style.display = "block"; + setTimeout("decrease_moving(" + (n-1) + ")", 1000); + } +} + +function suggest_move_async (time, f) { + show_moving_msg (time); var fm = function (m) { document.getElementById("working").style.display = "none"; document.getElementById("working").innerHTML = "Working..."; if (m != "") { show_move (m); f() } }; - async_srv("SUGGEST", 'c, 5, '+ play_py_id (CUR_PLAY_I), fm); + async_srv("SUGGEST", 'c, ' + time + ', '+ play_py_id (CUR_PLAY_I), fm); } function suggest_move_click () { - suggest_move_async (function () {}); + var mv_time = document.getElementById("speed").value; + suggest_move_async (mv_time, function () {}); } -function suggest_move_better_click () { - document.getElementById("working").innerHTML = "Moving in 10s ..."; - document.getElementById("working").style.display = "block"; - setTimeout("decrease_moving(9)", 1000) - var fm = function (m) { - document.getElementById("working").style.display = "none"; - document.getElementById("working").innerHTML = "Working..."; - if (m != "") { show_move (m); f() } - }; - async_srv("SUGGEST", 'c, 10, '+ play_py_id (CUR_PLAY_I), fm); -} - function toggle_suggestions () { var txt = document.getElementById("suggestions-toggle").innerHTML; - if (txt.indexOf ("Show") == -1) { + if (txt.indexOf ("Before") == -1) { + SIMPLE_MOVES = true; + document.getElementById("play-nbr-info").style.display = "none"; + document.getElementById("board").style.paddingTop = "1em"; document.getElementById("suggestions-toggle").innerHTML = - "Show Move Suggestions"; - document.getElementById("player-info-par").style.display = "none"; + "Ask Before Move"; + document.getElementById("move-info-par").style.display = "none"; } else { + SIMPLE_MOVES = false; + document.getElementById("play-nbr-info").style.display = "inline"; + document.getElementById("board").style.paddingTop = "0em"; document.getElementById("suggestions-toggle").innerHTML = - "Hide Move Suggestions"; - document.getElementById("player-info-par").style.display = "block"; + "Move Without Asking"; + document.getElementById("move-info-par").style.display = "block"; } } Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-05-14 14:30:21 UTC (rev 1441) +++ trunk/Toss/WebClient/Style.css 2011-05-15 22:48:50 UTC (rev 1442) @@ -116,6 +116,25 @@ top: 2px; } +#speed { + position: relative; + top: -2px; + font-weight: bold; + font-family: Verdana, 'TeXGyreHerosRegular', sans; + color: #400827; + background-color: #fff1d4; + border-color: #fff1d4; + border-radius: 4px; + -moz-border-radius: 4px; + border-width: 1px; +} + +.speed_val { + color: #400827; + background-color: #fff1d4; + border-color: #400827; +} + .forminput { border-color: #fff1d4; border-radius: 4px; @@ -159,7 +178,7 @@ #logoutbt { position: relative; - top: -0.2em; + top: -0.1em; font-family: Verdana, 'TeXGyreHerosRegular', sans; font-size: 1em; font-weight: bold; @@ -291,7 +310,7 @@ /* Bottom styles. */ -#contact { +.contact { position: absolute; top: 0px; right: 0.5em; @@ -421,7 +440,7 @@ #opponents { display: none; - position: absolute; + position: fixed; left: 0px; right: 0px; top: 4em; @@ -523,9 +542,16 @@ #move-info-par { margin-top: 0.5em; padding: 0px; + display: none; } +#new-play-par { + display: none; + padding: 0px; +} + #board { + padding-top: 1em; min-width: 10em; max-width: 120em; width: 100%; @@ -536,10 +562,10 @@ } #working { - position: absolute; + position: fixed; left: 0px; right: 0px; - top: 7em; + top: 4em; width: 10em; margin-left: auto; margin-right: auto; @@ -548,6 +574,7 @@ color: #fff1d4; background-color: #400827; padding: 1em; + border: 1px solid #260314; } #opening { @@ -626,13 +653,18 @@ #svg { min-width: 10em; max-width: 120em; - width: 75%; + width: 80%; min-height: 10em; - max-height: 35em; - height: 75%; + max-height: 40em; + height: 80%; /* border: 1px solid #260314; */ } +#board_connect4 { + fill: blue; + stroke: #260314; +} + .model-elem, .model-elem-0, .model-elem-1 { fill: #ffe4aa; /* #ffce9e; */ stroke: #260314; @@ -659,17 +691,35 @@ stroke-width: 3px; } +.Game-Connect4 .model-elem-highlight { + opacity: 0.3; +} + + .model-pred-P { fill: #400827; stroke: #260314; stroke-width: 5px; } +.Game-Connect4 .model-pred-P { + fill: red; + stroke: #260314; + stroke-width: 3px; +} + .model-pred-Q { fill: #ffe4aa; /* #ffce9e; */ stroke: #260314; + stroke-width: 3px; } +.Game-Connect4 .model-pred-Q { + fill: yellow; + stroke: #260314; + stroke-width: 3px; +} + .model-pred-C { fill: #fff1d4; stroke: #260314; @@ -695,13 +745,13 @@ } .Game-Checkers .model-pred-B { - fill: #fff1d4; + fill: white; stroke: #260314; stroke-width: 3px; } .Game-Checkers .model-pred-W { - fill: #400827; + fill: red; stroke: #260314; stroke-width: 3px; } @@ -712,8 +762,7 @@ stroke-width: 3px; } -.Game-Chess .chessW .chess-path-A, .Game-Pawn-Whopping .chessW .chess-path-A, - .Game-Checkers .chessB .chess-path-A { +.Game-Chess .chessW .chess-path-A, .Game-Pawn-Whopping .chessW .chess-path-A { opacity: 1; fill: #fff1d4; fill-opacity: 1; @@ -728,9 +777,23 @@ stroke-opacity: 1; } -.Game-Chess .chessB .chess-path-A, .Game-Pawn-Whopping .chessB .chess-path-A, - .Game-Checkers .chessW .chess-path-A { +.Game-Checkers .chessB .chess-path-A { opacity: 1; + fill: white; + fill-opacity: 1; + fill-rule: nonzero; + stroke: #260314; + stroke-width: 1.5; + stroke-linecap: round; + stroke-linejoin: miter; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-dashoffset: 10; + stroke-opacity: 1; +} + +.Game-Chess .chessB .chess-path-A, .Game-Pawn-Whopping .chessB .chess-path-A { + opacity: 1; fill: #400827; fill-opacity: 1; fill-rule: nonzero; @@ -744,9 +807,23 @@ stroke-opacity: 1; } -.Game-Chess .chessW .chess-path-B, .Game-Pawn-Whopping .chessW .chess-path-B, - .Game-Checkers .chessB .chess-path-B { +.Game-Checkers .chessW .chess-path-A { opacity: 1; + fill: red; + fill-opacity: 1; + fill-rule: nonzero; + stroke: #260314; + stroke-width: 1.5; + stroke-linecap: round; + stroke-linejoin: miter; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-dashoffset: 10; + stroke-opacity: 1; +} + +.Game-Chess .chessW .chess-path-B, .Game-Pawn-Whopping .chessW .chess-path-B { + opacity: 1; fill: #fff1d4; fill-opacity: 1; fill-rule: evenodd; @@ -759,9 +836,22 @@ stroke-opacity: 1; } -.Game-Chess .chessB .chess-path-B, .Game-Pawn-Whopping .chessB .chess-path-B, - .Game-Checkers .chessW .chess-path-B { +.Game-Checkers .chessB .chess-path-B { opacity: 1; + fill: white; + fill-opacity: 1; + fill-rule: evenodd; + stroke: #260314; + stroke-width: 1.5; + stroke-linecap: round; + stroke-linejoin: round; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-opacity: 1; +} + +.Game-Chess .chessB .chess-path-B, .Game-Pawn-Whopping .chessB .chess-path-B { + opacity: 1; fill: #400827; fill-opacity: 1; fill-rule: evenodd; @@ -774,9 +864,22 @@ stroke-opacity: 1; } +.Game-Checkers .chessW .chess-path-B { + opacity: 1; + fill: red; + fill-opacity: 1; + fill-rule: evenodd; + stroke: #260314; + stroke-width: 1.5; + stroke-linecap: round; + stroke-linejoin: round; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-opacity: 1; +} -.Game-Chess .chessW .chess-path-Bx, .Game-Pawn-Whopping .chessW .chess-path-Bx, - .Game-Checkers .chessB .chess-path-Bx { + +.Game-Chess .chessW .chess-path-Bx, .Game-Pawn-Whopping .chessW .chess-path-Bx { opacity: 1; fill: #fff1d4; fill-opacity: 1; @@ -790,9 +893,22 @@ stroke-opacity: 1; } -.Game-Chess .chessB .chess-path-Bx, .Game-Pawn-Whopping .chessB .chess-path-Bx, - .Game-Checkers .chessW .chess-path-Bx { +.Game-Checkers .chessB .chess-path-Bx { opacity: 1; + fill: white; + fill-opacity: 1; + fill-rule: evenodd; + stroke: #260314; + stroke-width: 1.5; + stroke-linecap: round; + stroke-linejoin: round; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-opacity: 1; +} + +.Game-Chess .chessB .chess-path-Bx, .Game-Pawn-Whopping .chessB .chess-path-Bx { + opacity: 1; fill: #fff1d4; fill-opacity: 1; fill-rule: evenodd; @@ -805,9 +921,22 @@ stroke-opacity: 1; } -.Game-Chess .chessW .chess-path-C, .Game-Pawn-Whopping .chessW .chess-path-C, - .Game-Checkers .chessB .chess-path-C { +.Game-Checkers .chessW .chess-path-Bx { opacity: 1; + fill: white; + fill-opacity: 1; + fill-rule: evenodd; + stroke: #400827; + stroke-width: 1.5; + stroke-linecap: round; + stroke-linejoin: round; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-opacity: 1; +} + +.Game-Chess .chessW .chess-path-C, .Game-Pawn-Whopping .chessW .chess-path-C { + opacity: 1; fill: #400827; fill-opacity: 1; stroke: #260314; @@ -819,8 +948,20 @@ stroke-opacity: 1; } -.Game-Chess .chessB .chess-path-C, .Game-Pawn-Whopping .chessB .chess-path-C, - .Game-Checkers .chessW .chess-path-C { +.Game-Checkers .chessB .chess-path-C { + opacity: 1; + fill: red; + fill-opacity: 1; + stroke: #260314; + stroke-width: 1.5; + stroke-linecap: round; + stroke-linejoin: round; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-opacity: 1; +} + +.Game-Chess .chessB .chess-path-C, .Game-Pawn-Whopping .chessB .chess-path-C { opacity:1; fill: #fff1d4; fill-opacity: 1; @@ -833,8 +974,20 @@ stroke-opacity: 1; } -.Game-Chess .chessW .chess-path-D, .Game-Pawn-Whopping .chessW .chess-path-D, - .Game-Checkers .chessB .chess-path-D { +.Game-Checkers .chessW .chess-path-C { + opacity:1; + fill: white; + fill-opacity: 1; + stroke: white; + stroke-width: 1.5; + stroke-linecap: round; + stroke-linejoin: round; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-opacity: 1; +} + +.Game-Chess .chessW .chess-path-D, .Game-Pawn-Whopping .chessW .chess-path-D { fill: #fff1d4; fill-opacity: 0.75; fill-rule: evenodd; @@ -847,8 +1000,20 @@ stroke-opacity: 1; } -.Game-Chess .chessB .chess-path-D, .Game-Pawn-Whopping .chessB .chess-path-D, - .Game-Checkers .chessW .chess-path-D { +.Game-Checkers .chessB .chess-path-D { + fill: white; + fill-opacity: 0.75; + fill-rule: evenodd; + stroke: #260314; + stroke-width: 1; + stroke-linecap: round; + stroke-linejoin: miter; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-opacity: 1; +} + +.Game-Chess .chessB .chess-path-D, .Game-Pawn-Whopping .chessB .chess-path-D { fill: #400827; fill-opacity: 0.75; fill-rule: evenodd; @@ -860,3 +1025,16 @@ stroke-dasharray: none; stroke-opacity: 1; } + +.Game-Checkers .chessW .chess-path-D { + fill: red; + fill-opacity: 0.75; + fill-rule: evenodd; + stroke: #260314; + stroke-width: 1; + stroke-linecap: round; + stroke-linejoin: miter; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-opacity: 1; +} Deleted: trunk/Toss/WebClient/contact.html =================================================================== --- trunk/Toss/WebClient/contact.html 2011-05-14 14:30:21 UTC (rev 1441) +++ trunk/Toss/WebClient/contact.html 2011-05-15 22:48:50 UTC (rev 1442) @@ -1,50 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xml:lang="en" lang="en"> -<head> - <meta http-equiv="Content-Type" content="text/xhtml+xml; charset=UTF-8" /> - <title>tPlay — Contact</title> - <meta http-equiv="X-UA-Compatible" content="chrome=1" /> - <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" /> - <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> - <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> - <script type="text/javascript" src="Login.js"> </script> -</head> - -<body> - -<div id="main"> - -<div id="top"> -<div id="logo"><a href="index.html"><img src="toss.png" alt="tPlay" /></a></div> -</div> - -<div id="register-content"> - -<h2>Contact tPlay</h2> - -Just write an email to -<script type="text/javascript">begin_mailto("tossplay", "gmail.com");</script> -tossplay [AT] gmail [DOT] com -<script type="text/javascript">end_mailto();</script> - -<h2>Links</h2> - -<ul> -<li><a class="ta" href="http://toss.sourceforge.net/">Toss Homepage</a></li> -<li><a class="ta" href="http://www.playok.com/">Online games on PlayOK</a></li> -<li><a class="ta" href="http://www.apronus.com/chess/wbeditor.php">Chess - on Apronus</a></li> -</ul> - -</div> - -<div id="bottom"> -<a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a> -<a href="contact.html" id="contact">Contact and Info</a> -</div> - -</div> - - -</body> -</html> Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-05-14 14:30:21 UTC (rev 1441) +++ trunk/Toss/WebClient/index.html 2011-05-15 22:48:50 UTC (rev 1442) @@ -47,6 +47,17 @@ </form> </div> <span id="topright"> + Speed: <select id="speed"> + <option class="speed_val" value="1">1s</option> + <option class="speed_val" value="2">2s</option> + <option class="speed_val" value="3">3s</option> + <option class="speed_val" value="4">4s</option> + <option class="speed_val" value="5">5s</option> + <option class="speed_val" value="10">10s</option> + <option class="speed_val" value="15">15s</option> + <option class="speed_val" value="30">30s</option> + <option class="speed_val" value="60">60s</option> + </select> <button id="logoutbt" onclick="logout()">Logout</button> </span> <span id="topright-register"> @@ -69,49 +80,44 @@ </div> <div id="welcome"> -<p id="welcome-top">Enjoy the best games on <span class="logo-in">tPlay</span> for free</p> -<p> +<p id="welcome-top">Enjoy the best games on <span class="logo-in">tPlay</span> + for free</p> +<p id="p-under-welcome" style="display: none;"> Strategic games are fun! <a href="register.html">Register</a>, login and enjoy quality games with our best interface on <span class="logo-in">tPlay</span>! </p> <p style="width:100%; text-align: justify"> -<button onclick="new_play_guest('Breakthrough')" style="width:24%" - class="boldobt" title="Play Breakthrough"> - <img style="max-width:95%" src="pics/Breakthrough.png" alt="Breakthrough Board"> -</button> -<button onclick="new_play_guest('Checkers')" style="width:24%" - class="boldobt" title="Play Checkers"> - <img style="max-width:95%" src="pics/Checkers.png" alt="Checkers Board"> -</button> -<button onclick="new_play_guest('Chess')" style="width:24%" +<button onclick="new_play_guest('Chess')" style="width:32%" class="boldobt" title="Play Chess"> - <img style="max-width:95%" src="pics/Chess.png" alt="Chess Board"> + <img style="max-width:95%" src="pics/Chess.png" alt="Chess Board" /> </button> -<button onclick="new_play_guest('Connect4')" style="width:24%" +<button onclick="new_play_guest('Connect4')" style="width:32%" class="boldobt" title="Play Connect4"> - <img style="max-width:95%" src="pics/Connect4.png" alt="Connect4 Board"> + <img style="max-width:95%" src="pics/Connect4.png" alt="Connect4 Board" /> </button> +<button onclick="new_play_guest('Pawn-Whopping')" style="width:32%" + class="boldobt" title="Play Pawn-Whopping"> + <img style="max-width:95%" src="pics/Pawn-Whopping.png" + alt="Pawn-Whopping Board" /> +</button> </p> <p style="width:100%; text-align: justify"> -<button onclick="new_play_guest('Entanglement')" style="width:24%" - class="boldobt" title="Play Entanglement"> - <img style="max-width:95%" src="pics/Entanglement.png" alt="Entanglement Board"> +<button onclick="new_play_guest('Breakthrough')" style="width:32%" + class="boldobt" title="Play Breakthrough"> + <img style="max-width:95%" src="pics/Breakthrough.png" + alt="Breakthrough Board" /> </button> -<button onclick="new_play_guest('Gomoku')" style="width:24%" +<button onclick="new_play_guest('Checkers')" style="width:32%" + class="boldobt" title="Play Checkers"> + <img style="max-width:95%" src="pics/Checkers.png" alt="Checkers Board" /> +</button> +<button onclick="new_play_guest('Gomoku')" style="width:32%" class="boldobt" title="Play Gomoku"> - <img style="max-width:95%" src="pics/Gomoku.png" alt="Gomoku Board"> + <img style="max-width:95%" src="pics/Gomoku.png" alt="Gomoku Board" /> </button> -<button onclick="new_play_guest('Pawn-Whopping')" style="width:24%" - class="boldobt" title="Play Pawn-Whopping"> - <img style="max-width:95%" src="pics/Pawn-Whopping.png" alt="Pawn-Whopping Board"> -</button> -<button onclick="new_play_guest('Tic-Tac-Toe')" style="width:24%" - class="boldobt" title="Play Tic-Tac-Toe"> - <img style="max-width:95%" src="pics/Tic-Tac-Toe.png" alt="Tic-Tac-Toe Board"> -</button> </p> <ul class="welcome-list"> @@ -131,11 +137,8 @@ <a href="http://en.wikipedia.org/wiki/Pawn_(chess)" >Pawn-Whopping,</a> and many other board games</li> +<li>Focus fully on the game thanks to our intuitive clean interface</li> <li>Challenge your friends or play a fast game against the computer for fun</li> -<li>Focus fully on the game thanks to our intuitive clean interface</li> -<li>Keep and analyze your games to improve your strength</li> -<li>Invent new games with <a href="http://toss.sourceforge.net/">Toss</a> - and play them online here</li> </ul> </div> @@ -231,34 +234,42 @@ <div id="game-disp"> <p id="game-info-par"> <span id="game-title"></span> - game <span id="play-number">?</span> + <span id="play-nbr-info" style="display:none;"> + (game <span id="play-number">?</span>) + </span> + <span id="payoffs" style="display:none;">Not Finished Yet</span> </p> + <p id="new-play-par"> + <button id="new_game_me" class="bt" onclick="play_anew(true)"> + New Game (You Start) + </button> + <button id="new_game_opp" class="bt" onclick="play_anew(false)"> + New Game (Opponent Starts) + </button> + </p> + <p id="move-info-par"> + <span style="display: none;">Moves: <span id="cur-player">?</span></span> <button id="movebt" class="bt" onclick="make_move ()">Make move:</button> - <span id="cur-move">none</span> - </p> - - <p id="player-info-par"> - Moving: <span id="cur-player">?</span> + <span id="cur-move">none</span> <button id="sugbt" class="bt" onclick="suggest_move_click()"> - Suggest (weak, fast) + Suggest </button> - <button id="sugbts" class="bt" onclick="suggest_move_better_click()"> - Suggest (stronger, slow) - </button> </p> - <div id="board"><div id="working">Working...</div></div> </div> <div id="bottom"> <button id="suggestions-toggle" onclick="toggle_suggestions()"> - Show Move Suggestions + Ask Before Move </button> <a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a> -<a href="contact.html" id="contact">Contact and Info</a> +<script type="text/javascript">begin_mailto( + "tossplay", "gmail.com", "Contact Us");</script> +tossplay [AT] gmail [DOT] com +<script type="text/javascript">end_mailto();</script> </div> </div> Modified: trunk/Toss/WebClient/pics/Breakthrough.png =================================================================== (Binary files differ) Modified: trunk/Toss/WebClient/pics/Checkers.png =================================================================== (Binary files differ) Modified: trunk/Toss/WebClient/pics/Chess.png =================================================================== (Binary files differ) Modified: trunk/Toss/WebClient/pics/Connect4.png =================================================================== (Binary files differ) Modified: trunk/Toss/WebClient/pics/Connect4.svg =================================================================== --- trunk/Toss/WebClient/pics/Connect4.svg 2011-05-14 14:30:21 UTC (rev 1441) +++ trunk/Toss/WebClient/pics/Connect4.svg 2011-05-15 22:48:50 UTC (rev 1442) @@ -1,2 +1,2 @@ -<?xml-stylesheet href="Style.css" type="text/css"?> -<svg id="svg" viewBox="0 0 580 580"><rect class="model-elem-0" x="15" y="515" width="50" height="50" id="elem_a1" ></rect><rect class="model-elem-1" x="98.33333333333333" y="515" width="50" height="50" id="elem_b1" ></rect><rect class="model-elem-0" x="181.66666666666666" y="515" width="50" height="50" id="elem_c1" ></rect><rect class="model-elem-1" x="265" y="515" width="50" height="50" id="elem_d1" ></rect><rect class="model-elem-0" x="348.3333333333333" y="515" width="50" height="50" id="elem_e1" ></rect><rect class="model-elem-1" x="431.6666666666667" y="515" width="50" height="50" id="elem_f1" ></rect><rect class="model-elem-0" x="515" y="515" width="50" height="50" id="elem_g1" ></rect><rect class="model-elem-1" x="15" y="415" width="50" height="50" id="elem_a2" ></rect><rect class="model-elem-0" x="98.33333333333333" y="415" width="50" height="50" id="elem_b2" ></rect><rect class="model-elem-1" x="181.66666666666666" y="415" width="50" height="50" id="elem_c2" ></rect><rect class="model-elem-0" x="265" y="415" width="50" height="50" id="elem_d2" ></rect><rect class="model-elem-1" x="348.3333333333333" y="415" width="50" height="50" id="elem_e2" ></rect><rect class="model-elem-0" x="431.6666666666667" y="415" width="50" height="50" id="elem_f2" ></rect><rect class="model-elem-1" x="515" y="415" width="50" height="50" id="elem_g2" ></rect><rect class="model-elem-0" x="15" y="315" width="50" height="50" id="elem_a3" ></rect><rect class="model-elem-1" x="98.33333333333333" y="315" width="50" height="50" id="elem_b3" ></rect><rect class="model-elem-0" x="181.66666666666666" y="315" width="50" height="50" id="elem_c3" ></rect><rect class="model-elem-1" x="265" y="315" width="50" height="50" id="elem_d3" ></rect><rect class="model-elem-0" x="348.3333333333333" y="315" width="50" height="50" id="elem_e3" ></rect><rect class="model-elem-1" x="431.6666666666667" y="315" width="50" height="50" id="elem_f3" ></rect><rect class="model-elem-0" x="515" y="315" width="50" height="50" id="elem_g3" ></rect><rect class="model-elem-1" x="15" y="215" width="50" height="50" id="elem_a4" ></rect><rect class="model-elem-0" x="98.33333333333333" y="215" width="50" height="50" id="elem_b4" ></rect><rect class="model-elem-1" x="181.66666666666666" y="215" width="50" height="50" id="elem_c4" ></rect><rect class="model-elem-0" x="265" y="215" width="50" height="50" id="elem_d4" ></rect><rect class="model-elem-1" x="348.3333333333333" y="215" width="50" height="50" id="elem_e4" ></rect><rect class="model-elem-0" x="431.6666666666667" y="215" width="50" height="50" id="elem_f4" ></rect><rect class="model-elem-1" x="515" y="215" width="50" height="50" id="elem_g4" ></rect><rect class="model-elem-0" x="15" y="115" width="50" height="50" id="elem_a5" ></rect><rect class="model-elem-1" x="98.33333333333333" y="115" width="50" height="50" id="elem_b5" ></rect><rect class="model-elem-0" x="181.66666666666666" y="115" width="50" height="50" id="elem_c5" ></rect><rect class="model-elem-1" x="265" y="115" width="50" height="50" id="elem_d5" ></rect><rect class="model-elem-0" x="348.3333333333333" y="115" width="50" height="50" id="elem_e5" ></rect><rect class="model-elem-1" x="431.6666666666667" y="115" width="50" height="50" id="elem_f5" ></rect><rect class="model-elem-0" x="515" y="115" width="50" height="50" id="elem_g5" ></rect><rect class="model-elem-1" x="15" y="15" width="50" height="50" id="elem_a6" ></rect><rect class="model-elem-0" x="98.33333333333333" y="15" width="50" height="50" id="elem_b6" ></rect><rect class="model-elem-1" x="181.66666666666666" y="15" width="50" height="50" id="elem_c6" ></rect><rect class="model-elem-0" x="265" y="15" width="50" height="50" id="elem_d6" ></rect><rect class="model-elem-1" x="348.3333333333333" y="15" width="50" height="50" id="elem_e6" ></rect><rect class="model-elem-0" x="431.6666666666667" y="15" width="50" height="50" id="elem_f6" ></rect><rect class="model-elem-1" x="515" y="15" width="50" height="50" id="elem_g6" ></rect><circle class="model-pred-Q" cx="206.66666666666666" cy="540" r="13" id="pred_c1_Q" stroke-width="4.5" ></circle><circle class="model-pred-Q" cx="373.3333333333333" cy="540" r="13" id="pred_e1_Q" stroke-width="4.5" ></circle><circle class="model-pred-Q" cx="206.66666666666666" cy="440" r="13" id="pred_c2_Q" stroke-width="4.5" ></circle><circle class="model-pred-Q" cx="456.6666666666667" cy="440" r="13" id="pred_f2_Q" stroke-width="4.5" ></circle><circle class="model-pred-Q" cx="290" cy="340" r="13" id="pred_d3_Q" stroke-width="4.5" ></circle><g transform="translate(290,540) scale(1.25,1.25)"><g class="model-pred-P" id="pred_d1_P" ><line x1="-10" y1="-10" x2="10" y2="10"></line><line x1="10" y1="-10" x2="-10" y2="10"></line></g> </g><g transform="translate(456.6666666666667,540) scale(1.25,1.25)"><g class="model-pred-P" id="pred_f1_P" ><line x1="-10" y1="-10" x2="10" y2="10"></line><line x1="10" y1="-10" x2="-10" y2="10"></line></g> </g><g transform="translate(290,440) scale(1.25,1.25)"><g class="model-pred-P" id="pred_d2_P" ><line x1="-10" y1="-10" x2="10" y2="10"></line><line x1="10" y1="-10" x2="-10" y2="10"></line></g> </g><g transform="translate(373.3333333333333,440) scale(1.25,1.25)"><g class="model-pred-P" id="pred_e2_P" ><line x1="-10" y1="-10" x2="10" y2="10"></line><line x1="10" y1="-10" x2="-10" y2="10"></line></g> </g><g transform="translate(456.6666666666667,340) scale(1.25,1.25)"><g class="model-pred-P" id="pred_f3_P" ><line x1="-10" y1="-10" x2="10" y2="10"></line><line x1="10" y1="-10" x2="-10" y2="10"></line></g> </g></svg> +<?xml-stylesheet href="Style3.css" type="text/css"?> +<svg id="svg" viewBox="-10 -10 600 600"><rect x="0" y="0" width="580" height="580" stroke-width="5" rx="5" ry="5" id="board_connect4"></rect><g transform="translate(40,540) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_a1" class="model-elem-0" ></circle></g><g transform="translate(123.33333333333333,540) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_b1" class="model-elem-1" ></circle></g><g transform="translate(206.66666666666666,540) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_c1" class="model-elem-0" ></circle></g><g transform="translate(290,540) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_d1" class="model-elem-1" ></circle></g><g transform="translate(373.3333333333333,540) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_e1" class="model-elem-0" ></circle></g><g transform="translate(456.6666666666667,540) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_f1" class="model-elem-1" ></circle></g><g transform="translate(540,540) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_g1" class="model-elem-0" ></circle></g><g transform="translate(40,440) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_a2" class="model-elem-1" ></circle></g><g transform="translate(123.33333333333333,440) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_b2" class="model-elem-0" ></circle></g><g transform="translate(206.66666666666666,440) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_c2" class="model-elem-1" ></circle></g><g transform="translate(290,440) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_d2" class="model-elem-0" ></circle></g><g transform="translate(373.3333333333333,440) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_e2" class="model-elem-1" ></circle></g><g transform="translate(456.6666666666667,440) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_f2" class="model-elem-0" ></circle></g><g transform="translate(540,440) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_g2" class="model-elem-1" ></circle></g><g transform="translate(40,340) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_a3" class="model-elem-0" ></circle></g><g transform="translate(123.33333333333333,340) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_b3" class="model-elem-1" ></circle></g><g transform="translate(206.66666666666666,340) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_c3" class="model-elem-0" ></circle></g><g transform="translate(290,340) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_d3" class="model-elem-1" ></circle></g><g transform="translate(373.3333333333333,340) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_e3" class="model-elem-0" ></circle></g><g transform="translate(456.6666666666667,340) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_f3" class="model-elem-1" ></circle></g><g transform="translate(540,340) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_g3" class="model-elem-0" ></circle></g><g transform="translate(40,240) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_a4" class="model-elem-1" ></circle></g><g transform="translate(123.33333333333333,240) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_b4" class="model-elem-0" ></circle></g><g transform="translate(206.66666666666666,240) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_c4" class="model-elem-1" ></circle></g><g transform="translate(290,240) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_d4" class="model-elem-0" ></circle></g><g transform="translate(373.3333333333333,240) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_e4" class="model-elem-1" ></circle></g><g transform="translate(456.6666666666667,240) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_f4" class="model-elem-0" ></circle></g><g transform="translate(540,240) scale(1.5,1.5)"><circle cx="0" cy="0" r="20" id="elem_g4" class="model-elem-1" ></circle></g><g transform="translate(40,140) scale(1.5,1.5)"><circle cx="0" cy="0" r=... [truncated message content] |
From: <luk...@us...> - 2011-05-16 17:40:29
|
Revision: 1443 http://toss.svn.sourceforge.net/toss/?rev=1443&view=rev Author: lukaszkaiser Date: 2011-05-16 17:40:23 +0000 (Mon, 16 May 2011) Log Message: ----------- Make parallel calls stable. Inefficient for now due to multi-threading cache misses. Modified Paths: -------------- trunk/Toss/Formula/Aux.ml trunk/Toss/Formula/Aux.mli trunk/Toss/Play/GameTree.ml trunk/Toss/Server/ReqHandler.ml Modified: trunk/Toss/Formula/Aux.ml =================================================================== --- trunk/Toss/Formula/Aux.ml 2011-05-15 22:48:50 UTC (rev 1442) +++ trunk/Toss/Formula/Aux.ml 2011-05-16 17:40:23 UTC (rev 1443) @@ -660,16 +660,21 @@ addr_arr.(0) with Not_found -> raise Host_not_found -let toss_call (client_port, client_addr_s) f x = - let client_addr = get_inet_addr client_addr_s in - let client_sock = Unix.ADDR_INET (client_addr, client_port) in - let (cl_in_ch, cl_out_ch) = Unix.open_connection client_sock in - output_string cl_out_ch "COMP\n"; - flush cl_out_ch; - Marshal.to_channel cl_out_ch (f, x) [Marshal.Closures]; - flush cl_out_ch; - fun () -> - let res = Marshal.from_channel cl_in_ch in - Unix.shutdown_connection cl_in_ch; - res +let toss_call (client_port, client_addr_s) f_in x = + try + let client_addr = get_inet_addr client_addr_s in + let client_sock = Unix.ADDR_INET (client_addr, client_port) in + let (cl_in_ch, cl_out_ch) = Unix.open_connection client_sock in + output_string cl_out_ch "COMP\n"; + flush cl_out_ch; + let f a = try `Res (f_in a) with exn -> `Exn exn in + Marshal.to_channel cl_out_ch (f, x) [Marshal.Closures]; + flush cl_out_ch; + (fun () -> + let res = Marshal.from_channel cl_in_ch in + Unix.shutdown_connection cl_in_ch; + match res with `Res r -> r | `Exn e -> raise e) + with Unix.Unix_error (e, f, s) -> + Printf.printf "Toss call failed: %s; %s %s\n%!" (Unix.error_message e) f s; + (fun () -> f_in x) Modified: trunk/Toss/Formula/Aux.mli =================================================================== --- trunk/Toss/Formula/Aux.mli 2011-05-15 22:48:50 UTC (rev 1442) +++ trunk/Toss/Formula/Aux.mli 2011-05-16 17:40:23 UTC (rev 1443) @@ -309,5 +309,8 @@ (** Determine the internet address or raise Host_not_found. *) val get_inet_addr : string -> Unix.inet_addr -(** Call a Toss Server on [port, server] to compute [f] on [x]. *) +(** Call a Toss Server on [port, server] to compute [f] on [x]. BEWARE: + (1) references are not sent, e.g. you must redo timeouts. + (2) on single-threaded servers handling calls (older Toss versions), + you have to collect the results, even on Exception in caller *) val toss_call : int * string -> ('a -> 'b) -> 'a -> (unit -> 'b) Modified: trunk/Toss/Play/GameTree.ml =================================================================== --- trunk/Toss/Play/GameTree.ml 2011-05-15 22:48:50 UTC (rev 1442) +++ trunk/Toss/Play/GameTree.ml 2011-05-16 17:40:23 UTC (rev 1443) @@ -14,8 +14,11 @@ if l = 0 then [||] else if l = 1 then [|f a.(0)|] else ( let (a1, a2) = (Array.sub a 0 (l/2+1), Array.sub a (l/2+1) (l-(l/2+1))) in let r1 = Aux.toss_call !parallel_toss (Array.map f) a1 in - let r2 = Array.map f a2 in - Array.append (r1 ()) (r2) + (* If the server handling COMP is single-threaded, they must wait for it! + In such case replace the last line with the two lines below. + try let r2 = Array.map f a2 in Array.append (r1 ()) (r2) with exn -> + ignore (r1 ()); raise exn *) + let r2 = Array.map f a2 in Array.append (r1 ()) r2 ) (* Abstract game tree, just stores state and move information. *) Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-05-15 22:48:50 UTC (rev 1442) +++ trunk/Toss/Server/ReqHandler.ml 2011-05-16 17:40:23 UTC (rev 1443) @@ -658,7 +658,7 @@ | None -> if line_in = "COMP" then let res = Marshal.from_channel in_ch in - if !debug_level > 0 then Printf.printf "COMP\n%!"; + if !debug_level > 0 then Printf.printf "COMP, %!"; ("COMP", Some (Aux.Right res)) else (* We put endlines, encoded by '$', back into the message. @@ -684,10 +684,14 @@ (new_rstate, continue) in match read_in_line in_ch with | (line, Some (Aux.Right (f, x))) when line = "COMP" -> - let res = f x in - Marshal.to_channel out_ch res [Marshal.Closures]; - flush out_ch; - (rstate, true) + (match Unix.fork () with + | 0 (* child *) -> + let res = f x in + Marshal.to_channel out_ch res [Marshal.Closures]; + flush out_ch; + (rstate, false) + | _ (* parent *) -> (rstate, true) + ) | (line, Some (Aux.Left (cmd, head, msg, ck))) when line = "HTTP" -> (match handle_http_msg rstate cmd head msg ck with | Aux.Left ((state, resp)) -> report (state, resp) true This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-19 23:54:30
|
Revision: 1448 http://toss.svn.sourceforge.net/toss/?rev=1448&view=rev Author: lukaszkaiser Date: 2011-05-19 23:54:24 +0000 (Thu, 19 May 2011) Log Message: ----------- Basic concurrency support (run -redodb examples to get concurrent tic-tac-toe). Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Play/GameTree.ml trunk/Toss/Play/Move.ml trunk/Toss/Play/Move.mli trunk/Toss/Server/DB.ml trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/index.html Added Paths: ----------- trunk/Toss/examples/Concurrent-Tic-Tac-Toe.toss Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2011-05-19 10:44:34 UTC (rev 1447) +++ trunk/Toss/Arena/Arena.ml 2011-05-19 23:54:24 UTC (rev 1448) @@ -293,7 +293,8 @@ (rr) ^ ", " ^ fpstr ("t", t_interval) ^ par_str (* Print a move as string. *) -let move_str (lb, i) = "["^ (label_str lb) ^" -> "^ (string_of_int i) ^"]" +let move_str (lb, i) = Printf.sprintf "[%s -> %i]" (label_str lb) i +let pmv_str (pl, lb, i) = Printf.sprintf "[%s,%s -> %i]" pl (label_str lb) i let fprint_loc_body_in struc pnames f player {payoff = in_p; moves = in_m} = Format.fprintf f "@ @[<0>PLAYER@ %s@ {@ %a}@]@," (Aux.rev_assoc pnames player) @@ -815,13 +816,15 @@ state_game.graph.(i) <- { state_game.graph.(i) with moves = moves }; ((state_game, state), "LOC MOVES SET") ) *) - | GetLocMoves (i) -> (* TODO! adapt for concurrency! *) + | GetLocMoves (i) -> if i < 0 || i > Array.length state_game.graph then ((state_game, state), "ERR location "^string_of_int i^" not found") else - let all_moves = List.concat (Array.to_list (Array.map ( - fun loc -> loc.moves) state_game.graph.(i))) in - ((state_game,state), (String.concat "; " (List.map move_str all_moves))) + let pl i = Aux.rev_assoc state_game.player_names i in + let all_moves = List.concat (Array.to_list ( + Array.mapi (fun i ploc -> List.map (fun (l, e) -> (pl i, l, e)) + ploc.moves) state_game.graph.(i))) in + ((state_game,state), (String.concat "; " (List.map pmv_str all_moves))) | SuggestLocMoves _ -> failwith "handle_req: SuggestLocMoves handled in Server" | EvalFormula (phi) -> ((state_game, state), "ERR eval not yet implemented") Modified: trunk/Toss/Play/GameTree.ml =================================================================== --- trunk/Toss/Play/GameTree.ml 2011-05-19 10:44:34 UTC (rev 1447) +++ trunk/Toss/Play/GameTree.ml 2011-05-19 23:54:24 UTC (rev 1448) @@ -101,7 +101,7 @@ let l_pl = moving_player game.Arena.graph.(leaf_s.Arena.cur_loc) in let l_info = info_leaf (depth+1) game leaf_s l_pl player in Leaf (leaf_s, l_pl, l_info) in - let children = parallel_map (fun (m,s) -> (m, leaf_of_move s)) moves in + let children = parallel_map (fun (_,m,s)-> (m, leaf_of_move s)) moves in Solver.M.clear_timeout (); Node (state, player,info_node depth game state player children,children) | Node (state, player, info, children) -> @@ -241,7 +241,8 @@ (* Choose one of the maximizing moves (at random) given a game tree. *) let choose_moves game = function | Terminal _ -> raise Not_found - | Leaf (state, _, _) -> Array.to_list (Move.list_moves game state) + | Leaf (state, _, _) -> + List.map (fun (_,a,b) -> (a,b)) (Array.to_list (Move.list_moves game state)) | Node (_, p, info, succ) -> let cmp (_, c1) (_, c2) = let nval child = (node_values child).(p) in Modified: trunk/Toss/Play/Move.ml =================================================================== --- trunk/Toss/Play/Move.ml 2011-05-19 10:44:34 UTC (rev 1447) +++ trunk/Toss/Play/Move.ml 2011-05-19 23:54:24 UTC (rev 1448) @@ -115,11 +115,13 @@ Array.of_list moves, Array.of_list models let list_moves game s = - let select_moving a =(*temporary function - accept just one player w/ moves*) - let locs = Aux.array_find_all (fun l -> l.Arena.moves <> []) a in - if List.length locs <> 1 then failwith "too many moves in loc for now" else - if locs = [] then a.(0) else List.hd locs in - let loc = select_moving (game.Arena.graph.(s.Arena.cur_loc)) in - let m = gen_moves cGRID_SIZE game.Arena.rules s.Arena.struc loc in - Array.of_list (gen_models_list game.Arena.rules s.Arena.struc s.Arena.time m) - + let select_moving a = + let pls = Aux.array_argfind_all (fun l -> l.Arena.moves <> []) a in + if pls = [] then [0] else pls in + let loc = game.Arena.graph.(s.Arena.cur_loc) in + let moving = select_moving loc in + let get_moves pl = + let m = gen_moves cGRID_SIZE game.Arena.rules s.Arena.struc loc.(pl) in + (gen_models_list game.Arena.rules s.Arena.struc s.Arena.time m) in + Array.of_list (List.concat ( + List.map (fun p -> List.map (fun (a,b) -> (p,a,b)) (get_moves p)) moving)) Modified: trunk/Toss/Play/Move.mli =================================================================== --- trunk/Toss/Play/Move.mli 2011-05-19 10:44:34 UTC (rev 1447) +++ trunk/Toss/Play/Move.mli 2011-05-19 23:54:24 UTC (rev 1448) @@ -34,4 +34,4 @@ float -> move array -> move array * Arena.game_state array val list_moves : Arena.game -> Arena.game_state -> - (move * Arena.game_state) array + (int * move * Arena.game_state) array Modified: trunk/Toss/Server/DB.ml =================================================================== --- trunk/Toss/Server/DB.ml 2011-05-19 10:44:34 UTC (rev 1447) +++ trunk/Toss/Server/DB.ml 2011-05-19 23:54:24 UTC (rev 1448) @@ -10,7 +10,8 @@ let dbFILE = ref ((Unix.getenv "HOME") ^ "/.tossdb.sqlite") let tGAMES = ref ["Breakthrough"; "Checkers"; "Chess"; "Connect4"; - "Entanglement"; "Gomoku"; "Pawn-Whopping"; "Tic-Tac-Toe"] + "Entanglement"; "Gomoku"; "Pawn-Whopping"; "Tic-Tac-Toe"; + "Concurrent-Tic-Tac-Toe"] let def_gdir = if Sys.file_exists "/usr/share/toss" then "/usr/share/toss/games" else "./examples" Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-05-19 10:44:34 UTC (rev 1447) +++ trunk/Toss/Server/ReqHandler.ml 2011-05-19 23:54:24 UTC (rev 1448) @@ -215,8 +215,9 @@ (strip_ws sep.(0), strip_ws d.(0), strip_ws d.(1)) in let make_move m = let gs = split "->" m in - let lab = split_list "," gs.(0) in - (strip_ws (List.hd lab), + let lab_all = split_list "," gs.(0) in + let (lab_pl, lab) = (List.hd lab_all, List.tl lab_all) in + (strip_ws lab_pl, strip_ws (List.hd lab), List.map (fun v -> make_itvl (strip_ws v)) (List.tl lab), strip_ws gs.(1)) in List.map (fun m -> make_move (strip_ws_lst m)) moves @@ -245,18 +246,20 @@ let client_open_from_str s = client_set_state ("#db#" ^ s) -let client_move_str (m, r, e) = +let client_move_str (pl, m, r, e) = let mstr m = String.concat ", " (List.map (fun (a, b) -> a ^ ": " ^ b) m) in - "({" ^ mstr m ^ "}, " ^ r ^ ", " ^ e ^ ")" + pl ^ ",({" ^ mstr m ^ "}, " ^ r ^ ", " ^ e ^ ")" let client_cur_moves () = - let append_move moves (r, _, endp) = (* FIXME! currently we ignore itvls *) - (List.map (fun m -> (m, r, endp)) (client_query r)) @ moves in + let append_move moves (pl, r, _, endp) = (* currently we ignore itvls *) + (List.map (fun m -> (pl, m, r, endp)) (client_query r)) @ moves in let cur_loc = client_get_cur_loc () in let moves = List.fold_left append_move [] (client_get_loc_moves cur_loc) in String.concat "; " (List.map client_move_str moves) -let client_get_loc_player i = client_msg ("GET LOC PLAYER " ^ i) +let client_get_loc_player i = + let msg = client_msg ("GET LOC PLAYER " ^ i) in + if (String.length msg > 3 && String.sub msg 0 3 = "ERR") then "-1" else msg let client_make_move m r endp = let _ = client_apply_rule r m "1.0" [] in @@ -276,7 +279,7 @@ (t.(0), t.(1)) -let client_suggest timeout advr = +let client_suggest pl timeout advr = let loc = client_get_cur_loc () in let (ts, t) = client_get_time () in let m = client_msg ("EVAL LOC MOVES " ^ advr ^ ".0 " ^ loc ^ @@ -288,7 +291,7 @@ let es = Array.map strip_ws (split ":" s) in (es.(0), es.(1)) :: emb in let emb = List.fold_left append_emb [] (split_list "," msg.(1)) in - client_move_str (emb, msg.(0), msg.(3)) + client_move_str (string_of_int pl, emb, msg.(0), msg.(3)) let client_model_get_elem_val el_id vl = @@ -412,7 +415,7 @@ | "sv" -> "image/svg+xml" | _ -> "text/html charset=utf-8" in http_msg true "200 OK" tp [] content - ) else http_msg true "404 NOT FOUND" "text/html charset=utf-8" [] + ) else http_msg true "404 NOT FOUND" "text/html; charset=utf-8" [] ("<html>\n<head><title>Toss: Page Not Found</title></head>\n" ^ "<body><p>Not found: " ^ fname_in ^ "</p></body>\n</html>") @@ -476,16 +479,16 @@ db_cur_insert game pl1 pl2 pid (string_of_int move_pl) model loc info ""; release_global_lock (); pid ^ "$" ^ info ^ "$" ^ (string_of_int move_pl) in - let game_select_s g p1 p2 pid m = + let game_select_s g p1 p2 pid = "game='" ^ g ^ "' and player1='" ^ p1 ^ "' and player2='" ^ p2 ^ - "' and playid=" ^ pid ^ " and move=" ^ m in + "' and playid=" ^ pid in let upd_svg g p1 p2 pid m svg_s = - let select = game_select_s g p1 p2 pid m in + let select = game_select_s g p1 p2 pid in let _ = DB.update_table dbFILE ~select ("svg='"^ svg_s ^"'") "cur_states" in "" in let db_escape s = str_replace "'" "''" s in let move_play move_tup g p1 p2 pid m = - let sel_s = game_select_s g p1 p2 pid m in + let sel_s = game_select_s g p1 p2 pid in let old_res= List.hd (dbtable sel_s "cur_states") in let (old_toss, old_loc, old_info, old_svg) = (old_res.(5), old_res.(6), old_res.(7), old_res.(8)) in @@ -509,14 +512,14 @@ [pid; g; p1; p2; m; old_toss; old_loc; old_info; old_svg]; new_info ^ "$" ^ (string_of_int new_pl) in let suggest time g p1 p2 pid m = - let res = List.hd (dbtable (game_select_s g p1 p2 pid m) "cur_states") in + let res = List.hd (dbtable (game_select_s g p1 p2 pid) "cur_states") in let (toss, loc) = (res.(5), res.(6)) in let game_toss = (List.hd (dbtable ("game='" ^ g ^ "'") "games")).(1) in client_open_from_str (game_toss ^ "\nMODEL " ^ toss); client_set_cur_loc loc; let adv_ratio_data = client_get_data "adv_ratio" in let adv_ratio = if adv_ratio_data = "none" then "4" else adv_ratio_data in - client_suggest time adv_ratio in + client_suggest (m+1) time adv_ratio in let register_user ui = if Array.length ui <> 5 then false else let (uid, name, surname, email, pwd) = @@ -538,7 +541,7 @@ let friends = dbtable ("id='" ^ uid ^ "'") "friends" in List.map (fun a -> a.(1)) friends in let open_db game p1 p2 pid move = - let res = dbtable (game_select_s game p1 p2 pid move) "cur_states" in + let res = dbtable (game_select_s game p1 p2 pid) "cur_states" in let (move, info) = ((List.hd res).(4), (List.hd res).(7)) in info ^ "$" ^ move in let add_opponent uid oppid = @@ -604,7 +607,8 @@ | "NEW_PLAY" -> let a = get_args data in new_play a.(1) a.(2) a.(3), [] | "SUGGEST" -> - let a = get_args data in suggest a.(1) a.(2) a.(3) a.(4) a.(5) a.(6), [] + let a = get_args data in + suggest a.(1) a.(2) a.(3) a.(4) a.(5) (int_of_string a.(6)), [] | "MOVE_PLAY" -> let (op_i, cl_i) = (String.index data '(', String.index data ')') in let tp_s = String.sub data (op_i+1) (cl_i - op_i-1) in @@ -618,7 +622,7 @@ move_play tp a.(0) a.(1) a.(2) a.(3) a.(4), [] | _ -> "MOD_PYTHON ERROR ; Traceback: Unknown Toss Command! \n " ^ tcmd, [] in - http_msg false "200 OK" "text/html charset=utf-8" new_cookies resp + http_msg false "200 OK" "text/html; charset=utf-8" new_cookies resp let handle_http_msg rstate cmd head msg ck = Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-05-19 10:44:34 UTC (rev 1447) +++ trunk/Toss/WebClient/Connect.js 2011-05-19 23:54:24 UTC (rev 1448) @@ -41,11 +41,11 @@ function set_info (info) { var res_arr = []; res_arr = info.split("$"); - if (res_arr.length != 5) { return (false); } + if (res_arr.length != 5) { alert (res_arr); return (false); } DIM_STR = res_arr[0]; ELEM_STR = res_arr[1]; RELS_STR = res_arr[2]; - if (res_arr[3].substring(0, 1) == "(") { + if (res_arr[3].substring(2, 3) == "(") { MOVES_STR = res_arr[3]; PAYOFF_STR = ""; } else { Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-05-19 10:44:34 UTC (rev 1447) +++ trunk/Toss/WebClient/Login.js 2011-05-19 23:54:24 UTC (rev 1448) @@ -30,6 +30,7 @@ list_plays_string ("Gomoku", udata[7]); list_plays_string ("Pawn-Whopping", udata[8]); list_plays_string ("Tic-Tac-Toe", udata[9]); + list_plays_string ("Concurrent-Tic-Tac-Toe", udata[10]); get_opponents (); } Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-05-19 10:44:34 UTC (rev 1447) +++ trunk/Toss/WebClient/Main.js 2011-05-19 23:54:24 UTC (rev 1448) @@ -244,8 +244,8 @@ document.getElementById("game-disp").style.display = "none"; document.getElementById("plays").style.display = "none"; GAME_NAME = game; - if (game == "Tic-Tac-Toe") { // bigger margins needed - create_svg_box (130, 130, "board"); + if (game == "Tic-Tac-Toe" || game == "Concurrent-Tic-Tac-Toe") { + create_svg_box (130, 130, "board"); // bigger margins needed } else { create_svg_box (40, 40, "board"); } @@ -277,9 +277,9 @@ function make_move () { if (ASYNC_ALL_REQ_PENDING != 0) { alert ("async"); return; } if (CUR_MOVE == "") return; - var m = PLAYS[CUR_PLAY_I][3]; + var m = parseInt(CUR_MOVE.substring (0, 1)) - 1; if (PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer") { - alert ("It is your Opponent's turn"); + alert ("It is your Opponent's move"); return; } if (! SIMPLE_MOVES) { Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-05-19 10:44:34 UTC (rev 1447) +++ trunk/Toss/WebClient/index.html 2011-05-19 23:54:24 UTC (rev 1448) @@ -258,6 +258,14 @@ <ul class="plays-list" id="plays-list-Tic-Tac-Toe"> <li style="display: none;"/> </ul> + <p class="game-par"> + <button onclick="new_play('Concurrent-Tic-Tac-Toe')" + class="boldobt">Concurrent-Tic-Tac-Toe</button> + (<a href="http://en.wikipedia.org/wiki/Tic-tac-toe">info</a>) + </p> + <ul class="plays-list" id="plays-list-Concurrent-Tic-Tac-Toe"> + <li style="display: none;"/> + </ul> </div> Added: trunk/Toss/examples/Concurrent-Tic-Tac-Toe.toss =================================================================== --- trunk/Toss/examples/Concurrent-Tic-Tac-Toe.toss (rev 0) +++ trunk/Toss/examples/Concurrent-Tic-Tac-Toe.toss 2011-05-19 23:54:24 UTC (rev 1448) @@ -0,0 +1,30 @@ +PLAYERS 1, 2 +DATA r1: circle, r2: line, adv_ratio: 5, depth: 3 +REL DiagA (x, y) = ex u (R(x, u) and C(u, y)) +REL DiagB (x, y) = ex u (R(x, u) and C(y, u)) +REL Row3 (x, y, z) = R(x, y) and R(y, z) +REL Col3 (x, y, z) = C(x, y) and C(y, z) +REL DiagA3 (x, y, z) = DiagA(x, y) and DiagA(y, z) +REL DiagB3 (x, y, z) = DiagB(x, y) and DiagB(y, z) +REL Conn3 (x, y, z) = + Row3(x, y, z) or Col3(x, y, z) or DiagA3(x, y, z) or DiagB3(x, y, z) +REL WinQ() = ex x, y, z (Q(x) and Q(y) and Q(z) and Conn3(x, y, z)) +REL WinP() = ex x, y, z (P(x) and P(y) and P(z) and Conn3(x, y, z)) +RULE Cross: + [a | P:1 {} | - ] -> [a | P (a) | - ] emb Q, P pre not (WinP() or WinQ()) +RULE Circle: + [a | Q:1 {} | - ] -> [a | Q (a) | - ] emb Q, P pre not (WinP() or WinQ()) +LOC 0 { + PLAYER 1 { PAYOFF :(WinP()) - :(WinQ()) + MOVES [Cross -> 0] } + PLAYER 2 { PAYOFF :(WinQ()) - :(WinP()) + MOVES [Circle -> 0] } +} +MODEL [ | P:1 {}; Q:1 {} | ] " + + . . . + + . . . + + . . . +" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-22 00:36:16
|
Revision: 1451 http://toss.svn.sourceforge.net/toss/?rev=1451&view=rev Author: lukaszkaiser Date: 2011-05-22 00:36:07 +0000 (Sun, 22 May 2011) Log Message: ----------- Resources trying to define Breakthrough by pictures alone. Modified Paths: -------------- trunk/Toss/Server/Picture.ml trunk/Toss/Server/Picture.mli trunk/Toss/Server/PictureTest.ml trunk/Toss/www/pub/first_order_counting_ggp.pdf Added Paths: ----------- trunk/Toss/Server/def_pics/ trunk/Toss/Server/def_pics/.cvsignore trunk/Toss/Server/def_pics/Breakthrough00.svg trunk/Toss/Server/def_pics/Breakthrough01.svg trunk/Toss/Server/def_pics/Breakthrough02.svg trunk/Toss/Server/def_pics/Breakthrough03.svg trunk/Toss/Server/def_pics/Breakthrough04.svg trunk/Toss/Server/def_pics/Breakthrough05.svg trunk/Toss/Server/def_pics/Breakthrough06.svg trunk/Toss/Server/def_pics/Breakthrough07.svg trunk/Toss/Server/def_pics/Breakthrough08.svg trunk/Toss/Server/def_pics/Breakthrough09.svg trunk/Toss/Server/def_pics/Breakthrough10.svg trunk/Toss/Server/def_pics/Breakthrough11.svg trunk/Toss/Server/def_pics/Breakthrough12.svg trunk/Toss/Server/def_pics/BreakthroughWin00.svg trunk/Toss/Server/def_pics/BreakthroughWin01.svg trunk/Toss/Server/def_pics/Makefile trunk/Toss/Server/def_pics/Style.css Modified: trunk/Toss/Server/Picture.ml =================================================================== --- trunk/Toss/Server/Picture.ml 2011-05-21 22:28:01 UTC (rev 1450) +++ trunk/Toss/Server/Picture.ml 2011-05-22 00:36:07 UTC (rev 1451) @@ -220,7 +220,7 @@ Printf.sprintf "e%i,%i" ni nj in let (s1, elem) = Structure.add_new_elem struc ~name () in let s2 = Structure.add_fun s1 "x" (elem, float (x1+x2) /. 2.) in - let s3 = Structure.add_fun s2 "y" (elem, float (y1+y2) /. (-2.)) in + let s3 = Structure.add_fun s2 "y" (elem, float (y1+y2) /. (2.)) in let s4 = Structure.add_fun s3 "x1" (elem, float x1) in let s5 = Structure.add_fun s4 "y1" (elem, float y1) in let s6 = Structure.add_fun s5 "x2" (elem, float x2) in @@ -232,4 +232,34 @@ let (s, _, _) = List.fold_left add_el (Structure.empty_structure (), 1, 0) dict in (s, !maxdx, !maxdy) - + + +(* Make a game from sequence of pictures. *) +let make_game ?(rels=[]) ?(offset=2) ?(threshold=70.) fname = + let formula_of_string s = + FormulaParser.parse_formula Lexer.lex (Lexing.from_string s) in + let get_struc fn = + let pic = read_pic (Scanf.Scanning.from_file fn) in + let (struc, dx, dy) = make_struc (segment 2 70. pic) in + let formula_r = formula_of_string (Printf.sprintf ( + ":y(a) = :y(b) and :x(a) < :x(b) and :x(b) < :x(a) + %i.8") dx) in + let formula_c = formula_of_string (Printf.sprintf ( + ":x(a) = :x(b) and :y(b) < :y(a) and :y(a) < :y(b) + %i.8") dy) in + let row, col = ("R", ["a"; "b"], formula_r), ("C", ["a"; "b"], formula_c) in + Arena.add_def_rels struc (row :: col :: rels) in + let flen = String.length fname in + let gname = if (flen > 6 && fname.[flen-4] = '.') then + String.sub fname 0 (flen - 6) else fname in + let name ?(suffix="") i = Printf.sprintf "%s%s%02i.ppm" gname suffix i in + let read_strucs () = + let (seq_strucs, win_strucs, i) = (ref [], ref [], ref 0) in + while Sys.file_exists (name !i) do + seq_strucs := get_struc (name !i) :: !seq_strucs; incr i + done; + i := 0; + while Sys.file_exists (name ~suffix:"Win" !i) do + win_strucs := get_struc (name ~suffix:"Win" !i) :: !win_strucs; incr i + done; + (List.rev !seq_strucs, List.rev !win_strucs) in + let (seq, wins) = read_strucs () in + Printf.sprintf "Read %i seq, %i win." (List.length seq) (List.length wins) Modified: trunk/Toss/Server/Picture.mli =================================================================== --- trunk/Toss/Server/Picture.mli 2011-05-21 22:28:01 UTC (rev 1450) +++ trunk/Toss/Server/Picture.mli 2011-05-22 00:36:07 UTC (rev 1451) @@ -48,3 +48,7 @@ (** Create a structure from segmented data. *) val make_struc : (((int * int) * (int * int)) * string) list -> Structure.structure * int * int + +(** Create a game from sequence of images. *) +val make_game : ?rels : (string * string list * Formula.formula) list -> + ?offset : int -> ?threshold : float -> string -> string Modified: trunk/Toss/Server/PictureTest.ml =================================================================== --- trunk/Toss/Server/PictureTest.ml 2011-05-21 22:28:01 UTC (rev 1450) +++ trunk/Toss/Server/PictureTest.ml 2011-05-22 00:36:07 UTC (rev 1451) @@ -7,7 +7,7 @@ (fun () -> let fname = "./www/img/Breakthrough.ppm" in let pic = Picture.read_pic (Scanf.Scanning.from_file fname) in - let seg = Picture.segment 2 40. pic in + let seg = Picture.segment 2 70. pic in assert_equal ~printer:string_of_int 64 (List.length seg) ); @@ -15,7 +15,7 @@ (fun () -> let fname = "./www/img/Breakthrough.ppm" in let pic = Picture.read_pic (Scanf.Scanning.from_file fname) in - let seg = Picture.segment 2 40. pic in + let seg = Picture.segment 2 70. pic in let (struc, _, _) = Picture.make_struc seg in assert_equal ~printer:string_of_int 16 (Structure.rel_size struc "P1") ); @@ -24,24 +24,27 @@ let main () = Aux.set_optimized_gc (); - let (file) = (ref "") in + let (file, game) = (ref "", ref "") in let dbg_level i = (Picture.set_debug_level i) in let opts = [ ("-v", Arg.Unit (fun () -> dbg_level 1), "be verbose"); ("-d", Arg.Int (fun i -> dbg_level i), "set debug level"); ("-f", Arg.String (fun s -> file := s), "process file"); + ("-g", Arg.String (fun s -> game := s), "process files for a game"); ] in Arg.parse opts (fun _ -> ()) "Try -help for help or one of the following."; - if !file = "" then ignore (OUnit.run_test_tt ~verbose:true tests) else ( + if !file <> "" then ( let pic = Picture.read_pic (Scanf.Scanning.from_file !file) in - let (struc, dx, dy) = Picture.make_struc (Picture.segment 2 40. pic) in + let (struc, dx, dy) = Picture.make_struc (Picture.segment 2 70. pic) in let formula_r = Printf.sprintf ":y(a) = :y(b) and :x(a) < :x(b) and :x(b) < :x(a) + %i.8" dx in let formula_c = Printf.sprintf ":x(a) = :x(b) and :y(b) < :y(a) and :y(a) < :y(b) + %i.8" dy in Printf.printf "MODEL \n %s \n with \n R(a, b) = %s;\n C(a, b) = %s\n\n%!" (Structure.sprint struc) formula_r formula_c; - ) + ) else if !game <> "" then ( + print_endline (Picture.make_game !game) + ) else ignore (OUnit.run_test_tt ~verbose:true tests) let _ = Aux.run_if_target "PictureTest" main Property changes on: trunk/Toss/Server/def_pics ___________________________________________________________________ Added: svn:ignore + # We are still using .cvsignore files as we find them easier to manage # than svn properties. Therefore if you change .cvsignore do the following. # svn propset svn:ignore -F .cvsignore . *~ *.ppm *.png *.toss Added: trunk/Toss/Server/def_pics/.cvsignore =================================================================== --- trunk/Toss/Server/def_pics/.cvsignore (rev 0) +++ trunk/Toss/Server/def_pics/.cvsignore 2011-05-22 00:36:07 UTC (rev 1451) @@ -0,0 +1,8 @@ +# We are still using .cvsignore files as we find them easier to manage +# than svn properties. Therefore if you change .cvsignore do the following. +# svn propset svn:ignore -F .cvsignore . + +*~ +*.ppm +*.png +*.toss Added: trunk/Toss/Server/def_pics/Breakthrough00.svg =================================================================== --- trunk/Toss/Server/def_pics/Breakthrough00.svg (rev 0) +++ trunk/Toss/Server/def_pics/Breakthrough00.svg 2011-05-22 00:36:07 UTC (rev 1451) @@ -0,0 +1,2 @@ +<?xml-stylesheet href="Style.css" type="text/css"?> +<svg id="svg" viewBox="0 0 580 580"><rect class="model-elem-0" x="4.285714285714285" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_a1" ></rect><rect class="model-elem-1" x="75.71428571428572" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_b1" ></rect><rect class="model-elem-0" x="147.14285714285714" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_c1" ></rect><rect class="model-elem-1" x="218.57142857142856" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_d1" ></rect><rect class="model-elem-0" x="290" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_e1" ></rect><rect class="model-elem-1" x="361.42857142857144" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_f1" ></rect><rect class="model-elem-0" x="432.85714285714283" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_g1" ></rect><rect class="model-elem-1" x="504.2857142857143" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_h1" ></rect><rect class="model-elem-1" x="4.285714285714285" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_a2" ></rect><rect class="model-elem-0" x="75.71428571428572" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_b2" ></rect><rect class="model-elem-1" x="147.14285714285714" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_c2" ></rect><rect class="model-elem-0" x="218.57142857142856" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_d2" ></rect><rect class="model-elem-1" x="290" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_e2" ></rect><rect class="model-elem-0" x="361.42857142857144" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_f2" ></rect><rect class="model-elem-1" x="432.85714285714283" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_g2" ></rect><rect class="model-elem-0" x="504.2857142857143" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_h2" ></rect><rect class="model-elem-0" x="4.285714285714285" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_a3" ></rect><rect class="model-elem-1" x="75.71428571428572" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_b3" ></rect><rect class="model-elem-0" x="147.14285714285714" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_c3" ></rect><rect class="model-elem-1" x="218.57142857142856" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_d3" ></rect><rect class="model-elem-0" x="290" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_e3" ></rect><rect class="model-elem-1" x="361.42857142857144" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_f3" ></rect><rect class="model-elem-0" x="432.85714285714283" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_g3" ></rect><rect class="model-elem-1" x="504.2857142857143" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_h3" ></rect><rect class="model-elem-1" x="4.285714285714285" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_a4" ></rect><rect class="model-elem-0" x="75.71428571428572" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_b4" ></rect><rect class="model-elem-1" x="147.14285714285714" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_c4" ></rect><rect class="model-elem-0" x="218.57142857142856" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_d4" ></rect><rect class="model-elem-1" x="290" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_e4" ></rect><rect class="model-elem-0" x="361.42857142857144" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_f4" ></rect><rect class="model-elem-1" x="432.85714285714283" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_g4" ></rect><rect class="model-elem-0" x="504.2857142857143" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_h4" ></rect><rect class="model-elem-0" x="4.285714285714285" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_a5" ></rect><rect class="model-elem-1" x="75.71428571428572" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_b5" ></rect><rect class="model-elem-0" x="147.14285714285714" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_c5" ></rect><rect class="model-elem-1" x="218.57142857142856" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_d5" ></rect><rect class="model-elem-0" x="290" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_e5" ></rect><rect class="model-elem-1" x="361.42857142857144" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_f5" ></rect><rect class="model-elem-0" x="432.85714285714283" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_g5" ></rect><rect class="model-elem-1" x="504.2857142857143" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_h5" ></rect><rect class="model-elem-1" x="4.285714285714285" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_a6" ></rect><rect class="model-elem-0" x="75.71428571428572" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_b6" ></rect><rect class="model-elem-1" x="147.14285714285714" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_c6" ></rect><rect class="model-elem-0" x="218.57142857142856" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_d6" ></rect><rect class="model-elem-1" x="290" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_e6" ></rect><rect class="model-elem-0" x="361.42857142857144" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_f6" ></rect><rect class="model-elem-1" x="432.85714285714283" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_g6" ></rect><rect class="model-elem-0" x="504.2857142857143" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_h6" ></rect><rect class="model-elem-0" x="4.285714285714285" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_a7" ></rect><rect class="model-elem-1" x="75.71428571428572" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_b7" ></rect><rect class="model-elem-0" x="147.14285714285714" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_c7" ></rect><rect class="model-elem-1" x="218.57142857142856" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_d7" ></rect><rect class="model-elem-0" x="290" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_e7" ></rect><rect class="model-elem-1" x="361.42857142857144" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_f7" ></rect><rect class="model-elem-0" x="432.85714285714283" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_g7" ></rect><rect class="model-elem-1" x="504.2857142857143" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_h7" ></rect><rect class="model-elem-1" x="4.285714285714285" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_a8" ></rect><rect class="model-elem-0" x="75.71428571428572" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_b8" ></rect><rect class="model-elem-1" x="147.14285714285714" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_c8" ></rect><rect class="model-elem-0" x="218.57142857142856" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_d8" ></rect><rect class="model-elem-1" x="290" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_e8" ></rect><rect class="model-elem-0" x="361.42857142857144" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_f8" ></rect><rect class="model-elem-1" x="432.85714285714283" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_g8" ></rect><rect class="model-elem-0" x="504.2857142857143" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_h8" ></rect><circle class="model-pred-W" cx="40" cy="540" r="23.714285714285715" id="pred_a1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="111.42857142857143" cy="540" r="23.714285714285715" id="pred_b1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="182.85714285714286" cy="540" r="23.714285714285715" id="pred_c1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="254.28571428571428" cy="540" r="23.714285714285715" id="pred_d1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="325.7142857142857" cy="540" r="23.714285714285715" id="pred_e1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="397.14285714285717" cy="540" r="23.714285714285715" id="pred_f1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="540" r="23.714285714285715" id="pred_g1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="540" r="23.714285714285715" id="pred_h1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="40" cy="468.57142857142856" r="23.714285714285715" id="pred_a2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="111.42857142857143" cy="468.57142857142856" r="23.714285714285715" id="pred_b2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="182.85714285714286" cy="468.57142857142856" r="23.714285714285715" id="pred_c2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="254.28571428571428" cy="468.57142857142856" r="23.714285714285715" id="pred_d2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="325.7142857142857" cy="468.57142857142856" r="23.714285714285715" id="pred_e2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="397.14285714285717" cy="468.57142857142856" r="23.714285714285715" id="pred_f2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="468.57142857142856" r="23.714285714285715" id="pred_g2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="468.57142857142856" r="23.714285714285715" id="pred_h2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="40" cy="111.42857142857143" r="23.714285714285715" id="pred_a7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="111.42857142857143" cy="111.42857142857143" r="23.714285714285715" id="pred_b7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="182.85714285714286" cy="111.42857142857143" r="23.714285714285715" id="pred_c7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="254.28571428571428" cy="111.42857142857143" r="23.714285714285715" id="pred_d7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="111.42857142857143" r="23.714285714285715" id="pred_e7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="397.14285714285717" cy="111.42857142857143" r="23.714285714285715" id="pred_f7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="468.57142857142856" cy="111.42857142857143" r="23.714285714285715" id="pred_g7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="540" cy="111.42857142857143" r="23.714285714285715" id="pred_h7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="40" cy="40" r="23.714285714285715" id="pred_a8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="111.42857142857143" cy="40" r="23.714285714285715" id="pred_b8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="182.85714285714286" cy="40" r="23.714285714285715" id="pred_c8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="254.28571428571428" cy="40" r="23.714285714285715" id="pred_d8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="40" r="23.714285714285715" id="pred_e8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="397.14285714285717" cy="40" r="23.714285714285715" id="pred_f8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="468.57142857142856" cy="40" r="23.714285714285715" id="pred_g8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="540" cy="40" r="23.714285714285715" id="pred_h8_B" stroke-width="5.571428571428571" ></circle></svg> Added: trunk/Toss/Server/def_pics/Breakthrough01.svg =================================================================== --- trunk/Toss/Server/def_pics/Breakthrough01.svg (rev 0) +++ trunk/Toss/Server/def_pics/Breakthrough01.svg 2011-05-22 00:36:07 UTC (rev 1451) @@ -0,0 +1,2 @@ +<?xml-stylesheet href="Style.css" type="text/css"?> +<svg id="svg" viewBox="0 0 580 580"><rect class="model-elem-0" x="4.285714285714285" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_a1" ></rect><rect class="model-elem-1" x="75.71428571428572" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_b1" ></rect><rect class="model-elem-0" x="147.14285714285714" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_c1" ></rect><rect class="model-elem-1" x="218.57142857142856" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_d1" ></rect><rect class="model-elem-0" x="290" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_e1" ></rect><rect class="model-elem-1" x="361.42857142857144" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_f1" ></rect><rect class="model-elem-0" x="432.85714285714283" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_g1" ></rect><rect class="model-elem-1" x="504.2857142857143" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_h1" ></rect><rect class="model-elem-1" x="4.285714285714285" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_a2" ></rect><rect class="model-elem-0" x="75.71428571428572" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_b2" ></rect><rect class="model-elem-1" x="147.14285714285714" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_c2" ></rect><rect class="model-elem-0" x="218.57142857142856" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_d2" ></rect><rect class="model-elem-1" x="290" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_e2" ></rect><rect class="model-elem-0" x="361.42857142857144" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_f2" ></rect><rect class="model-elem-1" x="432.85714285714283" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_g2" ></rect><rect class="model-elem-0" x="504.2857142857143" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_h2" ></rect><rect class="model-elem-0" x="4.285714285714285" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_a3" ></rect><rect class="model-elem-1" x="75.71428571428572" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_b3" ></rect><rect class="model-elem-0" x="147.14285714285714" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_c3" ></rect><rect class="model-elem-1" x="218.57142857142856" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_d3" ></rect><rect class="model-elem-0" x="290" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_e3" ></rect><rect class="model-elem-1" x="361.42857142857144" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_f3" ></rect><rect class="model-elem-0" x="432.85714285714283" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_g3" ></rect><rect class="model-elem-1" x="504.2857142857143" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_h3" ></rect><rect class="model-elem-1" x="4.285714285714285" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_a4" ></rect><rect class="model-elem-0" x="75.71428571428572" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_b4" ></rect><rect class="model-elem-1" x="147.14285714285714" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_c4" ></rect><rect class="model-elem-0" x="218.57142857142856" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_d4" ></rect><rect class="model-elem-1" x="290" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_e4" ></rect><rect class="model-elem-0" x="361.42857142857144" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_f4" ></rect><rect class="model-elem-1" x="432.85714285714283" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_g4" ></rect><rect class="model-elem-0" x="504.2857142857143" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_h4" ></rect><rect class="model-elem-0" x="4.285714285714285" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_a5" ></rect><rect class="model-elem-1" x="75.71428571428572" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_b5" ></rect><rect class="model-elem-0" x="147.14285714285714" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_c5" ></rect><rect class="model-elem-1" x="218.57142857142856" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_d5" ></rect><rect class="model-elem-0" x="290" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_e5" ></rect><rect class="model-elem-1" x="361.42857142857144" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_f5" ></rect><rect class="model-elem-0" x="432.85714285714283" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_g5" ></rect><rect class="model-elem-1" x="504.2857142857143" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_h5" ></rect><rect class="model-elem-1" x="4.285714285714285" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_a6" ></rect><rect class="model-elem-0" x="75.71428571428572" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_b6" ></rect><rect class="model-elem-1" x="147.14285714285714" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_c6" ></rect><rect class="model-elem-0" x="218.57142857142856" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_d6" ></rect><rect class="model-elem-1" x="290" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_e6" ></rect><rect class="model-elem-0" x="361.42857142857144" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_f6" ></rect><rect class="model-elem-1" x="432.85714285714283" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_g6" ></rect><rect class="model-elem-0" x="504.2857142857143" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_h6" ></rect><rect class="model-elem-0" x="4.285714285714285" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_a7" ></rect><rect class="model-elem-1" x="75.71428571428572" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_b7" ></rect><rect class="model-elem-0" x="147.14285714285714" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_c7" ></rect><rect class="model-elem-1" x="218.57142857142856" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_d7" ></rect><rect class="model-elem-0" x="290" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_e7" ></rect><rect class="model-elem-1" x="361.42857142857144" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_f7" ></rect><rect class="model-elem-0" x="432.85714285714283" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_g7" ></rect><rect class="model-elem-1" x="504.2857142857143" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_h7" ></rect><rect class="model-elem-1" x="4.285714285714285" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_a8" ></rect><rect class="model-elem-0" x="75.71428571428572" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_b8" ></rect><rect class="model-elem-1" x="147.14285714285714" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_c8" ></rect><rect class="model-elem-0" x="218.57142857142856" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_d8" ></rect><rect class="model-elem-1" x="290" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_e8" ></rect><rect class="model-elem-0" x="361.42857142857144" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_f8" ></rect><rect class="model-elem-1" x="432.85714285714283" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_g8" ></rect><rect class="model-elem-0" x="504.2857142857143" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_h8" ></rect><circle class="model-pred-W" cx="40" cy="540" r="23.714285714285715" id="pred_a1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="111.42857142857143" cy="540" r="23.714285714285715" id="pred_b1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="182.85714285714286" cy="540" r="23.714285714285715" id="pred_c1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="254.28571428571428" cy="540" r="23.714285714285715" id="pred_d1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="325.7142857142857" cy="540" r="23.714285714285715" id="pred_e1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="397.14285714285717" cy="540" r="23.714285714285715" id="pred_f1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="540" r="23.714285714285715" id="pred_g1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="540" r="23.714285714285715" id="pred_h1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="40" cy="468.57142857142856" r="23.714285714285715" id="pred_a2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="111.42857142857143" cy="468.57142857142856" r="23.714285714285715" id="pred_b2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="182.85714285714286" cy="468.57142857142856" r="23.714285714285715" id="pred_c2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="254.28571428571428" cy="468.57142857142856" r="23.714285714285715" id="pred_d2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="397.14285714285717" cy="468.57142857142856" r="23.714285714285715" id="pred_f2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="468.57142857142856" r="23.714285714285715" id="pred_g2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="468.57142857142856" r="23.714285714285715" id="pred_h2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="325.7142857142857" cy="397.14285714285717" r="23.714285714285715" id="pred_e3_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="40" cy="111.42857142857143" r="23.714285714285715" id="pred_a7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="111.42857142857143" cy="111.42857142857143" r="23.714285714285715" id="pred_b7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="182.85714285714286" cy="111.42857142857143" r="23.714285714285715" id="pred_c7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="254.28571428571428" cy="111.42857142857143" r="23.714285714285715" id="pred_d7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="111.42857142857143" r="23.714285714285715" id="pred_e7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="397.14285714285717" cy="111.42857142857143" r="23.714285714285715" id="pred_f7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="468.57142857142856" cy="111.42857142857143" r="23.714285714285715" id="pred_g7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="540" cy="111.42857142857143" r="23.714285714285715" id="pred_h7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="40" cy="40" r="23.714285714285715" id="pred_a8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="111.42857142857143" cy="40" r="23.714285714285715" id="pred_b8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="182.85714285714286" cy="40" r="23.714285714285715" id="pred_c8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="254.28571428571428" cy="40" r="23.714285714285715" id="pred_d8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="40" r="23.714285714285715" id="pred_e8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="397.14285714285717" cy="40" r="23.714285714285715" id="pred_f8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="468.57142857142856" cy="40" r="23.714285714285715" id="pred_g8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="540" cy="40" r="23.714285714285715" id="pred_h8_B" stroke-width="5.571428571428571" ></circle></svg> Added: trunk/Toss/Server/def_pics/Breakthrough02.svg =================================================================== --- trunk/Toss/Server/def_pics/Breakthrough02.svg (rev 0) +++ trunk/Toss/Server/def_pics/Breakthrough02.svg 2011-05-22 00:36:07 UTC (rev 1451) @@ -0,0 +1,3 @@ +<?xml-stylesheet href="Style.css" type="text/css"?> +<svg id="svg" viewBox="0 0 580 580"><rect class="model-elem-0" x="4.285714285714285" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_a1" ></rect><rect class="model-elem-1" x="75.71428571428572" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_b1" ></rect><rect class="model-elem-0" x="147.14285714285714" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_c1" ></rect><rect class="model-elem-1" x="218.57142857142856" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_d1" ></rect><rect class="model-elem-0" x="290" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_e1" ></rect><rect class="model-elem-1" x="361.42857142857144" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_f1" ></rect><rect class="model-elem-0" x="432.85714285714283" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_g1" ></rect><rect class="model-elem-1" x="504.2857142857143" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_h1" ></rect><rect class="model-elem-1" x="4.285714285714285" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_a2" ></rect><rect class="model-elem-0" x="75.71428571428572" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_b2" ></rect><rect class="model-elem-1" x="147.14285714285714" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_c2" ></rect><rect class="model-elem-0" x="218.57142857142856" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_d2" ></rect><rect class="model-elem-1" x="290" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_e2" ></rect><rect class="model-elem-0" x="361.42857142857144" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_f2" ></rect><rect class="model-elem-1" x="432.85714285714283" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_g2" ></rect><rect class="model-elem-0" x="504.2857142857143" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_h2" ></rect><rect class="model-elem-0" x="4.285714285714285" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_a3" ></rect><rect class="model-elem-1" x="75.71428571428572" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_b3" ></rect><rect class="model-elem-0" x="147.14285714285714" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_c3" ></rect><rect class="model-elem-1" x="218.57142857142856" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_d3" ></rect><rect class="model-elem-0" x="290" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_e3" ></rect><rect class="model-elem-1" x="361.42857142857144" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_f3" ></rect><rect class="model-elem-0" x="432.85714285714283" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_g3" ></rect><rect class="model-elem-1" x="504.2857142857143" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_h3" ></rect><rect class="model-elem-1" x="4.285714285714285" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_a4" ></rect><rect class="model-elem-0" x="75.71428571428572" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_b4" ></rect><rect class="model-elem-1" x="147.14285714285714" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_c4" ></rect><rect class="model-elem-0" x="218.57142857142856" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_d4" ></rect><rect class="model-elem-1" x="290" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_e4" ></rect><rect class="model-elem-0" x="361.42857142857144" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_f4" ></rect><rect class="model-elem-1" x="432.85714285714283" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_g4" ></rect><rect class="model-elem-0" x="504.2857142857143" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_h4" ></rect><rect class="model-elem-0" x="4.285714285714285" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_a5" ></rect><rect class="model-elem-1" x="75.71428571428572" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_b5" ></rect><rect class="model-elem-0" x="147.14285714285714" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_c5" ></rect><rect class="model-elem-1" x="218.57142857142856" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_d5" ></rect><rect class="model-elem-0" x="290" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_e5" ></rect><rect class="model-elem-1" x="361.42857142857144" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_f5" ></rect><rect class="model-elem-0" x="432.85714285714283" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_g5" ></rect><rect class="model-elem-1" x="504.2857142857143" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_h5" ></rect><rect class="model-elem-1" x="4.285714285714285" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_a6" ></rect><rect class="model-elem-0" x="75.71428571428572" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_b6" ></rect><rect class="model-elem-1" x="147.14285714285714" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_c6" ></rect><rect class="model-elem-0" x="218.57142857142856" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_d6" ></rect><rect class="model-elem-1" x="290" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_e6" ></rect><rect class="model-elem-0" x="361.42857142857144" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_f6" ></rect><rect class="model-elem-1" x="432.85714285714283" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_g6" ></rect><rect class="model-elem-0" x="504.2857142857143" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_h6" ></rect><rect class="model-elem-0" x="4.285714285714285" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_a7" ></rect><rect class="model-elem-1" x="75.71428571428572" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_b7" ></rect><rect class="model-elem-0" x="147.14285714285714" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_c7" ></rect><rect class="model-elem-1" x="218.57142857142856" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_d7" ></rect><rect class="model-elem-0" x="290" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_e7" ></rect><rect class="model-elem-1" x="361.42857142857144" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_f7" ></rect><rect class="model-elem-0" x="432.85714285714283" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_g7" ></rect><rect class="model-elem-1" x="504.2857142857143" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_h7" ></rect><rect class="model-elem-1" x="4.285714285714285" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_a8" ></rect><rect class="model-elem-0" x="75.71428571428572" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_b8" ></rect><rect class="model-elem-1" x="147.14285714285714" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_c8" ></rect><rect class="model-elem-0" x="218.57142857142856" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_d8" ></rect><rect class="model-elem-1" x="290" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_e8" ></rect><rect class="model-elem-0" x="361.42857142857144" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_f8" ></rect><rect class="model-elem-1" x="432.85714285714283" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_g8" ></rect><rect class="model-elem-0" x="504.2857142857143" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_h8" ></rect><circle class="model-pred-W" cx="40" cy="540" r="23.714285714285715" id="pred_a1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="111.42857142857143" cy="540" r="23.714285714285715" id="pred_b1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="182.85714285714286" cy="540" r="23.714285714285715" id="pred_c1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="254.28571428571428" cy="540" r="23.714285714285715" id="pred_d1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="325.7142857142857" cy="540" r="23.714285714285715" id="pred_e1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="397.14285714285717" cy="540" r="23.714285714285715" id="pred_f1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="540" r="23.714285714285715" id="pred_g1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="540" r="23.714285714285715" id="pred_h1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="40" cy="468.57142857142856" r="23.714285714285715" id="pred_a2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="111.42857142857143" cy="468.57142857142856" r="23.714285714285715" id="pred_b2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="182.85714285714286" cy="468.57142857142856" r="23.714285714285715" id="pred_c2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="254.28571428571428" cy="468.57142857142856" r="23.714285714285715" id="pred_d2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="397.14285714285717" cy="468.57142857142856" r="23.714285714285715" id="pred_f2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="468.57142857142856" r="23.714285714285715" id="pred_g2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="468.57142857142856" r="23.714285714285715" id="pred_h2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="325.7142857142857" cy="397.14285714285717" r="23.714285714285715" id="pred_e3_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="182.85714285714286" r="23.714285714285715" id="pred_e6_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="40" cy="111.42857142857143" r="23.714285714285715" id="pred_a7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="111.42857142857143" cy="111.42857142857143" r="23.714285714285715" id="pred_b7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="182.85714285714286" cy="111.42857142857143" r="23.714285714285715" id="pred_c7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="254.28571428571428" cy="111.42857142857143" r="23.714285714285715" id="pred_d7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="397.14285714285717" cy="111.42857142857143" r="23.714285714285715" id="pred_f7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="468.57142857142856" cy="111.42857142857143" r="23.714285714285715" id="pred_g7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="540" cy="111.42857142857143" r="23.714285714285715" id="pred_h7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="40" cy="40" r="23.714285714285715" id="pred_a8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="111.42857142857143" cy="40" r="23.714285714285715" id="pred_b8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="182.85714285714286" cy="40" r="23.714285714285715" id="pred_c8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="254.28571428571428" cy="40" r="23.714285714285715" id="pred_d8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="40" r="23.714285714285715" id="pred_e8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="397.14285714285717" cy="40" r="23.714285714285715" id="pred_f8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="468.57142857142856" cy="40" r="23.714285714285715" id="pred_g8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="540" cy="40" r="23.714285714285715" id="pred_h8_B" stroke-width="5.571428571428571" ></circle></svg> + Added: trunk/Toss/Server/def_pics/Breakthrough03.svg =================================================================== --- trunk/Toss/Server/def_pics/Breakthrough03.svg (rev 0) +++ trunk/Toss/Server/def_pics/Breakthrough03.svg 2011-05-22 00:36:07 UTC (rev 1451) @@ -0,0 +1,3 @@ +<?xml-stylesheet href="Style.css" type="text/css"?> +<svg id="svg" viewBox="0 0 580 580"><rect class="model-elem-0" x="4.285714285714285" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_a1" ></rect><rect class="model-elem-1" x="75.71428571428572" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_b1" ></rect><rect class="model-elem-0" x="147.14285714285714" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_c1" ></rect><rect class="model-elem-1" x="218.57142857142856" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_d1" ></rect><rect class="model-elem-0" x="290" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_e1" ></rect><rect class="model-elem-1" x="361.42857142857144" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_f1" ></rect><rect class="model-elem-0" x="432.85714285714283" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_g1" ></rect><rect class="model-elem-1" x="504.2857142857143" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_h1" ></rect><rect class="model-elem-1" x="4.285714285714285" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_a2" ></rect><rect class="model-elem-0" x="75.71428571428572" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_b2" ></rect><rect class="model-elem-1" x="147.14285714285714" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_c2" ></rect><rect class="model-elem-0" x="218.57142857142856" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_d2" ></rect><rect class="model-elem-1" x="290" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_e2" ></rect><rect class="model-elem-0" x="361.42857142857144" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_f2" ></rect><rect class="model-elem-1" x="432.85714285714283" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_g2" ></rect><rect class="model-elem-0" x="504.2857142857143" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_h2" ></rect><rect class="model-elem-0" x="4.285714285714285" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_a3" ></rect><rect class="model-elem-1" x="75.71428571428572" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_b3" ></rect><rect class="model-elem-0" x="147.14285714285714" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_c3" ></rect><rect class="model-elem-1" x="218.57142857142856" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_d3" ></rect><rect class="model-elem-0" x="290" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_e3" ></rect><rect class="model-elem-1" x="361.42857142857144" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_f3" ></rect><rect class="model-elem-0" x="432.85714285714283" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_g3" ></rect><rect class="model-elem-1" x="504.2857142857143" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_h3" ></rect><rect class="model-elem-1" x="4.285714285714285" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_a4" ></rect><rect class="model-elem-0" x="75.71428571428572" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_b4" ></rect><rect class="model-elem-1" x="147.14285714285714" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_c4" ></rect><rect class="model-elem-0" x="218.57142857142856" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_d4" ></rect><rect class="model-elem-1" x="290" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_e4" ></rect><rect class="model-elem-0" x="361.42857142857144" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_f4" ></rect><rect class="model-elem-1" x="432.85714285714283" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_g4" ></rect><rect class="model-elem-0" x="504.2857142857143" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_h4" ></rect><rect class="model-elem-0" x="4.285714285714285" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_a5" ></rect><rect class="model-elem-1" x="75.71428571428572" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_b5" ></rect><rect class="model-elem-0" x="147.14285714285714" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_c5" ></rect><rect class="model-elem-1" x="218.57142857142856" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_d5" ></rect><rect class="model-elem-0" x="290" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_e5" ></rect><rect class="model-elem-1" x="361.42857142857144" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_f5" ></rect><rect class="model-elem-0" x="432.85714285714283" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_g5" ></rect><rect class="model-elem-1" x="504.2857142857143" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_h5" ></rect><rect class="model-elem-1" x="4.285714285714285" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_a6" ></rect><rect class="model-elem-0" x="75.71428571428572" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_b6" ></rect><rect class="model-elem-1" x="147.14285714285714" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_c6" ></rect><rect class="model-elem-0" x="218.57142857142856" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_d6" ></rect><rect class="model-elem-1" x="290" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_e6" ></rect><rect class="model-elem-0" x="361.42857142857144" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_f6" ></rect><rect class="model-elem-1" x="432.85714285714283" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_g6" ></rect><rect class="model-elem-0" x="504.2857142857143" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_h6" ></rect><rect class="model-elem-0" x="4.285714285714285" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_a7" ></rect><rect class="model-elem-1" x="75.71428571428572" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_b7" ></rect><rect class="model-elem-0" x="147.14285714285714" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_c7" ></rect><rect class="model-elem-1" x="218.57142857142856" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_d7" ></rect><rect class="model-elem-0" x="290" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_e7" ></rect><rect class="model-elem-1" x="361.42857142857144" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_f7" ></rect><rect class="model-elem-0" x="432.85714285714283" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_g7" ></rect><rect class="model-elem-1" x="504.2857142857143" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_h7" ></rect><rect class="model-elem-1" x="4.285714285714285" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_a8" ></rect><rect class="model-elem-0" x="75.71428571428572" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_b8" ></rect><rect class="model-elem-1" x="147.14285714285714" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_c8" ></rect><rect class="model-elem-0" x="218.57142857142856" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_d8" ></rect><rect class="model-elem-1" x="290" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_e8" ></rect><rect class="model-elem-0" x="361.42857142857144" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_f8" ></rect><rect class="model-elem-1" x="432.85714285714283" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_g8" ></rect><rect class="model-elem-0" x="504.2857142857143" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_h8" ></rect><circle class="model-pred-W" cx="40" cy="540" r="23.714285714285715" id="pred_a1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="111.42857142857143" cy="540" r="23.714285714285715" id="pred_b1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="182.85714285714286" cy="540" r="23.714285714285715" id="pred_c1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="254.28571428571428" cy="540" r="23.714285714285715" id="pred_d1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="325.7142857142857" cy="540" r="23.714285714285715" id="pred_e1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="397.14285714285717" cy="540" r="23.714285714285715" id="pred_f1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="540" r="23.714285714285715" id="pred_g1_W" stroke-width="5.571428571428571" ></circle><cir... [truncated message content] |
From: <luk...@us...> - 2011-05-23 01:33:05
|
Revision: 1455 http://toss.svn.sourceforge.net/toss/?rev=1455&view=rev Author: lukaszkaiser Date: 2011-05-23 01:32:57 +0000 (Mon, 23 May 2011) Log Message: ----------- Generating Breakthrough from pictures, without winning condition for now. Modified Paths: -------------- trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Formula/FormulaOps.mli trunk/Toss/Formula/FormulaOpsTest.ml trunk/Toss/Server/Picture.ml trunk/Toss/Server/Picture.mli trunk/Toss/Server/def_pics/Makefile trunk/Toss/Solver/Structure.ml trunk/Toss/Solver/Structure.mli Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2011-05-22 14:52:01 UTC (rev 1454) +++ trunk/Toss/Formula/FormulaOps.ml 2011-05-23 01:32:57 UTC (rev 1455) @@ -615,6 +615,47 @@ fp_n real_str (List.length defs) (subst_once_rels_expr defs) r +(* --- AType with variables over given relations, no repetition, equality --- *) + +let atp rels vars_in = + if vars_in = [] then [] else + let vars = List.rev_map fo_var_of_string vars_in in + let rec rept i l = if i < 1 then [] else l :: (rept (i-1) l) in + let prod i = + if i < 1 then [] else if i = 1 then + List.map (fun v -> [|v|]) vars + else let arr l = + if List.length (Aux.unique_sorted l) = i then + Some (Array.of_list l) + else None in + Aux.map_some arr (Aux.product (rept i vars)) in + let atom (rel, i) = List.rev_map (fun vs -> Rel (rel, vs)) (prod i) in + let atoms = Array.of_list (List.concat (List.map atom rels)) in + let choices = Aux.product (rept (Array.length atoms) [true; false]) in + let atom_choice i c = if c then atoms.(i) else Not (atoms.(i)) in + let tp_of_choice l = And (Array.to_list (Array.mapi atom_choice l)) in + List.rev_map tp_of_choice (List.rev_map Array.of_list choices) + +let mintp f rels vars = + let (add_vars, cur_tp) = (ref [], ref (List.filter f (atp rels vars))) in + let rec rept i l = if i < 1 then [] else l :: (rept (i-1) l) in + let mk_tp () = + if !debug_level > 0 then Format.printf "Making new tp.\n%!"; + let atoms = atp rels (vars @ !add_vars) in + if !debug_level > 0 then Format.printf "Atomic %i\n%!" (List.length atoms); + let add_vars_v = List.map (fun v -> var_of_string v) !add_vars in + let qex = Aux.product (rept (List.length !add_vars) [false; true]) in + let qphi phi v b = if b then Ex ([v], phi) else All ([v], phi) in + let quant c phi = List.fold_left2 qphi phi add_vars_v c in + let qatoms c = List.filter f (List.rev_map (quant c) atoms) in + List.fold_left (fun l c -> if l = [] then qatoms c else l) [] qex in + let new_var () = snd (subst_name_avoiding_str (vars @ !add_vars) "x0") in + while !cur_tp = [] do + add_vars := new_var () :: !add_vars; cur_tp := mk_tp () + done; + !cur_tp + + (* ------------------------------------------------------------------------- *) (* Prenex normal form. *) (* ------------------------------------------------------------------------- *) Modified: trunk/Toss/Formula/FormulaOps.mli =================================================================== --- trunk/Toss/Formula/FormulaOps.mli 2011-05-22 14:52:01 UTC (rev 1454) +++ trunk/Toss/Formula/FormulaOps.mli 2011-05-23 01:32:57 UTC (rev 1455) @@ -134,7 +134,14 @@ (** Assign emptyset to an MSO-variable. *) val assign_emptyset : string -> formula -> formula +(** AType with variables over given relations, no repetition, equality. *) +val atp : (string * int) list -> string list -> formula list +(** Minimal type satisfying f over rels extending vars. *) +val mintp : (formula -> bool) -> (string * int) list -> string list -> + formula list + + (** {2 Transitive Closure} *) Modified: trunk/Toss/Formula/FormulaOpsTest.ml =================================================================== --- trunk/Toss/Formula/FormulaOpsTest.ml 2011-05-22 14:52:01 UTC (rev 1454) +++ trunk/Toss/Formula/FormulaOpsTest.ml 2011-05-23 01:32:57 UTC (rev 1455) @@ -319,6 +319,30 @@ "R (y, x)" "S(y, x) and ex x0 (S(x, x0))"; ); + "atp, mintp" >:: + (fun () -> + let report phis = + (* List.iter (fun f -> Format.printf "\n%!"; Formula.print f) phis; *) + phis in + + let phis = report (FormulaOps.atp [("R", 2); ("P", 1)] []) in + assert_equal ~printer:string_of_int 0 (List.length phis); + + let phis = report (FormulaOps.atp [("R", 2); ("P", 1)] ["x"]) in + assert_equal ~printer:string_of_int 2 (List.length phis); + + let phis = report (FormulaOps.atp [("R", 2); ("P", 1)] ["x"; "y"]) in + assert_equal ~printer:string_of_int 16 (List.length phis); + + let nv n phi = List.length (FormulaOps.all_vars phi) = n in + + let phis = report (FormulaOps.mintp (nv 1) [("R", 2); ("P", 1)] []) in + assert_equal ~printer:string_of_int 2 (List.length phis); + + let phis = report (FormulaOps.mintp (nv 2) [("R", 2); ("P", 1)] []) in + assert_equal ~printer:string_of_int 16 (List.length phis); + ); + "transitive closure creation" >:: (fun () -> let tc_eq x y phi1 phi2 = Modified: trunk/Toss/Server/Picture.ml =================================================================== --- trunk/Toss/Server/Picture.ml 2011-05-22 14:52:01 UTC (rev 1454) +++ trunk/Toss/Server/Picture.ml 2011-05-23 01:32:57 UTC (rev 1455) @@ -234,8 +234,76 @@ (s, !maxdx, !maxdy) + +(* Minimal types differentiating two structures. *) +let difftp rels s1 s2 = + let ok phi = Solver.M.check s1 phi && not (Solver.M.check s2 phi) in + FormulaOps.mintp ok rels [] + +(* Minimal type of elements in a structure which is part-positive. *) +let postp s rels els = + let app_rel_phi (st, fos, vs, i) e = + let r, v = "Elem" ^ (string_of_int i), Structure.elem_name st e in + (Structure.add_rel st r [|e|], + Formula.Rel (r, [|Formula.fo_var_of_string v|]) :: fos, v :: vs, i+1) in + let (struc, els_phis, vars, _) = List.fold_left app_rel_phi (s,[],[],0) els in + let neg_true = function Formula.Not _ -> Formula.And [] | x -> x in + let pos phi = + Formula.flatten (FormulaOps.map_to_literals neg_true (fun x->x) phi) in + let pos_ok phi = let psi = pos phi in if psi = Formula.And [] then false else + Solver.M.check struc (Formula.And (psi :: els_phis)) in + let ts = List.map pos (FormulaOps.mintp pos_ok rels vars) in + let tfvs = List.map (fun f -> (f,List.length (FormulaOps.free_vars f))) ts in + let maxfv = List.fold_left (fun m (_, x) -> max m x) 0 tfvs in + List.map fst (List.filter (fun (f, x) -> x = maxfv) tfvs) + +let tp_rule drels (left, right, delems) = + let not_drel (r,_) = not (List.mem r drels) in + let crels = List.filter not_drel (Structure.rel_signature left) in + if !debug_level > 0 then Printf.printf "CRels %i\n%!" (List.length crels); + let tp = postp left crels delems in + if !debug_level > 0 then + Format.printf "@[%a@]@ \n%!" Formula.fprint (Formula.And tp); + let cut s = List.fold_left Structure.del_elem s + (List.filter (fun e -> not (List.mem e delems)) (Structure.elements s)) in + (cut left, cut right, tp) + +let geom_rule drels (left, right, delems) = + let get_dim s e = (Structure.fun_val s "x" e, Structure.fun_val s "y" e) in + let rect s els = + let upd_rect (x1, y1, x2, y2) e = + let (x, y) = get_dim s e in (min x1 x, min y1 y, max x2 x, max y2 y) in + let (x, y) = get_dim s (List.hd els) in + List.fold_left upd_rect (x, y, x, y) (List.tl els) in + let in_rect s (x1, y1, x2, y2) e = + let (x, y) = get_dim s e in (x1 < x && x < x2 && y1 < y && y < y2) in + let (x1, y1, x2, y2) = rect left delems in + let r = (x1 -. 0.5, y1 -. 0.5, x2 +. 0.5, y2 +. 0.5) in + let els = List.filter (in_rect left r) (Structure.elements left) in + let new_els = List.filter (fun e -> not (List.mem e delems)) els in + if !debug_level > 0 then + Format.printf "%s\n%!" (String.concat ", " (List.map string_of_int els)); + let cut s = List.fold_left Structure.del_elem s + (List.filter (fun e -> not (List.mem e els)) (Structure.elements s)) in + let is_unary r = List.assoc r (Structure.rel_signature left) = 1 in + let un_drels = Aux.unique_sorted (List.filter is_unary drels) in + let un_opt_drels = List.map (fun r -> "_opt_" ^ r) un_drels in + let addopt s r = Structure.add_rels s r (List.map (fun e -> [|e|]) new_els) in + let addopts s = List.fold_left addopt s un_opt_drels in + let delopt s r = Structure.del_rels s r (List.map (fun e -> [|e|]) new_els) in + let delopts s = List.fold_left delopt s un_drels in + (addopts (delopts (cut left)), addopts (delopts (cut right)), []) + +let print_rule emb (name, (l, r, pre_l)) = + let emb_s = String.concat ", " (Aux.unique_sorted emb) in + let pre_s = Formula.sprint (Formula.And pre_l) in + let sprints () s = Structure.sprint s in + Format.sprintf "RULE %s:@ @[<2>%a@]@ ->@ @[<2>%a@]@ emb %s pre %s" + name sprints l sprints r emb_s pre_s + + (* Make a game from sequence of pictures. *) -let make_game ?(rels=[]) ?(offset=2) ?(threshold=70.) fname = +let make_game ?(rels=[]) ?(offset=2) ?(threshold=70.) ?(geom=true) fname = let formula_of_string s = FormulaParser.parse_formula Lexer.lex (Lexing.from_string s) in let get_struc fn = @@ -260,6 +328,41 @@ while Sys.file_exists (name ~suffix:"Win" !i) do win_strucs := get_struc (name ~suffix:"Win" !i) :: !win_strucs; incr i done; - (List.rev !seq_strucs, List.rev !win_strucs) in + (List.rev !seq_strucs, Array.of_list (List.rev !win_strucs)) in let (seq, wins) = read_strucs () in - Printf.sprintf "Read %i seq, %i win." (List.length seq) (List.length wins) + if seq = [] then failwith "Empty picture sequence for game play."; + let diff_struc (s, drels, prev) cur = + let dels, drels_l = List.split (Structure.diff_elems prev cur) in + ((prev, cur, dels) :: s, (List.concat drels_l) @ drels, cur) in + if !debug_level > 0 then Printf.printf "Diffstruc computed.\n%!"; + let (s, dr,_) = List.fold_left diff_struc ([],[],List.hd seq) (List.tl seq) in + let rules = if geom then List.rev_map (geom_rule dr) s else + List.rev_map (tp_rule dr) s in + let wi i = + formula_of_string (if i mod 2 = 0 then "not Win2()" else "not Win1()") in + let add_win i (l, r, pre) = (Printf.sprintf "Mv%i" i, (l, r, (wi i)::pre)) in + let wrs = Array.mapi (fun i r -> add_win i r) (Array.of_list rules) in + let emb = List.map fst (Structure.rel_signature (List.hd seq)) @ dr in + let rs = String.concat "\n" (List.map (print_rule emb) (Array.to_list wrs)) in + let allms = Array.to_list (Array.mapi (fun i _ -> i) (Array.of_list rules)) in + let (mvi1, mvi2) = List.partition (fun i -> i mod 2 = 0) allms in + let make_mv loc i = Printf.sprintf "[Mv%i -> %s]" i loc in + let mvs1 = String.concat "; " (List.map (make_mv "1") mvi1) in + let mvs2 = String.concat "; " (List.map (make_mv "0") mvi2) in + let pay1 = "PAYOFF :(Win1()) - :(Win2())" in + let pay2 = "PAYOFF :(Win2()) - :(Win1())" in + let loc0 = Printf.sprintf "LOC 0 {\n PLAYER 1 { %s }\n PLAYER 2 { %s }\n}" + (pay1 ^ "\n MOVES " ^ mvs1 ^ "\n") pay2 in + let loc1 = Printf.sprintf "LOC 1 {\n PLAYER 1 { %s }\n PLAYER 2 { %s }\n}" + pay1 (pay2 ^ "\n MOVES " ^ mvs2 ^ "\n") in + let model_s = Structure.sprint (List.hd seq) in + (* Printf.printf "DiffTp\n%!"; + FormulaOps.set_debug_level 1; + let w = difftp (Structure.rel_signature wins.(0)) wins.(0) wins.(1) in + if !debug_level > -1 then + Format.printf "@[%a@]@ \n%!" Formula.fprint (Formula.And w); + FormulaOps.set_debug_level 0; *) + let (win0, win1) = (Formula.Or [], Formula.Or []) in + let beg = Printf.sprintf "PLAYERS 1, 2\nREL Win0() = %s\nREL Win1() = %s" + (Formula.sprint win0) (Formula.sprint win1) in + Printf.sprintf "%s\n%s\n%s\n%s\nMODEL \n%s\n" beg rs loc0 loc1 model_s Modified: trunk/Toss/Server/Picture.mli =================================================================== --- trunk/Toss/Server/Picture.mli 2011-05-22 14:52:01 UTC (rev 1454) +++ trunk/Toss/Server/Picture.mli 2011-05-23 01:32:57 UTC (rev 1455) @@ -51,4 +51,4 @@ (** Create a game from sequence of images. *) val make_game : ?rels : (string * string list * Formula.formula) list -> - ?offset : int -> ?threshold : float -> string -> string + ?offset : int -> ?threshold : float -> ?geom : bool -> string -> string Modified: trunk/Toss/Server/def_pics/Makefile =================================================================== --- trunk/Toss/Server/def_pics/Makefile 2011-05-22 14:52:01 UTC (rev 1454) +++ trunk/Toss/Server/def_pics/Makefile 2011-05-23 01:32:57 UTC (rev 1455) @@ -14,7 +14,8 @@ Breakthrough06.ppm Breakthrough07.ppm Breakthrough08.ppm \ Breakthrough09.ppm Breakthrough10.ppm Breakthrough11.ppm \ Breakthrough12.ppm BreakthroughWin00.ppm BreakthroughWin01.ppm - ../../PictureTest.native -g Breakthrough > Breakthrough.toss + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../../PictureTest.native \ + -g Breakthrough | sed "s/P1/W/g" | sed "s/P2/B/g" > Breakthrough.toss clean: rm -rf *.ppm *.png *.toss *~ Modified: trunk/Toss/Solver/Structure.ml =================================================================== --- trunk/Toss/Solver/Structure.ml 2011-05-22 14:52:01 UTC (rev 1454) +++ trunk/Toss/Solver/Structure.ml 2011-05-23 01:32:57 UTC (rev 1455) @@ -54,7 +54,11 @@ let equal s1 s2 = (compare s1 s2 = 0) +let elements s = Elems.elements s.elements +let elem_nbr s el = StringMap.find el s.names +let elem_name s e = IntMap.find e s.inv_names + (* ----------------------- BASIC HELPER FUNCTIONS --------------------------- *) (* Number of tuples in a relation. *) @@ -342,19 +346,19 @@ (* ---------- REMOVING RELATION TUPLES AND ELEMENTS FROM A STRUCTURE -------- *) -(* Remove the tuple [tp] from relation [rn] in structure [struc]. May - raise [Not_found] if the tuple is not in the relation. *) +(* Remove the tuple [tp] from relation [rn] in structure [struc]. *) let del_rel struc rn tp = let del_rmap rmap = - StringMap.add rn (Tuples.remove tp (StringMap.find rn rmap)) rmap in + try StringMap.add rn (Tuples.remove tp (StringMap.find rn rmap)) rmap + with Not_found -> rmap in let new_rel = del_rmap struc.relations in let del_imap imap e = - IntMap.add e (Tuples.remove tp (IntMap.find e imap)) imap in + try IntMap.add e (Tuples.remove tp (IntMap.find e imap)) imap + with Not_found -> imap in let new_incidence = - let imap = - Array.fold_left del_imap (StringMap.find rn struc.incidence) tp in - StringMap.add rn imap struc.incidence in - { struc with relations = new_rel ; incidence = new_incidence } + let imap=Array.fold_left del_imap (StringMap.find rn struc.incidence) tp in + StringMap.add rn imap struc.incidence in + { struc with relations = new_rel ; incidence = new_incidence } (* Remove the tuples [tps] from relation [rn] in structure [struc]. *) let del_rels struc rn tps = @@ -1136,6 +1140,16 @@ true, "equal" with Diff_result expl -> false, expl +let diff_elems s1 s2 = + let rels, _ = List.split (rel_signature s1) in + let elems = Elems.elements s1.elements in + let inc s r e = try IntMap.find e (StringMap.find r s.incidence) with + Not_found -> Tuples.empty in + let diff_elem_rel e r = not (Tuples.equal (inc s1 r e) (inc s2 r e)) in + let diff_rels e = (e, List.filter (diff_elem_rel e) rels) in + List.filter (fun (_, rs) -> rs <> []) (List.rev_map diff_rels elems) + + (* -------------------- PARSER HELPERS -------------------- *) let is_uppercase c = c >= 'A' && c <= 'Z' Modified: trunk/Toss/Solver/Structure.mli =================================================================== --- trunk/Toss/Solver/Structure.mli 2011-05-22 14:52:01 UTC (rev 1454) +++ trunk/Toss/Solver/Structure.mli 2011-05-23 01:32:57 UTC (rev 1455) @@ -31,7 +31,11 @@ val compare : structure -> structure -> int val equal : structure -> structure -> bool +val elements : structure -> int list +val elem_nbr : structure -> string -> int +val elem_name : structure -> int -> string + (** {2 Basic helper functions} *) (** Size of a relation, i.e. number of tuples in it. *) @@ -126,6 +130,9 @@ ?cmp_funs:(float -> float -> bool) -> structure -> structure -> bool * string +(** Elements from s1 which differ in s2, with differing relation names. *) +val diff_elems : structure -> structure -> (int * string list) list + (** {2 Adding elements possibly with string names} *) @@ -197,18 +204,14 @@ (** {2 Removing relation tuples and elements from a structure} *) -(** Remove the tuple [tp] from relation [rn] in structure [struc]. May - raise [Not_found] if the tuple is not in the relation (but is not - guaranteed to). *) +(** Remove the tuple [tp] from relation [rn] in structure [struc]. *) val del_rel : structure -> string -> int array -> structure -(** Remove the tuples [tps] from relation [rn] in structure [struc]. May - raise [Not_found] if some tuple is not in the relation (but is not - guaranteed to). *) +(** Remove the tuples [tps] from relation [rn] in structure [struc]. *) val del_rels : structure -> string -> int array list -> structure -(** Remove all relations matching the predicate. By default, also remove - them from the signature. *) +(** Remove all relations matching the predicate. + By default, also remove them from the signature. *) val clear_rels : ?remove_from_sig:bool -> structure -> (string -> bool) -> structure This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-23 12:02:35
|
Revision: 1456 http://toss.svn.sourceforge.net/toss/?rev=1456&view=rev Author: lukstafi Date: 2011-05-23 12:02:27 +0000 (Mon, 23 May 2011) Log Message: ----------- Reference specification of GDL translation: {Concurrent Moves and Toss Locations} complete draft, work in progress. Modified Paths: -------------- trunk/Toss/www/reference/reference.tex Added Paths: ----------- trunk/Toss/GGP/examples/pacman3p.gdl Added: trunk/Toss/GGP/examples/pacman3p.gdl =================================================================== --- trunk/Toss/GGP/examples/pacman3p.gdl (rev 0) +++ trunk/Toss/GGP/examples/pacman3p.gdl 2011-05-23 12:02:27 UTC (rev 1456) @@ -0,0 +1,456 @@ +; pacman3p +(role pacman) +(role blinky) +(role inky) +(init (control pacman)) +(init (location pacman 5 3)) +(init (location blinky 4 6)) +(init (location inky 5 6)) +(init (location pellet 3 1)) +(init (location pellet 4 1)) +(init (location pellet 5 1)) +(init (location pellet 6 1)) +(init (location pellet 3 2)) +(init (location pellet 6 2)) +(init (location pellet 1 3)) +(init (location pellet 2 3)) +(init (location pellet 3 3)) +(init (location pellet 4 3)) +(init (location pellet 6 3)) +(init (location pellet 7 3)) +(init (location pellet 8 3)) +(init (location pellet 1 4)) +(init (location pellet 3 4)) +(init (location pellet 6 4)) +(init (location pellet 8 4)) +(init (location pellet 1 5)) +(init (location pellet 3 5)) +(init (location pellet 6 5)) +(init (location pellet 8 5)) +(init (location pellet 1 6)) +(init (location pellet 2 6)) +(init (location pellet 3 6)) +(init (location pellet 6 6)) +(init (location pellet 7 6)) +(init (location pellet 8 6)) +(init (location pellet 3 7)) +(init (location pellet 6 7)) +(init (location pellet 3 8)) +(init (location pellet 4 8)) +(init (location pellet 5 8)) +(init (location pellet 6 8)) +(init (blockednorth 4 1)) +(init (blockednorth 5 1)) +(init (blockednorth 1 2)) +(init (blockednorth 2 2)) +(init (blockednorth 4 2)) +(init (blockednorth 5 2)) +(init (blockednorth 7 2)) +(init (blockednorth 8 2)) +(init (blockednorth 2 3)) +(init (blockednorth 4 3)) +(init (blockednorth 5 3)) +(init (blockednorth 7 3)) +(init (blockednorth 2 5)) +(init (blockednorth 4 5)) +(init (blockednorth 5 5)) +(init (blockednorth 7 5)) +(init (blockednorth 1 6)) +(init (blockednorth 2 6)) +(init (blockednorth 4 6)) +(init (blockednorth 5 6)) +(init (blockednorth 7 6)) +(init (blockednorth 8 6)) +(init (blockednorth 4 7)) +(init (blockednorth 5 7)) +(init (blockedeast 1 4)) +(init (blockedeast 1 5)) +(init (blockedeast 2 1)) +(init (blockedeast 2 2)) +(init (blockedeast 2 4)) +(init (blockedeast 2 5)) +(init (blockedeast 2 7)) +(init (blockedeast 2 8)) +(init (blockedeast 3 2)) +(init (blockedeast 3 4)) +(init (blockedeast 3 5)) +(init (blockedeast 3 7)) +(init (blockedeast 5 2)) +(init (blockedeast 5 4)) +(init (blockedeast 5 5)) +(init (blockedeast 5 7)) +(init (blockedeast 6 1)) +(init (blockedeast 6 2)) +(init (blockedeast 6 4)) +(init (blockedeast 6 5)) +(init (blockedeast 6 7)) +(init (blockedeast 6 8)) +(init (blockedeast 7 4)) +(init (blockedeast 7 5)) +(init (collected 0)) +(init (step 1)) +(<= (legal pacman (move ?dir)) + (true (control pacman)) + (true (location pacman ?x ?y)) + (legalstep ?dir ?x ?y) + (distinct ?dir nowhere)) +(<= (legal pacman (move nowhere)) + (not (true (control pacman)))) +(<= (legal ?ghost (move ?dir)) + (ghost ?ghost) + (true (control ghosts)) + (true (location ?ghost ?x ?y)) + (legalstep ?dir ?x ?y) + (distinct ?dir nowhere)) +(<= (legal ?ghost (move nowhere)) + (ghost ?ghost) + (not (true (control ghosts)))) +(<= (next (control pacman)) + (true (control ghosts))) +(<= (next (control ghosts)) + (true (control pacman))) +(<= (next (location pellet ?xp ?yp)) + (true (location pellet ?xp ?yp)) + (true (location pacman ?xpm1 ?ypm1)) + (does pacman (move ?dir)) + (nextcell ?dir ?xpm1 ?ypm1 ?xpm2 ?ypm2) + (distinctcell ?xp ?yp ?xpm2 ?ypm2)) +(<= (next (collected ?n++)) + (true (location pacman ?x1 ?y1)) + (does pacman (move ?dir)) + (nextcell ?dir ?x1 ?y1 ?x2 ?y2) + (true (location pellet ?x2 ?y2)) + (true (collected ?n)) + (succ ?n ?n++)) +(<= (next (collected ?n)) + (true (location pacman ?x1 ?y1)) + (does pacman (move ?dir)) + (nextcell ?dir ?x1 ?y1 ?x2 ?y2) + (not (true (location pellet ?x2 ?y2))) + (true (collected ?n))) +(<= (next (blockednorth ?x ?y)) + (true (blockednorth ?x ?y))) +(<= (next (blockedeast ?x ?y)) + (true (blockedeast ?x ?y))) +(<= (next (location ?char ?x2 ?y2)) + (movable ?char) + (true (location ?char ?x1 ?y1)) + (does ?char (move ?dir)) + (nextcell ?dir ?x1 ?y1 ?x2 ?y2)) +(<= (next (step ?n++)) + (true (step ?n)) + (succ ?n ?n++)) +(<= terminal + captured) +(<= terminal + nopellets) +(<= terminal + timeout) +(<= (goal pacman ?g) + (true (collected ?n)) + (scoremap ?n ?g)) +(<= (goal blinky 0) + (true (location pacman ?xp ?yp)) + (true (location blinky ?xb ?yb)) + (distinctcell ?xp ?yp ?xb ?yb)) +(<= (goal blinky 100) + (true (location pacman ?x ?y)) + (true (location blinky ?x ?y))) +(<= (goal inky 0) + (true (location pacman ?xp ?yp)) + (true (location inky ?xi ?yi)) + (distinctcell ?xp ?yp ?xi ?yi)) +(<= (goal inky 100) + (true (location pacman ?x ?y)) + (true (location inky ?x ?y))) +(<= (legalstep north ?x ?y) + (++ ?y ?ynew) + (cell ?x ?ynew) + (not (blocked ?x ?y ?x ?ynew))) +(<= (legalstep south ?x ?y) + (-- ?y ?ynew) + (cell ?x ?ynew) + (not (blocked ?x ?y ?x ?ynew))) +(<= (legalstep east ?x ?y) + (++ ?x ?xnew) + (cell ?xnew ?y) + (not (blocked ?x ?y ?xnew ?y))) +(<= (legalstep west ?x ?y) + (-- ?x ?xnew) + (cell ?xnew ?y) + (not (blocked ?x ?y ?xnew ?y))) +(<= (legalstep nowhere ?x ?y) + (cell ?x ?y)) +(<= (nextcell north ?x ?y ?x ?ynew) + (index ?x) + (++ ?y ?ynew)) +(<= (nextcell south ?x ?y ?x ?ynew) + (index ?x) + (-- ?y ?ynew)) +(<= (nextcell east ?x ?y ?xnew ?y) + (index ?y) + (++ ?x ?xnew)) +(<= (nextcell west ?x ?y ?xnew ?y) + (index ?y) + (-- ?x ?xnew)) +(<= (nextcell nowhere ?x ?y ?x ?y) + (cell ?x ?y)) +(<= (blocked ?x ?y1 ?x ?y2) + (true (blockednorth ?x ?y1)) + (++ ?y1 ?y2)) +(<= (blocked ?x ?y2 ?x ?y1) + (true (blockednorth ?x ?y1)) + (++ ?y1 ?y2)) +(<= (blocked ?x1 ?y ?x2 ?y) + (true (blockedeast ?x1 ?y)) + (++ ?x1 ?x2)) +(<= (blocked ?x2 ?y ?x1 ?y) + (true (blockedeast ?x1 ?y)) + (++ ?x1 ?x2)) +(<= (distinctcell ?x1 ?y1 ?x2 ?y2) + (cell ?x1 ?y1) + (cell ?x2 ?y2) + (distinct ?x1 ?x2)) +(<= (distinctcell ?x1 ?y1 ?x2 ?y2) + (cell ?x1 ?y1) + (cell ?x2 ?y2) + (distinct ?y1 ?y2)) +(<= captured + (true (location pacman ?x ?y)) + (true (location blinky ?x ?y))) +(<= captured + (true (location pacman ?x ?y)) + (true (location inky ?x ?y))) +(<= nopellets + (true (collected 35))) +(<= timeout + (true (step 100))) +(movable pacman) +(movable blinky) +(movable inky) +(ghost blinky) +(ghost inky) +(index 1) +(index 2) +(index 3) +(index 4) +(index 5) +(index 6) +(index 7) +(index 8) +(cell 1 8) +(cell 2 8) +(cell 3 8) +(cell 4 8) +(cell 5 8) +(cell 6 8) +(cell 7 8) +(cell 8 8) +(cell 1 7) +(cell 2 7) +(cell 3 7) +(cell 4 7) +(cell 5 7) +(cell 6 7) +(cell 7 7) +(cell 8 7) +(cell 1 6) +(cell 2 6) +(cell 3 6) +(cell 4 6) +(cell 5 6) +(cell 6 6) +(cell 7 6) +(cell 8 6) +(cell 1 5) +(cell 2 5) +(cell 3 5) +(cell 4 5) +(cell 5 5) +(cell 6 5) +(cell 7 5) +(cell 8 5) +(cell 1 4) +(cell 2 4) +(cell 3 4) +(cell 4 4) +(cell 5 4) +(cell 6 4) +(cell 7 4) +(cell 8 4) +(cell 1 3) +(cell 2 3) +(cell 3 3) +(cell 4 3) +(cell 5 3) +(cell 6 3) +(cell 7 3) +(cell 8 3) +(cell 1 2) +(cell 2 2) +(cell 3 2) +(cell 4 2) +(cell 5 2) +(cell 6 2) +(cell 7 2) +(cell 8 2) +(cell 1 1) +(cell 2 1) +(cell 3 1) +(cell 4 1) +(cell 5 1) +(cell 6 1) +(cell 7 1) +(cell 8 1) +(++ 1 2) +(++ 2 3) +(++ 3 4) +(++ 4 5) +(++ 5 6) +(++ 6 7) +(++ 7 8) +(-- 8 7) +(-- 7 6) +(-- 6 5) +(-- 5 4) +(-- 4 3) +(-- 3 2) +(-- 2 1) +(succ 0 1) +(succ 1 2) +(succ 2 3) +(succ 3 4) +(succ 4 5) +(succ 5 6) +(succ 6 7) +(succ 7 8) +(succ 8 9) +(succ 9 10) +(succ 10 11) +(succ 11 12) +(succ 12 13) +(succ 13 14) +(succ 14 15) +(succ 15 16) +(succ 16 17) +(succ 17 18) +(succ 18 19) +(succ 19 20) +(succ 20 21) +(succ 21 22) +(succ 22 23) +(succ 23 24) +(succ 24 25) +(succ 25 26) +(succ 26 27) +(succ 27 28) +(succ 28 29) +(succ 29 30) +(succ 30 31) +(succ 31 32) +(succ 32 33) +(succ 33 34) +(succ 34 35) +(succ 35 36) +(succ 36 37) +(succ 37 38) +(succ 38 39) +(succ 39 40) +(succ 40 41) +(succ 41 42) +(succ 42 43) +(succ 43 44) +(succ 44 45) +(succ 45 46) +(succ 46 47) +(succ 47 48) +(succ 48 49) +(succ 49 50) +(succ 50 51) +(succ 51 52) +(succ 52 53) +(succ 53 54) +(succ 54 55) +(succ 55 56) +(succ 56 57) +(succ 57 58) +(succ 58 59) +(succ 59 60) +(succ 60 61) +(succ 61 62) +(succ 62 63) +(succ 63 64) +(succ 64 65) +(succ 65 66) +(succ 66 67) +(succ 67 68) +(succ 68 69) +(succ 69 70) +(succ 70 71) +(succ 71 72) +(succ 72 73) +(succ 73 74) +(succ 74 75) +(succ 75 76) +(succ 76 77) +(succ 77 78) +(succ 78 79) +(succ 79 80) +(succ 80 81) +(succ 81 82) +(succ 82 83) +(succ 83 84) +(succ 84 85) +(succ 85 86) +(succ 86 87) +(succ 87 88) +(succ 88 89) +(succ 89 90) +(succ 90 91) +(succ 91 92) +(succ 92 93) +(succ 93 94) +(succ 94 95) +(succ 95 96) +(succ 96 97) +(succ 97 98) +(succ 98 99) +(succ 99 100) +(scoremap 0 0) +(scoremap 1 2) +(scoremap 2 4) +(scoremap 3 6) +(scoremap 4 8) +(scoremap 5 10) +(scoremap 6 12) +(scoremap 7 14) +(scoremap 8 16) +(scoremap 9 18) +(scoremap 10 20) +(scoremap 11 23) +(scoremap 12 26) +(scoremap 13 29) +(scoremap 14 32) +(scoremap 15 35) +(scoremap 16 38) +(scoremap 17 41) +(scoremap 18 44) +(scoremap 19 47) +(scoremap 20 50) +(scoremap 21 53) +(scoremap 22 56) +(scoremap 23 59) +(scoremap 24 62) +(scoremap 25 65) +(scoremap 26 68) +(scoremap 27 71) +(scoremap 28 74) +(scoremap 29 77) +(scoremap 30 80) +(scoremap 31 83) +(scoremap 32 86) +(scoremap 33 89) +(scoremap 34 95) +(scoremap 35 100) + + Modified: trunk/Toss/www/reference/reference.tex =================================================================== --- trunk/Toss/www/reference/reference.tex 2011-05-23 01:32:57 UTC (rev 1455) +++ trunk/Toss/www/reference/reference.tex 2011-05-23 12:02:27 UTC (rev 1456) @@ -1772,8 +1772,11 @@ For each suitable tuple $\ol{\calC}, \ol{\calN}$ we have now created the unifier $\sigma_{\ol{\calC}, \ol{\calN}}$ and computed the erasure -clauses $\calE_{\ol{\calC}, \ol{\calN}}$. To create the rules, we need -to further partition the \emph{rule clauses} $\sigma_{\ol{\calC}, +clauses $\calE_{\ol{\calC}, \ol{\calN}}$. At this point, clauses +$\ol{\calC}, \ol{\calN}$ are optionally divided according to the +player of the \texttt{does} relation atom in them, see +Section~\ref{subsec-concurrency}. To create the rules, we need to +further partition the \emph{rule clauses} $\sigma_{\ol{\calC}, \ol{\calN}}(\calC_i), \sigma_{\ol{\calC}, \ol{\calN}}(\calN_i)$ and $\calE_{\ol{\calC}, \ol{\calN}}$, and augment them with further conditions. The reason is that the prepared rule clauses may have @@ -1816,12 +1819,10 @@ are extracted to be relations tuples in $\frakL$. Having constructed and filtered the rewriting rule candidates, we have -almost completed the definition of $T(G)$. The rules are assigned to -locations based on who moves in which location, as we only translate -turn-based games for now. Payoff formulas are derived by instantiating -variables standing for the \texttt{goal} values. The formulas defining -the \texttt{terminal} condition and specific \texttt{goal} value -conditions are translated as described in +almost completed the definition of $T(G)$. Payoff formulas are derived +by instantiating variables standing for the \texttt{goal} values. The +formulas defining the \texttt{terminal} condition and specific +\texttt{goal} value conditions are translated as described in Section~\ref{subsec-translate}, from disjunctions of bodies of their respective clauses. Actually, instead of ``freshening'' the clauses and translating the disjunction of their bodies, we (equivalently) @@ -1843,6 +1844,13 @@ a game state term $t$ such that $t\tpos_p = v$, and the incoming move has term $s$ at path $q$, then we add $Anch^s_p(x)$ to the precondition. +It is actually possible, that there is more than a single rule and/or +multiple embeddings; the semantics of the original GDL game +specification demands that all rules should be applied over all their +non-overlapping embeddings. For the most part we do not worry about +such exceptional situations, but we handle one natural case in +Paragraph~\ref{par-concurrent-moves}. + To translate the outgoing move, we recall the heads of the \texttt{legal} clauses of the rule that is selected, as we only need to substitute all their variables. To eliminate a variable $v$ contained in @@ -1851,6 +1859,51 @@ such that $t\tpos_p = v$, and $a\tpos^m_p = s$, then we substitute $v$ by $s$. The move translation function $\mu$ is thus constructed. +\subsubsection{Concurrent Moves and Toss Locations} \label{subsec-concurrency} + +In Section~\ref{subsec-rules}, we described the creation of +state-transition rewrite rules, \ie where a single Toss rule is +responsible for the transition to the next game state. But we also +remarked that the rule clauses can be divided by players to whose +actions they refer (by the \texttt{does} relation). In this case the +game state transition is jointly described by several Toss rules that +apply independently, each rule ``enacted'' by a player; such is the +default way of defining simultaneous moves in Toss. We now elaborate +on three modes of building the game graph in the translated game. + +\paragraph{Turn-based Games} are games where in any game state there +is at most a single player having genuine choice. Rather than +attempting a complex analysis to detect as many turn-based games as +possible, we recognize some cases where in all states, all players but +one have a single legal move that is a constant (term of size +one). Such move is conventionally called \texttt{noop}. We simply +check what moves are available to players in the states of the +aggregate playout. Due to the character of aggregate playout, we only +handle the case where the alternation of control forms a cycle +(players do not need to strictly alternate, for example a +single-player game is also a turn-based game, as another example in a +three-player game the first player may intersperse the moves of second +and third player). We build a corresponding cyclic graph of Toss +locations. + +\paragraph{Concurrent Moves Games} \label{par-concurrent-moves} When +translation as a turn-based game fails, but all rule clauses have at +most one atom of \texttt{does} relation, we divide the clauses among +players as mentioned earlier. For the clauses wihout \texttt{does} +atoms, a new player, ``environment'', is created. We designate the +``environment'' player to have all its matching rules applied, over +all embeddings, at each state transition. We translate using a +single-location game graph. (TODO: less terse descr) + +\paragraph{General Interaction Games} When some rule clause has +multiple \texttt{does} relations, we cannot use straightforward +translation of the previous paragraph. Instead, we translate into a +two-location graph, where game players declare their moves in one +location, and the (now obligatory) ``environment'' player carries out +state changes in the other location. In effect, large parts of the +translation function $\mu$ are built into the game. (TODO: will +specify soon) + \subsection{Translating Formulas} \label{subsec-translate} First we describe translation in the case all GDL relations other than This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-23 16:48:52
|
Revision: 1457 http://toss.svn.sourceforge.net/toss/?rev=1457&view=rev Author: lukaszkaiser Date: 2011-05-23 16:48:44 +0000 (Mon, 23 May 2011) Log Message: ----------- Complete Breakthrough generation from pictures. Modified Paths: -------------- trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Server/Picture.ml trunk/Toss/Server/Picture.mli trunk/Toss/Server/PictureTest.ml trunk/Toss/Server/def_pics/Makefile Added Paths: ----------- trunk/Toss/Server/def_pics/BreakthroughWin100.svg trunk/Toss/Server/def_pics/BreakthroughWin101.svg trunk/Toss/Server/def_pics/BreakthroughWin200.svg trunk/Toss/Server/def_pics/BreakthroughWin201.svg Removed Paths: ------------- trunk/Toss/Server/def_pics/BreakthroughWin00.svg trunk/Toss/Server/def_pics/BreakthroughWin01.svg Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2011-05-23 12:02:27 UTC (rev 1456) +++ trunk/Toss/Formula/FormulaOps.ml 2011-05-23 16:48:44 UTC (rev 1457) @@ -639,13 +639,26 @@ let mintp f rels vars = let (add_vars, cur_tp) = (ref [], ref (List.filter f (atp rels vars))) in let rec rept i l = if i < 1 then [] else l :: (rept (i-1) l) in - let mk_tp () = + let has_free v f = List.mem v (free_vars f) in + let rec cpush = function + | Ex ([v], Or fl) -> cpush (Ex ([v], And fl)) (* hack - we convert here *) + | All ([v], And fl) -> cpush (All ([v], Or fl)) (* TODO: FIXME: unhack!!! *) + | Ex ([v], And fl) -> + let (with_v, no_v) = List.partition (has_free v) fl in + if no_v = [] then Ex ([v], And fl) else if with_v = [] then And fl else + And (Ex ([v], And with_v) :: no_v) + | All ([v], Or fl) -> + let (with_v, no_v) = List.partition (has_free v) fl in + if no_v = [] then All ([v], Or fl) else if with_v = [] then Or fl else + And (All ([v], Or with_v) :: no_v) + | x -> x in + let mk_tp () = if !debug_level > 0 then Format.printf "Making new tp.\n%!"; let atoms = atp rels (vars @ !add_vars) in if !debug_level > 0 then Format.printf "Atomic %i\n%!" (List.length atoms); let add_vars_v = List.map (fun v -> var_of_string v) !add_vars in - let qex = Aux.product (rept (List.length !add_vars) [false; true]) in - let qphi phi v b = if b then Ex ([v], phi) else All ([v], phi) in + let qex = Aux.product (rept (List.length !add_vars) [true; false]) in + let qphi f v b = if b then cpush (Ex ([v], f)) else cpush (All ([v], f)) in let quant c phi = List.fold_left2 qphi phi add_vars_v c in let qatoms c = List.filter f (List.rev_map (quant c) atoms) in List.fold_left (fun l c -> if l = [] then qatoms c else l) [] qex in Modified: trunk/Toss/Server/Picture.ml =================================================================== --- trunk/Toss/Server/Picture.ml 2011-05-23 12:02:27 UTC (rev 1456) +++ trunk/Toss/Server/Picture.ml 2011-05-23 16:48:44 UTC (rev 1457) @@ -234,12 +234,6 @@ (s, !maxdx, !maxdy) - -(* Minimal types differentiating two structures. *) -let difftp rels s1 s2 = - let ok phi = Solver.M.check s1 phi && not (Solver.M.check s2 phi) in - FormulaOps.mintp ok rels [] - (* Minimal type of elements in a structure which is part-positive. *) let postp s rels els = let app_rel_phi (st, fos, vs, i) e = @@ -287,13 +281,20 @@ (List.filter (fun e -> not (List.mem e els)) (Structure.elements s)) in let is_unary r = List.assoc r (Structure.rel_signature left) = 1 in let un_drels = Aux.unique_sorted (List.filter is_unary drels) in - let un_opt_drels = List.map (fun r -> "_opt_" ^ r) un_drels in - let addopt s r = Structure.add_rels s r (List.map (fun e -> [|e|]) new_els) in - let addopts s = List.fold_left addopt s un_opt_drels in let delopt s r = Structure.del_rels s r (List.map (fun e -> [|e|]) new_els) in let delopts s = List.fold_left delopt s un_drels in - (addopts (delopts (cut left)), addopts (delopts (cut right)), []) + (delopts (cut left), delopts (cut right), delems) +let addopts drels (left, right, delems) = + let is_unary r = List.assoc r (Structure.rel_signature left) = 1 in + let un_drels = Aux.unique_sorted (List.filter is_unary drels) in + let un_opt_drels = List.map (fun r -> "_opt_" ^ r) un_drels in + let els = Structure.elements left in + let new_els = List.filter (fun e -> not (List.mem e delems)) els in + let addopt s r = Structure.add_rels s r (List.map (fun e -> [|e|]) new_els) in + let addoptrels s = List.fold_left addopt s un_opt_drels in + (addoptrels left, addoptrels right, []) + let print_rule emb (name, (l, r, pre_l)) = let emb_s = String.concat ", " (Aux.unique_sorted emb) in let pre_s = Formula.sprint (Formula.And pre_l) in @@ -301,43 +302,88 @@ Format.sprintf "RULE %s:@ @[<2>%a@]@ ->@ @[<2>%a@]@ emb %s pre %s" name sprints l sprints r emb_s pre_s +let formula_of_string s = + FormulaParser.parse_formula Lexer.lex (Lexing.from_string s) -(* Make a game from sequence of pictures. *) -let make_game ?(rels=[]) ?(offset=2) ?(threshold=70.) ?(geom=true) fname = - let formula_of_string s = - FormulaParser.parse_formula Lexer.lex (Lexing.from_string s) in +let read_strucs rels offset threshold gname suffix = let get_struc fn = let pic = read_pic (Scanf.Scanning.from_file fn) in - let (struc, dx, dy) = make_struc (segment 2 70. pic) in + let (struc, dx, dy) = make_struc (segment offset threshold pic) in let formula_r = formula_of_string (Printf.sprintf ( ":y(a) = :y(b) and :x(a) < :x(b) and :x(b) < :x(a) + %i.8") dx) in let formula_c = formula_of_string (Printf.sprintf ( ":x(a) = :x(b) and :y(b) < :y(a) and :y(a) < :y(b) + %i.8") dy) in let row, col = ("R", ["a"; "b"], formula_r), ("C", ["a"; "b"], formula_c) in Arena.add_def_rels struc (row :: col :: rels) in + let name i = Printf.sprintf "%s%s%02i.ppm" gname suffix i in + let (strucs, i) = (ref [], ref 0) in + while Sys.file_exists (name !i) do + strucs := get_struc (name !i) :: !strucs; incr i; + done; + List.rev !strucs + +let make_cond drels (right, wrong, delem_rels) = + let sg = Structure.rel_signature right in + let is_unary r = List.assoc r sg = 1 in + let name e = Structure.elem_name right e in + let mk_atom e r = Formula.Rel (r, [|Formula.fo_var_of_string (name e)|]) in + let preds (e, rels) = + Formula.And (List.map (mk_atom e) (List.filter is_unary rels)) in + let ex_var (e, _) = Formula.var_of_string (name e) in + let ex_vars = List.map ex_var delem_rels in + let basic = Formula.flatten (Formula.And ( + (List.fold_left (fun l x -> (preds x) :: l) [] delem_rels))) in + if not (Solver.M.check wrong basic) then Formula.Ex (ex_vars, basic) else ( + let app_s s = + let app_rel_phi (st, arels, fos, vs, i) (e, _) = + let r, v = "Elem" ^ (string_of_int i), Structure.elem_name st e in + (Structure.add_rel st r [|e|], (r, 1) :: arels, + Formula.Rel (r, [|Formula.fo_var_of_string v|]) :: fos, v::vs, i+1) in + List.fold_left app_rel_phi (s, [], [], [], 0) delem_rels in + let (right_el, arels, afos, vars, _) = app_s right in + let (wrong_el, _, _, _, _) = app_s wrong in + let csg = List.filter (fun (r,_) -> not (List.mem r drels)) sg in + let ok phi_in = + let phi = Formula.And [phi_in; basic] in + let psi = Formula.And (phi :: afos) in + Solver.M.check right_el psi && not (Solver.M.check wrong_el phi) in + let w = FormulaOps.mintp ok csg vars in + let minimize phi = + let atoms = ref [] in + let add_atom x = atoms := x :: !atoms; x in + ignore (FormulaOps.map_to_atoms add_atom phi); + let subst_atom a b x = if x = a then b else x in + let phi0 f a = FormulaOps.map_to_atoms (subst_atom a (Formula.Or[])) f in + let phi1 f a = FormulaOps.map_to_atoms (subst_atom a (Formula.And[])) f in + let mini f a = + let (f0, f1) = (phi0 f a, phi1 f a) in + Formula.flatten (if ok f0 then f0 else if ok f1 then f1 else f) in + List.fold_left mini phi (Aux.unique_sorted !atoms) in + let mw = List.map minimize w in + if !debug_level > 0 then + Format.printf "@[%a@]@ \n%!" Formula.fprint (Formula.And mw); + Formula.flatten (Formula.Ex (ex_vars, Formula.And (basic :: mw))) + ) + +(* Make a game from sequence of pictures. *) +let make_game ?(rels=[]) ?(offset=2) ?(threshold=70.) ?(types=false) fname = let flen = String.length fname in let gname = if (flen > 6 && fname.[flen-4] = '.') then String.sub fname 0 (flen - 6) else fname in - let name ?(suffix="") i = Printf.sprintf "%s%s%02i.ppm" gname suffix i in - let read_strucs () = - let (seq_strucs, win_strucs, i) = (ref [], ref [], ref 0) in - while Sys.file_exists (name !i) do - seq_strucs := get_struc (name !i) :: !seq_strucs; incr i - done; - i := 0; - while Sys.file_exists (name ~suffix:"Win" !i) do - win_strucs := get_struc (name ~suffix:"Win" !i) :: !win_strucs; incr i - done; - (List.rev !seq_strucs, Array.of_list (List.rev !win_strucs)) in - let (seq, wins) = read_strucs () in + let seq = read_strucs rels offset threshold gname "" in + let win1s = Array.of_list (read_strucs rels offset threshold gname "Win1") in + let win2s = Array.of_list (read_strucs rels offset threshold gname "Win2") in if seq = [] then failwith "Empty picture sequence for game play."; + if !debug_level > 0 then Printf.printf "Read %i move pics, %i+%i win.\n%!" + (List.length seq) (Array.length win1s) (Array.length win2s); let diff_struc (s, drels, prev) cur = let dels, drels_l = List.split (Structure.diff_elems prev cur) in ((prev, cur, dels) :: s, (List.concat drels_l) @ drels, cur) in - if !debug_level > 0 then Printf.printf "Diffstruc computed.\n%!"; + if !debug_level > 0 then Printf.printf "Diffstrucs computed.\n%!"; let (s, dr,_) = List.fold_left diff_struc ([],[],List.hd seq) (List.tl seq) in - let rules = if geom then List.rev_map (geom_rule dr) s else - List.rev_map (tp_rule dr) s in + let rules_geom = List.rev_map (geom_rule dr) s in + let rules = if not types then List.map (addopts dr) rules_geom else + List.map (tp_rule dr) rules_geom in let wi i = formula_of_string (if i mod 2 = 0 then "not Win2()" else "not Win1()") in let add_win i (l, r, pre) = (Printf.sprintf "Mv%i" i, (l, r, (wi i)::pre)) in @@ -356,13 +402,8 @@ let loc1 = Printf.sprintf "LOC 1 {\n PLAYER 1 { %s }\n PLAYER 2 { %s }\n}" pay1 (pay2 ^ "\n MOVES " ^ mvs2 ^ "\n") in let model_s = Structure.sprint (List.hd seq) in - (* Printf.printf "DiffTp\n%!"; - FormulaOps.set_debug_level 1; - let w = difftp (Structure.rel_signature wins.(0)) wins.(0) wins.(1) in - if !debug_level > -1 then - Format.printf "@[%a@]@ \n%!" Formula.fprint (Formula.And w); - FormulaOps.set_debug_level 0; *) - let (win0, win1) = (Formula.Or [], Formula.Or []) in - let beg = Printf.sprintf "PLAYERS 1, 2\nREL Win0() = %s\nREL Win1() = %s" - (Formula.sprint win0) (Formula.sprint win1) in - Printf.sprintf "%s\n%s\n%s\n%s\nMODEL \n%s\n" beg rs loc0 loc1 model_s + let dws a i = (a.(2*i+1), a.(2*i), Structure.diff_elems a.(2*i+1) a.(2*i)) in + let (win1, win2) = (make_cond dr (dws win1s 0), make_cond dr (dws win2s 0)) in + let beg = Printf.sprintf "PLAYERS 1, 2\nREL Win1() = %s\nREL Win2() = %s" + (Formula.sprint win1) (Formula.sprint win2) in + Printf.sprintf "%s\n%s\n%s\n%s\nMODEL\n%s\n" beg rs loc0 loc1 model_s Modified: trunk/Toss/Server/Picture.mli =================================================================== --- trunk/Toss/Server/Picture.mli 2011-05-23 12:02:27 UTC (rev 1456) +++ trunk/Toss/Server/Picture.mli 2011-05-23 16:48:44 UTC (rev 1457) @@ -51,4 +51,4 @@ (** Create a game from sequence of images. *) val make_game : ?rels : (string * string list * Formula.formula) list -> - ?offset : int -> ?threshold : float -> ?geom : bool -> string -> string + ?offset : int -> ?threshold : float -> ?types : bool -> string -> string Modified: trunk/Toss/Server/PictureTest.ml =================================================================== --- trunk/Toss/Server/PictureTest.ml 2011-05-23 12:02:27 UTC (rev 1456) +++ trunk/Toss/Server/PictureTest.ml 2011-05-23 16:48:44 UTC (rev 1457) @@ -24,13 +24,14 @@ let main () = Aux.set_optimized_gc (); - let (file, game) = (ref "", ref "") in + let (file, game, use_types) = (ref "", ref "", ref false) in let dbg_level i = (Picture.set_debug_level i) in let opts = [ ("-v", Arg.Unit (fun () -> dbg_level 1), "be verbose"); ("-d", Arg.Int (fun i -> dbg_level i), "set debug level"); ("-f", Arg.String (fun s -> file := s), "process file"); ("-g", Arg.String (fun s -> game := s), "process files for a game"); + ("-tp", Arg.Unit (fun () -> use_types := true), "use formulas in rules"); ] in Arg.parse opts (fun _ -> ()) "Try -help for help or one of the following."; if !file <> "" then ( @@ -43,7 +44,7 @@ Printf.printf "MODEL \n %s \n with \n R(a, b) = %s;\n C(a, b) = %s\n\n%!" (Structure.sprint struc) formula_r formula_c; ) else if !game <> "" then ( - print_endline (Picture.make_game !game) + print_endline (Picture.make_game ~types:!use_types !game) ) else ignore (OUnit.run_test_tt ~verbose:true tests) Deleted: trunk/Toss/Server/def_pics/BreakthroughWin00.svg =================================================================== --- trunk/Toss/Server/def_pics/BreakthroughWin00.svg 2011-05-23 12:02:27 UTC (rev 1456) +++ trunk/Toss/Server/def_pics/BreakthroughWin00.svg 2011-05-23 16:48:44 UTC (rev 1457) @@ -1,2 +0,0 @@ -<?xml-stylesheet href="Style.css" type="text/css"?> -<svg id="svg" viewBox="0 0 580 580"><rect class="model-elem-0" x="4.285714285714285" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_a1" ></rect><rect class="model-elem-1" x="75.71428571428572" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_b1" ></rect><rect class="model-elem-0" x="147.14285714285714" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_c1" ></rect><rect class="model-elem-1" x="218.57142857142856" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_d1" ></rect><rect class="model-elem-0" x="290" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_e1" ></rect><rect class="model-elem-1" x="361.42857142857144" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_f1" ></rect><rect class="model-elem-0" x="432.85714285714283" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_g1" ></rect><rect class="model-elem-1" x="504.2857142857143" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_h1" ></rect><rect class="model-elem-1" x="4.285714285714285" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_a2" ></rect><rect class="model-elem-0" x="75.71428571428572" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_b2" ></rect><rect class="model-elem-1" x="147.14285714285714" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_c2" ></rect><rect class="model-elem-0" x="218.57142857142856" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_d2" ></rect><rect class="model-elem-1" x="290" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_e2" ></rect><rect class="model-elem-0" x="361.42857142857144" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_f2" ></rect><rect class="model-elem-1" x="432.85714285714283" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_g2" ></rect><rect class="model-elem-0" x="504.2857142857143" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_h2" ></rect><rect class="model-elem-0" x="4.285714285714285" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_a3" ></rect><rect class="model-elem-1" x="75.71428571428572" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_b3" ></rect><rect class="model-elem-0" x="147.14285714285714" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_c3" ></rect><rect class="model-elem-1" x="218.57142857142856" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_d3" ></rect><rect class="model-elem-0" x="290" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_e3" ></rect><rect class="model-elem-1" x="361.42857142857144" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_f3" ></rect><rect class="model-elem-0" x="432.85714285714283" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_g3" ></rect><rect class="model-elem-1" x="504.2857142857143" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_h3" ></rect><rect class="model-elem-1" x="4.285714285714285" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_a4" ></rect><rect class="model-elem-0" x="75.71428571428572" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_b4" ></rect><rect class="model-elem-1" x="147.14285714285714" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_c4" ></rect><rect class="model-elem-0" x="218.57142857142856" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_d4" ></rect><rect class="model-elem-1" x="290" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_e4" ></rect><rect class="model-elem-0" x="361.42857142857144" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_f4" ></rect><rect class="model-elem-1" x="432.85714285714283" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_g4" ></rect><rect class="model-elem-0" x="504.2857142857143" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_h4" ></rect><rect class="model-elem-0" x="4.285714285714285" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_a5" ></rect><rect class="model-elem-1" x="75.71428571428572" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_b5" ></rect><rect class="model-elem-0" x="147.14285714285714" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_c5" ></rect><rect class="model-elem-1" x="218.57142857142856" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_d5" ></rect><rect class="model-elem-0" x="290" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_e5" ></rect><rect class="model-elem-1" x="361.42857142857144" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_f5" ></rect><rect class="model-elem-0" x="432.85714285714283" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_g5" ></rect><rect class="model-elem-1" x="504.2857142857143" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_h5" ></rect><rect class="model-elem-1" x="4.285714285714285" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_a6" ></rect><rect class="model-elem-0" x="75.71428571428572" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_b6" ></rect><rect class="model-elem-1" x="147.14285714285714" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_c6" ></rect><rect class="model-elem-0" x="218.57142857142856" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_d6" ></rect><rect class="model-elem-1" x="290" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_e6" ></rect><rect class="model-elem-0" x="361.42857142857144" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_f6" ></rect><rect class="model-elem-1" x="432.85714285714283" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_g6" ></rect><rect class="model-elem-0" x="504.2857142857143" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_h6" ></rect><rect class="model-elem-0" x="4.285714285714285" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_a7" ></rect><rect class="model-elem-1" x="75.71428571428572" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_b7" ></rect><rect class="model-elem-0" x="147.14285714285714" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_c7" ></rect><rect class="model-elem-1" x="218.57142857142856" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_d7" ></rect><rect class="model-elem-0" x="290" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_e7" ></rect><rect class="model-elem-1" x="361.42857142857144" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_f7" ></rect><rect class="model-elem-0" x="432.85714285714283" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_g7" ></rect><rect class="model-elem-1" x="504.2857142857143" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_h7" ></rect><rect class="model-elem-1" x="4.285714285714285" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_a8" ></rect><rect class="model-elem-0" x="75.71428571428572" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_b8" ></rect><rect class="model-elem-1" x="147.14285714285714" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_c8" ></rect><rect class="model-elem-0" x="218.57142857142856" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_d8" ></rect><rect class="model-elem-1" x="290" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_e8" ></rect><rect class="model-elem-0" x="361.42857142857144" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_f8" ></rect><rect class="model-elem-1" x="432.85714285714283" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_g8" ></rect><rect class="model-elem-0" x="504.2857142857143" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_h8" ></rect><circle class="model-pred-W" cx="40" cy="540" r="23.714285714285715" id="pred_a1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="111.42857142857143" cy="540" r="23.714285714285715" id="pred_b1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="254.28571428571428" cy="540" r="23.714285714285715" id="pred_d1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="325.7142857142857" cy="540" r="23.714285714285715" id="pred_e1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="397.14285714285717" cy="540" r="23.714285714285715" id="pred_f1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="540" r="23.714285714285715" id="pred_g1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="540" r="23.714285714285715" id="pred_h1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="40" cy="468.57142857142856" r="23.714285714285715" id="pred_a2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="111.42857142857143" cy="468.57142857142856" r="23.714285714285715" id="pred_b2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="182.85714285714286" cy="468.57142857142856" r="23.714285714285715" id="pred_c2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="397.14285714285717" cy="468.57142857142856" r="23.714285714285715" id="pred_f2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="468.57142857142856" r="23.714285714285715" id="pred_g2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="468.57142857142856" r="23.714285714285715" id="pred_h2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="254.28571428571428" cy="40" r="23.714285714285715" id="pred_d8_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="254.28571428571428" r="23.714285714285715" id="pred_e5_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="397.14285714285717" cy="254.28571428571428" r="23.714285714285715" id="pred_f5_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="40" cy="111.42857142857143" r="23.714285714285715" id="pred_a7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="111.42857142857143" cy="111.42857142857143" r="23.714285714285715" id="pred_b7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="182.85714285714286" cy="111.42857142857143" r="23.714285714285715" id="pred_c7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="111.42857142857143" r="23.714285714285715" id="pred_e7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="468.57142857142856" cy="111.42857142857143" r="23.714285714285715" id="pred_g7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="540" cy="111.42857142857143" r="23.714285714285715" id="pred_h7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="40" cy="40" r="23.714285714285715" id="pred_a8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="111.42857142857143" cy="40" r="23.714285714285715" id="pred_b8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="40" r="23.714285714285715" id="pred_e8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="397.14285714285717" cy="40" r="23.714285714285715" id="pred_f8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="468.57142857142856" cy="40" r="23.714285714285715" id="pred_g8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="540" cy="40" r="23.714285714285715" id="pred_h8_B" stroke-width="5.571428571428571" ></circle></svg> Deleted: trunk/Toss/Server/def_pics/BreakthroughWin01.svg =================================================================== --- trunk/Toss/Server/def_pics/BreakthroughWin01.svg 2011-05-23 12:02:27 UTC (rev 1456) +++ trunk/Toss/Server/def_pics/BreakthroughWin01.svg 2011-05-23 16:48:44 UTC (rev 1457) @@ -1,2 +0,0 @@ -<?xml-stylesheet href="Style.css" type="text/css"?> -<svg id="svg" viewBox="0 0 580 580"><rect class="model-elem-0" x="4.285714285714285" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_a1" ></rect><rect class="model-elem-1" x="75.71428571428572" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_b1" ></rect><rect class="model-elem-0" x="147.14285714285714" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_c1" ></rect><rect class="model-elem-1" x="218.57142857142856" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_d1" ></rect><rect class="model-elem-0" x="290" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_e1" ></rect><rect class="model-elem-1" x="361.42857142857144" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_f1" ></rect><rect class="model-elem-0" x="432.85714285714283" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_g1" ></rect><rect class="model-elem-1" x="504.2857142857143" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_h1" ></rect><rect class="model-elem-1" x="4.285714285714285" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_a2" ></rect><rect class="model-elem-0" x="75.71428571428572" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_b2" ></rect><rect class="model-elem-1" x="147.14285714285714" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_c2" ></rect><rect class="model-elem-0" x="218.57142857142856" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_d2" ></rect><rect class="model-elem-1" x="290" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_e2" ></rect><rect class="model-elem-0" x="361.42857142857144" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_f2" ></rect><rect class="model-elem-1" x="432.85714285714283" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_g2" ></rect><rect class="model-elem-0" x="504.2857142857143" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_h2" ></rect><rect class="model-elem-0" x="4.285714285714285" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_a3" ></rect><rect class="model-elem-1" x="75.71428571428572" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_b3" ></rect><rect class="model-elem-0" x="147.14285714285714" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_c3" ></rect><rect class="model-elem-1" x="218.57142857142856" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_d3" ></rect><rect class="model-elem-0" x="290" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_e3" ></rect><rect class="model-elem-1" x="361.42857142857144" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_f3" ></rect><rect class="model-elem-0" x="432.85714285714283" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_g3" ></rect><rect class="model-elem-1" x="504.2857142857143" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_h3" ></rect><rect class="model-elem-1" x="4.285714285714285" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_a4" ></rect><rect class="model-elem-0" x="75.71428571428572" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_b4" ></rect><rect class="model-elem-1" x="147.14285714285714" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_c4" ></rect><rect class="model-elem-0" x="218.57142857142856" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_d4" ></rect><rect class="model-elem-1" x="290" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_e4" ></rect><rect class="model-elem-0" x="361.42857142857144" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_f4" ></rect><rect class="model-elem-1" x="432.85714285714283" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_g4" ></rect><rect class="model-elem-0" x="504.2857142857143" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_h4" ></rect><rect class="model-elem-0" x="4.285714285714285" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_a5" ></rect><rect class="model-elem-1" x="75.71428571428572" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_b5" ></rect><rect class="model-elem-0" x="147.14285714285714" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_c5" ></rect><rect class="model-elem-1" x="218.57142857142856" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_d5" ></rect><rect class="model-elem-0" x="290" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_e5" ></rect><rect class="model-elem-1" x="361.42857142857144" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_f5" ></rect><rect class="model-elem-0" x="432.85714285714283" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_g5" ></rect><rect class="model-elem-1" x="504.2857142857143" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_h5" ></rect><rect class="model-elem-1" x="4.285714285714285" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_a6" ></rect><rect class="model-elem-0" x="75.71428571428572" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_b6" ></rect><rect class="model-elem-1" x="147.14285714285714" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_c6" ></rect><rect class="model-elem-0" x="218.57142857142856" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_d6" ></rect><rect class="model-elem-1" x="290" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_e6" ></rect><rect class="model-elem-0" x="361.42857142857144" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_f6" ></rect><rect class="model-elem-1" x="432.85714285714283" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_g6" ></rect><rect class="model-elem-0" x="504.2857142857143" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_h6" ></rect><rect class="model-elem-0" x="4.285714285714285" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_a7" ></rect><rect class="model-elem-1" x="75.71428571428572" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_b7" ></rect><rect class="model-elem-0" x="147.14285714285714" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_c7" ></rect><rect class="model-elem-1" x="218.57142857142856" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_d7" ></rect><rect class="model-elem-0" x="290" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_e7" ></rect><rect class="model-elem-1" x="361.42857142857144" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_f7" ></rect><rect class="model-elem-0" x="432.85714285714283" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_g7" ></rect><rect class="model-elem-1" x="504.2857142857143" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_h7" ></rect><rect class="model-elem-1" x="4.285714285714285" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_a8" ></rect><rect class="model-elem-0" x="75.71428571428572" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_b8" ></rect><rect class="model-elem-1" x="147.14285714285714" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_c8" ></rect><rect class="model-elem-0" x="218.57142857142856" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_d8" ></rect><rect class="model-elem-1" x="290" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_e8" ></rect><rect class="model-elem-0" x="361.42857142857144" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_f8" ></rect><rect class="model-elem-1" x="432.85714285714283" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_g8" ></rect><rect class="model-elem-0" x="504.2857142857143" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_h8" ></rect><circle class="model-pred-W" cx="397.14285714285717" cy="540" r="23.714285714285715" id="pred_f1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="540" r="23.714285714285715" id="pred_h1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="468.57142857142856" r="23.714285714285715" id="pred_h2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="40" cy="397.14285714285717" r="23.714285714285715" id="pred_a3_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="397.14285714285717" r="23.714285714285715" id="pred_g3_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="40" cy="325.7142857142857" r="23.714285714285715" id="pred_a4_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="254.28571428571428" cy="325.7142857142857" r="23.714285714285715" id="pred_d4_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="325.7142857142857" cy="325.7142857142857" r="23.714285714285715" id="pred_e4_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="40" cy="182.85714285714286" r="23.714285714285715" id="pred_a6_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="540" r="23.714285714285715" id="pred_e1_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="182.85714285714286" cy="111.42857142857143" r="23.714285714285715" id="pred_c7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="254.28571428571428" cy="111.42857142857143" r="23.714285714285715" id="pred_d7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="40" cy="40" r="23.714285714285715" id="pred_a8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="111.42857142857143" cy="40" r="23.714285714285715" id="pred_b8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="182.85714285714286" cy="40" r="23.714285714285715" id="pred_c8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="254.28571428571428" cy="40" r="23.714285714285715" id="pred_d8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="40" r="23.714285714285715" id="pred_e8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="397.14285714285717" cy="40" r="23.714285714285715" id="pred_f8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="468.57142857142856" cy="40" r="23.714285714285715" id="pred_g8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="540" cy="40" r="23.714285714285715" id="pred_h8_B" stroke-width="5.571428571428571" ></circle></svg> Added: trunk/Toss/Server/def_pics/BreakthroughWin100.svg =================================================================== --- trunk/Toss/Server/def_pics/BreakthroughWin100.svg (rev 0) +++ trunk/Toss/Server/def_pics/BreakthroughWin100.svg 2011-05-23 16:48:44 UTC (rev 1457) @@ -0,0 +1,2 @@ +<?xml-stylesheet href="Style.css" type="text/css"?> +<svg id="svg" viewBox="0 0 580 580"><rect class="model-elem-0" x="4.285714285714285" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_a1" ></rect><rect class="model-elem-1" x="75.71428571428572" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_b1" ></rect><rect class="model-elem-0" x="147.14285714285714" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_c1" ></rect><rect class="model-elem-1" x="218.57142857142856" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_d1" ></rect><rect class="model-elem-0" x="290" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_e1" ></rect><rect class="model-elem-1" x="361.42857142857144" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_f1" ></rect><rect class="model-elem-0" x="432.85714285714283" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_g1" ></rect><rect class="model-elem-1" x="504.2857142857143" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_h1" ></rect><rect class="model-elem-1" x="4.285714285714285" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_a2" ></rect><rect class="model-elem-0" x="75.71428571428572" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_b2" ></rect><rect class="model-elem-1" x="147.14285714285714" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_c2" ></rect><rect class="model-elem-0" x="218.57142857142856" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_d2" ></rect><rect class="model-elem-1" x="290" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_e2" ></rect><rect class="model-elem-0" x="361.42857142857144" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_f2" ></rect><rect class="model-elem-1" x="432.85714285714283" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_g2" ></rect><rect class="model-elem-0" x="504.2857142857143" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_h2" ></rect><rect class="model-elem-0" x="4.285714285714285" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_a3" ></rect><rect class="model-elem-1" x="75.71428571428572" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_b3" ></rect><rect class="model-elem-0" x="147.14285714285714" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_c3" ></rect><rect class="model-elem-1" x="218.57142857142856" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_d3" ></rect><rect class="model-elem-0" x="290" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_e3" ></rect><rect class="model-elem-1" x="361.42857142857144" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_f3" ></rect><rect class="model-elem-0" x="432.85714285714283" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_g3" ></rect><rect class="model-elem-1" x="504.2857142857143" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_h3" ></rect><rect class="model-elem-1" x="4.285714285714285" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_a4" ></rect><rect class="model-elem-0" x="75.71428571428572" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_b4" ></rect><rect class="model-elem-1" x="147.14285714285714" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_c4" ></rect><rect class="model-elem-0" x="218.57142857142856" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_d4" ></rect><rect class="model-elem-1" x="290" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_e4" ></rect><rect class="model-elem-0" x="361.42857142857144" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_f4" ></rect><rect class="model-elem-1" x="432.85714285714283" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_g4" ></rect><rect class="model-elem-0" x="504.2857142857143" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_h4" ></rect><rect class="model-elem-0" x="4.285714285714285" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_a5" ></rect><rect class="model-elem-1" x="75.71428571428572" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_b5" ></rect><rect class="model-elem-0" x="147.14285714285714" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_c5" ></rect><rect class="model-elem-1" x="218.57142857142856" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_d5" ></rect><rect class="model-elem-0" x="290" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_e5" ></rect><rect class="model-elem-1" x="361.42857142857144" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_f5" ></rect><rect class="model-elem-0" x="432.85714285714283" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_g5" ></rect><rect class="model-elem-1" x="504.2857142857143" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_h5" ></rect><rect class="model-elem-1" x="4.285714285714285" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_a6" ></rect><rect class="model-elem-0" x="75.71428571428572" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_b6" ></rect><rect class="model-elem-1" x="147.14285714285714" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_c6" ></rect><rect class="model-elem-0" x="218.57142857142856" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_d6" ></rect><rect class="model-elem-1" x="290" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_e6" ></rect><rect class="model-elem-0" x="361.42857142857144" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_f6" ></rect><rect class="model-elem-1" x="432.85714285714283" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_g6" ></rect><rect class="model-elem-0" x="504.2857142857143" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_h6" ></rect><rect class="model-elem-0" x="4.285714285714285" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_a7" ></rect><rect class="model-elem-1" x="75.71428571428572" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_b7" ></rect><rect class="model-elem-0" x="147.14285714285714" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_c7" ></rect><rect class="model-elem-1" x="218.57142857142856" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_d7" ></rect><rect class="model-elem-0" x="290" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_e7" ></rect><rect class="model-elem-1" x="361.42857142857144" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_f7" ></rect><rect class="model-elem-0" x="432.85714285714283" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_g7" ></rect><rect class="model-elem-1" x="504.2857142857143" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_h7" ></rect><rect class="model-elem-1" x="4.285714285714285" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_a8" ></rect><rect class="model-elem-0" x="75.71428571428572" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_b8" ></rect><rect class="model-elem-1" x="147.14285714285714" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_c8" ></rect><rect class="model-elem-0" x="218.57142857142856" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_d8" ></rect><rect class="model-elem-1" x="290" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_e8" ></rect><rect class="model-elem-0" x="361.42857142857144" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_f8" ></rect><rect class="model-elem-1" x="432.85714285714283" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_g8" ></rect><rect class="model-elem-0" x="504.2857142857143" y="4.285714285714285" width="71.42857142857143" height="71.42857142857143" id="elem_h8" ></rect><circle class="model-pred-W" cx="40" cy="540" r="23.714285714285715" id="pred_a1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="111.42857142857143" cy="540" r="23.714285714285715" id="pred_b1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="254.28571428571428" cy="540" r="23.714285714285715" id="pred_d1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="325.7142857142857" cy="540" r="23.714285714285715" id="pred_e1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="397.14285714285717" cy="540" r="23.714285714285715" id="pred_f1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="540" r="23.714285714285715" id="pred_g1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="540" r="23.714285714285715" id="pred_h1_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="40" cy="468.57142857142856" r="23.714285714285715" id="pred_a2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="111.42857142857143" cy="468.57142857142856" r="23.714285714285715" id="pred_b2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="182.85714285714286" cy="468.57142857142856" r="23.714285714285715" id="pred_c2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="397.14285714285717" cy="468.57142857142856" r="23.714285714285715" id="pred_f2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="468.57142857142856" cy="468.57142857142856" r="23.714285714285715" id="pred_g2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-W" cx="540" cy="468.57142857142856" r="23.714285714285715" id="pred_h2_W" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="325.7142857142857" cy="254.28571428571428" r="23.714285714285715" id="pred_e5_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="397.14285714285717" cy="254.28571428571428" r="23.714285714285715" id="pred_f5_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="40" cy="111.42857142857143" r="23.714285714285715" id="pred_a7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="111.42857142857143" cy="111.42857142857143" r="23.714285714285715" id="pred_b7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="182.85714285714286" cy="111.42857142857143" r="23.714285714285715" id="pred_c7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="468.57142857142856" cy="111.42857142857143" r="23.714285714285715" id="pred_g7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="540" cy="111.42857142857143" r="23.714285714285715" id="pred_h7_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="40" cy="40" r="23.714285714285715" id="pred_a8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="111.42857142857143" cy="40" r="23.714285714285715" id="pred_b8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="397.14285714285717" cy="40" r="23.714285714285715" id="pred_f8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="468.57142857142856" cy="40" r="23.714285714285715" id="pred_g8_B" stroke-width="5.571428571428571" ></circle><circle class="model-pred-B" cx="540" cy="40" r="23.714285714285715" id="pred_h8_B" stroke-width="5.571428571428571" ></circle></svg> Added: trunk/Toss/Server/def_pics/BreakthroughWin101.svg =================================================================== --- trunk/Toss/Server/def_pics/BreakthroughWin101.svg (rev 0) +++ trunk/Toss/Server/def_pics/BreakthroughWin101.svg 2011-05-23 16:48:44 UTC (rev 1457) @@ -0,0 +1,2 @@ +<?xml-stylesheet href="Style.css" type="text/css"?> +<svg id="svg" viewBox="0 0 580 580"><rect class="model-elem-0" x="4.285714285714285" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_a1" ></rect><rect class="model-elem-1" x="75.71428571428572" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_b1" ></rect><rect class="model-elem-0" x="147.14285714285714" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_c1" ></rect><rect class="model-elem-1" x="218.57142857142856" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_d1" ></rect><rect class="model-elem-0" x="290" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_e1" ></rect><rect class="model-elem-1" x="361.42857142857144" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_f1" ></rect><rect class="model-elem-0" x="432.85714285714283" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_g1" ></rect><rect class="model-elem-1" x="504.2857142857143" y="504.2857142857143" width="71.42857142857143" height="71.42857142857143" id="elem_h1" ></rect><rect class="model-elem-1" x="4.285714285714285" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_a2" ></rect><rect class="model-elem-0" x="75.71428571428572" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_b2" ></rect><rect class="model-elem-1" x="147.14285714285714" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_c2" ></rect><rect class="model-elem-0" x="218.57142857142856" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_d2" ></rect><rect class="model-elem-1" x="290" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_e2" ></rect><rect class="model-elem-0" x="361.42857142857144" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_f2" ></rect><rect class="model-elem-1" x="432.85714285714283" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_g2" ></rect><rect class="model-elem-0" x="504.2857142857143" y="432.85714285714283" width="71.42857142857143" height="71.42857142857143" id="elem_h2" ></rect><rect class="model-elem-0" x="4.285714285714285" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_a3" ></rect><rect class="model-elem-1" x="75.71428571428572" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_b3" ></rect><rect class="model-elem-0" x="147.14285714285714" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_c3" ></rect><rect class="model-elem-1" x="218.57142857142856" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_d3" ></rect><rect class="model-elem-0" x="290" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_e3" ></rect><rect class="model-elem-1" x="361.42857142857144" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_f3" ></rect><rect class="model-elem-0" x="432.85714285714283" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_g3" ></rect><rect class="model-elem-1" x="504.2857142857143" y="361.42857142857144" width="71.42857142857143" height="71.42857142857143" id="elem_h3" ></rect><rect class="model-elem-1" x="4.285714285714285" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_a4" ></rect><rect class="model-elem-0" x="75.71428571428572" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_b4" ></rect><rect class="model-elem-1" x="147.14285714285714" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_c4" ></rect><rect class="model-elem-0" x="218.57142857142856" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_d4" ></rect><rect class="model-elem-1" x="290" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_e4" ></rect><rect class="model-elem-0" x="361.42857142857144" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_f4" ></rect><rect class="model-elem-1" x="432.85714285714283" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_g4" ></rect><rect class="model-elem-0" x="504.2857142857143" y="290" width="71.42857142857143" height="71.42857142857143" id="elem_h4" ></rect><rect class="model-elem-0" x="4.285714285714285" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_a5" ></rect><rect class="model-elem-1" x="75.71428571428572" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_b5" ></rect><rect class="model-elem-0" x="147.14285714285714" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_c5" ></rect><rect class="model-elem-1" x="218.57142857142856" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_d5" ></rect><rect class="model-elem-0" x="290" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_e5" ></rect><rect class="model-elem-1" x="361.42857142857144" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_f5" ></rect><rect class="model-elem-0" x="432.85714285714283" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_g5" ></rect><rect class="model-elem-1" x="504.2857142857143" y="218.57142857142856" width="71.42857142857143" height="71.42857142857143" id="elem_h5" ></rect><rect class="model-elem-1" x="4.285714285714285" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_a6" ></rect><rect class="model-elem-0" x="75.71428571428572" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_b6" ></rect><rect class="model-elem-1" x="147.14285714285714" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_c6" ></rect><rect class="model-elem-0" x="218.57142857142856" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_d6" ></rect><rect class="model-elem-1" x="290" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_e6" ></rect><rect class="model-elem-0" x="361.42857142857144" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_f6" ></rect><rect class="model-elem-1" x="432.85714285714283" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_g6" ></rect><rect class="model-elem-0" x="504.2857142857143" y="147.14285714285714" width="71.42857142857143" height="71.42857142857143" id="elem_h6" ></rect><rect class="model-elem-0" x="4.285714285714285" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_a7" ></rect><rect class="model-elem-1" x="75.71428571428572" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_b7" ></rect><rect class="model-elem-0" x="147.14285714285714" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_c7" ></rect><rect class="model-elem-1" x="218.57142857142856" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_d7" ></rect><rect class="model-elem-0" x="290" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_e7" ></rect><rect class="model-elem-1" x="361.42857142857144" y="75.71428571428572" width="71.42857142857143" height="71.42857142857143" id="elem_f7" ></rect><rect class="model-elem-0" x="432.85714285714283" y="75.71428571428572" width="71.4... [truncated message content] |
From: <luk...@us...> - 2011-05-26 00:56:11
|
Revision: 1459 http://toss.svn.sourceforge.net/toss/?rev=1459&view=rev Author: lukaszkaiser Date: 2011-05-26 00:56:05 +0000 (Thu, 26 May 2011) Log Message: ----------- Some typo corrections. Modified Paths: -------------- trunk/Toss/Server/def_pics/Makefile trunk/Toss/www/pub/gdl_to_toss_translation.pdf Modified: trunk/Toss/Server/def_pics/Makefile =================================================================== --- trunk/Toss/Server/def_pics/Makefile 2011-05-23 23:20:49 UTC (rev 1458) +++ trunk/Toss/Server/def_pics/Makefile 2011-05-26 00:56:05 UTC (rev 1459) @@ -16,7 +16,7 @@ Breakthrough12.ppm BreakthroughWin100.ppm BreakthroughWin101.ppm \ BreakthroughWin200.ppm BreakthroughWin201.ppm OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../../PictureTest.native -tp \ - -g Breakthrough | sed "s/P1/W/g" | sed "s/P2/B/g" > Breakthrough.toss + -g Breakthrough | sed "s/P1/B/g" | sed "s/P2/W/g" > Breakthrough.toss clean: rm -rf *.ppm *.png *.toss *~ Modified: trunk/Toss/www/pub/gdl_to_toss_translation.pdf =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-26 23:14:28
|
Revision: 1461 http://toss.svn.sourceforge.net/toss/?rev=1461&view=rev Author: lukaszkaiser Date: 2011-05-26 23:14:21 +0000 (Thu, 26 May 2011) Log Message: ----------- Support for recursively defined relations. Modified Paths: -------------- trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Formula/FormulaOps.mli trunk/Toss/Formula/FormulaOpsTest.ml trunk/Toss/Server/Picture.ml Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2011-05-26 22:02:48 UTC (rev 1460) +++ trunk/Toss/Formula/FormulaOps.ml 2011-05-26 23:14:21 UTC (rev 1461) @@ -382,7 +382,13 @@ let map_to_atoms_expr f r = map_to_literals_expr (function Not (x) -> Not (f x) | x -> f x) (fun x -> x) r +let get_atoms phi = + let atoms = ref [] in + let add_atom x = atoms := x :: !atoms; x in + ignore (map_to_atoms add_atom phi); + Aux.unique_sorted !atoms + let rec fold_over_literals f phi acc = match phi with | Rel _ | Eq _ | In _ | SO _ as x -> f x acc @@ -581,7 +587,7 @@ let subst_r defs = function (* Helper function for atoms. *) | Rel (rn, vs) -> ( try - let (dvs, dphi) = List.assoc rn defs in + let (_, dvs, dphi) = List.assoc rn defs in let ovs = List.map var_str (Array.to_list vs) in subst_vars (List.combine dvs ovs) dphi with Not_found -> Rel (rn, vs) ) @@ -590,11 +596,13 @@ (* Substitute once in [phi] relations in [defs] by corresponding subformulas (with instantiated parameters). *) let subst_once_rels defs phi = - map_to_atoms (subst_r defs) phi + let cdefs = List.map (fun (n, (v, f)) -> (n, ([], v, f))) defs in + map_to_atoms (subst_r cdefs) phi (* Substitute once in [r] relations defined in [defs] by their definitions. *) let subst_once_rels_expr defs r = - map_to_atoms_expr (subst_r defs) r + let cdefs = List.map (fun (n, (v, f)) -> (n, ([], v, f))) defs in + map_to_atoms_expr (subst_r cdefs) r (* Helper function: fixed-point up to [n] *) let rec fp_n print n f x = @@ -606,15 +614,63 @@ else fp_n print (n-1) f nx -(* Substitute recursively in [phi] relations defined in [defs]. *) -let subst_rels defs phi = - fp_n str (List.length defs) (subst_once_rels defs) phi - (* Substitute recursively in [r] relations defined in [defs]. *) let subst_rels_expr defs r = fp_n real_str (List.length defs) (subst_once_rels_expr defs) r +(* Substitute recursively in [phi] relations defined in [defs]. *) +let subst_rels defs phi = + let rels f = + Aux.map_some (function Rel (r, _) -> Some r | _ -> None) (get_atoms f) in + let rels_def defs f = List.filter (fun r -> List.mem_assoc r defs) (rels f) in + let cdefs = List.map (fun (n, (vs,f)) -> (n, (rels_def defs f, vs,f))) defs in + let cdfstr (n, (rs, _, _)) = + Printf.sprintf "rel %s calls %s" n + (if (List.length rs) = 0 then "nothing" else + let rstr = String.concat ", " rs in + if List.mem n rs then "self, " ^ rstr else rstr) in + if !debug_level > 1 then + Printf.printf "Subst:\n %s\n" (String.concat "\n " (List.map cdfstr cdefs)); + let is_basic (_, (rs, _, _)) = List.length rs = 0 in + let self_calls (n, (rs, _, _)) = List.mem n rs in + let subst_once_fm defs phi = map_to_atoms (subst_r defs) phi in + let subst_once rdefs defs (n, (rs, v, f)) = + let nf = subst_once_fm defs f in + (n, (rels_def rdefs nf, v, nf)) in + let subst_once_defs defs lst = List.map (subst_once lst defs) lst in + let rec rec_subst_rels cdefs phi = + if cdefs = [] then phi else + let (basic, other) = List.partition is_basic cdefs in + if basic <> [] then + rec_subst_rels (subst_once_defs basic other) (subst_once_fm basic phi) + else + let cdefss = List.sort Pervasives.compare cdefs in (* repeatability *) + let (selfc, otherc) = List.partition self_calls cdefss in + if otherc <> [] then + let (d, ds) = (List.hd otherc, (List.tl otherc) @ selfc) in + rec_subst_rels (subst_once_defs [d] ds) (subst_once_fm [d] phi) + else + let sovar n = so_var_of_string ("|" ^ n) in + let sorels rels = function + | Rel (m, rvs) when List.mem m rels -> SO (sovar m, rvs) + | x -> x in + let do_lfp (n, (calls, vs, f)) = + let va = Array.of_list (List.map fo_var_of_string vs) in + let nf = map_to_atoms (sorels [n]) f in + (n, ([], vs, Lfp ((sovar n :> [mso_var | so_var]), va, nf))) in + let (d, ds) = do_lfp (List.hd selfc), List.tl selfc in + rec_subst_rels (subst_once_defs [d] ds) (subst_once_fm [d] phi) in + let res_phi = rec_subst_rels cdefs phi in + let simpfpvars = List.map (fun (n, _) -> "|" ^ n) cdefs in (*TODO:reoccurs?*) + let rec simp_def_lfp acc fpvar fpvs fpdef = + if List.mem fpvar acc && List.mem (var_str fpvar) simpfpvars then + SO (to_so (fpvar :> var), fpvs) + else + let smap = { identity_map with map_Lfp = simp_def_lfp (fpvar :: acc) } in + Lfp (fpvar, fpvs, map_formula smap fpdef) in + map_formula { identity_map with map_Lfp = simp_def_lfp []} res_phi + (* --- AType with variables over given relations, no repetition, equality --- *) let atp rels vars_in = Modified: trunk/Toss/Formula/FormulaOps.mli =================================================================== --- trunk/Toss/Formula/FormulaOps.mli 2011-05-26 22:02:48 UTC (rev 1460) +++ trunk/Toss/Formula/FormulaOps.mli 2011-05-26 23:14:21 UTC (rev 1461) @@ -105,6 +105,7 @@ real_expr -> real_expr val map_to_atoms : (formula -> formula) -> formula -> formula val map_to_atoms_expr : (formula -> formula) -> real_expr -> real_expr +val get_atoms : formula -> formula list val fold_over_literals : (formula -> 'a -> 'a) -> formula -> 'a -> 'a Modified: trunk/Toss/Formula/FormulaOpsTest.ml =================================================================== --- trunk/Toss/Formula/FormulaOpsTest.ml 2011-05-26 22:02:48 UTC (rev 1460) +++ trunk/Toss/Formula/FormulaOpsTest.ml 2011-05-26 23:14:21 UTC (rev 1461) @@ -317,6 +317,21 @@ defs_eq [("R", (["x"; "y"], formula_of_string "S (x, y) and ex x S(y, x)"))] "R (y, x)" "S(y, x) and ex x0 (S(x, x0))"; + defs_eq + [("R", (["x"; "y"], formula_of_string "P(x) or R(x, y)"))] + "R (x, y)" "lfp |R (x, y) = (P(x) or |R(x, y))"; + defs_eq + [("R", (["x"; "y"], formula_of_string "P(x) or S(x, y)")); + ("S", (["x"; "y"], formula_of_string "Q(x) or R(x, y)"))] + "R (x, y)" "P (x) or lfp |S (x, y) = (Q(x) or P(x) or |S(x, y))"; + defs_eq + [("R", (["x"; "y"], formula_of_string "R(x, y) or P(x) or S(x, y)")); + ("S", (["x"; "y"], formula_of_string "S(x, y) or Q(x) or R(x, y)"))] + "R(x, y) and S(x, y)" + ("lfp |R(x,y) = ((|R(x, y) or P(x) or lfp |S(x, y) =" ^ + " (|S(x, y) or Q(x) or |R(x, y)))) and " ^ + "lfp |S(x, y) = ((|S(x, y) or Q(x) or lfp |R(x, y) =" ^ + " (|R(x, y) or P(x) or |S(x, y))))"); ); "atp, mintp" >:: Modified: trunk/Toss/Server/Picture.ml =================================================================== --- trunk/Toss/Server/Picture.ml 2011-05-26 22:02:48 UTC (rev 1460) +++ trunk/Toss/Server/Picture.ml 2011-05-26 23:14:21 UTC (rev 1461) @@ -349,16 +349,14 @@ Solver.M.check right_el psi && not (Solver.M.check wrong_el phi) in let w = FormulaOps.mintp ok csg vars in let minimize phi = - let atoms = ref [] in - let add_atom x = atoms := x :: !atoms; x in - ignore (FormulaOps.map_to_atoms add_atom phi); + let atoms = FormulaOps.get_atoms phi in let subst_atom a b x = if x = a then b else x in let phi0 f a = FormulaOps.map_to_atoms (subst_atom a (Formula.Or[])) f in let phi1 f a = FormulaOps.map_to_atoms (subst_atom a (Formula.And[])) f in let mini f a = let (f0, f1) = (phi0 f a, phi1 f a) in Formula.flatten (if ok f0 then f0 else if ok f1 then f1 else f) in - List.fold_left mini phi (Aux.unique_sorted !atoms) in + List.fold_left mini phi atoms in let mw = List.map minimize w in if !debug_level > 0 then Format.printf "@[%a@]@ \n%!" Formula.fprint (Formula.And mw); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-30 01:25:24
|
Revision: 1465 http://toss.svn.sourceforge.net/toss/?rev=1465&view=rev Author: lukaszkaiser Date: 2011-05-30 01:25:16 +0000 (Mon, 30 May 2011) Log Message: ----------- More JavaScript cleanups. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Drawing.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html trunk/Toss/WebClient/profile.html Removed Paths: ------------- trunk/Toss/WebClient/State.js Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-05-29 17:55:27 UTC (rev 1464) +++ trunk/Toss/Server/ReqHandler.ml 2011-05-30 01:25:16 UTC (rev 1465) @@ -446,7 +446,7 @@ let or_s = "(player1='" ^ pl_id ^ "' or player2='" ^ pl_id ^ "')" in let plays = dbtable ("game='" ^ game ^ "' and " ^ or_s) "cur_states" in let play_name p = (* p = (pid, g, p1, p2, move, _, _, _, _) *) - "/plays/"^ p.(1) ^"_"^ p.(2) ^"_"^ p.(3) ^"_"^ p.(0) ^"_"^ p.(4) in + "/" ^ p.(1) ^ "_" ^ p.(2) ^ "_" ^ p.(3) ^ "_" ^ p.(0) ^ "_" ^ p.(4) in lstr (List.map play_name plays) in let user_plays uid = let (name, _, _) = get_user_name_surname_mail uid in @@ -479,19 +479,14 @@ db_cur_insert game pl1 pl2 pid (string_of_int move_pl) model loc info ""; release_global_lock (); pid ^ "$" ^ info ^ "$" ^ (string_of_int move_pl) in - let game_select_s g p1 p2 pid = - "game='" ^ g ^ "' and player1='" ^ p1 ^ "' and player2='" ^ p2 ^ - "' and playid=" ^ pid in - let upd_svg g p1 p2 pid m svg_s = - let select = game_select_s g p1 p2 pid in - let _ = DB.update_table dbFILE ~select ("svg='"^ svg_s ^"'") "cur_states" in - "" in + let game_select_s pid = "playid=" ^ pid in let db_escape s = str_replace "'" "''" s in - let move_play move_tup g p1 p2 pid m = - let sel_s = game_select_s g p1 p2 pid in + let move_play move_tup pid = + let sel_s = game_select_s pid in let old_res= List.hd (dbtable sel_s "cur_states") in - let (old_toss, old_loc, old_info, old_svg) = - (old_res.(5), old_res.(6), old_res.(7), old_res.(8)) in + let (g, p1, p2, m, old_toss, old_loc, old_info, old_svg) = + (old_res.(1), old_res.(2), old_res.(3), old_res.(4), + old_res.(5), old_res.(6), old_res.(7), old_res.(8)) in let game_toss = (List.hd (dbtable ("game='" ^ g ^ "'") "games")).(1) in client_open_from_str (game_toss ^ "\nMODEL " ^ old_toss); client_set_cur_loc old_loc; @@ -511,9 +506,9 @@ "playid, game, player1, player2, move, toss, loc, info, svg" [pid; g; p1; p2; m; old_toss; old_loc; old_info; old_svg]; new_info ^ "$" ^ (string_of_int new_pl) in - let suggest time g p1 p2 pid m = - let res = List.hd (dbtable (game_select_s g p1 p2 pid) "cur_states") in - let (toss, loc) = (res.(5), res.(6)) in + let suggest time pid = + let res = List.hd (dbtable (game_select_s pid) "cur_states") in + let (g, m, toss, loc) = (res.(1),int_of_string res.(4), res.(5), res.(6)) in let game_toss = (List.hd (dbtable ("game='" ^ g ^ "'") "games")).(1) in client_open_from_str (game_toss ^ "\nMODEL " ^ toss); client_set_cur_loc loc; @@ -540,8 +535,8 @@ if all then List.map (fun a -> a.(0)) (dbtable "" "users") else let friends = dbtable ("id='" ^ uid ^ "'") "friends" in List.map (fun a -> a.(1)) friends in - let open_db game p1 p2 pid move = - let res = dbtable (game_select_s game p1 p2 pid) "cur_states" in + let open_db pid = + let res = dbtable (game_select_s pid) "cur_states" in let (move, info) = ((List.hd res).(4), (List.hd res).(7)) in info ^ "$" ^ move in let add_opponent uid oppid = @@ -600,15 +595,11 @@ | "LIST_PLAYS" -> let a = get_args data in list_plays a.(0) a.(1), [] | "OPEN_DB" -> - let a = get_args data in open_db a.(0) a.(1) a.(2) a.(3) a.(4), [] - | "UPD_SVG" -> - let a = Array.map (strip_all ["'"]) (split ~bound:(Some 6) ", " data) in - upd_svg a.(0) a.(1) a.(2) a.(3) a.(4) a.(5), [] + let a = get_args data in open_db a.(0), [] | "NEW_PLAY" -> - let a = get_args data in new_play a.(1) a.(2) a.(3), [] + let a = get_args data in new_play a.(0) a.(1) a.(2), [] | "SUGGEST" -> - let a = get_args data in - suggest a.(1) a.(2) a.(3) a.(4) a.(5) (int_of_string a.(6)), [] + let a = get_args data in suggest a.(0) a.(1), [] | "MOVE_PLAY" -> let (op_i, cl_i) = (String.index data '(', String.index data ')') in let tp_s = String.sub data (op_i+1) (cl_i - op_i-1) in @@ -619,7 +610,7 @@ let tp1 = String.sub tp_s (tp_j+1) (tp_i - tp_j - 1) in let tp2 = String.sub tp_s (tp_i+1) (tp_l - tp_i - 1) in let tp, a = (strip_ws tp0, strip_ws tp1, strip_ws tp2), get_args args_s in - move_play tp a.(0) a.(1) a.(2) a.(3) a.(4), [] + move_play tp a.(0), [] | _ -> "MOD_PYTHON ERROR ; Traceback: Unknown Toss Command! \n " ^ tcmd, [] in http_msg false "200 OK" "text/html; charset=utf-8" new_cookies resp Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-05-29 17:55:27 UTC (rev 1464) +++ trunk/Toss/WebClient/Connect.js 2011-05-30 01:25:16 UTC (rev 1465) @@ -1,8 +1,5 @@ // JavaScript Toss Module -- Connect (basic Toss Server connection routines) -var UNAME = ""; -var GAME_NAME = ""; // name of current game, e.g. "Breakthrough" - var ASYNC_ALL_REQ_PENDING = 0; var ASYNC_CMD_REQ_PENDING = {}; @@ -104,21 +101,18 @@ this.get_name = function (uname) { return (srv ("GET_NAME", uname)); } this.list_plays = function (game, uname) { - return (srv ("LIST_PLAYS", "'" + game + "', '" + UNAME + "'")); + return (srv ("LIST_PLAYS", game + ", " + uname)); } this.open_db = function (pid) { return (srv ("OPEN_DB", pid)); } this.new_play = function (g, un, opp) { - return (srv("NEW_PLAY", "c, '" + g + "', '" + un + "', '" + opp +"'")); + return (srv ("NEW_PLAY", g + ", " + un + ", " + opp)); } this.make_move = function (move_s, pid, cont) { - async_srv("MOVE_PLAY", 'c, '+ move_s +', '+ pid, cont); + async_srv("MOVE_PLAY", move_s + ', ' + pid, cont); } - this.upd_svg = function (pid, svg_s) { - async_srv_ignore ("UPD_SVG", pid + ", " + svg_s); - } this.suggest = function (time, pid, cont) { - async_srv("SUGGEST", 'c, ' + time + ', '+ pid, cont); + async_srv("SUGGEST", time + ', ' + pid, cont); } this.friends = function () { return (srv ("LIST_FRIENDS", "user")); } Modified: trunk/Toss/WebClient/Drawing.js =================================================================== --- trunk/Toss/WebClient/Drawing.js 2011-05-29 17:55:27 UTC (rev 1464) +++ trunk/Toss/WebClient/Drawing.js 2011-05-30 01:25:16 UTC (rev 1465) @@ -6,55 +6,178 @@ var SVG_MARGINY = 50; var VIEW_MIRROR = 0; -var SUGGESTED_ELEM_SIZEX = 25; // suggested size of elements -var SUGGESTED_ELEM_SIZEY = 25; // suggested size of elements +// ------ Move Object ----- +// Create a move from the string [s]. +function Move (s) { + var vals = []; + var arr = strip('(', ')', s).split(','); + for (var i = 0; i < arr.length; i++) { + if (arr[i].indexOf(':') > -1) { + var v = arr[i].substring (arr[i].indexOf(':')+1, arr[i].length); + vals.push (strip ('\'', ' ', strip ('{', '}', v))); + } + } + vals.sort (); + this.matched = vals; + this.length = vals.length; + this.rule = strip ("'", " ", + s.substring (s.indexOf("},")+3, s.lastIndexOf(','))); + this.matched_str = strip (' ', ' ', this.matched.toString ()); + this.def_str = s; + return (this) +} -// ------ Drawing functions ---- +function move_did_match (s) { + for (var i = 0; i < this.matched.length; i++) { + if (this.matched[i] == s) { return (true) } + } + return (false); +} +Move.prototype.did_match = move_did_match; -// Create basic svg box. -function create_svg_box (margx, margy, parent_id) { - SVG_MARGINX = margx; - SVG_MARGINY = margx; - var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); - svg.setAttribute('id', 'svg'); - var wx = SVG_WIDTH + 2*SVG_MARGINX + 20; - var wy = SVG_HEIGHT + 2*SVG_MARGINY + 20; - svg.setAttribute('viewBox', '-10 -10 ' + wx + " " + wy); - document.getElementById(parent_id).appendChild(svg); + +// --------- Elem and Rel Objects ----- + +function Elem (id, x, y) { + this.id = id; + this.x = x; + this.y = y; } -// Draw the model. -function draw_model (game, state) { - var sqrt = Math.round (Math.sqrt (state.elems.length)); - if (sqrt * sqrt == state.elems.length) { // perhaps a grid - SUGGESTED_ELEM_SIZEX = SVG_WIDTH / (2.0 * (sqrt-1)); - SUGGESTED_ELEM_SIZEY = SVG_HEIGHT / (2.0 * (sqrt-1)); +function Rel (name, args) { + this.name = name; + this.args = args; +} + + +// --------- State Object ------ + + +// Object representing a state of the system (game). +function State (game, info_string) { + // We create an SVG box with margins depending on the game. + this.game = game; + + var create_svg_box = function (margx, margy, parent_id) { + SVG_MARGINX = margx; + SVG_MARGINY = margx; + var svg = document.createElementNS('http://www.w3.org/2000/svg','svg'); + svg.setAttribute('id', 'svg'); + var wx = SVG_WIDTH + 2*SVG_MARGINX + 20; + var wy = SVG_HEIGHT + 2*SVG_MARGINY + 20; + svg.setAttribute('viewBox', '-10 -10 ' + wx + " " + wy); + document.getElementById(parent_id).appendChild(svg); + } + + if (game == "Tic-Tac-Toe" || game == "Concurrent-Tic-Tac-Toe") { + create_svg_box (130, 130, "board"); // bigger margins needed } else { - SUGGESTED_ELEM_SIZEX = SVG_WIDTH / 20; - SUGGESTED_ELEM_SIZEY = SVG_HEIGHT / 20; + create_svg_box (40, 40, "board"); } - draw_background (game); - for (var i = 0; i < state.elems.length; i++) { - draw_elem (game, state.elems[i]); + + // Private: Translate position from Model coordinates to SVG coordinates. + var translate_pos = function (pos, minx, miny, width, height) { + var x = ((pos[0] - minx) * SVG_WIDTH) / width; + if (VIEW_MIRROR == 0) { + var y = ((pos[1] - miny) * SVG_HEIGHT) / height; + } else { + var y = ((height - (pos[1] - miny))*SVG_WIDTH) / height; + } + return ([x + SVG_MARGINX, y + SVG_MARGINY]) + }; + + // The info is a $-separated array of 5 components. + var res_arr = []; + res_arr = info_string.split("$"); + if (res_arr.length != 5) { alert (res_arr); return (undefined); } + + // The first component gives the dimenstions of the structure. + var dim = strip('(', ')', res_arr[0]).split(','); + this.maxx = parseFloat(strip(' ', ' ', dim[0])); + this.minx = parseFloat(strip(' ', ' ', dim[1])); + this.maxy = parseFloat(strip(' ', ' ', dim[2])); + this.miny = parseFloat(strip(' ', ' ', dim[3])); + this.width = Math.max (SVG_WIDTH / 100, (this.maxx - this.minx)); + this.height = Math.max (SVG_HEIGHT / 100, (this.maxy - this.miny)); + + // The second component is the list of elements of the structure. + var l = convert_python_list(',', res_arr[1]); + this.elems = []; + for (var i = 0; i < l.length; i++) { + var e = convert_python_list (';', l[i]); + var pos = translate_pos ([parseFloat(e[1]), parseFloat(e[2])], + this.minx, this.miny, this.width, this.height); + this.elems.push (new Elem (e[0], pos[0], pos[1])); } - for (var i = 0; i < state.rels.length; i++) { - draw_rel (game, state.rels[i]); + + var find_elem = function (elem_id, els) { + for (var i = 0; i < els.length; i++) { + if (els[i].id == elem_id) { return (els[i]); } + } + return (undefined); } + + // The third component are the relations in the structure. + var r = convert_python_list(';', res_arr[2]); + var rels = []; + for (var i = 0; i < r.length; i++) { + var rel_name = strip(' ', '\'', r[i].substring(1,r[i].indexOf(','))); + var args_s = r[i].substring(r[i].indexOf('[')+1, r[i].indexOf(']')); + var args = convert_python_list (',', args_s); + var is_undefined = false; + for (var j = 0; j < args.length; j++) { + args[j] = find_elem (args[j], this.elems); + if (args[j] == undefined) { is_undefined = true }; + } + if (rel_name[0] != "_" && args_s != "''" && is_undefined == false) { + rels.push (new Rel (rel_name, args)); + } + } + this.rels = rels; + + // The fourth component is either the list of possible moves. + // If there are no moves possible, it is the payoff. + if (res_arr[3].substring(2, 3) == "(") { + var move_strs = convert_python_list (';', res_arr[3]); + var mvs = []; + for (i = 0; i < move_strs.length; i++) { + mvs.push (new Move (move_strs[i])); + } + this.moves = mvs; + this.payoff = ""; + } else { + this.moves = []; + this.payoff = res_arr[3]; + }; + + // The last component is the player (to be removed). + this.PLAYER_STR = res_arr[4]; + + return (this); } -// Mostly we skip background drawings, but when needed, they are here. -function draw_background (game) { - var x = SVG_MARGINX; - var y = SVG_MARGINY; - var w = SVG_WIDTH + 2 * x; - var h = SVG_HEIGHT + 2 * x; - var bg = SHAPES.background_svg (game, 0, 0, w, h, []); - if (bg != undefined) { document.getElementById("svg").appendChild(bg); } +// Get moves applicable to [elem] in a game. +function state_get_moves (elem, other) { + var elem_moves = []; + for (i = 0; i < this.moves.length; i++) { + if (this.moves[i].did_match(elem)) { + if (other == "") { + elem_moves.push(this.moves[i]) + } else if (this.moves[i].did_match(other)) { + elem_moves.push(this.moves[i]) + } + } + } + return (elem_moves) } +State.prototype.get_moves = state_get_moves; -// To draw chess board we distinguish even/odd placed elements. + +// ------ Drawing functions ---- + +// Helper: to draw chess board we distinguish even/odd placed elements. function elem_class (elemid) { var elem_cl = "model-elem"; var is_int = function (s) { return (parseInt(s).toString() == s) }; @@ -65,68 +188,106 @@ return (elem_cl); } -// Draw the element [elem]. -function draw_elem (game, elem) { - if (game != "Connect4") { - var r = SHAPES.rect ( - elem.x, elem.y, 2 * SUGGESTED_ELEM_SIZEX, 2 * SUGGESTED_ELEM_SIZEY, - [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], - ["onclick", ("handle_elem_click('" + elem.id + "')")]]); - document.getElementById("svg").appendChild(r); +// Draw the model. +function state_draw_model (game) { + var draw_background = function (game) { + var x = SVG_MARGINX; + var y = SVG_MARGINY; + var w = SVG_WIDTH + 2 * x; + var h = SVG_HEIGHT + 2 * x; + var bg = SHAPES.background_svg (game, 0, 0, w, h, []); + if (bg != undefined) {document.getElementById("svg").appendChild(bg);} + } + + // Draw the element [elem]. + var draw_elem = function (game, elem) { + if (game != "Connect4") { + var r = SHAPES.rect ( + elem.x, elem.y, 2 * SHAPES.elem_size_x, 2 * SHAPES.elem_size_y, + [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], + ["onclick", ("handle_elem_click('" + elem.id + "')")]]); + document.getElementById("svg").appendChild(r); + } else { + var circ = SHAPES.circle ( + elem.x, elem.y, 30, + [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], + ["onclick", "handle_elem_click('" + elem.id + "')"]]); + document.getElementById("svg").appendChild(circ); + } + } + + + // Draw relation [rel_name] between elements [args]. + function draw_rel (game, rel) { + if (rel.args.length == 1) { + var ihatrs = [["id", "pred_" + rel.args[0].id + "_" + rel.name], + ["onclick","handle_elem_click('"+rel.args[0].id+"')"]] + var pos = [rel.args[0].x, rel.args[0].y]; + var f = SHAPES.rel_svg (game, pos[0],pos[1],20,20, rel.name,ihatrs); + if (f != undefined) { + document.getElementById("svg").appendChild(f); + } else { + var circ = SHAPES.circle ( + pos[0], pos[1], SHAPES.elem_size_x - 10, + [["id", "pred_" + rel.args[0].id + "_" + rel.name], + ["class", "model-pred-" + rel.name], + ["stroke-width", (SHAPES.elem_size_x / 10) + 2], + ["onclick", ("handle_elem_click('"+rel.args[0].id+"')")]]); + document.getElementById("svg").appendChild(circ); + } + } + if (rel.args.length == 2) { + if (rel.name == "E") { + var l = SHAPES.line (rel.args[0].x, rel.args[0].y, + rel.args[1].x, rel.args[1].y, + [["class", "model-edge-E"]]); + document.getElementById("svg").appendChild(l); + } + } + } + + // Main draw_model function. + var sqrt = Math.round (Math.sqrt (this.elems.length)); + if (sqrt * sqrt == this.elems.length) { // perhaps a grid + SHAPES.elem_size_x = SVG_WIDTH / (2.0 * (sqrt-1)); + SHAPES.elem_size_y = SVG_HEIGHT / (2.0 * (sqrt-1)); } else { - var circ = SHAPES.circle ( - elem.x, elem.y, 30, - [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], - ["onclick", "handle_elem_click('" + elem.id + "')"]]); - document.getElementById("svg").appendChild(circ); + SHAPES.elem_size_x = SVG_WIDTH / 20; + SHAPES.elem_size_y = SVG_HEIGHT / 20; } + draw_background (game); + for (var i = 0; i < this.elems.length; i++) { + draw_elem (game, this.elems[i]); + } + for (var i = 0; i < this.rels.length; i++) { + draw_rel (game, this.rels[i]); + } } +State.prototype.draw_model = state_draw_model; // Highlight the element [elem]. -function highlight_elem (elemid) { +function state_highlight_elem (elemid) { var e = document.getElementById ("elem_" + elemid); e.setAttribute ("class", "model-elem-highlight"); } +State.prototype.highlight_elem = state_highlight_elem; // Unhighlight the element [elem]. -function unhighlight_elem (elemid) { +function state_unhighlight_elem (elemid) { var e = document.getElementById ("elem_" + elemid); e.setAttribute ("class", elem_class(elemid)); } +State.prototype.unhighlight_elem = state_unhighlight_elem; -// Draw relation [rel_name] between elements [args]. -function draw_rel (game, rel) { - if (rel.args.length == 1) { - var ihatrs = [["id", "pred_" + rel.args[0].id + "_" + rel.name], - ["onclick", "handle_elem_click('"+ rel.args[0].id +"')"]] - var pos = [rel.args[0].x, rel.args[0].y]; - var f = SHAPES.rel_svg (game, pos[0],pos[1],20,20, rel.name,ihatrs); - if (f != undefined) { - document.getElementById("svg").appendChild(f); - } else { - var circ = SHAPES.circle ( - pos[0], pos[1], SUGGESTED_ELEM_SIZEX - 10, - [["id", "pred_" + rel.args[0].id + "_" + rel.name], - ["class", "model-pred-" + rel.name], - ["stroke-width", (SUGGESTED_ELEM_SIZEX / 10) + 2], - ["onclick", ("handle_elem_click('"+ rel.args[0].id +"')")]]); - document.getElementById("svg").appendChild(circ); - } - } - if (rel.args.length == 2) { - if (rel.name == "E") { - var l = SHAPES.line (rel.args[0].x, rel.args[0].y, - rel.args[1].x, rel.args[1].y, - [["class", "model-edge-E"]]); - document.getElementById("svg").appendChild(l); - } - } -} + // ------------ Shape Drawings in SVG ------------------- function Shapes () { + this.elem_size_x = 25; // suggested size of elements + this.elem_size_y = 25; // suggested size of elements + var DEFpawn = '<g transform="translate(-22.5,-22.5)"> \ <path \ d="M 22,9 C 19.792,9 18,10.792 18,13 C 18,13.885 18.294,14.712 18.781,15.375 C 16.829,16.497 15.5,18.588 15.5,21 C 15.5,23.034 16.442,24.839 17.906,26.031 C 14.907,27.089 10.5,31.578 10.5,39.5 L 33.5,39.5 C 33.5,31.578 29.093,27.089 26.094,26.031 C 27.558,24.839 28.5,23.034 28.5,21 C 28.5,18.588 27.171,16.497 25.219,15.375 C 25.706,14.712 26,13.885 26,13 C 26,10.792 24.208,9 22,9 z " \ @@ -294,11 +455,11 @@ // Create new svg element [elem], child of svg, set attributes, scale. - var svg_from_string = function (x, y, sizex, sizey, s, attrs) { + var svg_from_string = function (th, x, y, sizex, sizey, s, attrs) { var parser = new DOMParser (); var svgs = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg">'; - var scfx = (SUGGESTED_ELEM_SIZEX - 10) / sizex; - var scfy = (SUGGESTED_ELEM_SIZEY - 10) / sizey; + var scfx = (th.elem_size_x - 10) / sizex; + var scfy = (th.elem_size_y - 10) / sizey; var sc = "scale(" + scfx + "," + scfy + ")"; var gs = '<g transform="translate(' + x + "," + y + ") " + sc + '">'; var doc = parser.parseFromString(svgs+ gs+ s +'</g></svg>', "text/xml"); @@ -321,13 +482,13 @@ } } if (svg_s == undefined) { return (undefined) }; - return (svg_from_string (posx, posy, sizex, sizey, svg_s, attrs)); + return (svg_from_string (this, posx, posy, sizex, sizey, svg_s, attrs)); } this.rel_svg = shapes_rel_svg; var shapes_circle = function (cx, cy, r, attrs) { - return (svg_from_string (cx, cy, SUGGESTED_ELEM_SIZEX - 10, - SUGGESTED_ELEM_SIZEY - 10, + return (svg_from_string (this, cx, cy, + this.elem_size_x - 10, this.elem_size_y - 10, '<circle cx="0" cy="0" r="' + r + '" />', attrs)); } @@ -335,8 +496,8 @@ var shapes_rect = function (x, y, w, h, attrs) { var rs = '<rect x="0" y="0" width="' + w + '" height="' + h + '" />' - return (svg_from_string (x - w/2, y - w/2, SUGGESTED_ELEM_SIZEX - 10, - SUGGESTED_ELEM_SIZEY - 10, rs, attrs)); + return (svg_from_string (this, x - w/2, y - w/2, this.elem_size_x - 10, + this.elem_size_y - 10, rs, attrs)); } this.rect = shapes_rect; @@ -346,25 +507,25 @@ else if (x < -0.01) { return (-1); } else { return (0); } } - var dx = SUGGESTED_ELEM_SIZEX * sign (x1 - x2); - var dy = SUGGESTED_ELEM_SIZEY * sign (y1 - y2); + var dx = this.elem_size_x * sign (x1 - x2); + var dy = this.elem_size_y * sign (y1 - y2); var nx1 = x1 - dx; var nx2 = x2 + dx; var ny1 = y1 - dy; var ny2 = y2 + dy; var ls = '<line x1="' + nx1 + '" y1="' + ny1 + '" x2="' + nx2 + '" y2="' + ny2 + '" />'; - return (svg_from_string (0, 0, SUGGESTED_ELEM_SIZEX - 10, - SUGGESTED_ELEM_SIZEY - 10, ls, attrs)); + return (svg_from_string (this, 0, 0, this.elem_size_x - 10, + this.elem_size_y - 10, ls, attrs)); } this.line = shapes_line; var shapes_background_svg = function (game, x, y, w, h, attrs) { var bg = background[game]; if (bg == undefined) { return (undefined); } - var ws = (SUGGESTED_ELEM_SIZEX - 10) / (w / 500); - var hs = (SUGGESTED_ELEM_SIZEY - 10) / (h / 500); - return (svg_from_string (x, y, ws, hs, bg, attrs)); + var ws = (this.elem_size_x - 10) / (w / 500); + var hs = (this.elem_size_y - 10) / (h / 500); + return (svg_from_string (this, x, y, ws, hs, bg, attrs)); } this.background_svg = shapes_background_svg; Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-05-29 17:55:27 UTC (rev 1464) +++ trunk/Toss/WebClient/Main.js 2011-05-30 01:25:16 UTC (rev 1465) @@ -1,5 +1,8 @@ // JavaScript Toss Module -- Main (requires Connect.js, DefaultStyle.js) +var UNAME = ""; +var GAME_NAME = ""; // name of current game, e.g. "Breakthrough" + var ELEM_COUNTERS = {}; var CUR_MOVE = ""; var CUR_ELEMS = []; @@ -29,7 +32,7 @@ CUR_ELEMS = []; document.getElementById('cur-move').innerHTML = "none"; var svg_e = document.getElementById("svg"); - svg_e.parentNode.removeChild (svg_e); + if (svg_e != undefined) { svg_e.parentNode.removeChild (svg_e); } } function win_s (i) { @@ -52,17 +55,17 @@ } // Full redraw. -function full_redraw () { +function full_redraw (game, info_s) { clear_svg (); + ST = new State (game, info_s); + ST.draw_model (game); if (! SIMPLE_MOVES) { document.getElementById("working").style.display = "block"; } for (var i = 0; i < ST.elems.length; i++) { ELEM_COUNTERS[ST.elems[i].id] = 0; } - create_svg_box (SVG_MARGINX, SVG_MARGINY, "board"); - draw_model (GAME_NAME, ST); - if (ST.payoff == "") { + if (ST.payoff == "") { document.getElementById('movebt').innerHTML = "Make move:"; document.getElementById('cur-move').innerHTML = "none"; } else { @@ -82,10 +85,10 @@ // Helper function: highlight move, unhighlight old, save current. function show_move (m) { for (var i = 0; i < CUR_ELEMS.length; i++) { - unhighlight_elem (CUR_ELEMS[i]); + ST.unhighlight_elem (CUR_ELEMS[i]); } for (var i = 0; i < m.matched.length; i++) { - highlight_elem (m.matched[i]); + ST.highlight_elem (m.matched[i]); } if (m.matched_str == "") { document.getElementById('cur-move').innerHTML = "none"; @@ -107,7 +110,7 @@ }; if (moves.length == 0) { // still no moves, unhighlight for (var i = 0; i < CUR_ELEMS.length; i++) { - unhighlight_elem (CUR_ELEMS[i]); + ST.unhighlight_elem (CUR_ELEMS[i]); } CUR_ELEMS = []; CUR_MOVE = ""; @@ -135,10 +138,10 @@ }; if (moves.length > 1 && LAST_CLICKED_ELEM == "") { for (var i = 0; i < CUR_ELEMS.length; i++) { - unhighlight_elem (CUR_ELEMS[i]); + ST.unhighlight_elem (CUR_ELEMS[i]); } document.getElementById('cur-move').innerHTML = elem + " — ?" - highlight_elem (elem); + ST.highlight_elem (elem); CUR_ELEMS = [elem]; CUR_MOVE = ""; }; @@ -146,8 +149,7 @@ } function play_py_id (i) { - return ("'" + GAME_NAME + "', '" + PLAYS[i][0] + "', '" + - PLAYS[i][1] + "', '" + PLAYS[i][2] + "', '" + PLAYS[i][3] + "'") + return (PLAYS[i][2]) } function disp_name (uname) { @@ -196,25 +198,16 @@ } -function game_click (game) { +function play_click (game, play_id, pi) { + document.getElementById("opponents").style.display = "none"; + list_plays (game); document.getElementById("welcome").style.display = "none"; document.getElementById("game-disp").style.display = "none"; document.getElementById("plays").style.display = "none"; GAME_NAME = game; - if (game == "Tic-Tac-Toe" || game == "Concurrent-Tic-Tac-Toe") { - create_svg_box (130, 130, "board"); // bigger margins needed - } else { - create_svg_box (40, 40, "board"); - } var gd = document.getElementById("game-disp"); gd.style.display = "block"; gd.setAttribute ("class", "Game-" + game); -} - -function play_click (game, play_id, pi) { - document.getElementById("opponents").style.display = "none"; - list_plays (game); - game_click (game); document.getElementById ("game-title").innerHTML = game; document.getElementById("game-disp").style.display = "block"; document.getElementById("play-number").innerHTML = "" + play_id; @@ -222,12 +215,9 @@ if (game == "Connect4") { VIEW_MIRROR = 0; } else { VIEW_MIRROR = (PLAYS[CUR_PLAY_I][0] == UNAME) ? 0 : 1; } - document.getElementById("cur-player").innerHTML = - disp_name(PLAYS[CUR_PLAY_I][PLAYS[CUR_PLAY_I][3]]); var info = CONN.open_db (play_py_id (pi)); - ST = new State (info); document.getElementById("suggestions-toggle").style.display = "inline"; - full_redraw (); + full_redraw (GAME_NAME, info); } @@ -247,16 +237,8 @@ } function make_move_continue (info) { - ST = new State (info); - CUR_MOVE = ""; - CUR_ELEMS = []; - ELEM_COUNTERS = {}; - PLAYS[CUR_PLAY_I][3] = ST.PLAYER_STR; - document.getElementById("cur-player").innerHTML = - disp_name(PLAYS[CUR_PLAY_I][ST.PLAYER_STR]); document.getElementById("working").style.display = "none"; - full_redraw (); - CONN.upd_svg (play_py_id(CUR_PLAY_I), svg_string()); + full_redraw (GAME_NAME, info); var old_li = document.getElementById ("plays-list-" + GAME_NAME + "-elem-" + CUR_PLAY_I); var li = new_play_item (GAME_NAME, CUR_PLAY_I); @@ -392,8 +374,13 @@ } function new_play_do (opp_uid, vm) { - list_plays (GAME_NAME) - game_click (GAME_NAME) + list_plays (GAME_NAME); + document.getElementById("welcome").style.display = "none"; + document.getElementById("game-disp").style.display = "none"; + document.getElementById("plays").style.display = "none"; + var gd = document.getElementById("game-disp"); + gd.style.display = "block"; + gd.setAttribute ("class", "Game-" + GAME_NAME); document.getElementById ("game-title").innerHTML = GAME_NAME; document.getElementById("opponents").style.display = "none"; var olist = document.getElementById("opponents-list"); @@ -405,19 +392,16 @@ info_nbr = CONN.new_play (GAME_NAME, UNAME, opp_uid); document.getElementById("working").style.display = "none"; document.getElementById("suggestions-toggle").style.display = "inline"; - info_idx = info_nbr.indexOf('$'); + info_idx = info_nbr.indexOf('$'); FREE_PLAY_NO = parseInt(info_nbr.substring(0, info_idx)); document.getElementById("play-number").innerHTML = "" + FREE_PLAY_NO; CUR_PLAY_I = PLAYS.length; VIEW_MIRROR = vm; - document.getElementById("cur-player").innerHTML = disp_name(UNAME); document.getElementById("game-disp").style.display = "block"; document.getElementById("plays").style.left = "30em"; - var p = [UNAME, opp_uid, FREE_PLAY_NO, 0]; + var p = [UNAME, opp_uid, FREE_PLAY_NO]; PLAYS.push(p); - ST = new State (info_nbr.substring(info_idx+1)); - full_redraw (); - CONN.upd_svg (play_py_id(CUR_PLAY_I), svg_string()); + full_redraw (GAME_NAME, info_nbr.substring(info_idx+1)); li = new_play_item (GAME_NAME, CUR_PLAY_I); document.getElementById("plays-list-" + GAME_NAME).appendChild(li); } Deleted: trunk/Toss/WebClient/State.js =================================================================== --- trunk/Toss/WebClient/State.js 2011-05-29 17:55:27 UTC (rev 1464) +++ trunk/Toss/WebClient/State.js 2011-05-30 01:25:16 UTC (rev 1465) @@ -1,148 +0,0 @@ -// JavaScript Toss Module -- State representation and parsing. - -// ------ Move Object ----- - -// Create a move from the string [s]. -function Move (s) { - var vals = []; - var arr = strip('(', ')', s).split(','); - for (var i = 0; i < arr.length; i++) { - if (arr[i].indexOf(':') > -1) { - var v = arr[i].substring (arr[i].indexOf(':')+1, arr[i].length); - vals.push (strip ('\'', ' ', strip ('{', '}', v))); - } - } - vals.sort (); - this.matched = vals; - this.length = vals.length; - this.rule = strip ("'", " ", - s.substring (s.indexOf("},")+3, s.lastIndexOf(','))); - this.matched_str = strip (' ', ' ', this.matched.toString ()); - this.def_str = s; - return (this) -} - -function move_did_match (s) { - for (var i = 0; i < this.matched.length; i++) { - if (this.matched[i] == s) { return (true) } - } - return (false); -} -Move.prototype.did_match = move_did_match; - - -// --------- Elem and Rel Objects ----- - -function Elem (id, x, y) { - this.id = id; - this.x = x; - this.y = y; -} - -function Rel (name, args) { - this.name = name; - this.args = args; -} - - -// --------- State Object ------ - - -// Object representing a state of the system (game). -function State (info_string) { - // Private: Translate position from Model coordinates to SVG coordinates. - var translate_pos = function (pos, minx, miny, width, height) { - var x = ((pos[0] - minx) * SVG_WIDTH) / width; - if (VIEW_MIRROR == 0) { - var y = ((pos[1] - miny) * SVG_HEIGHT) / height; - } else { - var y = ((height - (pos[1] - miny))*SVG_WIDTH) / height; - } - return ([x + SVG_MARGINX, y + SVG_MARGINY]) - }; - - // The info is a $-separated array of 5 components. - var res_arr = []; - res_arr = info_string.split("$"); - if (res_arr.length != 5) { alert (res_arr); return (undefined); } - - // The first component gives the dimenstions of the structure. - var dim = strip('(', ')', res_arr[0]).split(','); - this.maxx = parseFloat(strip(' ', ' ', dim[0])); - this.minx = parseFloat(strip(' ', ' ', dim[1])); - this.maxy = parseFloat(strip(' ', ' ', dim[2])); - this.miny = parseFloat(strip(' ', ' ', dim[3])); - this.width = Math.max (SVG_WIDTH / 100, (this.maxx - this.minx)); - this.height = Math.max (SVG_HEIGHT / 100, (this.maxy - this.miny)); - - // The second component is the list of elements of the structure. - var l = convert_python_list(',', res_arr[1]); - this.elems = []; - for (var i = 0; i < l.length; i++) { - var e = convert_python_list (';', l[i]); - var pos = translate_pos ([parseFloat(e[1]), parseFloat(e[2])], - this.minx, this.miny, this.width, this.height); - this.elems.push (new Elem (e[0], pos[0], pos[1])); - } - - var find_elem = function (elem_id, els) { - for (var i = 0; i < els.length; i++) { - if (els[i].id == elem_id) { return (els[i]); } - } - return (undefined); - } - - // The third component are the relations in the structure. - var r = convert_python_list(';', res_arr[2]); - var rels = []; - for (var i = 0; i < r.length; i++) { - var rel_name = strip(' ', '\'', r[i].substring(1,r[i].indexOf(','))); - var args_s = r[i].substring(r[i].indexOf('[')+1, r[i].indexOf(']')); - var args = convert_python_list (',', args_s); - var is_undefined = false; - for (var j = 0; j < args.length; j++) { - args[j] = find_elem (args[j], this.elems); - if (args[j] == undefined) { is_undefined = true }; - } - if (rel_name[0] != "_" && args_s != "''" && is_undefined == false) { - rels.push (new Rel (rel_name, args)); - } - } - this.rels = rels; - - // The fourth component is either the list of possible moves. - // If there are no moves possible, it is the payoff. - if (res_arr[3].substring(2, 3) == "(") { - var move_strs = convert_python_list (';', res_arr[3]); - var mvs = []; - for (i = 0; i < move_strs.length; i++) { - mvs.push (new Move (move_strs[i])); - } - this.moves = mvs; - this.payoff = ""; - } else { - this.moves = []; - this.payoff = res_arr[3]; - }; - - // The last component is the player (to be removed). - this.PLAYER_STR = res_arr[4]; - - return (this); -} - -// Get moves applicable to [elem] in a game. -function state_get_moves (elem, other) { - var elem_moves = []; - for (i = 0; i < this.moves.length; i++) { - if (this.moves[i].did_match(elem)) { - if (other == "") { - elem_moves.push(this.moves[i]) - } else if (this.moves[i].did_match(other)) { - elem_moves.push(this.moves[i]) - } - } - } - return (elem_moves) -} -State.prototype.get_moves = state_get_moves; Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-05-29 17:55:27 UTC (rev 1464) +++ trunk/Toss/WebClient/Style.css 2011-05-30 01:25:16 UTC (rev 1465) @@ -651,7 +651,7 @@ padding: 1em; } -#cur-move, #cur-player { +#cur-move { margin-top: 0em; margin-bottom: 0em; } Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-05-29 17:55:27 UTC (rev 1464) +++ trunk/Toss/WebClient/index.html 2011-05-30 01:25:16 UTC (rev 1465) @@ -11,7 +11,6 @@ <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> <script type="text/javascript" src="crypto-sha256.js"> </script> <script type="text/javascript" src="Connect.js"> </script> - <script type="text/javascript" src="State.js"> </script> <script type="text/javascript" src="Drawing.js"> </script> <script type="text/javascript" src="Main.js"> </script> <script type="text/javascript" src="Login.js"> </script> @@ -289,7 +288,6 @@ </p> <p id="move-info-par"> - <span style="display: none;">Moves: <span id="cur-player">?</span></span> <button id="movebt" class="bt" onclick="make_move ()">Make move:</button> <span id="cur-move">none</span> <button id="sugbt" class="bt" onclick="suggest_move_click()"> Modified: trunk/Toss/WebClient/profile.html =================================================================== --- trunk/Toss/WebClient/profile.html 2011-05-29 17:55:27 UTC (rev 1464) +++ trunk/Toss/WebClient/profile.html 2011-05-30 01:25:16 UTC (rev 1465) @@ -9,7 +9,6 @@ <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> <script type="text/javascript" src="crypto-sha256.js"> </script> <script type="text/javascript" src="Connect.js"> </script> - <script type="text/javascript" src="State.js"> </script> <script type="text/javascript" src="Drawing.js"> </script> <script type="text/javascript" src="Main.js"> </script> <script type="text/javascript" src="Login.js"> </script> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-30 20:31:09
|
Revision: 1466 http://toss.svn.sourceforge.net/toss/?rev=1466&view=rev Author: lukaszkaiser Date: 2011-05-30 20:31:01 +0000 (Mon, 30 May 2011) Log Message: ----------- More JavaScript orders. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/index.html trunk/Toss/WebClient/profile.html Added Paths: ----------- trunk/Toss/WebClient/State.js Removed Paths: ------------- trunk/Toss/WebClient/Drawing.js Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-05-30 01:25:16 UTC (rev 1465) +++ trunk/Toss/Server/ReqHandler.ml 2011-05-30 20:31:01 UTC (rev 1466) @@ -257,14 +257,9 @@ let moves = List.fold_left append_move [] (client_get_loc_moves cur_loc) in String.concat "; " (List.map client_move_str moves) -let client_get_loc_player i = - let msg = client_msg ("GET LOC PLAYER " ^ i) in - if (String.length msg > 3 && String.sub msg 0 3 = "ERR") then "-1" else msg - let client_make_move m r endp = let _ = client_apply_rule r m "1.0" [] in - client_set_cur_loc endp; - client_get_loc_player endp + client_set_cur_loc endp let client_get_data data_id = let m = client_msg ("GET DATA " ^ data_id) in @@ -285,13 +280,14 @@ let m = client_msg ("EVAL LOC MOVES " ^ advr ^ ".0 " ^ loc ^ " TIMEOUT " ^ timeout ^ " 55500 alpha_beta_ord") in client_set_time ts t; + print_endline m; let msg = Array.map strip_ws (split ";" m) in if Array.length msg < 2 then "" else let append_emb emb s = let es = Array.map strip_ws (split ":" s) in (es.(0), es.(1)) :: emb in let emb = List.fold_left append_emb [] (split_list "," msg.(1)) in - client_move_str (string_of_int pl, emb, msg.(0), msg.(3)) + client_move_str (pl, emb, msg.(0), msg.(3)) let client_model_get_elem_val el_id vl = @@ -473,12 +469,11 @@ let info = client_get_game_info () in let model = client_get_model () in let loc = client_get_cur_loc () in - let move_pl = int_of_string (client_get_loc_player loc) - 1 in get_global_lock (); let pid = string_of_int (get_free_id ()) in - db_cur_insert game pl1 pl2 pid (string_of_int move_pl) model loc info ""; + db_cur_insert game pl1 pl2 pid "0" model loc info ""; release_global_lock (); - pid ^ "$" ^ info ^ "$" ^ (string_of_int move_pl) in + pid ^ "$" ^ info in let game_select_s pid = "playid=" ^ pid in let db_escape s = str_replace "'" "''" s in let move_play move_tup pid = @@ -492,7 +487,7 @@ client_set_cur_loc old_loc; let (move1a, move2, move3) = move_tup in let move1 = strip_all ["{"; "}"] move1a in - let new_pl = int_of_string (client_make_move move1 move2 move3) - 1 in + client_make_move move1 move2 move3; let new_toss = db_escape (client_get_model ()) in let new_info = client_get_game_info () in let new_info_db = db_escape new_info in @@ -501,12 +496,12 @@ cur_upd ("toss='" ^ new_toss ^ "'"); cur_upd ("info='" ^ new_info_db ^ "'"); cur_upd ("loc='" ^ move3 ^ "'"); - cur_upd ("move=" ^ (string_of_int new_pl)); + cur_upd ("move=" ^ (string_of_int ((int_of_string m) + 1))); DB.insert_table dbFILE "old_states" "playid, game, player1, player2, move, toss, loc, info, svg" [pid; g; p1; p2; m; old_toss; old_loc; old_info; old_svg]; - new_info ^ "$" ^ (string_of_int new_pl) in - let suggest time pid = + new_info in + let suggest player time pid = let res = List.hd (dbtable (game_select_s pid) "cur_states") in let (g, m, toss, loc) = (res.(1),int_of_string res.(4), res.(5), res.(6)) in let game_toss = (List.hd (dbtable ("game='" ^ g ^ "'") "games")).(1) in @@ -514,7 +509,7 @@ client_set_cur_loc loc; let adv_ratio_data = client_get_data "adv_ratio" in let adv_ratio = if adv_ratio_data = "none" then "4" else adv_ratio_data in - client_suggest (m+1) time adv_ratio in + client_suggest player time adv_ratio in let register_user ui = if Array.length ui <> 5 then false else let (uid, name, surname, email, pwd) = @@ -538,7 +533,7 @@ let open_db pid = let res = dbtable (game_select_s pid) "cur_states" in let (move, info) = ((List.hd res).(4), (List.hd res).(7)) in - info ^ "$" ^ move in + info in let add_opponent uid oppid = if uid = "" then "You must login first to add opponents." else let (name, _, _) = get_user_name_surname_mail oppid in @@ -599,7 +594,7 @@ | "NEW_PLAY" -> let a = get_args data in new_play a.(0) a.(1) a.(2), [] | "SUGGEST" -> - let a = get_args data in suggest a.(0) a.(1), [] + let a = get_args data in suggest a.(0) a.(1) a.(2), [] | "MOVE_PLAY" -> let (op_i, cl_i) = (String.index data '(', String.index data ')') in let tp_s = String.sub data (op_i+1) (cl_i - op_i-1) in Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-05-30 01:25:16 UTC (rev 1465) +++ trunk/Toss/WebClient/Connect.js 2011-05-30 20:31:01 UTC (rev 1466) @@ -111,8 +111,8 @@ this.make_move = function (move_s, pid, cont) { async_srv("MOVE_PLAY", move_s + ', ' + pid, cont); } - this.suggest = function (time, pid, cont) { - async_srv("SUGGEST", time + ', ' + pid, cont); + this.suggest = function (player, time, pid, cont) { + async_srv("SUGGEST", player + ', ' + time + ', ' + pid, cont); } this.friends = function () { return (srv ("LIST_FRIENDS", "user")); } Deleted: trunk/Toss/WebClient/Drawing.js =================================================================== --- trunk/Toss/WebClient/Drawing.js 2011-05-30 01:25:16 UTC (rev 1465) +++ trunk/Toss/WebClient/Drawing.js 2011-05-30 20:31:01 UTC (rev 1466) @@ -1,535 +0,0 @@ -// JavaScript Toss Module -- Drawing - -var SVG_WIDTH = 500; -var SVG_HEIGHT = 500; -var SVG_MARGINX = 50; -var SVG_MARGINY = 50; -var VIEW_MIRROR = 0; - - -// ------ Move Object ----- - -// Create a move from the string [s]. -function Move (s) { - var vals = []; - var arr = strip('(', ')', s).split(','); - for (var i = 0; i < arr.length; i++) { - if (arr[i].indexOf(':') > -1) { - var v = arr[i].substring (arr[i].indexOf(':')+1, arr[i].length); - vals.push (strip ('\'', ' ', strip ('{', '}', v))); - } - } - vals.sort (); - this.matched = vals; - this.length = vals.length; - this.rule = strip ("'", " ", - s.substring (s.indexOf("},")+3, s.lastIndexOf(','))); - this.matched_str = strip (' ', ' ', this.matched.toString ()); - this.def_str = s; - return (this) -} - -function move_did_match (s) { - for (var i = 0; i < this.matched.length; i++) { - if (this.matched[i] == s) { return (true) } - } - return (false); -} -Move.prototype.did_match = move_did_match; - - -// --------- Elem and Rel Objects ----- - -function Elem (id, x, y) { - this.id = id; - this.x = x; - this.y = y; -} - -function Rel (name, args) { - this.name = name; - this.args = args; -} - - -// --------- State Object ------ - - -// Object representing a state of the system (game). -function State (game, info_string) { - // We create an SVG box with margins depending on the game. - this.game = game; - - var create_svg_box = function (margx, margy, parent_id) { - SVG_MARGINX = margx; - SVG_MARGINY = margx; - var svg = document.createElementNS('http://www.w3.org/2000/svg','svg'); - svg.setAttribute('id', 'svg'); - var wx = SVG_WIDTH + 2*SVG_MARGINX + 20; - var wy = SVG_HEIGHT + 2*SVG_MARGINY + 20; - svg.setAttribute('viewBox', '-10 -10 ' + wx + " " + wy); - document.getElementById(parent_id).appendChild(svg); - } - - if (game == "Tic-Tac-Toe" || game == "Concurrent-Tic-Tac-Toe") { - create_svg_box (130, 130, "board"); // bigger margins needed - } else { - create_svg_box (40, 40, "board"); - } - - // Private: Translate position from Model coordinates to SVG coordinates. - var translate_pos = function (pos, minx, miny, width, height) { - var x = ((pos[0] - minx) * SVG_WIDTH) / width; - if (VIEW_MIRROR == 0) { - var y = ((pos[1] - miny) * SVG_HEIGHT) / height; - } else { - var y = ((height - (pos[1] - miny))*SVG_WIDTH) / height; - } - return ([x + SVG_MARGINX, y + SVG_MARGINY]) - }; - - // The info is a $-separated array of 5 components. - var res_arr = []; - res_arr = info_string.split("$"); - if (res_arr.length != 5) { alert (res_arr); return (undefined); } - - // The first component gives the dimenstions of the structure. - var dim = strip('(', ')', res_arr[0]).split(','); - this.maxx = parseFloat(strip(' ', ' ', dim[0])); - this.minx = parseFloat(strip(' ', ' ', dim[1])); - this.maxy = parseFloat(strip(' ', ' ', dim[2])); - this.miny = parseFloat(strip(' ', ' ', dim[3])); - this.width = Math.max (SVG_WIDTH / 100, (this.maxx - this.minx)); - this.height = Math.max (SVG_HEIGHT / 100, (this.maxy - this.miny)); - - // The second component is the list of elements of the structure. - var l = convert_python_list(',', res_arr[1]); - this.elems = []; - for (var i = 0; i < l.length; i++) { - var e = convert_python_list (';', l[i]); - var pos = translate_pos ([parseFloat(e[1]), parseFloat(e[2])], - this.minx, this.miny, this.width, this.height); - this.elems.push (new Elem (e[0], pos[0], pos[1])); - } - - var find_elem = function (elem_id, els) { - for (var i = 0; i < els.length; i++) { - if (els[i].id == elem_id) { return (els[i]); } - } - return (undefined); - } - - // The third component are the relations in the structure. - var r = convert_python_list(';', res_arr[2]); - var rels = []; - for (var i = 0; i < r.length; i++) { - var rel_name = strip(' ', '\'', r[i].substring(1,r[i].indexOf(','))); - var args_s = r[i].substring(r[i].indexOf('[')+1, r[i].indexOf(']')); - var args = convert_python_list (',', args_s); - var is_undefined = false; - for (var j = 0; j < args.length; j++) { - args[j] = find_elem (args[j], this.elems); - if (args[j] == undefined) { is_undefined = true }; - } - if (rel_name[0] != "_" && args_s != "''" && is_undefined == false) { - rels.push (new Rel (rel_name, args)); - } - } - this.rels = rels; - - // The fourth component is either the list of possible moves. - // If there are no moves possible, it is the payoff. - if (res_arr[3].substring(2, 3) == "(") { - var move_strs = convert_python_list (';', res_arr[3]); - var mvs = []; - for (i = 0; i < move_strs.length; i++) { - mvs.push (new Move (move_strs[i])); - } - this.moves = mvs; - this.payoff = ""; - } else { - this.moves = []; - this.payoff = res_arr[3]; - }; - - // The last component is the player (to be removed). - this.PLAYER_STR = res_arr[4]; - - return (this); -} - -// Get moves applicable to [elem] in a game. -function state_get_moves (elem, other) { - var elem_moves = []; - for (i = 0; i < this.moves.length; i++) { - if (this.moves[i].did_match(elem)) { - if (other == "") { - elem_moves.push(this.moves[i]) - } else if (this.moves[i].did_match(other)) { - elem_moves.push(this.moves[i]) - } - } - } - return (elem_moves) -} -State.prototype.get_moves = state_get_moves; - - -// ------ Drawing functions ---- - -// Helper: to draw chess board we distinguish even/odd placed elements. -function elem_class (elemid) { - var elem_cl = "model-elem"; - var is_int = function (s) { return (parseInt(s).toString() == s) }; - if (is_int (elemid.substring(1))) { - var psum = elemid.charCodeAt(0) + parseInt (elemid.substring(1)); - elem_cl = "model-elem-" + (psum % 2); - }; - return (elem_cl); -} - -// Draw the model. -function state_draw_model (game) { - var draw_background = function (game) { - var x = SVG_MARGINX; - var y = SVG_MARGINY; - var w = SVG_WIDTH + 2 * x; - var h = SVG_HEIGHT + 2 * x; - var bg = SHAPES.background_svg (game, 0, 0, w, h, []); - if (bg != undefined) {document.getElementById("svg").appendChild(bg);} - } - - // Draw the element [elem]. - var draw_elem = function (game, elem) { - if (game != "Connect4") { - var r = SHAPES.rect ( - elem.x, elem.y, 2 * SHAPES.elem_size_x, 2 * SHAPES.elem_size_y, - [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], - ["onclick", ("handle_elem_click('" + elem.id + "')")]]); - document.getElementById("svg").appendChild(r); - } else { - var circ = SHAPES.circle ( - elem.x, elem.y, 30, - [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], - ["onclick", "handle_elem_click('" + elem.id + "')"]]); - document.getElementById("svg").appendChild(circ); - } - } - - - // Draw relation [rel_name] between elements [args]. - function draw_rel (game, rel) { - if (rel.args.length == 1) { - var ihatrs = [["id", "pred_" + rel.args[0].id + "_" + rel.name], - ["onclick","handle_elem_click('"+rel.args[0].id+"')"]] - var pos = [rel.args[0].x, rel.args[0].y]; - var f = SHAPES.rel_svg (game, pos[0],pos[1],20,20, rel.name,ihatrs); - if (f != undefined) { - document.getElementById("svg").appendChild(f); - } else { - var circ = SHAPES.circle ( - pos[0], pos[1], SHAPES.elem_size_x - 10, - [["id", "pred_" + rel.args[0].id + "_" + rel.name], - ["class", "model-pred-" + rel.name], - ["stroke-width", (SHAPES.elem_size_x / 10) + 2], - ["onclick", ("handle_elem_click('"+rel.args[0].id+"')")]]); - document.getElementById("svg").appendChild(circ); - } - } - if (rel.args.length == 2) { - if (rel.name == "E") { - var l = SHAPES.line (rel.args[0].x, rel.args[0].y, - rel.args[1].x, rel.args[1].y, - [["class", "model-edge-E"]]); - document.getElementById("svg").appendChild(l); - } - } - } - - // Main draw_model function. - var sqrt = Math.round (Math.sqrt (this.elems.length)); - if (sqrt * sqrt == this.elems.length) { // perhaps a grid - SHAPES.elem_size_x = SVG_WIDTH / (2.0 * (sqrt-1)); - SHAPES.elem_size_y = SVG_HEIGHT / (2.0 * (sqrt-1)); - } else { - SHAPES.elem_size_x = SVG_WIDTH / 20; - SHAPES.elem_size_y = SVG_HEIGHT / 20; - } - draw_background (game); - for (var i = 0; i < this.elems.length; i++) { - draw_elem (game, this.elems[i]); - } - for (var i = 0; i < this.rels.length; i++) { - draw_rel (game, this.rels[i]); - } -} -State.prototype.draw_model = state_draw_model; - -// Highlight the element [elem]. -function state_highlight_elem (elemid) { - var e = document.getElementById ("elem_" + elemid); - e.setAttribute ("class", "model-elem-highlight"); -} -State.prototype.highlight_elem = state_highlight_elem; - -// Unhighlight the element [elem]. -function state_unhighlight_elem (elemid) { - var e = document.getElementById ("elem_" + elemid); - e.setAttribute ("class", elem_class(elemid)); -} -State.prototype.unhighlight_elem = state_unhighlight_elem; - - - - -// ------------ Shape Drawings in SVG ------------------- - -function Shapes () { - this.elem_size_x = 25; // suggested size of elements - this.elem_size_y = 25; // suggested size of elements - - var DEFpawn = '<g transform="translate(-22.5,-22.5)"> \ - <path \ - d="M 22,9 C 19.792,9 18,10.792 18,13 C 18,13.885 18.294,14.712 18.781,15.375 C 16.829,16.497 15.5,18.588 15.5,21 C 15.5,23.034 16.442,24.839 17.906,26.031 C 14.907,27.089 10.5,31.578 10.5,39.5 L 33.5,39.5 C 33.5,31.578 29.093,27.089 26.094,26.031 C 27.558,24.839 28.5,23.034 28.5,21 C 28.5,18.588 27.171,16.497 25.219,15.375 C 25.706,14.712 26,13.885 26,13 C 26,10.792 24.208,9 22,9 z " \ - class="chess-path-A" /> \ - </g>'; - - var DEFknight = '<g transform="translate(-22.5,-22.5)"> \ - <path \ - d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18" \ - class="chess-path-B" /> \ - <path \ - d="M 24,18 C 24.384,20.911 18.447,25.369 16,27 C 13,29 13.181,31.343 11,31 C 9.9583,30.056 12.413,27.962 11,28 C 10,28 11.187,29.232 10,30 C 9,30 5.9968,31 6,26 C 6,24 12,14 12,14 C 12,14 13.886,12.098 14,10.5 C 13.274,9.5056 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.282,8.0081 21,7 C 22,7 22,10 22,10" \ - class="chess-path-B" /> \ - <path \ - d="M 9 23.5 A 0.5 0.5 0 1 1 8,23.5 A 0.5 0.5 0 1 1 9 23.5 z" \ - transform="translate(0.5,2)" \ - class="chess-path-C" /> \ - <path \ - d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z" \ - transform="matrix(0.866,0.5,-0.5,0.866,9.6926,-5.1734)" \ - class="chess-path-C" /> \ - <path \ - d="M 37,39 C 38,19 31.5,11.5 25,10.5" \ - class="chess-path-D" /> \ - </g>'; - - var DEFbishop = '<g transform="translate(-22.5,-22.5)"> \ - <path \ - d="M 9,36 C 12.385,35.028 19.115,36.431 22.5,34 C 25.885,36.431 32.615,35.028 36,36 C 36,36 37.646,36.542 39,38 C 38.323,38.972 37.354,38.986 36,38.5 C 32.615,37.528 25.885,38.958 22.5,37.5 C 19.115,38.958 12.385,37.528 9,38.5 C 7.6459,38.986 6.6771,38.972 6,38 C 7.3541,36.055 9,36 9,36 z " \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ - <path \ - d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z " \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ - <path \ - d="M 25 10 A 2.5 2.5 0 1 1 20,10 A 2.5 2.5 0 1 1 25 10 z" \ - transform="translate(0,-2)" \ - style="stroke-linecap:butt;" class="chess-path-Bx" /> \ - <path \ - d="M 17.5,26 L 27.5,26" \ - style="stroke-linecap:butt;" class="chess-path-D" /> \ - <path \ - d="M 15,30 L 30,30" \ - style="stroke-linecap:butt;" class="chess-path-D" /> \ - <path \ - d="M 22.5,15.5 L 22.5,20.5" \ - style="stroke-linecap:butt;" class="chess-path-D" /> \ - <path \ - d="M 20,18 L 25,18" \ - style="stroke-linecap:butt;" class="chess-path-D" /> \ - </g>'; - - var DEFrook = '<g transform="translate(-22.5,-22.5)"> \ - <path \ - d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z " \ - style="stroke-linecap:butt;" class="chess-path-Bx" /> \ - <path \ - d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z " \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ - <path \ - d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14" \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ - <path \ - d="M 34,14 L 31,17 L 14,17 L 11,14" \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ - <path \ - d="M 31,17 L 31,29.5 L 14,29.5 L 14,17" \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ - <path \ - d="M 31,29.5 L 32.5,32 L 12.5,32 L 14,29.5" \ - class="chess-path-B" /> \ - <path \ - d="M 11,14 L 34,14" \ - class="chess-path-D" /> \ - </g>'; - - var DEFqueen = '<g transform="translate(-22.5,-22.5)"> \ - <path \ - d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" \ - transform="translate(-1,-1)" \ - style="fill-rule: none;" class="chess-path-B" /> \ - <path \ - d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" \ - transform="translate(15.5,-5.5)" \ - style="fill-rule: none;" class="chess-path-B" /> \ - <path \ - d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" \ - transform="translate(32,-1)" \ - style="fill-rule: none;" class="chess-path-B" /> \ - <path \ - d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" \ - transform="translate(7,-4.5)" \ - style="fill-rule: none;" class="chess-path-B" /> \ - <path \ - d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" \ - transform="translate(24,-4)" \ - style="fill-rule: none;" class="chess-path-B" /> \ - <path \ - d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38,14 L 31,25 L 31,11 L 25.5,24.5 L 22.5,9.5 L 19.5,24.5 L 14,10.5 L 14,25 L 7,14 L 9,26 z " \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ - <path \ - d="M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 10.5,36 10.5,36 C 9,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z " \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ - <path \ - d="M 11.5,30 C 15,29 30,29 33.5,30" \ - class="chess-path-D" /> \ - <path \ - d="M 12,33.5 C 18,32.5 27,32.5 33,33.5" \ - class="chess-path-D" /> \ - <path \ - d="M 10.5,36 C 15.5,35 29,35 34,36" \ - class="chess-path-D" /> \ - </g>'; - - var DEFking = '<g transform="translate(-22.5,-22.5)"> \ - <path d="M 22.5,11.625 L 22.5,6" class="chess-path-B" /> \ - <path d="M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25" \ - style="fill:stroke-linecap:butt;" class="chess-path-B" /> \ - <path d="M 11.5,37 C 17,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 19,16 9.5,13 6.5,19.5 C 3.5,25.5 11.5,29.5 11.5,29.5 L 11.5,37 z " \ - class="chess-path-B" /> \ - <path d="M 20,8 L 25,8" class="chess-path-B" /> \ - <path d="M 11.5,29.5 C 17,27 27,27 32.5,30" class="chess-path-D" /> \ - <path d="M 11.5,37 C 17,34.5 27,34.5 32.5,37" \ - class="chess-path-D" /> \ - <path d="M 11.5,33.5 C 17,31.5 27,31.5 32.5,33.5" \ - class="chess-path-D" /> \ - </g>'; - - var default_rel = {}; - default_rel["wP"] = '<g class="chessW">' + DEFpawn + '</g>'; - default_rel["bP"] = '<g class="chessB">' + DEFpawn + '</g>'; - default_rel["wN"] = '<g class="chessW">' + DEFknight + '</g>'; - default_rel["bN"] = '<g class="chessB">' + DEFknight + '</g>'; - default_rel["wB"] = '<g class="chessW">' + DEFbishop + '</g>'; - default_rel["bB"] = '<g class="chessB">' + DEFbishop + '</g>'; - default_rel["wR"] = '<g class="chessW">' + DEFrook + '</g>'; - default_rel["bR"] = '<g class="chessB">' + DEFrook + '</g>'; - default_rel["wQ"] = '<g class="chessW">' + DEFqueen + '</g>'; - default_rel["Wq"] = '<g class="chessW">' + DEFqueen + '</g>'; - default_rel["bQ"] = '<g class="chessB">' + DEFqueen + '</g>'; - default_rel["Bq"] = '<g class="chessB">' + DEFqueen + '</g>'; - default_rel["wK"] = '<g class="chessW">' + DEFking + '</g>'; - default_rel["bK"] = '<g class="chessB">' + DEFking + '</g>'; - default_rel["P"] = - '<g class="model-pred-P">' + // Cross - '<line x1="-17" y1="-17" x2="17" y2="17" />' + - '<line x1="17" y1="-17" x2="-17" y2="17" /></g>'; - default_rel["Q"] = - '<circle class="model-pred-Q" cx="0" cy="0" r="17" />'; // Circle - - var game_rel = {}; - game_rel["Entanglement"] = {}; - game_rel["Entanglement"]["R"] = - '<circle class="model-pred-R" cx="0" cy="0" r="25" />'; - - game_rel["Connect4"] = {}; - game_rel["Connect4"]["P"] = - '<circle class="model-pred-P" cx="0" cy="0" r="40" />'; - game_rel["Connect4"]["Q"] = - '<circle class="model-pred-Q" cx="0" cy="0" r="40" />'; - - - var background = {}; - background["Connect4"] = '<rect x="0" y="0" width="500" height="500" ' + - 'stroke-width="5" rx="5" ry="5" id="board_connect4" />'; - - - // Create new svg element [elem], child of svg, set attributes, scale. - var svg_from_string = function (th, x, y, sizex, sizey, s, attrs) { - var parser = new DOMParser (); - var svgs = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg">'; - var scfx = (th.elem_size_x - 10) / sizex; - var scfy = (th.elem_size_y - 10) / sizey; - var sc = "scale(" + scfx + "," + scfy + ")"; - var gs = '<g transform="translate(' + x + "," + y + ") " + sc + '">'; - var doc = parser.parseFromString(svgs+ gs+ s +'</g></svg>', "text/xml"); - var elem = document.adoptNode(doc.childNodes[0]).childNodes[0]; - var elem_in = elem.childNodes[0]; - for (var i = 0; i < attrs.length; i++) { - elem_in.setAttribute (attrs[i][0], attrs[i][1].toString()); - } - return (elem); - } - - - // Public methods - - var shapes_rel_svg = function (game, posx, posy, sizex, sizey, rn, attrs) { - var svg_s = default_rel[rn]; - if (game_rel[game] != undefined) { - if (game_rel[game][rn] != undefined) { - svg_s = game_rel[game][rn]; - } - } - if (svg_s == undefined) { return (undefined) }; - return (svg_from_string (this, posx, posy, sizex, sizey, svg_s, attrs)); - } - this.rel_svg = shapes_rel_svg; - - var shapes_circle = function (cx, cy, r, attrs) { - return (svg_from_string (this, cx, cy, - this.elem_size_x - 10, this.elem_size_y - 10, - '<circle cx="0" cy="0" r="' + r + '" />', - attrs)); - } - this.circle = shapes_circle; - - var shapes_rect = function (x, y, w, h, attrs) { - var rs = '<rect x="0" y="0" width="' + w + '" height="' + h + '" />' - return (svg_from_string (this, x - w/2, y - w/2, this.elem_size_x - 10, - this.elem_size_y - 10, rs, attrs)); - } - this.rect = shapes_rect; - - var shapes_line = function (x1, y1, x2, y2, attrs) { - var sign = function (x) { - if (x > 0.01) { return (1); } - else if (x < -0.01) { return (-1); } - else { return (0); } - } - var dx = this.elem_size_x * sign (x1 - x2); - var dy = this.elem_size_y * sign (y1 - y2); - var nx1 = x1 - dx; - var nx2 = x2 + dx; - var ny1 = y1 - dy; - var ny2 = y2 + dy; - var ls = '<line x1="' + nx1 + '" y1="' + ny1 + - '" x2="' + nx2 + '" y2="' + ny2 + '" />'; - return (svg_from_string (this, 0, 0, this.elem_size_x - 10, - this.elem_size_y - 10, ls, attrs)); - } - this.line = shapes_line; - - var shapes_background_svg = function (game, x, y, w, h, attrs) { - var bg = background[game]; - if (bg == undefined) { return (undefined); } - var ws = (this.elem_size_x - 10) / (w / 500); - var hs = (this.elem_size_y - 10) / (h / 500); - return (svg_from_string (this, x, y, ws, hs, bg, attrs)); - } - this.background_svg = shapes_background_svg; - - return (this); -} - -var SHAPES = new Shapes (); Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-05-30 01:25:16 UTC (rev 1465) +++ trunk/Toss/WebClient/Main.js 2011-05-30 20:31:01 UTC (rev 1466) @@ -243,7 +243,7 @@ "-elem-" + CUR_PLAY_I); var li = new_play_item (GAME_NAME, CUR_PLAY_I); old_li.parentNode.replaceChild (li, old_li); - if (PLAYS[CUR_PLAY_I][ST.PLAYER_STR] == "computer") { + if (ST.players.length==1 && PLAYS[CUR_PLAY_I][ST.players[0]]=="computer") { var mv_time = document.getElementById("speed").value; suggest_move_async (mv_time, make_move); } @@ -462,7 +462,7 @@ document.getElementById("working").innerHTML = "Working..."; if (m != "") { show_move (new Move (m)); f() } }; - CONN.suggest (time, play_py_id (CUR_PLAY_I), fm); + CONN.suggest (ST.players[0]+1, time, play_py_id (CUR_PLAY_I), fm); } function suggest_move_click () { Copied: trunk/Toss/WebClient/State.js (from rev 1465, trunk/Toss/WebClient/Drawing.js) =================================================================== --- trunk/Toss/WebClient/State.js (rev 0) +++ trunk/Toss/WebClient/State.js 2011-05-30 20:31:01 UTC (rev 1466) @@ -0,0 +1,545 @@ +// JavaScript Toss Module -- Drawing + +var SVG_WIDTH = 500; +var SVG_HEIGHT = 500; +var SVG_MARGINX = 50; +var SVG_MARGINY = 50; +var VIEW_MIRROR = 0; + + +// ------ Move Object ----- + +// Create a move from the string [s]. +function Move (s) { + var vals = []; + var arr = strip('(', ')', s).split(','); + for (var i = 0; i < arr.length; i++) { + if (arr[i].indexOf(':') > -1) { + var v = arr[i].substring (arr[i].indexOf(':')+1, arr[i].length); + vals.push (strip ('\'', ' ', strip ('{', '}', v))); + } + } + vals.sort (); + this.matched = vals; + this.length = vals.length; + this.rule = strip ("'", " ", + s.substring (s.indexOf("},")+3, s.lastIndexOf(','))); + this.matched_str = strip (' ', ' ', this.matched.toString ()); + this.def_str = s; + this.player = parseInt(s.substring(0, 1)) - 1; + return (this) +} + +function move_did_match (s) { + for (var i = 0; i < this.matched.length; i++) { + if (this.matched[i] == s) { return (true) } + } + return (false); +} +Move.prototype.did_match = move_did_match; + + +// --------- Elem and Rel Objects ----- + +function Elem (id, x, y) { + this.id = id; + this.x = x; + this.y = y; +} + +function Rel (name, args) { + this.name = name; + this.args = args; +} + + +// --------- State Object ------ + + +// Object representing a state of the system (game). +function State (game, info_string) { + // We create an SVG box with margins depending on the game. + this.game = game; + + var create_svg_box = function (margx, margy, parent_id) { + SVG_MARGINX = margx; + SVG_MARGINY = margx; + var svg = document.createElementNS('http://www.w3.org/2000/svg','svg'); + svg.setAttribute('id', 'svg'); + var wx = SVG_WIDTH + 2*SVG_MARGINX + 20; + var wy = SVG_HEIGHT + 2*SVG_MARGINY + 20; + svg.setAttribute('viewBox', '-10 -10 ' + wx + " " + wy); + document.getElementById(parent_id).appendChild(svg); + } + + if (game == "Tic-Tac-Toe" || game == "Concurrent-Tic-Tac-Toe") { + create_svg_box (130, 130, "board"); // bigger margins needed + } else { + create_svg_box (40, 40, "board"); + } + + // Private: Translate position from Model coordinates to SVG coordinates. + var translate_pos = function (pos, minx, miny, width, height) { + var x = ((pos[0] - minx) * SVG_WIDTH) / width; + if (VIEW_MIRROR == 0) { + var y = ((pos[1] - miny) * SVG_HEIGHT) / height; + } else { + var y = ((height - (pos[1] - miny))*SVG_WIDTH) / height; + } + return ([x + SVG_MARGINX, y + SVG_MARGINY]) + }; + + // The info is a $-separated array of 4 components. + var res_arr = []; + res_arr = info_string.split("$"); + if (res_arr.length != 4) { alert (res_arr); return (undefined); } + + // The first component gives the dimenstions of the structure. + var dim = strip('(', ')', res_arr[0]).split(','); + this.maxx = parseFloat(strip(' ', ' ', dim[0])); + this.minx = parseFloat(strip(' ', ' ', dim[1])); + this.maxy = parseFloat(strip(' ', ' ', dim[2])); + this.miny = parseFloat(strip(' ', ' ', dim[3])); + this.width = Math.max (SVG_WIDTH / 100, (this.maxx - this.minx)); + this.height = Math.max (SVG_HEIGHT / 100, (this.maxy - this.miny)); + + // The second component is the list of elements of the structure. + var l = convert_python_list(',', res_arr[1]); + this.elems = []; + for (var i = 0; i < l.length; i++) { + var e = convert_python_list (';', l[i]); + var pos = translate_pos ([parseFloat(e[1]), parseFloat(e[2])], + this.minx, this.miny, this.width, this.height); + this.elems.push (new Elem (e[0], pos[0], pos[1])); + } + + var find_elem = function (elem_id, els) { + for (var i = 0; i < els.length; i++) { + if (els[i].id == elem_id) { return (els[i]); } + } + return (undefined); + } + + // The third component are the relations in the structure. + var r = convert_python_list(';', res_arr[2]); + var rels = []; + for (var i = 0; i < r.length; i++) { + var rel_name = strip(' ', '\'', r[i].substring(1,r[i].indexOf(','))); + var args_s = r[i].substring(r[i].indexOf('[')+1, r[i].indexOf(']')); + var args = convert_python_list (',', args_s); + var is_undefined = false; + for (var j = 0; j < args.length; j++) { + args[j] = find_elem (args[j], this.elems); + if (args[j] == undefined) { is_undefined = true }; + } + if (rel_name[0] != "_" && args_s != "''" && is_undefined == false) { + rels.push (new Rel (rel_name, args)); + } + } + this.rels = rels; + + var in_lst = function (lst, elem) { + for (var j = 0; j < lst.length; j++) { + if (lst[j] == elem) { return (true); } + } + return (false); + } + + // The fourth component is either the list of possible moves. + // If there are no moves possible, it is the payoff. + if (res_arr[3].substring(2, 3) == "(") { + var move_strs = convert_python_list (';', res_arr[3]); + var mvs = []; + var pls = []; + for (i = 0; i < move_strs.length; i++) { + var new_mv = new Move (move_strs[i]); + mvs.push (new_mv); + if (! in_lst(pls, new_mv.player)) { pls.push (new_mv.player); } + } + this.moves = mvs; + this.players = pls; + this.payoff = ""; + } else { + this.moves = []; + this.players = []; + this.payoff = res_arr[3]; + }; + + return (this); +} + +// Get moves applicable to [elem] in a game. +function state_get_moves (elem, other) { + var elem_moves = []; + for (i = 0; i < this.moves.length; i++) { + if (this.moves[i].did_match(elem)) { + if (other == "") { + elem_moves.push(this.moves[i]) + } else if (this.moves[i].did_match(other)) { + elem_moves.push(this.moves[i]) + } + } + } + return (elem_moves) +} +State.prototype.get_moves = state_get_moves; + + +// ------ Drawing functions ---- + +// Helper: to draw chess board we distinguish even/odd placed elements. +function elem_class (elemid) { + var elem_cl = "model-elem"; + var is_int = function (s) { return (parseInt(s).toString() == s) }; + if (is_int (elemid.substring(1))) { + var psum = elemid.charCodeAt(0) + parseInt (elemid.substring(1)); + elem_cl = "model-elem-" + (psum % 2); + }; + return (elem_cl); +} + +// Draw the model. +function state_draw_model (game) { + var draw_background = function (game) { + var x = SVG_MARGINX; + var y = SVG_MARGINY; + var w = SVG_WIDTH + 2 * x; + var h = SVG_HEIGHT + 2 * x; + var bg = SHAPES.background_svg (game, 0, 0, w, h, []); + if (bg != undefined) {document.getElementById("svg").appendChild(bg);} + } + + // Draw the element [elem]. + var draw_elem = function (game, elem) { + if (game != "Connect4") { + var r = SHAPES.rect ( + elem.x, elem.y, 2 * SHAPES.elem_size_x, 2 * SHAPES.elem_size_y, + [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], + ["onclick", ("handle_elem_click('" + elem.id + "')")]]); + document.getElementById("svg").appendChild(r); + } else { + var circ = SHAPES.circle ( + elem.x, elem.y, 30, + [["id", "elem_" + elem.id], ["class", elem_class(elem.id)], + ["onclick", "handle_elem_click('" + elem.id + "')"]]); + document.getElementById("svg").appendChild(circ); + } + } + + + // Draw relation [rel_name] between elements [args]. + function draw_rel (game, rel) { + if (rel.args.length == 1) { + var ihatrs = [["id", "pred_" + rel.args[0].id + "_" + rel.name], + ["onclick","handle_elem_click('"+rel.args[0].id+"')"]] + var pos = [rel.args[0].x, rel.args[0].y]; + var f = SHAPES.rel_svg (game, pos[0],pos[1],20,20, rel.name,ihatrs); + if (f != undefined) { + document.getElementById("svg").appendChild(f); + } else { + var circ = SHAPES.circle ( + pos[0], pos[1], SHAPES.elem_size_x - 10, + [["id", "pred_" + rel.args[0].id + "_" + rel.name], + ["class", "model-pred-" + rel.name], + ["stroke-width", (SHAPES.elem_size_x / 10) + 2], + ["onclick", ("handle_elem_click('"+rel.args[0].id+"')")]]); + document.getElementById("svg").appendChild(circ); + } + } + if (rel.args.length == 2) { + if (rel.name == "E") { + var l = SHAPES.line (rel.args[0].x, rel.args[0].y, + rel.args[1].x, rel.args[1].y, + [["class", "model-edge-E"]]); + document.getElementById("svg").appendChild(l); + } + } + } + + // Main draw_model function. + var sqrt = Math.round (Math.sqrt (this.elems.length)); + if (sqrt * sqrt == this.elems.length) { // perhaps a grid + SHAPES.elem_size_x = SVG_WIDTH / (2.0 * (sqrt-1)); + SHAPES.elem_size_y = SVG_HEIGHT / (2.0 * (sqrt-1)); + } else { + SHAPES.elem_size_x = SVG_WIDTH / 20; + SHAPES.elem_size_y = SVG_HEIGHT / 20; + } + draw_background (game); + for (var i = 0; i < this.elems.length; i++) { + draw_elem (game, this.elems[i]); + } + for (var i = 0; i < this.rels.length; i++) { + draw_rel (game, this.rels[i]); + } +} +State.prototype.draw_model = state_draw_model; + +// Highlight the element [elem]. +function state_highlight_elem (elemid) { + var e = document.getElementById ("elem_" + elemid); + e.setAttribute ("class", "model-elem-highlight"); +} +State.prototype.highlight_elem = state_highlight_elem; + +// Unhighlight the element [elem]. +function state_unhighlight_elem (elemid) { + var e = document.getElementById ("elem_" + elemid); + e.setAttribute ("class", elem_class(elemid)); +} +State.prototype.unhighlight_elem = state_unhighlight_elem; + + + + +// ------------ Shape Drawings in SVG ------------------- + +function Shapes () { + this.elem_size_x = 25; // suggested size of elements + this.elem_size_y = 25; // suggested size of elements + + var DEFpawn = '<g transform="translate(-22.5,-22.5)"> \ + <path \ + d="M 22,9 C 19.792,9 18,10.792 18,13 C 18,13.885 18.294,14.712 18.781,15.375 C 16.829,16.497 15.5,18.588 15.5,21 C 15.5,23.034 16.442,24.839 17.906,26.031 C 14.907,27.089 10.5,31.578 10.5,39.5 L 33.5,39.5 C 33.5,31.578 29.093,27.089 26.094,26.031 C 27.558,24.839 28.5,23.034 28.5,21 C 28.5,18.588 27.171,16.497 25.219,15.375 C 25.706,14.712 26,13.885 26,13 C 26,10.792 24.208,9 22,9 z " \ + class="chess-path-A" /> \ + </g>'; + + var DEFknight = '<g transform="translate(-22.5,-22.5)"> \ + <path \ + d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18" \ + class="chess-path-B" /> \ + <path \ + d="M 24,18 C 24.384,20.911 18.447,25.369 16,27 C 13,29 13.181,31.343 11,31 C 9.9583,30.056 12.413,27.962 11,28 C 10,28 11.187,29.232 10,30 C 9,30 5.9968,31 6,26 C 6,24 12,14 12,14 C 12,14 13.886,12.098 14,10.5 C 13.274,9.5056 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.282,8.0081 21,7 C 22,7 22,10 22,10" \ + class="chess-path-B" /> \ + <path \ + d="M 9 23.5 A 0.5 0.5 0 1 1 8,23.5 A 0.5 0.5 0 1 1 9 23.5 z" \ + transform="translate(0.5,2)" \ + class="chess-path-C" /> \ + <path \ + d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z" \ + transform="matrix(0.866,0.5,-0.5,0.866,9.6926,-5.1734)" \ + class="chess-path-C" /> \ + <path \ + d="M 37,39 C 38,19 31.5,11.5 25,10.5" \ + class="chess-path-D" /> \ + </g>'; + + var DEFbishop = '<g transform="translate(-22.5,-22.5)"> \ + <path \ + d="M 9,36 C 12.385,35.028 19.115,36.431 22.5,34 C 25.885,36.431 32.615,35.028 36,36 C 36,36 37.646,36.542 39,38 C 38.323,38.972 37.354,38.986 36,38.5 C 32.615,37.528 25.885,38.958 22.5,37.5 C 19.115,38.958 12.385,37.528 9,38.5 C 7.6459,38.986 6.6771,38.972 6,38 C 7.3541,36.055 9,36 9,36 z " \ + style="stroke-linecap:butt;" class="chess-path-B" /> \ + <path \ + d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z " \ + style="stroke-linecap:butt;" class="chess-path-B" /> \ + <path \ + d="M 25 10 A 2.5 2.5 0 1 1 20,10 A 2.5 2.5 0 1 1 25 10 z" \ + transform="translate(0,-2)" \ + style="stroke-linecap:butt;" class="chess-path-Bx" /> \ + <path \ + d="M 17.5,26 L 27.5,26" \ + style="stroke-linecap:butt;" class="chess-path-D" /> \ + <path \ + d="M 15,30 L 30,30" \ + style="stroke-linecap:butt;" class="chess-path-D" /> \ + <path \ + d="M 22.5,15.5 L 22.5,20.5" \ + style="stroke-linecap:butt;" class="chess-path-D" /> \ + <path \ + d="M 20,18 L 25,18" \ + style="stroke-linecap:butt;" class="chess-path-D" /> \ + </g>'; + + var DEFrook = '<g transform="translate(-22.5,-22.5)"> \ + <path \ + d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z " \ + style="stroke-linecap:butt;" class="chess-path-Bx" /> \ + <path \ + d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z " \ + style="stroke-linecap:butt;" class="chess-path-B" /> \ + <path \ + d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14" \ + style="stroke-linecap:butt;" class="chess-path-B" /> \ + <path \ + d="M 34,14 L 31,17 L 14,17 L 11,14" \ + style="stroke-linecap:butt;" class="chess-path-B" /> \ + <path \ + d="M 31,17 L 31,29.5 L 14,29.5 L 14,17" \ + style="stroke-linecap:butt;" class="chess-path-B" /> \ + <path \ + d="M 31,29.5 L 32.5,32 L 12.5,32 L 14,29.5" \ + class="chess-path-B" /> \ + <path \ + d="M 11,14 L 34,14" \ + class="chess-path-D" /> \ + </g>'; + + var DEFqueen = '<g transform="translate(-22.5,-22.5)"> \ + <path \ + d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" \ + transform="translate(-1,-1)" \ + style="fill-rule: none;" class="chess-path-B" /> \ + <path \ + d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" \ + transform="translate(15.5,-5.5)" \ + style="fill-rule: none;" class="chess-path-B" /> \ + <path \ + d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" \ + transform="translate(32,-1)" \ + style="fill-rule: none;" class="chess-path-B" /> \ + <path \ + d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" \ + transform="translate(7,-4.5)" \ + style="fill-rule: none;" class="chess-path-B" /> \ + <path \ + d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" \ + transform="translate(24,-4)" \ + style="fill-rule: none;" class="chess-path-B" /> \ + <path \ + d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38,14 L 31,25 L 31,11 L 25.5,24.5 L 22.5,9.5 L 19.5,24.5 L 14,10.5 L 14,25 L 7,14 L 9,26 z " \ + style="stroke-linecap:butt;" class="chess-path-B" /> \ + <path \ + d="M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 10.5,36 10.5,36 C 9,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z " \ + style="stroke-linecap:butt;" class="chess-path-B" /> \ + <path \ + d="M 11.5,30 C 15,29 30,29 33.5,30" \ + class="chess-path-D" /> \ + <path \ + d="M 12,33.5 C 18,32.5 27,32.5 33,33.5" \ + class="chess-path-D" /> \ + <path \ + d="M 10.5,36 C 15.5,35 29,35 34,36" \ + class="chess-path-D" /> \ + </g>'; + + var DEFking = '<g transform="translate(-22.5,-22.5)"> \ + <path d="M 22.5,11.625 L 22.5,6" class="chess-path-B" /> \ + <path d="M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25" \ + style="fill:stroke-linecap:butt;" class="chess-path-B" /> \ + <path d="M 11.5,37 C 17,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 19,16 9.5,13 6.5,19.5 C 3.5,25.5 11.5,29.5 11.5,29.5 L 11.5,37 z " \ + class="chess-path-B" /> \ + <path d="M 20,8 L 25,8" class="chess-path-B" /> \ + <path d="M 11.5,29.5 C 17,27 27,27 32.5,30" class="chess-path-D" /> \ + <path d="M 11.5,37 C 17,34.5 27,34.5 32.5,37" \ + class="chess-path-D" /> \ + <path d="M 11.5,33.5 C 17,31.5 27,31.5 32.5,33.5" \ + class="chess-path-D" /> \ + </g>'; + + var default_rel = {}; + default_rel["wP"] = '<g class="chessW">' + DEFpawn + '</g>'; + default_rel["bP"] = '<g class="chessB">' + DEFpawn + '</g>'; + default_rel["wN"] = '<g class="chessW">' + DEFknight + '</g>'; + default_rel["bN"] = '<g class="chessB">' + DEFknight + '</g>'; + default_rel["wB"] = '<g class="chessW">' + DEFbishop + '</g>'; + default_rel["bB"] = '<g class="chessB">' + DEFbishop + '</g>'; + default_rel["wR"] = '<g class="chessW">' + DEFrook + '</g>'; + default_rel["bR"] = '<g class="chessB">' + DEFrook + '</g>'; + default_rel["wQ"] = '<g class="chessW">' + DEFqueen + '</g>'; + default_rel["Wq"] = '<g class="chessW">' + DEFqueen + '</g>'; + default_rel["bQ"] = '<g class="chessB">' + DEFqueen + '</g>'; + default_rel["Bq"] = '<g class="chessB">' + DEFqueen + '</g>'; + default_rel["wK"] = '<g class="chessW">' + DEFking + '</g>'; + default_rel["bK"] = '<g class="chessB">' + DEFking + '</g>'; + default_rel["P"] = + '<g class="model-pred-P">' + // Cross + '<line x1="-17" y1="-17" x2="17" y2="17" />' + + '<line x1="17" y1="-17" x2="-17" y2="17" /></g>'; + default_rel["Q"] = + '<circle class="model-pred-Q" cx="0" cy="0" r="17" />'; // Circle + + var game_rel = {}; + game_rel["Entanglement"] = {}; + game_rel["Entanglement"]["R"] = + '<circle class="model-pred-R" cx="0" cy="0" r="25" />'; + + game_rel["Connect4"] = {}; + game_rel["Connect4"]["P"] = + '<circle class="model-pred-P" cx="0" cy="0" r="40" />'; + game_rel["Connect4"]["Q"] = + '<circle class="model-pred-Q" cx="0" cy="0" r="40" />'; + + + var background = {}; + background["Connect4"] = '<rect x="0" y="0" width="500" height="500" ' + + 'stroke-width="5" rx="5" ry="5" id="board_connect4" />'; + + + // Create new svg element [elem], child of svg, set attributes, scale. + var svg_from_string = function (th, x, y, sizex, sizey, s, attrs) { + var parser = new DOMParser (); + var svgs = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg">'; + var scfx = (th.elem_size_x - 10) / sizex; + var scfy = (th.elem_size_y - 10) / sizey; + var sc = "scale(" + scfx + "," + scfy + ")"; + var gs = '<g transform="translate(' + x + "," + y + ") " + sc + '">'; + var doc = parser.parseFromString(svgs+ gs+ s +'</g></svg>', "text/xml"); + var elem = document.adoptNode(doc.childNodes[0]).childNodes[0]; + var elem_in = elem.childNodes[0]; + for (var i = 0; i < attrs.length; i++) { + elem_in.setAttribute (attrs[i][0], attrs[i][1].toString()); + } + return (elem); + } + + + // Public methods + + var shapes_rel_svg = function (game, posx, posy, sizex, sizey, rn, attrs) { + var svg_s = default_rel[rn]; + if (game_rel[game] != undefined) { + if (game_rel[game][rn] != undefined) { + svg_s = game_rel[game][rn]; + } + } + if (svg_s == undefined) { return (undefined) }; + return (svg_from_string (this, posx, posy, sizex, sizey, svg_s, attrs)); + } + this.rel_svg = shapes_rel_svg; + + var shapes_circle = function (cx, cy, r, attrs) { + return (svg_from_string (this, cx, cy, + this.elem_size_x - 10, this.elem_size_y - 10, + '<circle cx="0" cy="0" r="' + r + '" />', + attrs)); + } + this.circle = shapes_circle; + + var shapes_rect = function (x, y, w, h, attrs) { + var rs = '<rect x="0" y="0" width="' + w + '" height="' + h + '" />' + return (svg_from_string (this, x - w/2, y - w/2, this.elem_size_x - 10, + this.elem_size_y - 10, rs, attrs)); + } + this.rect = shapes_rect; + + var shapes_line = function (x1, y1, x2, y2, attrs) { + var sign = function (x) { + if (x > 0.01) { return (1); } + else if (x < -0.01) { return (-1); } + else { return (0); } + } + var dx = this.elem_size_x * sign (x1 - x2); + var dy = this.elem_size_y * sign (y1 - y2); + var nx1 = x1 - dx; + var nx2 = x2 + dx; + var ny1 = y1 - dy; + var ny2 = y2 + dy; + var ls = '<line x1="' + nx1 + '" y1="' + ny1 + + '" x2="' + nx2 + '" y2="' + ny2 + '" />'; + return (svg_from_string (this, 0, 0, this.elem_size_x - 10, + this.elem_size_y - 10, ls, attrs)); + } + this.line = shapes_line; + + var shapes_background_svg = function (game, x, y, w, h, attrs) { + var bg = background[game]; + if (bg == undefined) { return (undefined); } + var ws = (this.elem_size_x - 10) / (w / 500); + var hs = (this.elem_size_y - 10) / (h / 500); + return (svg_from_string (this, x, y, ws, hs, bg, attrs)); + } + this.background_svg = shapes_background_svg; + + return (this); +} + +var SHAPES = new Shapes (); Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-05-30 01:25:16 UTC (rev 1465) +++ trunk/Toss/WebClient/index.html 2011-05-30 20:31:01 UTC (rev 1466) @@ -11,7 +11,7 @@ <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> <script type="text/javascript" src="crypto-sha256.js"> </script> <script type="text/javascript" src="Connect.js"> </script> - <script type="text/javascript" src="Drawing.js"> </script> + <script type="text/javascript" src="State.js"> </script> <script type="text/javascript" src="Main.js"> </script> <script type="text/javascript" src="Login.js"> </script> </head> Modified: trunk/Toss/WebClient/profile.html =================================================================== --- trunk/Toss/WebClient/profile.html 2011-05-30 01:25:16 UTC (rev 1465) +++ trunk/Toss/WebClient/profile.html 2011-05-30 20:31:01 UTC (rev 1466) @@ -9,7 +9,7 @@ <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> <script type="text/javascript" src="crypto-sha256.js"> </script> <script type="text/javascript" src="Connect.js"> </script> - <script type="text/javascript" src="Drawing.js"> </script> + <script type="text/javascript" src="State.js"> </script> <script type="text/javascript" src="Main.js"> </script> <script type="text/javascript" src="Login.js"> </script> </head> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-31 20:33:09
|
Revision: 1468 http://toss.svn.sourceforge.net/toss/?rev=1468&view=rev Author: lukaszkaiser Date: 2011-05-31 20:33:02 +0000 (Tue, 31 May 2011) Log Message: ----------- Improving register html. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/register.html Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-05-30 21:35:49 UTC (rev 1467) +++ trunk/Toss/Server/ReqHandler.ml 2011-05-31 20:33:02 UTC (rev 1468) @@ -280,7 +280,6 @@ let m = client_msg ("EVAL LOC MOVES " ^ advr ^ ".0 " ^ loc ^ " TIMEOUT " ^ timeout ^ " 55500 alpha_beta_ord") in client_set_time ts t; - print_endline m; let msg = Array.map strip_ws (split ";" m) in if Array.length msg < 2 then "" else let append_emb emb s = @@ -511,14 +510,17 @@ let adv_ratio = if adv_ratio_data = "none" then "4" else adv_ratio_data in client_suggest player time adv_ratio in let register_user ui = - if Array.length ui <> 5 then false else + let mail_in_use email = + List.length (dbtable ("email='" ^ email ^ "'") "users") > 0 in + if Array.length ui <> 5 then Some "Identifier" else let (uid, name, surname, email, pwd) = (ui.(0), ui.(1), ui.(2), ui.(3), ui.(4)) in - match passwd_from_db uid with Some _ -> false | None -> - DB.insert_table dbFILE "users" "id, name, surname, email, passwd" - [uid; name; surname; email; pwd]; - DB.insert_table dbFILE "friends" "id, fid" [uid; "computer"]; - true in + if mail_in_use email then Some ("Email " ^ email) else + match passwd_from_db uid with Some _ -> Some ("Username "^uid) | None-> + DB.insert_table dbFILE "users" "id, name, surname, email, passwd" + [uid; name; surname; email; pwd]; + DB.insert_table dbFILE "friends" "id, fid" [uid; "computer"]; + None in let login_user uid chk pwd = match passwd_from_db uid with | None -> ("no such user registered", []) @@ -558,11 +560,12 @@ if verif_uid () = "" then "", [] else user_plays (verif_uid ()), [] | "REGISTER" -> let ui = split "$" data in - if register_user ui then - "Registration successful for " ^ ui.(0) ^ ".", [] - else - "Registration failed:\n username " ^ ui.(0) ^ " already in use." ^ - "\nPlease choose another username and try again.", [] + (match register_user ui with + | None -> "Registration successful for " ^ ui.(0) ^ ".", [] + | Some msg -> + "Registration failed:\n" ^ msg ^ " already in use."^ + "\nPlease choose another one and try again.", [] + ) | "LOGIN" -> let ui = split "$" data in if Array.length ui = 3 then ( Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-05-30 21:35:49 UTC (rev 1467) +++ trunk/Toss/WebClient/Login.js 2011-05-31 20:33:02 UTC (rev 1468) @@ -163,6 +163,25 @@ return; } +var UID_MANUAL = false; +var NAME_MANUAL = false; +function register_uid_change () { UID_MANUAL = true; } +function register_name_change () { NAME_MANUAL = true; } + +// Email changed in the registration form - update name and username. +function register_email_change() { + var email = document.getElementById('email').value; + var n = email; + if (email.indexOf("@") > 0) { n = email.substr (0, email.indexOf("@")); } + if (! UID_MANUAL) { + document.getElementById('username').value = n; + } + if (! NAME_MANUAL) { + var m = n.substr(0,1).toUpperCase() + n.substr(1); + document.getElementById('name').value = m; + } +} + // Register new user function register () { var unv = document.getElementById('username').value; @@ -196,10 +215,6 @@ alert ("Your name was not given and it is necessary." + CORRMSG); return; } - if (surname == "") { - alert ("Your surname was not given and it is necessary." + CORRMSG); - return; - } if (email.indexOf("@") < 1 || email.indexOf(".") < 1) { alert ("Please provide a valid email address."); return; @@ -212,6 +227,13 @@ var data = un + "$" + name + "$" + surname + "$" + email; var resp = CONN.register (data, crypt(TSALT + pwd)); alert (resp); + if (resp.indexOf(" successful") > 0) { + var resp = CONN.login (un, true, crypt(TSALT + pwd)); + if (resp == "OK") { + var url = "http://" + window.location.host + "/index.html"; + window.location.replace(url); + } + } } // Change user data @@ -223,10 +245,6 @@ alert ("Your name was not given and it is necessary." + CORRMSG); return; } - if (surname == "") { - alert ("Your surname was not given and it is necessary." + CORRMSG); - return; - } if (email.indexOf("@") < 1 || email.indexOf(".") < 1) { alert ("Please provide a valid email address."); return; Modified: trunk/Toss/WebClient/register.html =================================================================== --- trunk/Toss/WebClient/register.html 2011-05-30 21:35:49 UTC (rev 1467) +++ trunk/Toss/WebClient/register.html 2011-05-31 20:33:02 UTC (rev 1468) @@ -25,8 +25,10 @@ <h2>Register on tPlay</h2> <form id="registerform" action=""> -<p> <span class="reglabel">Username:</span> - <input class="forminput" type="text" name="username" id="username" /> </p> +<p> <span class="reglabel">Email:</span> + <input class="forminput" type="text" name="email" + id="email" onchange="register_email_change()" /> +</p> <p> <span class="reglabel">Password:</span> <input class="forminput" type="password" name="password" id="password" /> </p> @@ -34,16 +36,19 @@ <input class="forminput" type="password" name="rptpassword" id="rptpassword" /> </p> +<p><button class="bt" id="registerbt" type="button" + onclick="register()">Register</button></p> +<p> <span class="reglabel">Username:</span> + <input class="forminput" type="text" name="username" + id="username" onchange="register_uid_change()" /> +</p> <p> <span class="reglabel">Name:</span> - <input class="forminput" type="text" name="name" id="name" /> + <input class="forminput" type="text" name="name" + id="name" onchange="register_name_change()" /> </p> <p> <span class="reglabel">Surname:</span> <input class="forminput" type="text" name="surname" id="surname" /> </p> -<p> <span class="reglabel">Email:</span> - <input class="forminput" type="text" name="email" id="email" /> -</p> -<p><button class="bt" id="registerbt" type="button" onclick="register()">Register</button></p> </form> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-03 20:24:32
|
Revision: 1469 http://toss.svn.sourceforge.net/toss/?rev=1469&view=rev Author: lukaszkaiser Date: 2011-06-03 20:24:22 +0000 (Fri, 03 Jun 2011) Log Message: ----------- Hiding structure type in Structure ml (first, mostly formal step). Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/ContinuousRule.ml trunk/Toss/Arena/DiscreteRule.ml trunk/Toss/GGP/GameSimpl.ml trunk/Toss/Play/Heuristic.ml trunk/Toss/Play/HeuristicTest.ml trunk/Toss/Solver/Solver.ml trunk/Toss/Solver/Structure.ml trunk/Toss/Solver/Structure.mli trunk/Toss/Solver/StructureTest.ml Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2011-05-31 20:33:02 UTC (rev 1468) +++ trunk/Toss/Arena/Arena.ml 2011-06-03 20:24:22 UTC (rev 1469) @@ -90,7 +90,7 @@ | AssignmentSet.Empty -> Structure.add_rel_name r_name (List.length vars) struc | _ -> - let tuples = AssignmentSet.tuples struc.Structure.elements vars def_asg in + let tuples = AssignmentSet.tuples (Structure.elems struc) vars def_asg in Structure.add_rels struc r_name tuples let add_def_rels struc rels = List.fold_left add_def_rel_single struc rels @@ -704,13 +704,13 @@ get_from_loc fun_signature loc (state_game, state) "get signature") | GetAllTuples (loc, rel) -> let tuples struc = - let tps = Structure.StringMap.find rel struc.Structure.relations in + let tps = Structure.rel_find rel struc in Structure.rel_str struc rel tps in ((state_game, state), get_from_loc tuples loc (state_game, state) "get all tuples") | GetAllElems loc -> let elems struc = - let els = Structure.Elems.elements struc.Structure.elements in + let els = Structure.elements struc in let el_name e = Structure.elem_str struc e in String.concat "; " (List.map el_name els) in ((state_game, state), @@ -734,8 +734,8 @@ with Not_found -> ((state_game, state), "ERR no data") ) | SetArity (rel, ar) -> - if (try Structure.StringMap.find rel - struc.Structure.rel_signature = ar with Not_found -> false) + if (try List.assoc rel (Structure.rel_signature struc) = ar + with Not_found -> false) then (state_game, state), "SET ARITY" else let s = Structure.force_add_rel_name rel ar struc in @@ -743,8 +743,7 @@ | GetArity (rel) -> ( if rel = "" then ((state_game, state), sig_str state) else try ((state_game, state), string_of_int - (Structure.StringMap.find rel - state.struc.Structure.rel_signature)) + (List.assoc rel (Structure.rel_signature state.struc))) with Not_found -> ((state_game, state), "ERR relation "^rel^" arity not found") ) Modified: trunk/Toss/Arena/ContinuousRule.ml =================================================================== --- trunk/Toss/Arena/ContinuousRule.ml 2011-05-31 20:33:02 UTC (rev 1468) +++ trunk/Toss/Arena/ContinuousRule.ml 2011-06-03 20:24:22 UTC (rev 1469) @@ -170,9 +170,9 @@ not updated later *) let ns = DiscreteRule.rewrite_single !last_struc m r.compiled in let set_val struc ((f, e), v) = - let e_rel = + let e_rel = (* DiscreteRule adds RHS element names to rewritten result *) - Structure.StringMap.find ("_right_" ^ e) struc.Structure.relations in + Structure.rel_find ("_right_" ^ e) struc in let elem = (Structure.Tuples.choose e_rel).(0) in Structure.add_fun struc f (elem, v) in let upd_struc = List.fold_left set_val ns upd_vals in Modified: trunk/Toss/Arena/DiscreteRule.ml =================================================================== --- trunk/Toss/Arena/DiscreteRule.ml 2011-05-31 20:33:02 UTC (rev 1468) +++ trunk/Toss/Arena/DiscreteRule.ml 2011-06-03 20:24:22 UTC (rev 1469) @@ -305,7 +305,7 @@ by {!find_matchings} for the same structure and rewrite rule. Does not guarantee that rewriting will succeed. *) let choose_match model rule_obj matches = - let elem = Structure.Elems.choose model.Structure.elements in + let elem = Structure.Elems.choose (Structure.elems model) in let default = List.map (fun v->v,elem) rule_obj.lhs_elem_vars in let asgn = AssignmentSet.choose_fo default matches in assignment_to_embedding rule_obj asgn @@ -331,7 +331,7 @@ (* Enumerate matchings returned by {!find_matchings} for the same structure and rewrite rule. *) let enumerate_matchings model rule matches = - let all_elems = Structure.Elems.elements model.Structure.elements in + let all_elems = Structure.elements model in let asgns = enumerate_asgns all_elems rule.lhs_elem_vars matches in List.map (assignment_to_embedding rule) asgns @@ -373,7 +373,7 @@ (* remove the matched elements *) let (model, drel_tuples) = Structure.del_elems model del_elems in let del_elems = elems_of_list del_elems in - let elems = Els.diff model.Structure.elements del_elems in + let elems = Els.diff (Structure.elems model) del_elems in (* Allocate new elements garbage-collecting the numbers. *) let _, alloc_elems, rmmap = List.fold_left (fun (next, alloc_elems, rmmap) evar -> @@ -389,7 +389,7 @@ let all_names = SSMap.fold (fun name el all_names -> if Els.mem el del_elems then all_names else Aux.Strings.add name all_names) - model.Structure.names Aux.Strings.empty in + (Structure.names model) Aux.Strings.empty in let rec select (all_names, elem_names, inv_names as acc) = function | [] -> acc | ne::nels -> @@ -406,7 +406,7 @@ | Some le when rev_assoc_all rlmap le = [re] -> let name = SIMap.find (List.assoc le ldmap) - given_model.Structure.inv_names in + (Structure.inv_names given_model) in if Aux.Strings.mem name all_names then let olde = SSMap.find name elem_names in select @@ -417,7 +417,7 @@ | Some le -> let lname = SIMap.find (List.assoc le ldmap) - given_model.Structure.inv_names in + (Structure.inv_names given_model) in select (accu (not_conflicting_name all_names (lname^"_"^re))) nels @@ -430,9 +430,8 @@ with Not_found -> all_names, elem_names, inv_names in let (all_names, elem_names, inv_names) = - select - (all_names, model.Structure.names, - model.Structure.inv_names) alloc_elems in + select (all_names, Structure.names model, Structure.inv_names model) + alloc_elems in (* For a tuple removed from the structure, if its preimage does not appear negatively on the RHS, add all tuples from the corresponding product of replacement elements (which can be @@ -493,7 +492,7 @@ SSMap.fold (fun f graph model -> if SIMap.mem oe graph then Structure.add_fun model f (ne, SIMap.find oe graph) - else model) given_model.Structure.functions model + else model) (Structure.functions given_model) model ) model rlmap in (* Add the new trace. *) let model = @@ -528,7 +527,7 @@ Structure.add_rel arg_model crel ntup else arg_model) up_model ctups) model rule_obj.rhs_neg_tuples in - {model with Structure.names = elem_names; inv_names = inv_names} + Structure.replace_names model elem_names inv_names (* Rewrite the model keeping the number and identity of elements. *) let rewrite_nonstruct model rmmap pos_tuples neg_tuples rhs_elem_names = @@ -776,30 +775,28 @@ opt_rels, pos_rels, pos_expanded in let lhs_name_of e = - elemvar_of_elem rule_src.lhs_struc.Structure.inv_names e in + elemvar_of_elem (Structure.inv_names rule_src.lhs_struc) e in let rhs_name_of e = - elemvar_of_elem rule_src.rhs_struc.Structure.inv_names e in + elemvar_of_elem (Structure.inv_names rule_src.rhs_struc) e in (* check if the map is a total 1-1 onto, if so, [rlmap=None], optimize *) let rlmap = let rimg, ldom = List.split rule_src.rule_s in let rimg = Aux.unique (=) rimg and ldom = Aux.unique (=) ldom in let nimg = List.length rimg and ndom = List.length ldom in - if nimg = Els.cardinal rule_src.rhs_struc.Structure.elements && - ndom = Els.cardinal rule_src.lhs_struc.Structure.elements && + if nimg = Structure.nbr_elems rule_src.rhs_struc && + ndom = Structure.nbr_elems rule_src.lhs_struc && nimg = ndom then None else Some (List.map (fun (re,le) -> rhs_name_of re, lhs_name_of le) rule_src.rule_s) in - let rhs_elems = - Els.elements rule_src.rhs_struc.Structure.elements in + let rhs_elems = Structure.elements rule_src.rhs_struc in let rhs_elem_vars = List.map rhs_name_of rhs_elems in (* [rlmap=None] optimization permutes LHS so that [rule_s] becomes identity and LHS variables are replaced by RHS ones *) let lhs_elems = - if rlmap = None then rhs_elems - else Els.elements rule_src.lhs_struc.Structure.elements in + if rlmap = None then rhs_elems else Structure.elements rule_src.lhs_struc in let lhs_elem_vars = if rlmap = None then rhs_elem_vars else List.map lhs_name_of lhs_elems in @@ -810,7 +807,7 @@ let lhs_rels = SSMap.fold (fun rel tups rels -> (rel, List.map opt_map (STups.elements tups)) :: rels) - rule_src.lhs_struc.Structure.relations [] in + (Structure.relations rule_src.lhs_struc) [] in (* rename the corresponding variables in the precondition *) let precond = if rlmap = None then @@ -827,14 +824,14 @@ if rlmap = None then SSMap.fold (fun name re acc -> SSMap.add name (List.assoc re rule_src.rule_s) acc) - rule_src.rhs_struc.Structure.names SSMap.empty - else rule_src.lhs_struc.Structure.names in + (Structure.names rule_src.rhs_struc) SSMap.empty + else (Structure.names rule_src.lhs_struc) in let lhs_elem_inv_names = if rlmap = None then SIMap.fold (fun re name acc -> SIMap.add (List.assoc re rule_src.rule_s) name acc) - rule_src.rhs_struc.Structure.inv_names SIMap.empty - else rule_src.lhs_struc.Structure.inv_names in + (Structure.inv_names rule_src.rhs_struc) SIMap.empty + else Structure.inv_names rule_src.lhs_struc in (* lhs_pos_tups keep their defined rels to be substituted in the embedding formula, but we need to avoid negating their support *) let lhs_opt_rels, lhs_pos_tups, lhs_pos_expanded = @@ -908,7 +905,7 @@ SSMap.fold (fun rel tups rels -> if STups.is_empty tups then rels else (rel, STups.elements tups) :: rels) - rule_src.rhs_struc.Structure.relations [] in + (Structure.relations rule_src.rhs_struc) [] in let rhs_opt_rels, rhs_rels, _ = compile_opt_rels rhs_rels in if List.exists (fun (drel, _) -> List.mem_assoc drel rhs_rels) @@ -980,7 +977,7 @@ lhs_elem_vars = lhs_elem_vars; lhs_neg_tups = lhs_neg_tups; lhs_form = emb; - rhs_elem_names = rule_src.rhs_struc.Structure.names; + rhs_elem_names = Structure.names rule_src.rhs_struc; rhs_elem_vars = rhs_elem_vars; rhs_pos_tuples = rhs_pos_tuples; rhs_neg_tuples = rhs_neg_tuples; @@ -1131,8 +1128,8 @@ let is_alpha_identity r = not (r.rule_s = []) && let len = List.length r.rule_s in - len = Structure.Elems.cardinal r.lhs_struc.Structure.elements && - len = Structure.Elems.cardinal r.rhs_struc.Structure.elements && + len = Structure.nbr_elems r.lhs_struc && + len = Structure.nbr_elems r.rhs_struc && let l_str le = Structure.elem_str r.lhs_struc le in let r_str re = Structure.elem_str r.rhs_struc re in List.for_all (fun (rhs,lhs) -> r_str rhs = l_str lhs) @@ -1226,15 +1223,15 @@ let r_str re = Structure.elem_str rhs re in match rule_s with | None -> - let lnum = Structure.Elems.cardinal lhs.Structure.elements in - let rnum = Structure.Elems.cardinal rhs.Structure.elements in + let lnum = Structure.nbr_elems lhs in + let rnum = Structure.nbr_elems rhs in if lnum <> rnum then failwith (Printf.sprintf "\"with\" clause not given but LHS and RHS \ structures have different sizes %d and %d" lnum rnum) else Structure.Elems.fold (fun re acc -> (re, l_elem (r_str re))::acc) - rhs.Structure.elements [] + (Structure.elems rhs) [] | Some rs -> List.map (fun (re,le) -> r_elem re, l_elem le) rs Modified: trunk/Toss/GGP/GameSimpl.ml =================================================================== --- trunk/Toss/GGP/GameSimpl.ml 2011-05-31 20:33:02 UTC (rev 1468) +++ trunk/Toss/GGP/GameSimpl.ml 2011-06-03 20:24:22 UTC (rev 1469) @@ -145,7 +145,7 @@ let simplify ?(keep_nonempty_predicates=true) (game, state) = let struc = state.Arena.struc in let signat = Structure.rel_signature struc in - let nelems = Structure.Elems.cardinal struc.Structure.elements in + let nelems = Structure.nbr_elems struc in let tcard tups = Tups.cardinal tups in let posi_f, nega_f, indef_f = Arena.all_fluents game in let fluents = @@ -168,14 +168,13 @@ let complemented = ref [] in let predicate_tups = Structure.Elems.fold (fun e tups -> Tups.add [|e|] tups) - struc.Structure.elements Tups.empty in + (Structure.elems struc) Tups.empty in let struc = ref struc in let signat = ref signat in let used_rels = ref used_rels in let complements = List.fold_left (fun table (rel,arity) -> - let rel_tups = - Structure.StringMap.find rel !struc.Structure.relations in + let rel_tups = Structure.rel_find rel !struc in let ntups = tcard rel_tups in let crel = Structure.StringMap.fold (fun rel2 rel2_tups crel -> @@ -195,7 +194,7 @@ (* }}} *) Some rel2 ) else None - ) !struc.Structure.relations None in + ) (Structure.relations !struc) None in let crel = if not !introduce_complement || arity <> 1 || crel <> None || ntups <= nelems / 2 @@ -225,13 +224,11 @@ (* prepare for (1bc) and (2) *) let subset_table = List.fold_left (fun table (rel,arity) -> - let rel_tups = - Structure.StringMap.find rel struc.Structure.relations in + let rel_tups = Structure.rel_find rel struc in let row = List.fold_left (fun row (rel2,arity2) -> if arity2 = arity && - Tups.subset rel_tups - (Structure.StringMap.find rel2 struc.Structure.relations) + Tups.subset rel_tups (Structure.rel_find rel2 struc) then Aux.Strings.add rel2 row else row ) Aux.Strings.empty signat in @@ -320,8 +317,7 @@ Aux.unique_sorted ( List.fold_left (fun emb_rels rel -> let tups = - try Structure.StringMap.find rel - lhs_struc.Structure.relations + try Structure.rel_find rel lhs_struc with Not_found -> Tups.empty in if removable rel && not (Tups.is_empty tups) && @@ -370,12 +366,11 @@ Structure.add_rels lhs_struc orig (List.assoc rel lhs_neg_tups) else lhs_struc - ) lhs_struc.Structure.relations lhs_struc in + ) (Structure.relations lhs_struc) lhs_struc in let lhs_all_tups n = List.map Array.of_list (Aux.product ( Aux.fold_n (fun acc -> - Structure.Elems.elements - lhs_struc.Structure.elements::acc) [] n)) in + Structure.elements lhs_struc ::acc) [] n)) in let lhs_struc = List.fold_left (fun lhs_struc emb_rel -> (* {{{ log entry *) @@ -387,15 +382,13 @@ try List.assoc emb_rel lhs_neg_tups with Not_found -> [] in let all_tups = lhs_all_tups - (Structure.StringMap.find emb_rel - struc.Structure.rel_signature) in + (List.assoc emb_rel (Structure.rel_signature struc)) in let avoid_tups = Aux.concat_map (fun (rel1,(rel2,neg)) -> if not (removable rel1) || not neg || rel2 <> emb_rel then [] else (* neg *) - (try ltups (Structure.StringMap.find rel1 - lhs_struc.Structure.relations) + (try ltups (Structure.rel_find rel1 lhs_struc) with Not_found -> []) ) equivalent in (* {{{ log entry *) @@ -436,8 +429,7 @@ (* 3 *) let intersect_rels struc grel rels = let rel_graphs = - List.map (fun rel -> - Structure.StringMap.find rel struc.Structure.relations) rels in + List.map (fun rel -> Structure.rel_find rel struc) rels in let graph = match rel_graphs with | [] -> assert false @@ -447,11 +439,9 @@ let tuples = Tups.elements graph in Structure.add_rels struc grel tuples in let intersect_with_inv struc grel rel1 rel2 = - let graph1 = - Structure.StringMap.find rel1 struc.Structure.relations in + let graph1 = Structure.rel_find rel1 struc in let tuples2 = - Tups.elements - (Structure.StringMap.find rel2 struc.Structure.relations) in + Tups.elements (Structure.rel_find rel2 struc) in let inv_graph = Structure.tuples_of_list (List.map (function | [|e1; e2|] -> [|e2; e1|] @@ -785,7 +775,7 @@ then List.map (fun tup->rel, tup) (Tups.elements tups) @ cands - else cands) lhs.Structure.relations [] in + else cands) (Structure.relations lhs) [] in let result = glue_lhs cands in let lhs, cands = List.fold_left (fun (lhs, cands) (grel, rels, args) -> Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-05-31 20:33:02 UTC (rev 1468) +++ trunk/Toss/Play/Heuristic.ml 2011-06-03 20:24:22 UTC (rev 1469) @@ -651,10 +651,10 @@ let expanded_description max_alt_descr frels struc phi = - let elems = Elems.elements struc.elements in + let elems = Structure.elements struc in let rels = Structure.StringMap.fold (fun rel tups rels-> - (rel, tups)::rels) struc.Structure.relations [] in + (rel, tups)::rels) (Structure.relations struc) [] in let rels = List.filter (fun (rel, _) -> not (Strings.mem rel frels)) rels in let vars = @@ -694,7 +694,7 @@ } in FormulaOps.fold_formula gfold in let i2f = float_of_int in - let nelems = Structure.Elems.cardinal struc.Structure.elements in + let nelems = Structure.nbr_elems struc in (* {{{ log entry *) if !debug_level > 2 then ( Printf.printf @@ -710,10 +710,10 @@ let expanded_form max_alt_descr frels struc phi = - let elems = Elems.elements struc.elements in + let elems = Structure.elements struc in let rels = Structure.StringMap.fold (fun rel tups rels-> - (rel, tups)::rels) struc.Structure.relations [] in + (rel, tups)::rels) (Structure.relations struc) [] in let rels = List.filter (fun (rel,_) -> not (Strings.mem rel frels)) rels in let rec aux all_vars = function @@ -1114,7 +1114,7 @@ (snd (List.hd rules) ).ContinuousRule.discrete.DiscreteRule.rhs_struc in let signat rel = - Structure.StringMap.find rel signat_struc.Structure.rel_signature in + List.assoc rel (Structure.rel_signature signat_struc) in let fluent_preconds = if monotonic then Some (DiscreteRule.fluent_preconds drules signat Modified: trunk/Toss/Play/HeuristicTest.ml =================================================================== --- trunk/Toss/Play/HeuristicTest.ml 2011-05-31 20:33:02 UTC (rev 1468) +++ trunk/Toss/Play/HeuristicTest.ml 2011-06-03 20:24:22 UTC (rev 1469) @@ -62,11 +62,8 @@ let signat_struc = match struc with Some struc -> struc | None -> (List.hd rules).DiscreteRule.rhs_struc in - let signat rel = - Structure.StringMap.find rel signat_struc.Structure.rel_signature in - let signature = Structure.StringMap.fold - (fun r ar si -> (r,ar)::si) - signat_struc.Structure.rel_signature [] in + let signature = Structure.rel_signature signat_struc in + let signat rel = List.assoc rel signature in let drules = List.map (DiscreteRule.compile_rule signature []) rules in let posi_frels, nega_frels, indef_frels = DiscreteRule.fluents drules in Modified: trunk/Toss/Solver/Solver.ml =================================================================== --- trunk/Toss/Solver/Solver.ml 2011-05-31 20:33:02 UTC (rev 1468) +++ trunk/Toss/Solver/Solver.ml 2011-06-03 20:24:22 UTC (rev 1469) @@ -130,12 +130,12 @@ if aset = Empty then Empty else match phi with | Rel (relname, vl) -> - let tuples_s = - try StringMap.find relname model.relations - with Not_found -> Tuples.empty in - let inc_map = - try StringMap.find relname model.incidence - with Not_found -> IntMap.empty in + let tuples_s = + try Structure.rel_find relname model + with Not_found -> Tuples.empty in + let inc_map = + try Structure.rel_incidence relname model + with Not_found -> IntMap.empty in report (join_rel aset vl tuples_s inc_map elems) | Eq (x, y) -> report (equal_vars elems x y aset) | SO (v, vl) -> @@ -276,7 +276,8 @@ (* Evaluate with assignment, no cache. *) let evaluate_partial_aset solver ~formula struc fo_aset = let elems = - ref (Set (Elems.cardinal struc.elements, struc.elements)) in + ref (Set (Elems.cardinal (Structure.elems struc), + (Structure.elems struc))) in let phi = Hashtbl.find solver.formulas_eval formula in incr eval_counter; eval [] struc elems fo_aset phi @@ -289,23 +290,6 @@ let (b, nl) = assoc_del x l in (b, pair :: nl) -let diffrels_struc s1 s2 = - if Structure.equal { s1 with relations = StringMap.empty; } - { s2 with relations = StringMap.empty; } then - let is_eq_in map rel tp = - try - Structure.Tuples.equal (Structure.StringMap.find rel map) tp - with Not_found -> false in - let is_eq_in1, is_eq_in2 = is_eq_in s1.relations, is_eq_in s2.relations in - let diffrels = ref [] in - let appdiff1 r tp = if not (is_eq_in1 r tp) then diffrels := r::!diffrels in - let appdiff2 r tp = if not (is_eq_in2 r tp) then diffrels := r::!diffrels in - Structure.StringMap.iter appdiff1 s2.relations; - Structure.StringMap.iter appdiff2 s1.relations; - if !debug_level > 1 then - print_endline ("SOME DIFF: " ^ (String.concat ", " !diffrels)); - Some (Aux.unique_sorted !diffrels) - else None let phi_rels phi = let rels = ref [] in @@ -372,7 +356,8 @@ res with Not_found -> if !debug_level > 0 then print_endline ("Eval_m " ^ (str phi)); - let els = Set (Elems.cardinal struc.elements, struc.elements) in + let els = Set (Elems.cardinal (Structure.elems struc), + (Structure.elems struc)) in check_timeout "Solver.eval_m.not_found"; let asg = eval [] struc (ref els) Any phi in incr eval_counter; @@ -382,7 +367,8 @@ (* Helper function, assignment of tuple. *) let asg_of_tuple struc vars tuple = - let els = Set (Elems.cardinal struc.elements, struc.elements) in + let els = Set (Elems.cardinal (Structure.elems struc), + (Structure.elems struc)) in assignments_of_list (ref els) (Array.of_list vars) [tuple] (* Evaluate real expressions. Result is represented as assignments with @@ -459,7 +445,8 @@ ); check_timeout "Solver.get_real_val.sum"; let asg_gd = join asg (eval_cache_sentences solver struc guard) in - let tps = tuples struc.elements (List.map var_str all_vs) asg_gd in + let tps = tuples (Structure.elems struc) + (List.map var_str all_vs) asg_gd in let add_val acc tp = let tp_asg = asg_of_tuple struc all_vs tp in acc +. (get_real_val solver tp_asg r struc) in Modified: trunk/Toss/Solver/Structure.ml =================================================================== --- trunk/Toss/Solver/Structure.ml 2011-05-31 20:33:02 UTC (rev 1468) +++ trunk/Toss/Solver/Structure.ml 2011-06-03 20:24:22 UTC (rev 1469) @@ -55,10 +55,16 @@ let equal s1 s2 = (compare s1 s2 = 0) let elements s = Elems.elements s.elements +let elems s = s.elements let elem_nbr s el = StringMap.find el s.names let elem_name s e = IntMap.find e s.inv_names +let nbr_elems s = Elems.cardinal s.elements +let names s = s.names +let inv_names s = s.inv_names +let replace_names s nms inms = { s with names = nms; inv_names = inms } +let functions s = s.functions +let relations s = s.relations - (* ----------------------- BASIC HELPER FUNCTIONS --------------------------- *) (* Number of tuples in a relation. *) @@ -122,8 +128,14 @@ StringMap.fold (fun f _ acc -> f :: acc) struc.functions [] +(* Find a relation in a model, throw Not_found if not found. *) +let rel_find relname model = StringMap.find relname model.relations +(* Incidences of a relation in a model, throw Not_found if not found. *) +let rel_incidence relname model = StringMap.find relname model.incidence + + (* ---------- ADDING ELEMENTS POSSIBLY WITH HASHED STRING NAMES ---------- *) (* Nonexisting elements or relations, signature mismatch, etc. *) @@ -1150,6 +1162,25 @@ List.filter (fun (_, rs) -> rs <> []) (List.rev_map diff_rels elems) +let diffrels_struc s1 s2 = + if equal { s1 with relations = StringMap.empty; } + { s2 with relations = StringMap.empty; } then + let is_eq_in map rel tp = + try + Tuples.equal (StringMap.find rel map) tp + with Not_found -> false in + let is_eq_in1, is_eq_in2 = is_eq_in s1.relations, is_eq_in s2.relations in + let diffrels = ref [] in + let appdiff1 r tp = if not (is_eq_in1 r tp) then diffrels := r::!diffrels in + let appdiff2 r tp = if not (is_eq_in2 r tp) then diffrels := r::!diffrels in + StringMap.iter appdiff1 s2.relations; + StringMap.iter appdiff2 s1.relations; + if !debug_level > 1 then + print_endline ("SOME DIFF: " ^ (String.concat ", " !diffrels)); + Some (Aux.unique_sorted !diffrels) + else None + + (* -------------------- PARSER HELPERS -------------------- *) let is_uppercase c = c >= 'A' && c <= 'Z' Modified: trunk/Toss/Solver/Structure.mli =================================================================== --- trunk/Toss/Solver/Structure.mli 2011-05-31 20:33:02 UTC (rev 1468) +++ trunk/Toss/Solver/Structure.mli 2011-06-03 20:24:22 UTC (rev 1469) @@ -17,25 +17,24 @@ (** No element is named by a decimal numeral other than its number. Elements not appearing in [names] are assumed to be named by their decimal numeral. *) -type structure = { - rel_signature : int StringMap.t ; - elements : Elems.t ; (** Elements should be *positive* integers. *) - relations : Tuples.t StringMap.t ; - functions : (float IntMap.t) StringMap.t ; - incidence : (Tuples.t IntMap.t) StringMap.t ; - names : int StringMap.t ; - inv_names : string IntMap.t ; -} +type structure val compare_elems : int -> int -> int val compare : structure -> structure -> int val equal : structure -> structure -> bool val elements : structure -> int list +val elems : structure -> Elems.t +val nbr_elems : structure -> int + val elem_nbr : structure -> string -> int val elem_name : structure -> int -> string +val names : structure -> int StringMap.t +val inv_names : structure -> string IntMap.t +val replace_names : structure -> int StringMap.t -> string IntMap.t -> structure +val functions : structure -> (float IntMap.t) StringMap.t +val relations : structure -> Tuples.t StringMap.t - (** {2 Basic helper functions} *) (** Size of a relation, i.e. number of tuples in it. *) @@ -59,12 +58,19 @@ (** Check if a relation holds for a tuple. *) val check_rel : structure -> string -> int array -> bool +(** Find a relation in a model, throw Not_found if not found. *) +val rel_find : string -> structure -> Tuples.t + +(** Incidences of a relation in a model, throw Not_found if not found. *) +val rel_incidence : string -> structure -> Tuples.t IntMap.t + (** Return the value of function [f] on [e] in [struc]. *) val fun_val : structure -> string -> int -> float (** Return the list of functions. *) val f_signature : structure -> string list +(** Return the list of relations with their arities. *) val rel_signature : structure -> (string * int) list (** Cardinality of graphs of all relations in the structure. *) @@ -227,7 +233,10 @@ no defined properties, unless [ignore_funs] is given). *) val gc_elems : ?ignore_funs:bool -> structure -> structure +(** Differing relations (used in solver cache) *) +val diffrels_struc: structure -> structure -> string list option + (** {2 Parser Helpers} *) exception Board_parse_error of string Modified: trunk/Toss/Solver/StructureTest.ml =================================================================== --- trunk/Toss/Solver/StructureTest.ml 2011-05-31 20:33:02 UTC (rev 1468) +++ trunk/Toss/Solver/StructureTest.ml 2011-06-03 20:24:22 UTC (rev 1469) @@ -25,7 +25,7 @@ let struc = struc_of_string s in assert_equal ~printer:(String.concat " | ") result (List.map (test_incident_in_struc struc) - (Elems.elements struc.elements)) + (Structure.elements struc)) let test_del s en result = let struc = struc_of_string s in This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-05 21:15:41
|
Revision: 1470 http://toss.svn.sourceforge.net/toss/?rev=1470&view=rev Author: lukaszkaiser Date: 2011-06-05 21:15:35 +0000 (Sun, 05 Jun 2011) Log Message: ----------- Replacing incidence maps with arrays over elements in Structure ml. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Solver/Assignments.ml trunk/Toss/Solver/Assignments.mli trunk/Toss/Solver/Solver.ml trunk/Toss/Solver/Structure.ml trunk/Toss/Solver/Structure.mli Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2011-06-03 20:24:22 UTC (rev 1469) +++ trunk/Toss/Arena/Arena.ml 2011-06-05 21:15:35 UTC (rev 1470) @@ -738,7 +738,7 @@ with Not_found -> false) then (state_game, state), "SET ARITY" else - let s = Structure.force_add_rel_name rel ar struc in + let s = Structure.add_rel_name rel ar struc in ((state_game, { state with struc = s }), "SET ARITY") | GetArity (rel) -> ( if rel = "" then ((state_game, state), sig_str state) else Modified: trunk/Toss/Solver/Assignments.ml =================================================================== --- trunk/Toss/Solver/Assignments.ml 2011-06-03 20:24:22 UTC (rev 1469) +++ trunk/Toss/Solver/Assignments.ml 2011-06-05 21:15:35 UTC (rev 1470) @@ -482,13 +482,13 @@ match aset with (* TODO: better use of incidence map? *) | Empty -> Empty | FO (v, map) when Aux.array_mem v vars -> - let tps e = - try IntMap.find e incidence_map with Not_found -> Tuples.empty in - let aset_tuples = - List.fold_left (fun s (e,_)-> Tuples.union s (tps e)) Tuples.empty map - in - if aset_tuples = Tuples.empty then Empty else - full_join_rel aset vars aset_tuples all_elems + let tps e = + if e < Array.length incidence_map then incidence_map.(e) else + Tuples.empty in + let aset_tuples = + List.fold_left (fun s (e,_)->Tuples.union s (tps e)) Tuples.empty map in + if aset_tuples = Tuples.empty then Empty else + full_join_rel aset vars aset_tuples all_elems | _ -> full_join_rel aset vars tuples_set all_elems and full_join_rel aset vars tuples_set all_elems = Modified: trunk/Toss/Solver/Assignments.mli =================================================================== --- trunk/Toss/Solver/Assignments.mli 2011-06-03 20:24:22 UTC (rev 1469) +++ trunk/Toss/Solver/Assignments.mli 2011-06-05 21:15:35 UTC (rev 1470) @@ -98,7 +98,7 @@ val join_rel : assignment_set -> Formula.fo_var array -> Structure.Tuples.t -> - Structure.Tuples.t Structure.IntMap.t -> set_list ref -> assignment_set + Structure.Tuples.t array -> set_list ref -> assignment_set val full_join_rel : assignment_set -> Formula.fo_var array -> Structure.Tuples.t -> set_list ref -> assignment_set Modified: trunk/Toss/Solver/Solver.ml =================================================================== --- trunk/Toss/Solver/Solver.ml 2011-06-03 20:24:22 UTC (rev 1469) +++ trunk/Toss/Solver/Solver.ml 2011-06-05 21:15:35 UTC (rev 1470) @@ -133,9 +133,7 @@ let tuples_s = try Structure.rel_find relname model with Not_found -> Tuples.empty in - let inc_map = - try Structure.rel_incidence relname model - with Not_found -> IntMap.empty in + let inc_map = Structure.rel_incidence relname model in report (join_rel aset vl tuples_s inc_map elems) | Eq (x, y) -> report (equal_vars elems x y aset) | SO (v, vl) -> Modified: trunk/Toss/Solver/Structure.ml =================================================================== --- trunk/Toss/Solver/Structure.ml 2011-06-03 20:24:22 UTC (rev 1469) +++ trunk/Toss/Solver/Structure.ml 2011-06-05 21:15:35 UTC (rev 1470) @@ -30,12 +30,30 @@ let tuples_of_list nes = add_tuples nes Tuples.empty +module TIntMap = struct + type t = Tuples.t array + let empty = Array.make 4 Tuples.empty + let is_empty a = + let res = ref true in + Array.iter (fun t -> if not (Tuples.is_empty t) then res := false) a; + !res + let find i a = if i < 0 || i+1 > Array.length a then Tuples.empty else a.(i) + let add i tuples a = + let l = Array.length a in + if i < l then let b = Array.copy a in b.(i) <- tuples; b else + let b = Array.make (max (i-l+1) l) Tuples.empty in + let c = Array.append a b in c.(i) <- tuples; c + let remove i a = + if i < 0 || i+1 > Array.length a || Tuples.is_empty a.(i) then a else + let b = Array.copy a in b.(i) <- Tuples.empty; b +end + type structure = { rel_signature : int StringMap.t ; elements : Elems.t ; relations : Tuples.t StringMap.t ; functions : (float IntMap.t) StringMap.t ; - incidence : (Tuples.t IntMap.t) StringMap.t ; + incidence : (TIntMap.t) StringMap.t ; names : int StringMap.t ; inv_names : string IntMap.t ; } @@ -104,11 +122,9 @@ (* Return the list of relation tuples incident to an element [e] in [struc]. *) let incident struc e = let acc_incident rname inc_map acc = - try - (rname, Tuples.elements (IntMap.find e inc_map)) :: acc - with Not_found -> acc - in - StringMap.fold acc_incident struc.incidence [] + let tps = TIntMap.find e inc_map in + if Tuples.is_empty tps then acc else (rname, Tuples.elements tps) :: acc in + StringMap.fold acc_incident struc.incidence [] (* Check if a relation holds for a tuple. *) @@ -132,7 +148,8 @@ let rel_find relname model = StringMap.find relname model.relations (* Incidences of a relation in a model, throw Not_found if not found. *) -let rel_incidence relname model = StringMap.find relname model.incidence +let rel_incidence relname model = + try StringMap.find relname model.incidence with Not_found -> TIntMap.empty @@ -208,7 +225,7 @@ { struc with rel_signature = StringMap.add rn arity struc.rel_signature; relations = StringMap.add rn Tuples.empty struc.relations; - incidence = StringMap.add rn IntMap.empty struc.incidence; } + incidence = StringMap.add rn TIntMap.empty struc.incidence; } let empty_with_signat signat = List.fold_right (fun (rn,ar) -> add_rel_name rn ar) signat @@ -220,7 +237,7 @@ { struc with rel_signature = StringMap.add rn arity struc.rel_signature; relations = StringMap.add rn Tuples.empty struc.relations; - incidence = StringMap.add rn IntMap.empty struc.incidence; } + incidence = StringMap.add rn TIntMap.empty struc.incidence; } (* Add tuple [tp] to relation [rn] in structure [struc]. *) let add_rel struc rn tp = @@ -233,14 +250,14 @@ let new_rel = add_to_relmap new_struc.relations in let add_to_imap imap e = try - IntMap.add e (Tuples.add tp (IntMap.find e imap)) imap + TIntMap.add e (Tuples.add tp (TIntMap.find e imap)) imap with Not_found -> - IntMap.add e (Tuples.singleton tp) imap in + TIntMap.add e (Tuples.singleton tp) imap in let new_incidence_imap = try Array.fold_left add_to_imap (StringMap.find rn new_struc.incidence) tp with Not_found -> - Array.fold_left add_to_imap IntMap.empty tp in + Array.fold_left add_to_imap TIntMap.empty tp in let new_incidence = StringMap.add rn new_incidence_imap new_struc.incidence in { new_struc with relations = new_rel ; incidence = new_incidence } @@ -260,14 +277,14 @@ StringMap.add rn (Tuples.add tp tps) struc.relations in let add_to_imap imap e = try - IntMap.add e (Tuples.add tp (IntMap.find e imap)) imap + TIntMap.add e (Tuples.add tp (TIntMap.find e imap)) imap with Not_found -> - IntMap.add e (Tuples.singleton tp) imap in + TIntMap.add e (Tuples.singleton tp) imap in let new_incidence_imap = try Array.fold_left add_to_imap (StringMap.find rn struc.incidence) tp with Not_found -> - Array.fold_left add_to_imap IntMap.empty tp in + Array.fold_left add_to_imap TIntMap.empty tp in let new_incidence = StringMap.add rn new_incidence_imap struc.incidence in { struc with relations = new_rel ; incidence = new_incidence } @@ -365,7 +382,7 @@ with Not_found -> rmap in let new_rel = del_rmap struc.relations in let del_imap imap e = - try IntMap.add e (Tuples.remove tp (IntMap.find e imap)) imap + try TIntMap.add e (Tuples.remove tp (TIntMap.find e imap)) imap with Not_found -> imap in let new_incidence = let imap=Array.fold_left del_imap (StringMap.find rn struc.incidence) tp in @@ -431,7 +448,7 @@ let gc_elems = List.filter (fun e -> StringMap.fold (fun _ incmap empty -> - empty && try Tuples.is_empty (IntMap.find e incmap) + empty && try Tuples.is_empty (TIntMap.find e incmap) with Not_found -> true) struc.incidence true) all_elems in let gc_elems = if ignore_funs then gc_elems @@ -939,9 +956,9 @@ Tuples.mem tup tmap && let rmap = try StringMap.find pred !ret.incidence - with Not_found -> IntMap.empty in + with Not_found -> TIntMap.empty in not (Tuples.is_empty ( - try IntMap.find elem rmap + try TIntMap.find elem rmap with Not_found -> Tuples.empty))) all_predicates in let up_line = String.make 3 ' ' @@ -1155,7 +1172,7 @@ let diff_elems s1 s2 = let rels, _ = List.split (rel_signature s1) in let elems = Elems.elements s1.elements in - let inc s r e = try IntMap.find e (StringMap.find r s.incidence) with + let inc s r e = try TIntMap.find e (StringMap.find r s.incidence) with Not_found -> Tuples.empty in let diff_elem_rel e r = not (Tuples.equal (inc s1 r e) (inc s2 r e)) in let diff_rels e = (e, List.filter (diff_elem_rel e) rels) in Modified: trunk/Toss/Solver/Structure.mli =================================================================== --- trunk/Toss/Solver/Structure.mli 2011-06-03 20:24:22 UTC (rev 1469) +++ trunk/Toss/Solver/Structure.mli 2011-06-05 21:15:35 UTC (rev 1470) @@ -62,7 +62,7 @@ val rel_find : string -> structure -> Tuples.t (** Incidences of a relation in a model, throw Not_found if not found. *) -val rel_incidence : string -> structure -> Tuples.t IntMap.t +val rel_incidence : string -> structure -> Tuples.t array (** Return the value of function [f] on [e] in [struc]. *) val fun_val : structure -> string -> int -> float @@ -164,10 +164,6 @@ (** Ensure relation named [rn] exists in [struc], add if needed. *) val add_rel_name : string -> int -> structure -> structure -(** Add relation named [rn] to [struc], with given arity, regardless of - whether it already existed. *) -val force_add_rel_name : string -> int -> structure -> structure - (** Add tuple [tp] to relation [rn] in structure [struc]. *) val add_rel : structure -> string -> int array -> structure This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-05 23:34:14
|
Revision: 1471 http://toss.svn.sourceforge.net/toss/?rev=1471&view=rev Author: lukaszkaiser Date: 2011-06-05 23:34:06 +0000 (Sun, 05 Jun 2011) Log Message: ----------- Pre-caching game states, speedup in web client. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/Arena.mli trunk/Toss/Arena/ArenaParser.mly trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Server/ReqHandler.ml trunk/Toss/Server/ReqHandler.mli trunk/Toss/Server/Server.ml Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2011-06-05 21:15:35 UTC (rev 1470) +++ trunk/Toss/Arena/Arena.ml 2011-06-05 23:34:06 UTC (rev 1471) @@ -585,8 +585,9 @@ | SetTime of float * float (* Set time step and time *) | GetTime (* Get time step and time *) | SetState of game * game_state (* Set the full state *) + | GetState (* Return the state *) + | SetModel of Structure.structure (* Set the model *) | GetModel (* Return the current model*) - | GetState (* Return the state *) (* --------------------------- REQUEST HANDLER ------------------------------ *) @@ -996,8 +997,9 @@ ((state_game, state), string_of_float (ts) ^ " / " ^ string_of_float (t)) | SetState (g, s) -> ((g, s), "STATE SET") + | GetState -> ((state_game, state), state_str (state_game, state)) + | SetModel m -> ((state_game, { state with struc = m }), "MODEL SET") | GetModel -> ((state_game, state), Structure.sprint state.struc) - | GetState -> ((state_game, state), state_str (state_game, state)) let can_modify_game = function Modified: trunk/Toss/Arena/Arena.mli =================================================================== --- trunk/Toss/Arena/Arena.mli 2011-06-05 21:15:35 UTC (rev 1470) +++ trunk/Toss/Arena/Arena.mli 2011-06-05 23:34:06 UTC (rev 1471) @@ -211,9 +211,11 @@ | SetTime of float * float (** Set time step and time *) | GetTime (** Get time step and time *) | SetState of game * game_state (** Set the full state *) - | GetModel (** Return the model *) | GetState (** Return the state *) + | SetModel of Structure.structure (** Set the model *) + | GetModel (** Return the model *) + val handle_request : game * game_state -> request -> (game * game_state) * string Modified: trunk/Toss/Arena/ArenaParser.mly =================================================================== --- trunk/Toss/Arena/ArenaParser.mly 2011-06-05 21:15:35 UTC (rev 1470) +++ trunk/Toss/Arena/ArenaParser.mly 2011-06-05 23:34:06 UTC (rev 1471) @@ -143,6 +143,10 @@ | SET_CMD STATE_SPEC gs=game_state { let (g, s) = gs in SetState (g, s) } | GET_CMD STATE_SPEC { GetState } | GET_CMD MODEL_SPEC { GetModel } + | SET_CMD MODEL_SPEC struct_expr { SetModel $3 } + | SET_CMD MODEL_SPEC model = struct_expr WITH + defs = separated_list (SEMICOLON, rel_def_simple) + { SetModel (Arena.add_def_rels model defs) } | ADD_CMD ELEM_MOD struct_location { AddElem ($3) } | ADD_CMD REL_MOD Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2011-06-05 21:15:35 UTC (rev 1470) +++ trunk/Toss/Formula/FormulaOps.ml 2011-06-05 23:34:06 UTC (rev 1471) @@ -531,15 +531,15 @@ (* --------------------------- TRANSITIVE CLOSURE --------------------------- *) (* We construct the lfp transitive closure of phi(x, y, z) over x, y as - "lfp T(y) = (y = x or ex n (n in T and phi (n, y, z)))" *) + "x = y or lfp T(y) = (phi(x, y, z) or ex n (n in T and phi (n, y, z)))" *) let make_lfp_tc x y phi = let (fv, xv, yv) = (free_vars phi, fo_var_of_string x, fo_var_of_string y) in let (_, nn) = subst_name_avoiding fv (fo_var_of_string "n") in let nnv = fo_var_of_string nn in let frT = mso_var_of_string(snd(subst_name_avoiding fv(var_of_string "T"))) in let nphi = subst_vars [(x, nn)] phi in - let fpphi = Or [Eq (xv, yv); Ex([(nnv :> var)], And [In (nnv, frT); nphi])] in - Lfp ((frT :> [ mso_var | so_var ]), [|yv|], fpphi) + let fpphi = Or [phi; Ex([(nnv :> var)], And [In (nnv, frT); nphi])] in + Or [Eq (xv, yv); Lfp ((frT :> [ mso_var | so_var ]), [|yv|], fpphi)] (* We construct the mso transitive closure of phi(x, y, z) over x, y as "all X (x in X and (all x',y' Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-05 21:15:35 UTC (rev 1470) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-05 23:34:06 UTC (rev 1471) @@ -196,8 +196,21 @@ let client_get_model () = client_msg "GET MODEL" -let client_set_state state_s = ignore (client_msg ("SET STATE " ^ state_s)) +let client_set_model model_s = ignore (client_msg ("SET MODEL " ^ model_s)) +let client_game_states = Hashtbl.create 7 + +let client_set_game game = + let client_set_state state_s = ignore (client_msg ("SET STATE "^ state_s)) in + let dbtable select tbl = DB.get_table !DB.dbFILE ~select tbl in + try + let game_cl = Hashtbl.find client_game_states game in + client := game_cl + with Not_found -> + let toss = (List.hd (dbtable ("game='" ^ game ^ "'") "games")).(1) in + ignore (client_set_state ("#db#" ^ toss)); + Hashtbl.add client_game_states game !client + let client_get_cur_loc () = strip_ws (split "/" (client_msg "GET LOC")).(0) @@ -244,8 +257,6 @@ let add_shift_s sh s = add_shift sh (Array.map strip_ws (split "," s)) in List.fold_left add_shift_s [] (List.map strip_ws (split_list ";" m)) -let client_open_from_str s = client_set_state ("#db#" ^ s) - let client_move_str (pl, m, r, e) = let mstr m = String.concat ", " (List.map (fun (a, b) -> a ^ ": " ^ b) m) in pl ^ ",({" ^ mstr m ^ "}, " ^ r ^ ", " ^ e ^ ")" @@ -415,6 +426,8 @@ "<body><p>Not found: " ^ fname_in ^ "</p></body>\n</html>") let handle_http_post cmd head msg ck = + let http_start_time = Unix.gettimeofday () in + let http_time () = Unix.gettimeofday() -. http_start_time in let (tID, dbFILE) = (!DB.tID, !DB.dbFILE) in let get_args s = Array.map (strip_all ["'"]) (split ", " s) in let dbtable select tbl = DB.get_table dbFILE ~select tbl in @@ -463,8 +476,7 @@ if !debug_level > 1 then print_endline "Glob lock release"; ignore (DB.update_table dbFILE ~select "locked='false'" "lock") in let new_play game pl1 pl2 = - let toss = (List.hd (dbtable ("game='" ^ game ^ "'") "games")).(1) in - client_open_from_str toss; + client_set_game (game); let info = client_get_game_info () in let model = client_get_model () in let loc = client_get_cur_loc () in @@ -481,8 +493,8 @@ let (g, p1, p2, m, old_toss, old_loc, old_info, old_svg) = (old_res.(1), old_res.(2), old_res.(3), old_res.(4), old_res.(5), old_res.(6), old_res.(7), old_res.(8)) in - let game_toss = (List.hd (dbtable ("game='" ^ g ^ "'") "games")).(1) in - client_open_from_str (game_toss ^ "\nMODEL " ^ old_toss); + client_set_game (g); + client_set_model (old_toss); client_set_cur_loc old_loc; let (move1a, move2, move3) = move_tup in let move1 = strip_all ["{"; "}"] move1a in @@ -503,9 +515,10 @@ let suggest player time pid = let res = List.hd (dbtable (game_select_s pid) "cur_states") in let (g, m, toss, loc) = (res.(1),int_of_string res.(4), res.(5), res.(6)) in - let game_toss = (List.hd (dbtable ("game='" ^ g ^ "'") "games")).(1) in - client_open_from_str (game_toss ^ "\nMODEL " ^ toss); + client_set_game (g); + client_set_model (toss); client_set_cur_loc loc; + if !debug_level>1 then Printf.printf "Suggest setup: %fs\n%!" (http_time()); let adv_ratio_data = client_get_data "adv_ratio" in let adv_ratio = if adv_ratio_data = "none" then "4" else adv_ratio_data in client_suggest player time adv_ratio in Modified: trunk/Toss/Server/ReqHandler.mli =================================================================== --- trunk/Toss/Server/ReqHandler.mli 2011-06-05 21:15:35 UTC (rev 1470) +++ trunk/Toss/Server/ReqHandler.mli 2011-06-05 23:34:06 UTC (rev 1471) @@ -25,3 +25,7 @@ val full_req_handle : req_state -> in_channel -> out_channel -> req_state * bool + + +(* Client db game setting - public only for caching reasons. *) +val client_set_game : string -> unit Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-06-05 21:15:35 UTC (rev 1470) +++ trunk/Toss/Server/Server.ml 2011-06-05 23:34:06 UTC (rev 1471) @@ -141,6 +141,7 @@ (Aux.Left (ArenaParser.parse_request Lexer.lex (Lexing.from_string s))) in new_st in print_endline ("Precaching " ^ g); + ReqHandler.client_set_game g; let toss = DB.get_table !DB.dbFILE ~select:("game='" ^ g ^ "'") "games" in let init_g = handle (ReqHandler.init_state) ("SET STATE #db#" ^ (List.hd toss).(1)) in @@ -152,7 +153,7 @@ let main () = Aux.set_optimized_gc (); let (server, port, gmdir) = (ref "localhost", ref 8110, ref "") in - let (test_s, test_full, precache) = (ref "# # / $", ref false, ref false) in + let (test_s, test_full, precache) = (ref "# # / $", ref false, ref true) in let (experiment, e_len, e_d1, e_d2) = (ref false, ref 1, ref 2, ref 2) in let set_parallel_port p = let (_, s) = !GameTree.parallel_toss in @@ -190,7 +191,7 @@ ("-test", Arg.String (fun s -> test_s := s), "unit tests for given path"); ("-fulltest", Arg.String (fun s -> test_s := s; test_full := true), "full unit tests for given path, might take longer"); - ("-precache", Arg.Unit (fun () -> precache := true), "do game pre-caching"); + ("-nocache", Arg.Unit (fun () -> precache := false), "do no pre-caching"); ("-experiment", Arg.Tuple [Arg.Int (fun i -> experiment := true; e_len := i); Arg.Int (fun d1 -> e_d1 := d1); Arg.Int (fun d2 -> e_d2 := d2)], @@ -200,10 +201,6 @@ "Use a parallel running Toss client (port [p] server [s]) for computation") ] in Arg.parse opts (fun _ -> ()) "Try -help for help or one of the following."; - if !precache then ( - List.iter precache_game !DB.tGAMES; - print_endline "- precaching finished"; - ); if !test_s <> "# # / $" then ( let (name, full) = (!test_s, !test_full) in let len = String.length name in @@ -224,10 +221,16 @@ run_test !e_len !e_d1 !e_d2 ) else if !gmdir <> "" then ( DB.renew_db ~games_dir:!gmdir - ) else try - start_server req_handle !port !server + ) else ( + if !precache then ( + List.iter precache_game !DB.tGAMES; + print_endline "- precaching finished"; + ); + try + start_server req_handle !port !server with Aux.Host_not_found -> print_endline "The host you specified was not found." + ) let _ = (* Test against being called from a test... *) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-09 23:12:57
|
Revision: 1472 http://toss.svn.sourceforge.net/toss/?rev=1472&view=rev Author: lukaszkaiser Date: 2011-06-09 23:12:47 +0000 (Thu, 09 Jun 2011) Log Message: ----------- Handling forgotten passwords (reset, send email) in WebClient. Modified Paths: -------------- trunk/Toss/Server/DB.ml trunk/Toss/Server/DB.mli trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/register.html Modified: trunk/Toss/Server/DB.ml =================================================================== --- trunk/Toss/Server/DB.ml 2011-06-05 23:34:06 UTC (rev 1471) +++ trunk/Toss/Server/DB.ml 2011-06-09 23:12:47 UTC (rev 1472) @@ -17,6 +17,9 @@ "/usr/share/toss/games" else "./examples" +let tSALT = "toss##in$$some167S4lT_-" (* must be as in JavaScript! *) + + (* ------- Toss DB Creation ------- *) let create_db dbfname games_path games = @@ -120,3 +123,180 @@ let update_table dbfile ?(select="") set_s tbl = snd (apply_cmd dbfile select ("update " ^ tbl ^ " set " ^ set_s)) + + + + +(* SHA256. Thanks to mbac32768 for providing this implementation online. *) +let sha256_hash s = + let pack64 x = + let b = Buffer.create 8 in + for i = 0 to 7 do + let shft = (7-i)*8 in + Buffer.add_char b (char_of_int (Int64.to_int (Int64.logand (Int64.shift_right x shft) 0xFFL))); + done; + b in + + let pack x n = + if (n mod 8) = 0 then + let n' = n/8 in + let b = Buffer.create n' in + for i = 0 to n'-1 do + let shft = ((n'-1)-i)*8 in + Buffer.add_char b (char_of_int (Int32.to_int (Int32.logand (Int32.shift_right x shft) 0xFFl))); + done; + b + else + raise (Invalid_argument ("pack: " ^ (string_of_int n) ^ " is not a multiple of 8")) in + + let pack32 x = pack x 32 in + + let k = [| + 0x428a2f98l; 0x71374491l; 0xb5c0fbcfl; 0xe9b5dba5l; + 0x3956c25bl; 0x59f111f1l; 0x923f82a4l; 0xab1c5ed5l; + 0xd807aa98l; 0x12835b01l; 0x243185bel; 0x550c7dc3l; + 0x72be5d74l; 0x80deb1fel; 0x9bdc06a7l; 0xc19bf174l; + 0xe49b69c1l; 0xefbe4786l; 0x0fc19dc6l; 0x240ca1ccl; + 0x2de92c6fl; 0x4a7484aal; 0x5cb0a9dcl; 0x76f988dal; + 0x983e5152l; 0xa831c66dl; 0xb00327c8l; 0xbf597fc7l; + 0xc6e00bf3l; 0xd5a79147l; 0x06ca6351l; 0x14292967l; + 0x27b70a85l; 0x2e1b2138l; 0x4d2c6dfcl; 0x53380d13l; + 0x650a7354l; 0x766a0abbl; 0x81c2c92el; 0x92722c85l; + 0xa2bfe8a1l; 0xa81a664bl; 0xc24b8b70l; 0xc76c51a3l; + 0xd192e819l; 0xd6990624l; 0xf40e3585l; 0x106aa070l; + 0x19a4c116l; 0x1e376c08l; 0x2748774cl; 0x34b0bcb5l; + 0x391c0cb3l; 0x4ed8aa4al; 0x5b9cca4fl; 0x682e6ff3l; + 0x748f82eel; 0x78a5636fl; 0x84c87814l; 0x8cc70208l; + 0x90befffal; 0xa4506cebl; 0xbef9a3f7l; 0xc67178f2l |] in + let add_int32 x y = Int32.add x y in + let left_int32 x n = Int32.shift_left x n in + let right_int32 x n = Int32.shift_right_logical x n in + let or_int32 x y = Int32.logor x y in + let xor_int32 x y = Int32.logxor x y in + let and_int32 x y = Int32.logand x y in + let not_int32 x = Int32.lognot x in + + let rotate x n = (or_int32 (right_int32 x n) (left_int32 x (32 - n))) in + let shift x n = right_int32 x n in + let ch x y z = xor_int32 (and_int32 x y) (and_int32 (not_int32 x) z) in + let maj x y z = (xor_int32 (and_int32 x y) (xor_int32 (and_int32 x z) (and_int32 y z))) in + let sum0 x = (xor_int32 (rotate x 2) (xor_int32 (rotate x 13) (rotate x 22))) in + let sum1 x = (xor_int32 (rotate x 6) (xor_int32 (rotate x 11) (rotate x 25))) in + let rh00 x = (xor_int32 (rotate x 7) (xor_int32 (rotate x 18) (shift x 3))) in + let rh01 x = (xor_int32 (rotate x 17) (xor_int32 (rotate x 19) (shift x 10))) in + + let as_bytes bits = + match (bits mod 8) with + | 0 -> (bits / 8) + | _ -> failwith "as_bytes: bits must be multiple of 8" + in + let as_bits bytes = bytes * 8 in + let sha = [| + 0x6a09e667l; + 0xbb67ae85l; + 0x3c6ef372l; + 0xa54ff53al; + 0x510e527fl; + 0x9b05688cl; + 0x1f83d9abl; + 0x5be0cd19l + |] + in + let message = Buffer.create (as_bytes 512) in (* smallest possible buffer is at least 512 bits *) + begin + Buffer.add_string message s; + let original_length = as_bits (Buffer.length message) in + Buffer.add_char message '\x80'; (* append '1' bit *) + let pad_start = as_bits (Buffer.length message) in + let pad_blocks = if (original_length mod 512) < 448 then 1 else 2 in + let message_length = ((original_length / 512) + pad_blocks) * 512 in + begin (* appending k bits of 0 (where message_length-64 is our k) *) + for i = as_bytes pad_start to (as_bytes (message_length - (as_bytes 64)))-8 do + Buffer.add_char message '\x00' + done; + Buffer.add_buffer message (pack64 (Int64.of_int original_length)) + end + end; + let rec process_block i blocks = + let array_of_block i = + let boff = i*(as_bytes 512) in + let to_int32 x = (Int32.of_int (int_of_char x)) in + let w = Array.make (as_bytes 512) 0l in + begin + for t = 0 to 15 do + w.(t) <- (or_int32 (left_int32 (to_int32 (Buffer.nth message (boff + (t*4 )))) 24) + (or_int32 (left_int32 (to_int32 (Buffer.nth message (boff + (t*4+1)))) 16) + (or_int32 (left_int32 (to_int32 (Buffer.nth message (boff + (t*4+2)))) 8) + (to_int32 (Buffer.nth message (boff + (t*4+3)))) ))); + done; + for t = 16 to 63 do + w.(t) <- add_int32 (add_int32 (rh01 w.(t-2)) w.(t-7)) (add_int32 (rh00 w.(t-15)) w.(t-16)) + done; + w + end + in + if i = blocks then + let sha256 = Buffer.create (as_bytes 256) in + let rec pack_sha256 i = + match i with + | 8 -> Buffer.contents sha256 + | _ -> + begin + Buffer.add_buffer sha256 (pack32 sha.(i)); + pack_sha256 (i+1) + end + in pack_sha256 0 + else + begin + let w = array_of_block i in + let tem = [| 0l; 0l |] in + begin + let a = ref sha.(0) in + let b = ref sha.(1) in + let c = ref sha.(2) in + let d = ref sha.(3) in + let e = ref sha.(4) in + let f = ref sha.(5) in + let g = ref sha.(6) in + let h = ref sha.(7) in + for t = 0 to 63 do + begin + tem.(0) <- add_int32 (add_int32 !h (sum1 !e)) (add_int32 (ch !e !f !g) (add_int32 k.(t) w.(t))); + tem.(1) <- add_int32 (sum0 !a) (maj !a !b !c); + h := !g; + g := !f; + f := !e; + e := add_int32 !d tem.(0); + d := !c; + c := !b; + b := !a; + a := add_int32 tem.(0) tem.(1); + end + done; + sha.(0) <- add_int32 sha.(0) !a; + sha.(1) <- add_int32 sha.(1) !b; + sha.(2) <- add_int32 sha.(2) !c; + sha.(3) <- add_int32 sha.(3) !d; + sha.(4) <- add_int32 sha.(4) !e; + sha.(5) <- add_int32 sha.(5) !f; + sha.(6) <- add_int32 sha.(6) !g; + sha.(7) <- add_int32 sha.(7) !h; + + (* good faith attempt to clear memory *) + let z = Int32.of_int 0 in + for i = 0 to 63 do w.(i) <- z done; + tem.(0) <- z; tem.(1) <- z; + a := z; b := z; c := z; d := z; e := z; f := z; g := z; h := z; + end; + process_block (i+1) blocks + end + in + let hexdigits s = + let rec hexdigits_inner hx i = + match i with + | 32 -> hx + | _ -> hexdigits_inner (hx ^ (Printf.sprintf "%02x" (int_of_char s.[i]))) (i+1) + in hexdigits_inner "" 0 in + hexdigits (process_block 0 ((Buffer.length message) / (as_bytes 512))) + +let coded_password s = sha256_hash (tSALT ^ s) Modified: trunk/Toss/Server/DB.mli =================================================================== --- trunk/Toss/Server/DB.mli 2011-06-05 23:34:06 UTC (rev 1471) +++ trunk/Toss/Server/DB.mli 2011-06-09 23:12:47 UTC (rev 1472) @@ -19,3 +19,7 @@ val update_table : string -> ?select : string -> string -> string -> int val renew_db : games_dir : string -> unit + +val coded_password : string -> string + +val sha256_hash : string -> string Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-05 23:34:06 UTC (rev 1471) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-09 23:12:47 UTC (rev 1472) @@ -367,6 +367,21 @@ (* ------------ Http Handlers ------------ *) +let send_mail addr subj mail = + let tossaddr = "tos...@gm..." in + let start = Printf.sprintf "mailx -S from=\"%s\" -S replyto=\"%s\" -s \"%s\"" + tossaddr tossaddr subj in + let line = Printf.sprintf "%s %s <<EOF\n%s\nEOF" start addr mail in + Printf.printf "Sending mail to: %s\n%!" addr; + Unix.system line + +let random_pwd () = + Random.self_init (); + let rand_chr () = Char.chr (97 + (Random.int 26)) in + let s = "alamakota" in + for i = 0 to String.length s - 1 do s.[i] <- rand_chr () done; + s + let http_msg get code mimetp cookies s = let get_tm s = let t = Unix.gmtime (Unix.gettimeofday() +. s) in @@ -565,6 +580,24 @@ upd ("surname='" ^ udata.(1) ^ "'"); upd ("email='" ^ udata.(2) ^ "'"); "OK" in + let forgotpwd email = + let mail_s = "email='" ^ email ^ "'" in + let usrs = dbtable mail_s "users" in + if List.length usrs = 0 then + Printf.sprintf "Sorry, %s is not a registered email." email + else + let usr, new_pwd = List.hd usrs, random_pwd () in + let upd s = ignore (DB.update_table dbFILE ~select:mail_s s "users") in + upd ("passwd='" ^ (DB.coded_password new_pwd) ^ "'"); + let mailtxt = + ("\nThank you for playing on tPlay org!\n\n" ^ + "Your tPlay username is: " ^ usr.(0) ^ "\n" ^ + " and your new password: " ^ new_pwd ^ "\n" ^ + "\nYou can change it after you login on tPlay.\n" ^ + "\nThank You!\n\ntPlay Team\n") in + ignore (send_mail email "New password on tPlay.org" mailtxt); + print_endline mailtxt; + "Your password has been reset and sent to " ^ email ^ "." in let (tcmd, data) = split_two "#" msg in let resp, new_cookies = match tcmd with | "USERNAME" -> @@ -601,6 +634,8 @@ | "GET_MAIL" -> if verif_uid()="" then "You must login first to get email data.", [] else let (_, _, mail) = get_user_name_surname_mail data in mail, [] + | "FORGOTPWD" -> + forgotpwd data, [] | "CHANGEUSR" -> change_user_data (verif_uid ()) (split "$" data), [] | "LIST_PLAYS" -> Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-06-05 23:34:06 UTC (rev 1471) +++ trunk/Toss/WebClient/Connect.js 2011-06-09 23:12:47 UTC (rev 1472) @@ -132,6 +132,7 @@ this.register = function (data, cpwd) { return (srv ("REGISTER", data + "$" + cpwd)); } + this.forgotpwd = function (mail) { return (srv("FORGOTPWD", mail)); } this.change_data = function (name, surname, email) { return (srv ("CHANGEUSR", name +"$"+ surname +"$"+ email)); } Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-05 23:34:06 UTC (rev 1471) +++ trunk/Toss/WebClient/Login.js 2011-06-09 23:12:47 UTC (rev 1472) @@ -236,6 +236,13 @@ } } +// Send new password to user +function forgotpwd () { + var email = document.getElementById('email').value; + var resp = CONN.forgotpwd (email); + alert (resp); +} + // Change user data function change_profile () { var name = document.getElementById('name').value; Modified: trunk/Toss/WebClient/register.html =================================================================== --- trunk/Toss/WebClient/register.html 2011-06-05 23:34:06 UTC (rev 1471) +++ trunk/Toss/WebClient/register.html 2011-06-09 23:12:47 UTC (rev 1472) @@ -36,7 +36,8 @@ <input class="forminput" type="password" name="rptpassword" id="rptpassword" /> </p> -<p><button class="bt" id="registerbt" type="button" +<p><span class="reglabel"> </span> + <button class="bt" id="registerbt" type="button" onclick="register()">Register</button></p> <p> <span class="reglabel">Username:</span> <input class="forminput" type="text" name="username" @@ -50,7 +51,10 @@ <input class="forminput" type="text" name="surname" id="surname" /> </p> </form> - +<p> </p> +<p> <span class="reglabel">Forgot your password?</span> + <button class="bt" id="forgotbt" type="button" + onclick="forgotpwd()">Email New One</button></p> </div> <div id="bottom"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-09 23:25:14
|
Revision: 1473 http://toss.svn.sourceforge.net/toss/?rev=1473&view=rev Author: lukaszkaiser Date: 2011-06-09 23:25:06 +0000 (Thu, 09 Jun 2011) Log Message: ----------- Block accidental email sending during development. Modified Paths: -------------- trunk/Toss/README trunk/Toss/Server/ReqHandler.ml trunk/Toss/Server/ReqHandler.mli trunk/Toss/Server/Server.ml Modified: trunk/Toss/README =================================================================== --- trunk/Toss/README 2011-06-09 23:12:47 UTC (rev 1472) +++ trunk/Toss/README 2011-06-09 23:25:06 UTC (rev 1473) @@ -11,7 +11,7 @@ -- Installing dependencies under Ubuntu Run the following in terminal: - sudo apt-get install g++ python-qt4 python-dev pyqt4-dev-tools ocaml-findlib menhir libounit-ocaml-dev libsqlite3-ocaml-dev + sudo apt-get install g++ python-qt4 python-dev pyqt4-dev-tools ocaml-findlib menhir libounit-ocaml-dev libsqlite3-ocaml-dev heirloom-mailx Finally to compile Toss just type make Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-09 23:12:47 UTC (rev 1472) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-09 23:25:06 UTC (rev 1473) @@ -6,9 +6,11 @@ let html_dir_path = ref (if Sys.file_exists "/usr/share/toss" then "/usr/share/toss/html" else "WebClient/") -let quit_on_eof = ref true; +let quit_on_eof = ref true +let do_mails = ref false + (* ---------- Basic request type and internal handler ---------- *) type req_state = @@ -372,8 +374,8 @@ let start = Printf.sprintf "mailx -S from=\"%s\" -S replyto=\"%s\" -s \"%s\"" tossaddr tossaddr subj in let line = Printf.sprintf "%s %s <<EOF\n%s\nEOF" start addr mail in - Printf.printf "Sending mail to: %s\n%!" addr; - Unix.system line + Printf.printf "Sending %b mail to: %s\n%!" !do_mails addr; + if !do_mails then Some (Unix.system line) else None let random_pwd () = Random.self_init (); Modified: trunk/Toss/Server/ReqHandler.mli =================================================================== --- trunk/Toss/Server/ReqHandler.mli 2011-06-09 23:12:47 UTC (rev 1472) +++ trunk/Toss/Server/ReqHandler.mli 2011-06-09 23:25:06 UTC (rev 1473) @@ -7,6 +7,9 @@ val quit_on_eof : bool ref +val do_mails : bool ref + + (** {2 Request Handling Functions} *) val html_dir_path : string ref Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-06-09 23:12:47 UTC (rev 1472) +++ trunk/Toss/Server/Server.ml 2011-06-09 23:25:06 UTC (rev 1473) @@ -170,6 +170,7 @@ ("-nm", Arg.Unit (fun () -> Heuristic.use_monotonic := false), " monotonicity off"); ("-p", Arg.Int (fun i -> (port := i)), " port number (default: 8110)"); + ("-mail", Arg.Unit (fun () -> ReqHandler.do_mails:= true), "do send mails"); ("-eof", Arg.Unit (fun () -> ReqHandler.quit_on_eof := false), "do not quit server on end of file of requests"); ("-html", Arg.String (fun s -> ReqHandler.html_dir_path := s), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-10 17:39:04
|
Revision: 1474 http://toss.svn.sourceforge.net/toss/?rev=1474&view=rev Author: lukaszkaiser Date: 2011-06-10 17:38:57 +0000 (Fri, 10 Jun 2011) Log Message: ----------- WebClient updates to migrate from the old format (without concurrency) easier. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/State.js Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-09 23:25:06 UTC (rev 1473) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-10 17:38:57 UTC (rev 1474) @@ -514,8 +514,9 @@ client_set_model (old_toss); client_set_cur_loc old_loc; let (move1a, move2, move3) = move_tup in - let move1 = strip_all ["{"; "}"] move1a in - client_make_move move1 move2 move3; + let del_q s = String.concat "" (split_list "'" s) in + let move1 = strip_all ["{"; "}"] (del_q move1a) in + client_make_move move1 (del_q move2) move3; let new_toss = db_escape (client_get_model ()) in let new_info = client_get_game_info () in let new_info_db = db_escape new_info in @@ -527,7 +528,7 @@ cur_upd ("move=" ^ (string_of_int ((int_of_string m) + 1))); DB.insert_table dbFILE "old_states" "playid, game, player1, player2, move, toss, loc, info, svg" - [pid; g; p1; p2; m; old_toss; old_loc; old_info; old_svg]; + [pid; g; p1; p2; m; old_toss; old_loc; del_q old_info; old_svg]; new_info in let suggest player time pid = let res = List.hd (dbtable (game_select_s pid) "cur_states") in Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-09 23:25:06 UTC (rev 1473) +++ trunk/Toss/WebClient/Main.js 2011-06-10 17:38:57 UTC (rev 1474) @@ -226,7 +226,7 @@ if (ASYNC_ALL_REQ_PENDING != 0) { alert ("async"); return; } if (CUR_MOVE == "") return; var m = parseInt(CUR_MOVE.substring (0, 1)) - 1; - if (PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer") { + if (!isNaN(m) && PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer") { alert ("It is your Opponent's move"); return; } Modified: trunk/Toss/WebClient/State.js =================================================================== --- trunk/Toss/WebClient/State.js 2011-06-09 23:25:06 UTC (rev 1473) +++ trunk/Toss/WebClient/State.js 2011-06-10 17:38:57 UTC (rev 1474) @@ -147,7 +147,8 @@ // The fourth component is either the list of possible moves. // If there are no moves possible, it is the payoff. - if (res_arr[3].substring(2, 3) == "(") { + // The second option in "or" below is just for old format, will be removed. + if (res_arr[3].substring(2, 3) =="(" || res_arr[3].substring(0, 1) =="(") { var move_strs = convert_python_list (';', res_arr[3]); var mvs = []; var pls = []; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-11 13:39:01
|
Revision: 1478 http://toss.svn.sourceforge.net/toss/?rev=1478&view=rev Author: lukaszkaiser Date: 2011-06-11 13:38:53 +0000 (Sat, 11 Jun 2011) Log Message: ----------- Send play state data with play list. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-11 01:03:18 UTC (rev 1477) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-11 13:38:53 UTC (rev 1478) @@ -160,7 +160,7 @@ let client = ref init_state -let lstr l = "[" ^ (String.concat ", " l) ^ "]" +let lstr ?(sep=",") l = "[" ^ (String.concat sep l) ^ "]" let split_list ?(bound=None) pat s = let r = Str.regexp_string pat in @@ -471,13 +471,13 @@ let or_s = "(player1='" ^ pl_id ^ "' or player2='" ^ pl_id ^ "')" in let plays = dbtable ("game='" ^ game ^ "' and " ^ or_s) "cur_states" in let play_name p = (* p = (pid, g, p1, p2, move, _, _, _, _) *) - "/" ^ p.(1) ^ "_" ^ p.(2) ^ "_" ^ p.(3) ^ "_" ^ p.(0) ^ "_" ^ p.(4) in - lstr (List.map play_name plays) in + "/" ^ p.(1) ^ "_" ^ p.(2) ^ "_" ^ p.(3) ^ "_" ^ p.(0) ^ "_" ^ p.(4) ^ "_" ^ p.(7) in + lstr ~sep:"#" (List.map play_name plays) in let user_plays uid = let (name, _, _) = get_user_name_surname_mail uid in - let app_plays plays g = plays ^ "$" ^ (list_plays g uid) in + let app_plays plays g = plays ^ "@" ^ (list_plays g uid) in let plays = List.fold_left app_plays "" !DB.tGAMES in - uid ^ "$" ^ name ^ plays in + uid ^ "@" ^ name ^ plays in let get_free_id () = (DB.count_table dbFILE "cur_states") + 1 in let db_cur_insert game p1 p2 pid move toss loc info svg_str = DB.insert_table dbFILE "cur_states" Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-11 01:03:18 UTC (rev 1477) +++ trunk/Toss/WebClient/Login.js 2011-06-11 13:38:53 UTC (rev 1478) @@ -53,7 +53,7 @@ document.getElementById("nosvg").style.display = "block"; } else { var udata = CONN.plays (); - if (udata != "") { setup_user (udata.split("$")) }; + if (udata != "") { setup_user (udata.split("@")) }; } if (window.location.href.indexOf("?simple=true") > 0) { SIMPLE_SET = true; Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-11 01:03:18 UTC (rev 1477) +++ trunk/Toss/WebClient/Main.js 2011-06-11 13:38:53 UTC (rev 1478) @@ -177,7 +177,7 @@ } function list_plays_string (game, lst) { - PLAYS = convert_python_list (',', lst); + PLAYS = convert_python_list ('#', lst); var plist = document.getElementById("plays-list-" + game); while (plist.childNodes.length > 0) { plist.removeChild(plist.firstChild); } var d = game.length + 2; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-15 20:32:08
|
Revision: 1483 http://toss.svn.sourceforge.net/toss/?rev=1483&view=rev Author: lukaszkaiser Date: 2011-06-15 20:32:00 +0000 (Wed, 15 Jun 2011) Log Message: ----------- Small stability and debugging improvements. Modified Paths: -------------- trunk/Toss/GGP/Makefile trunk/Toss/Server/ReqHandler.ml trunk/Toss/Server/ServerGDLTest.in2 trunk/Toss/WebClient/Main.js Modified: trunk/Toss/GGP/Makefile =================================================================== --- trunk/Toss/GGP/Makefile 2011-06-14 07:07:32 UTC (rev 1482) +++ trunk/Toss/GGP/Makefile 2011-06-15 20:32:00 UTC (rev 1483) @@ -9,13 +9,13 @@ %.black: examples/%.gdl make -C .. - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../TossServer -d 2 & + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../TossServer -nocache -d 1 & java -jar gamecontroller-cli.jar play $< 600 10 1 -random 1 -remote 2 toss localhost 8110 1 | grep results killall -v TossServer %.white: examples/%.gdl make -C .. - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../TossServer -d 2 & + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../TossServer -nocache -d 1 & java -jar gamecontroller-cli.jar play $< 600 10 1 -random 2 -remote 1 toss localhost 8110 1 | grep results killall -v TossServer Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-14 07:07:32 UTC (rev 1482) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-15 20:32:00 UTC (rev 1483) @@ -455,7 +455,10 @@ | x when x > 1 -> failwith ("passwd from db: multiple entries for " ^ uid) | _ -> let r = List.hd res in (* r = (uid,_,_,_,pwd) *) Some (r.(4)) in let get_user_name_surname_mail uid = - let res = dbtable ("id='" ^ uid ^ "'") "users" in + let res0 = dbtable ("id='" ^ uid ^ "'") "users" in + let res = if res0 = [] then + dbtable ("id='" ^ (str_replace "-" "_" uid) ^ "'") "users" + else res0 in match List.length res with | 0 -> ("", "", "") | x when x > 1 -> failwith ("get_user_name: multiple entries for " ^ uid) @@ -470,8 +473,10 @@ let list_plays game pl_id = let or_s = "(player1='" ^ pl_id ^ "' or player2='" ^ pl_id ^ "')" in let plays = dbtable ("game='" ^ game ^ "' and " ^ or_s) "cur_states" in + let rpl s = str_replace "_" "-" s in let play_name p = (* p = (pid, g, p1, p2, move, _, _, _, _) *) - "/" ^ p.(1) ^ "_" ^ p.(2) ^ "_" ^ p.(3) ^ "_" ^ p.(0) ^ "_" ^ p.(4) ^ "_" ^ p.(7) in + "/" ^ (rpl p.(1)) ^ "_" ^ (rpl p.(2)) ^ "_" ^ (rpl p.(3)) ^ "_" ^ + (rpl p.(0)) ^ "_" ^ (rpl p.(4)) ^ "_" ^ (rpl p.(7)) in lstr ~sep:"#" (List.map play_name plays) in let user_plays uid = let (name, _, _) = get_user_name_surname_mail uid in @@ -673,45 +678,48 @@ else try Aux.Left (req_handle rstate (Aux.Right (GDLParser.parse_request KIFLexer.lex (Lexing.from_string msg)))) - with Parsing.Parse_error | Lexer.Parsing_error _ -> - Aux.Right (rstate, fun () -> handle_http_post cmd head msg ck) + with Parsing.Parse_error | Lexer.Parsing_error _ | + Failure "lexing: empty token" -> + print_endline (head ^ "\n" ^ cmd); + Aux.Right (rstate, fun () -> handle_http_post cmd head msg ck) + - - (* ------- Full Request Handler (both Html and Generic Toss) ------- *) let rec read_in_line in_ch = let line_in = let rec nonempty () = let line_in = input_line in_ch in - if line_in = "" || line_in = "\r" then nonempty () + if line_in = "" || line_in = "\r" then + try nonempty () with End_of_file -> "" else line_in in nonempty () in let line_in_len = String.length line_in in + if line_in_len = 0 then ("", None) else (* TODO: who needs escaping? *) - let line_in = - if line_in.[line_in_len-1] <> '\r' then + let line_in = + if line_in.[line_in_len-1] <> '\r' then (* String.escaped *) line_in - else + else (* String.escaped *) (String.sub line_in 0 (line_in_len-1)) in - match Aux.input_if_http_message line_in in_ch with - | Some (head, msg, cookies) -> - if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" msg; - let ck = List.map (fun (k, v) -> (strip_ws k, strip_ws v)) cookies in - ("HTTP", Some (Aux.Left (line_in, head, msg, ck))) - | None -> - if line_in = "COMP" then - let res = Marshal.from_channel in_ch in - if !debug_level > 0 then Printf.printf "COMP, %!"; - ("COMP", Some (Aux.Right res)) - else - (* We put endlines, encoded by '$', back into the message. - TODO: perhaps a "better" solution now that HTTP has one? *) - let line = - String.concat "\n" - (Str.split (Str.regexp "\\$") line_in) in - if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" line; - (line, None) + match Aux.input_if_http_message line_in in_ch with + | Some (head, msg, cookies) -> + if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" msg; + let ck = List.map (fun (k, v) -> (strip_ws k, strip_ws v)) cookies in + ("HTTP", Some (Aux.Left (line_in, head, msg, ck))) + | None -> + if line_in = "COMP" then + let res = Marshal.from_channel in_ch in + if !debug_level > 0 then Printf.printf "COMP, %!"; + ("COMP", Some (Aux.Right res)) + else + (* We put endlines, encoded by '$', back into the message. + TODO: perhaps a "better" solution now that HTTP has one? *) + let line = + String.concat "\n" + (Str.split (Str.regexp "\\$") line_in) in + if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" line; + (line, None) let full_req_handle rstate in_ch out_ch = @@ -727,6 +735,7 @@ flush out_ch; (new_rstate, continue) in match read_in_line in_ch with + | ("", None) -> print_endline "Empty line."; (rstate, true) | (line, Some (Aux.Right (f, x))) when line = "COMP" -> (match Unix.fork () with | 0 (* child *) -> Modified: trunk/Toss/Server/ServerGDLTest.in2 =================================================================== --- trunk/Toss/Server/ServerGDLTest.in2 2011-06-14 07:07:32 UTC (rev 1482) +++ trunk/Toss/Server/ServerGDLTest.in2 2011-06-15 20:32:00 UTC (rev 1483) @@ -50,4 +50,4 @@ Content-type: text/acl Content-length: 41 -(STOP MATCH.3316980891 (NOOP (MARK 3 2))) +(STOP MATCH.3316980891 (NOOP (MARK 3 2))) \ No newline at end of file Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-14 07:07:32 UTC (rev 1482) +++ trunk/Toss/WebClient/Main.js 2011-06-15 20:32:00 UTC (rev 1483) @@ -227,7 +227,7 @@ if (ASYNC_ALL_REQ_PENDING != 0) { alert ("async"); return; } if (CUR_MOVE == "") return; var m = parseInt(CUR_MOVE.substring (0, 1)) - 1; - if (!isNaN(m) && PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer") { + if (!isNaN(m) && PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer" && PLAYS[CUR_PLAY_I][m] != UNAME.replace("_", "-")) { alert ("It is your Opponent's move"); return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-17 20:31:51
|
Revision: 1487 http://toss.svn.sourceforge.net/toss/?rev=1487&view=rev Author: lukaszkaiser Date: 2011-06-17 20:31:43 +0000 (Fri, 17 Jun 2011) Log Message: ----------- PlayDisplay object and previous move command. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Play.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-17 20:31:43 UTC (rev 1487) @@ -425,7 +425,7 @@ with Not_found -> fname_in1 in let fname = !html_dir_path ^ fname_in in if !debug_level > 1 then Printf.printf "SERVING FILE: %s;\n%!" fname; - if Sys.file_exists fname then ( + if Sys.file_exists fname && not (Sys.is_directory fname) then ( let f = open_in fname in let content = Aux.input_file f in close_in f; @@ -572,6 +572,9 @@ let res = dbtable (game_select_s pid) "cur_states" in let (move, info) = ((List.hd res).(4), (List.hd res).(7)) in info in + let open_old pid move = + let res = dbtable ("playid=" ^ pid ^ " and move=" ^ move) "old_states" in + if res = [] then "NONE" else (List.hd res).(7) in let add_opponent uid oppid = if uid = "" then "You must login first to add opponents." else let (name, _, _) = get_user_name_surname_mail oppid in @@ -650,6 +653,8 @@ let a = get_args data in list_plays a.(0) a.(1), [] | "OPEN_DB" -> let a = get_args data in open_db a.(0), [] + | "PREV_MOVE" -> + let a = get_args data in open_old a.(0) a.(1), [] | "NEW_PLAY" -> let a = get_args data in new_play a.(0) a.(1) a.(2), [] | "SUGGEST" -> Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/Connect.js 2011-06-17 20:31:43 UTC (rev 1487) @@ -108,6 +108,9 @@ } this.open_db = function (pid) { return (srv ("OPEN_DB", pid)); } + this.prev_move = function (pid, mv) { + return (srv ("PREV_MOVE", pid + ", " + mv)); + } this.new_play = function (g, un, opp) { return (srv ("NEW_PLAY", g + ", " + un + ", " + opp)); } Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/Login.js 2011-06-17 20:31:43 UTC (rev 1487) @@ -224,6 +224,16 @@ alert ("Your data must not contain $, i.e. the dolar sign." + CORRMSG); return; } + if (un.indexOf ("#") > 0 || name.indexOf ("#") > 0 || + surname.indexOf ("#") > 0 || email.indexOf ("#") > 0) { + alert ("Your data must not contain #, i.e. the hash symbol." + CORRMSG); + return; + } + if (un.indexOf (",") > 0 || name.indexOf (",") > 0 || + surname.indexOf (",") > 0 || email.indexOf (",") > 0) { + alert ("Your data must not contain commas." + CORRMSG); + return; + } var data = un + "$" + name + "$" + surname + "$" + email; var resp = CONN.register (data, crypt(TSALT + pwd)); alert (resp); Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/Main.js 2011-06-17 20:31:43 UTC (rev 1487) @@ -22,6 +22,7 @@ UNAME_TO_NAME_MAP[uname] = name; return (name); } +nameDISP = disp_name; function handle_elem_click (elem) { PLAYS[CUR_PLAY_I].handle_click (elem); @@ -32,17 +33,18 @@ } function make_move_continue (info) { - var listing_f = function (play) {/* - var old_li = document.getElementById ("plays-list-" + play.game + - "-elem-" + CUR_PLAY_I); - var li = new_play_item (play.game, CUR_PLAY_I); - old_li.parentNode.replaceChild (li, old_li); - */}; var suggest_f = function (time) { suggest_move_async (time, make_move) }; - PLAYS[CUR_PLAY_I].move_continue (info, listing_f, suggest_f, disp_name); + PLAYS[CUR_PLAY_I].move_continue (info, suggest_f); } +function prev_move_click () { + PLAYS[CUR_PLAY_I].prev_move (); +} +function next_move_click () { + PLAYS[CUR_PLAY_I].next_move (); +} + function play_from_string (game, s) { var d = game.length + 2; var p = s.substring(s.lastIndexOf('/') + d); @@ -131,7 +133,7 @@ document.getElementById("play-number").innerHTML = "" + play_id; document.getElementById("suggestions-toggle").style.display = "inline"; CUR_PLAY_I = pi; - PLAYS[CUR_PLAY_I].redraw (disp_name); + PLAYS[CUR_PLAY_I].redraw (); } @@ -279,7 +281,7 @@ var p = new Play (GAME_NAME, [0,1], [UNAME, opp_uid], FREE_PLAY_NO, 0, info_nbr.substring(info_idx+1), UNAME); PLAYS.push(p); - p.redraw (disp_name); + p.redraw (); //li = new_play_item (GAME_NAME, CUR_PLAY_I); //document.getElementById("plays-list-" + GAME_NAME).appendChild(li); } Modified: trunk/Toss/WebClient/Play.js =================================================================== --- trunk/Toss/WebClient/Play.js 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/Play.js 2011-06-17 20:31:43 UTC (rev 1487) @@ -1,6 +1,8 @@ // JavaScript Toss Module -- Play (requires Connect.js, State.js) var SIMPLE_MOVES = true; +var nameDISP = undefined; +var PlayDISP = undefined; // --------- Play Object with Methods -------------- @@ -44,52 +46,15 @@ Play.prototype.clear = play_clear; // Full redraw. -function play_redraw (f_disp_name) { +function play_redraw () { this.clear (); - document.getElementById('cur-move').innerHTML = "none"; - this.cur_state.draw_model (this.game); - - // Functions to substitute players for 0 and 1 in a payoff string. - var win_s = function (pl, un) { - if (pl == un) { return ("You Win!"); } - return (f_disp_name(pl) + " Wins"); - } - var subst_pl = function (pl, str) { - var un = pl.cur_player_uid; - var s = strip (' ', '\n', str); - if (s == "0: 1., 1: -1.") { return (win_s (pl.players[0], un)); } - if (s == "0: -1., 1: 1.") { return (win_s (pl.players[1], un)); } - if (s == "0: 0., 1: 0.") { return ("Tie"); } - var s1 = s.replace (/0:/g, f_disp_name(pl.players[0]) + ":"); - var s2 = s1.replace (/1:/g, f_disp_name(pl.players[1]) + ":"); - var s3 = s2.replace (/1.,/g, "1,"); - var s4 = s3.replace (/0.,/g, "0,"); - var s5 = s4.replace (/1.$/g, "1"); - return (s5.replace (/0.$/g, "0")); - } - - - if (! SIMPLE_MOVES) { - document.getElementById("working").style.display = "block"; - } for (var i = 0; i < this.cur_state.elems.length; i++) { this.ELEM_COUNTERS[this.cur_state.elems[i].id] = 0; } - if (this.cur_state.payoff == "") { - document.getElementById('movebt').innerHTML = "Make move:"; - document.getElementById('cur-move').innerHTML = "none"; - } else { - if (SIMPLE_MOVES) { - document.getElementById("board").style.paddingTop = "0em"; - } - document.getElementById("move-info-par").style.display = "none"; - document.getElementById("game-info-par").style.paddingBottom = "0em"; - document.getElementById('payoffs').innerHTML = - "Result: " + subst_pl(this, this.cur_state.payoff); - document.getElementById('payoffs').style.display = "inline"; - document.getElementById('new-play-par').style.display = "block"; - } - document.getElementById("working").style.display = "none"; + PlayDISP.free (); + PlayDISP.set_cur_move ("", ""); + PlayDISP.show_payoff (this); + this.cur_state.draw_model (this.game); } Play.prototype.redraw = play_redraw; @@ -102,12 +67,7 @@ for (var i = 0; i < m.matched.length; i++) { this.cur_state.highlight_elem (m.matched[i]); } - if (m.matched_str == "") { - document.getElementById('cur-move').innerHTML = "none"; - } else { - document.getElementById('cur-move').innerHTML = - m.matched_str.replace (/,/g, " — ") + " (" + m.rule + ")" - } + PlayDISP.set_cur_move (m.matched_str, m.rule); this.CUR_ELEMS = m.matched; this.CUR_MOVE = m.def_str; } @@ -156,7 +116,7 @@ for (var i = 0; i < this.CUR_ELEMS.length; i++) { this.cur_state.unhighlight_elem (this.CUR_ELEMS[i]); } - document.getElementById('cur-move').innerHTML = elem + " — ?" + PlayDISP.set_cur_move (elem + ", ?", ""); this.cur_state.highlight_elem (elem); this.CUR_ELEMS = [elem]; this.CUR_MOVE = ""; @@ -177,18 +137,15 @@ alert ("It is your Opponent's move"); return; } - if (! SIMPLE_MOVES) { - document.getElementById("working").style.display = "block"; - } + if (! SIMPLE_MOVES) { PlayDISP.busy (); } CONN.make_move (this.CUR_MOVE, this.pid, make_move_continue); } Play.prototype.move = play_move; -function play_move_continue (info, listing_redraw_f, suggest_f, name_f) { - document.getElementById("working").style.display = "none"; +function play_move_continue (info, suggest_f) { + PlayDISP.free (); this.new_state (info); - this.redraw (name_f); - listing_redraw_f (this); + this.redraw (); if (this.cur_state.players.length == 1 && this.players[this.cur_state.players[0]] == "computer") { var mv_time = document.getElementById("speed").value; @@ -196,3 +153,83 @@ } } Play.prototype.move_continue = play_move_continue; + +function play_prev_move () { + alert (CONN.prev_move (this.pid, this.move_nbr - 1)); +} +Play.prototype.prev_move = play_prev_move; + +function play_next_move () { + alert (CONN.prev_move (this.pid, this.move_nbr + 1)); +} +Play.prototype.next_move = play_next_move; + + +// --- Wrapper Class for unified handling of Play display functions --- + +function PlayDisplay (busy_id, cur_move_id) { + this.busy_id = busy_id; + this.cur_move_id = cur_move_id; + return (this); +} + +function pd_busy () { + document.getElementById (this.busy_id).style.display = "block"; +} +PlayDisplay.prototype.busy = pd_busy; + +function pd_free () { + document.getElementById (this.busy_id).style.display = "none"; +} +PlayDisplay.prototype.free = pd_free; + +function pd_set_cur_move (matched_str, rule_str) { + if (matched_str == "") { + document.getElementById(this.cur_move_id).innerHTML = "none"; + } else { + var rule = " (" + rule_str + ")"; + if (rule_str == "") { rule = "" }; + document.getElementById(this.cur_move_id).innerHTML = + matched_str.replace (/,/g, " — ") + rule + } +} +PlayDisplay.prototype.set_cur_move = pd_set_cur_move; + +function pd_show_payoff (play) { + // Functions to substitute players for 0 and 1 in a payoff string. + var win_s = function (pl, un) { + if (pl == un) { return ("You Win!"); } + return (nameDISP(pl) + " Wins"); + } + var subst_pl = function (pl, str) { + var un = pl.cur_player_uid; + var s = strip (' ', '\n', str); + if (s == "0: 1., 1: -1.") { return (win_s (pl.players[0], un)); } + if (s == "0: -1., 1: 1.") { return (win_s (pl.players[1], un)); } + if (s == "0: 0., 1: 0.") { return ("Tie"); } + var s1 = s.replace (/0:/g, nameDISP(pl.players[0]) + ":"); + var s2 = s1.replace (/1:/g, nameDISP(pl.players[1]) + ":"); + var s3 = s2.replace (/1.,/g, "1,"); + var s4 = s3.replace (/0.,/g, "0,"); + var s5 = s4.replace (/1.$/g, "1"); + return (s5.replace (/0.$/g, "0")); + } + + if (play.cur_state.payoff == "") { + document.getElementById('movebt').innerHTML = "Make move:"; + this.set_cur_move ("", ""); + } else { + if (SIMPLE_MOVES) { + document.getElementById("board").style.paddingTop = "0em"; + } + document.getElementById("move-info-par").style.display = "none"; + document.getElementById("game-info-par").style.paddingBottom = "0em"; + document.getElementById('payoffs').innerHTML = + "Result: " + subst_pl(play, play.cur_state.payoff); + document.getElementById('payoffs').style.display = "inline"; + document.getElementById('new-play-par').style.display = "block"; + } +} +PlayDisplay.prototype.show_payoff = pd_show_payoff; + +PlayDISP = new PlayDisplay ("working", "cur-move"); Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/Style.css 2011-06-17 20:31:43 UTC (rev 1487) @@ -685,7 +685,7 @@ .game-par { padding: 0px; padding-bottom: 0.2em; - border-bottom: 1px solid #260314; + /* border-bottom: 1px solid #260314; */ } #plays { @@ -717,6 +717,7 @@ padding-left: 0px; list-style: none; margin-top: 0em; + border-top: 1px solid #260314; } .plays-list-elem { Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-17 07:26:16 UTC (rev 1486) +++ trunk/Toss/WebClient/index.html 2011-06-17 20:31:43 UTC (rev 1487) @@ -197,12 +197,12 @@ <button onclick="new_play('Breakthrough')" class="boldobt">Breakthrough</button> </p> -<ul class="plays-list" id="a-plays-list-Breakthrough"> + <ul class="plays-list" id="a-plays-list-Breakthrough"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Breakthrough"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Breakthrough"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Checkers')" class="boldobt">Checkers</button> @@ -210,9 +210,9 @@ <ul class="plays-list" id="a-plays-list-Checkers"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Checkers"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Checkers"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Chess')" class="boldobt">Chess</button> @@ -220,9 +220,9 @@ <ul class="plays-list" id="a-plays-list-Chess"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Chess"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Chess"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Connect4')" class="boldobt">Connect4</button> @@ -230,9 +230,9 @@ <ul class="plays-list" id="a-plays-list-Connect4"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Connect4"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Connect4"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Entanglement')" class="boldobt">Entanglement</button> @@ -240,9 +240,9 @@ <ul class="plays-list" id="a-plays-list-Entanglement"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Entanglement"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Entanglement"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Gomoku')" class="boldobt">Gomoku</button> @@ -250,9 +250,9 @@ <ul class="plays-list" id="a-plays-list-Gomoku"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Gomoku"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Gomoku"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Pawn-Whopping')" class="boldobt">Pawn-Whopping</button> @@ -260,9 +260,9 @@ <ul class="plays-list" id="a-plays-list-Pawn-Whopping"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Pawn-Whopping"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Pawn-Whopping"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Tic-Tac-Toe')" class="boldobt">Tic-Tac-Toe</button> @@ -270,9 +270,9 @@ <ul class="plays-list" id="a-plays-list-Tic-Tac-Toe"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Tic-Tac-Toe"> + <li style="display: none;"/> + </ul> <p class="game-par"> <button onclick="new_play('Concurrent-Tic-Tac-Toe')" class="boldobt">Concurrent-Tic-Tac-Toe</button> @@ -280,9 +280,9 @@ <ul class="plays-list" id="a-plays-list-Concurrent-Tic-Tac-Toe"> <li style="display: none;"/> </ul> - <ul class="plays-list" id="d-plays-list-Concurrent-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> + <ul class="plays-list" id="d-plays-list-Concurrent-Tic-Tac-Toe"> + <li style="display: none;"/> + </ul> </div> @@ -295,7 +295,6 @@ </span> <span id="payoffs" style="display:none;">Not Finished Yet</span> </p> - <p id="new-play-par"> <button id="new_game_me" class="bt" onclick="play_anew(true)"> New Game (You Start) @@ -304,13 +303,18 @@ New Game (Opponent Starts) </button> </p> - <p id="move-info-par"> <button id="movebt" class="bt" onclick="make_move ()">Make move:</button> <span id="cur-move">none</span> <button id="sugbt" class="bt" onclick="suggest_move_click()"> Suggest </button> + <button id="prevmovebt" class="bt" onclick="prev_move_click()"> + Prev + </button> + <button id="nextmovebt" class="bt" onclick="next_move_click()"> + Next + </button> </p> <div id="board"><div id="working">Working...</div></div> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-19 18:04:37
|
Revision: 1490 http://toss.svn.sourceforge.net/toss/?rev=1490&view=rev Author: lukaszkaiser Date: 2011-06-19 18:04:31 +0000 (Sun, 19 Jun 2011) Log Message: ----------- First PacMan example, some JS cleanups and news section in index html. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Play.js trunk/Toss/WebClient/State.js trunk/Toss/WebClient/index.html trunk/Toss/WebClient/msw.js Added Paths: ----------- trunk/Toss/WebClient/pics/appstore.png trunk/Toss/examples/PacMan.toss Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-19 18:04:31 UTC (rev 1490) @@ -455,10 +455,7 @@ | x when x > 1 -> failwith ("passwd from db: multiple entries for " ^ uid) | _ -> let r = List.hd res in (* r = (uid,_,_,_,pwd) *) Some (r.(4)) in let get_user_name_surname_mail uid = - let res0 = dbtable ("id='" ^ uid ^ "'") "users" in - let res = if res0 = [] then - dbtable ("id='" ^ (str_replace "-" "_" uid) ^ "'") "users" - else res0 in + let res = dbtable ("id='" ^ uid ^ "'") "users" in match List.length res with | 0 -> ("", "", "") | x when x > 1 -> failwith ("get_user_name: multiple entries for " ^ uid) @@ -473,11 +470,9 @@ let list_plays game pl_id = let or_s = "(player1='" ^ pl_id ^ "' or player2='" ^ pl_id ^ "')" in let plays = dbtable ("game='" ^ game ^ "' and " ^ or_s) "cur_states" in - let rpl s = str_replace "_" "-" s in let play_name p = (* p = (pid, g, p1, p2, move, _, _, _, _) *) - "/" ^ (rpl p.(1)) ^ "_" ^ (rpl p.(2)) ^ "_" ^ (rpl p.(3)) ^ "_" ^ - (rpl p.(0)) ^ "_" ^ (rpl p.(4)) ^ "_" ^ (rpl p.(7)) in - lstr ~sep:"#" (List.map play_name plays) in + p.(1) ^"#"^ p.(2) ^"#"^ p.(3) ^"#"^ p.(0) ^"#"^ p.(4) ^"#"^ p.(7) in + lstr ~sep:"##" (List.map play_name plays) in let user_plays uid = let (name, _, _) = get_user_name_surname_mail uid in let app_plays plays g = plays ^ "@" ^ (list_plays g uid) in Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/Connect.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -20,7 +20,7 @@ // Convert a string [str] representing python list to array and return it. // WARNING: we use [sep] as separator, it must not occur in list elements! -function convert_python_list (sep, str_in) { +function parse_list (sep, str_in) { var res_arr = []; var str = strip(' ', '\n', str_in); res_arr = strip('[', ']', str).split(sep); Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/Login.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -68,6 +68,7 @@ document.getElementById("toss-link").style.display = "none"; document.getElementById("welcome-top").style.display = "none"; document.getElementById("welcome-list-main").style.display = "none"; + document.getElementById("news").style.display = "none"; document.getElementById("topuser").innerHTML = "Choose Your Next Game"; document.getElementById("leftupperlogo-link").href = "index.html?simple=true"; @@ -114,7 +115,7 @@ o.appendChild (li); } var lst = CONN.allopnts (); - var users = convert_python_list (',', lst); + var users = parse_list (',', lst); var u = document.getElementById("users-list"); for (var i = 0; i < users.length; i++) { if (users[i] != un && FRIENDS.indexOf(users[i]) == -1) { @@ -229,6 +230,11 @@ alert ("Your data must not contain #, i.e. the hash symbol." + CORRMSG); return; } + if (un.indexOf ("@") > 0 || name.indexOf ("@") > 0 || + surname.indexOf ("@") > 0) { + alert ("Your username, name and surname must not contain @." + CORRMSG); + return; + } if (un.indexOf (",") > 0 || name.indexOf (",") > 0 || surname.indexOf (",") > 0 || email.indexOf (",") > 0) { alert ("Your data must not contain commas." + CORRMSG); Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/Main.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -46,9 +46,8 @@ } function play_from_string (game, s) { - var d = game.length + 2; - var p = s.substring(s.lastIndexOf('/') + d); - var lst = convert_python_list ('_', p); + var p = s.substring(game.length + 1); + var lst = parse_list ('#', p); return (new Play (game, [0, 1], [lst[0], lst[1]], lst[2], lst[3], lst[4], UNAME)); } @@ -136,7 +135,7 @@ function list_plays_string (game, lst) { - PLAYS = convert_python_list ('#', lst); + PLAYS = parse_list ('##', lst); var a_plist = document.getElementById("a-plays-list-" + game); var d_plist = document.getElementById("d-plays-list-" + game); while (a_plist.childNodes.length > 0) { a_plist.removeChild(a_plist.firstChild); } @@ -332,7 +331,7 @@ function get_opponents () { var lst = CONN.friends (); - FRIENDS = convert_python_list (',', lst); + FRIENDS = parse_list (',', lst); } function play_anew (me_starts) { Modified: trunk/Toss/WebClient/Play.js =================================================================== --- trunk/Toss/WebClient/Play.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/Play.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -132,8 +132,7 @@ if (this.CUR_MOVE == "") return; var m = parseInt(this.CUR_MOVE.substring (0, 1)) - 1; if (!isNaN(m) && this.players[m] != this.cur_player_uid && - this.players[m] != "computer" && - this.players[m] != this.cur_player_uid.replace("_", "-")) { + this.players[m] != "computer") { alert ("It is your Opponent's move"); return; } Modified: trunk/Toss/WebClient/State.js =================================================================== --- trunk/Toss/WebClient/State.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/State.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -106,10 +106,10 @@ this.height = Math.max (SVG_HEIGHT / 100, (this.maxy - this.miny)); // The second component is the list of elements of the structure. - var l = convert_python_list(',', res_arr[1]); + var l = parse_list(',', res_arr[1]); this.elems = []; for (var i = 0; i < l.length; i++) { - var e = convert_python_list (';', l[i]); + var e = parse_list (';', l[i]); var pos = translate_pos ([parseFloat(e[1]), parseFloat(e[2])], this.minx, this.miny, this.width, this.height, this.mirror); @@ -124,12 +124,12 @@ } // The third component are the relations in the structure. - var r = convert_python_list(';', res_arr[2]); + var r = parse_list(';', res_arr[2]); var rels = []; for (var i = 0; i < r.length; i++) { var rel_name = strip(' ', '\'', r[i].substring(1,r[i].indexOf(','))); var args_s = r[i].substring(r[i].indexOf('[')+1, r[i].indexOf(']')); - var args = convert_python_list (',', args_s); + var args = parse_list (',', args_s); var is_undefined = false; for (var j = 0; j < args.length; j++) { args[j] = find_elem (args[j], this.elems); @@ -153,7 +153,7 @@ // If there are no moves possible, it is the payoff. // The second option in "or" below is just for old format, will be removed. if (res_arr[3].substring(2, 3) =="(" || res_arr[3].substring(0, 1) =="(") { - var move_strs = convert_python_list (';', res_arr[3]); + var move_strs = parse_list (';', res_arr[3]); var mvs = []; var pls = []; for (i = 0; i < move_strs.length; i++) { Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/index.html 2011-06-19 18:04:31 UTC (rev 1490) @@ -94,7 +94,11 @@ <div id="welcome"> <p id="welcome-top">Enjoy the best games on <span class="logo-in">tPlay</span> - for free</p> + for free + <a href="http://itunes.apple.com/us/app/tplay/id438620686"> + <img style="height: 2em; float:right;" src="pics/appstore.png" /> + </a> +</p> <p id="p-under-welcome" style="display: none;"> Strategic games are fun! <a href="register.html">Register</a>, login and enjoy quality games @@ -172,8 +176,22 @@ <li>Challenge your friends or play a fast game against the computer for fun</li> </ul> +<div id="news"> +<h3>News</h3> +<ul id="welcome-list-news" class="welcome-list"> +<li><b>19/06/11</b> News section on the front page of tPlay</li> +<li><b>15/06/11</b> Bug with underscores in user names corrected</li> +<li><b>10/06/11</b> New register site handles forgotten passwords</li> +<li><b>05/06/11</b> Pre-caching client states improves response times</li> +<li><b>03/06/11</b> Corrected tPlay 1.1 app accepted on App Store</li> +<li><b>30/05/11</b> Large restructuring of JavaScript code finished</li> +<li><b>24/05/11</b> Breakthrough generation from examples in SVN</li> +<li><b>23/05/11</b> First tPlay application accepted on App Store</li> +</ul> </div> +</div> + <div id="nosvg"> <p style="padding-left: 1.2em; font-size: 1.2em;"><b>SVG Support Missing</b></p> <p>Your browser does not seem to support SVG, Modified: trunk/Toss/WebClient/msw.js =================================================================== --- trunk/Toss/WebClient/msw.js 2011-06-19 11:57:18 UTC (rev 1489) +++ trunk/Toss/WebClient/msw.js 2011-06-19 18:04:31 UTC (rev 1490) @@ -1,11 +1,11 @@ function msw_list_plays_string (game, lst) { - PLAYS = convert_python_list ('#', lst); + PLAYS = parse_list ('#', lst); //var plist = document.getElementById("plays-list-" + game); //while (plist.childNodes.length > 0) { plist.removeChild(plist.firstChild); } var d = game.length + 2; for (var i = 0; i < PLAYS.length; i++) { var p = PLAYS[i].substring(PLAYS[i].lastIndexOf('/') + d); - PLAYS[i] = convert_python_list ('_', p); + PLAYS[i] = parse_list ('_', p); //plist.appendChild(new_play_item (game, i)); } /*if (PLAYS.length == 0) { Added: trunk/Toss/WebClient/pics/appstore.png =================================================================== (Binary files differ) Property changes on: trunk/Toss/WebClient/pics/appstore.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/Toss/examples/PacMan.toss =================================================================== --- trunk/Toss/examples/PacMan.toss (rev 0) +++ trunk/Toss/examples/PacMan.toss 2011-06-19 18:04:31 UTC (rev 1490) @@ -0,0 +1,45 @@ +PLAYERS 1, 2, 3 +RULE Go1: + [ a1, a2 | C { (a1) }; E { (a1, a2) } | - ] + -> + [ a1, a2 | C { (a2) }; E { (a1, a2) } | - ] +emb C, C2 +RULE Go2: + [ a1, a2 | C2 { (a1) }; E { (a1, a2) } | - ] + -> + [ a1, a2 | C2 { (a2) }; E { (a1, a2) } | - ] +emb C, C2 +RULE Wait: + [ a1 | R { (a1) } | - ] -> [ a1 | R { (a1) } | - ] +emb R, C, C2 +RULE Wait1: + [ a1 | C { (a1) } | - ] -> [ a1 | C { (a1) } | - ] +emb R, C, C2 +RULE Wait2: + [ a1 | C2 { (a1) } | - ] -> [ a1 | C2 { (a1) } | - ] +emb R, C, C2 +RULE Run: + [ a1, a2 | E { (a1, a2) }; R { (a1) } | - ] + -> + [ a1, a2 | E { (a1, a2) }; R { (a2) } | - ] +emb R, C, C2 +LOC 0 { + PLAYER 1 { PAYOFF 0. } + PLAYER 2 { + PAYOFF 0. + MOVES [Go1 -> 1]; [Wait1 -> 1] + } + PLAYER 3 { + PAYOFF 0. + MOVES [Go2 -> 1]; [Wait2 -> 1] + } +} +LOC 1 { + PLAYER 1 { + PAYOFF -1. + MOVES [Run -> 0]; [Wait -> 0] + } + PLAYER 2 { PAYOFF 1. } + PLAYER 3 { PAYOFF 1. } +} +MODEL [ a1, a2, b1, b2, c1, c2, d1, d2, f1, f2, g1, g2, h1, h2, e1, e2, i1, i2 | C { (a1) }; C2 { (a2) }; E { (a2, a1); (a2, b2); (a1, a2); (a1, b1); (b1, a1); (b1, b2); (b1, c1); (b2, a2); (b2, b1); (b2, c2); (c2, b2); (c2, c1); (c2, d2); (c1, b1); (c1, c2); (c1, d1); (d2, c2); (d2, d1); (d2, e1); (d1, c1); (d1, d2); (d1, e2); (f1, f2); (f1, g1); (f1, e1); (f2, f1); (f2, g2); (f2, e2); (g1, f1); (g1, g2); (g1, h1); (g2, f2); (g2, g1); (g2, h2); (h1, g1); (h1, h2); (h1, i1); (h2, g2); (h2, h1); (h2, i2); (e1, d2); (e1, f1); (e1, e2); (e2, d1); (e2, f2); (e2, e1); (i1, h1); (i1, i2); (i2, h2); (i2, i1) }; R { (e1) }; _opt_C:1 { } | vx { d4->0., a2->0., a1->0., b1->0., b2->0., e4->0., c2->0., c1->0., f4->0., d2->0., d1->0., f1->0., f2->0., g1->0., g2->0., h1->0., h2->0., e1->0., e2->0., i1->0., i2->0. }; vy { d4->0., a2->0., a1->0., b1->0., b2->0., e4->0., c2->0., c1->0., f4->0., d2->0., d1->0., f1->0., f2->0., g1->0., g2->0., h1->0., h2->0., e1->0., e2->0., i1->0., i2->0. }; x { d4->100., a2->-50., a1->-50., b1->0., b2->0., e4->150., c2->50., c1->50., f4->200., d2->100., d1->100., f1->200., f2->200., g1->250., g2->250., h1->300., h2->300., e1->150., e2->150., i1->350., i2->350. }; y { d4->-150., a2->-100., a1->-50., b1->-50., b2->-100., e4->0., c2->-100., c1->-50., f4->-150., d2->-100., d1->-50., f1->-100., f2->-50., g1->-100., g2->-50., h1->-100., h2->-50., e1->-100., e2->-50., i1->-100., i2->-50. } ] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-22 22:37:44
|
Revision: 1494 http://toss.svn.sourceforge.net/toss/?rev=1494&view=rev Author: lukaszkaiser Date: 2011-06-22 22:37:37 +0000 (Wed, 22 Jun 2011) Log Message: ----------- Lists of plays in JavaScript. Modified Paths: -------------- trunk/Toss/Toss.py trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html Modified: trunk/Toss/Toss.py =================================================================== --- trunk/Toss/Toss.py 2011-06-22 07:34:03 UTC (rev 1493) +++ trunk/Toss/Toss.py 2011-06-22 22:37:37 UTC (rev 1494) @@ -35,7 +35,7 @@ app_win.show() sys.exit(app.exec_()) else: - args = [toss_dir + "/TossServer", "-s", host, "-p", str(port), "-d", log_level] + args = [toss_dir + "/TossServer", "-nocache", "-s", host, "-p", str(port), "-d", log_level] # gather exception backtrace information os.environ['OCAMLRUNPARAM'] = 'b' server_proc = subprocess.Popen(args) Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-06-22 07:34:03 UTC (rev 1493) +++ trunk/Toss/WebClient/Login.js 2011-06-22 22:37:37 UTC (rev 1494) @@ -30,7 +30,7 @@ list_plays_string ("Gomoku", udata[7]); list_plays_string ("Pawn-Whopping", udata[8]); list_plays_string ("Tic-Tac-Toe", udata[9]); - list_plays_string ("Concurrent-Tic-Tac-Toe", udata[10]); + /* list_plays_string ("Concurrent-Tic-Tac-Toe", udata[10]); */ get_opponents (); } @@ -48,6 +48,7 @@ // Onload handler function startup (game) { + GAMESPAGE = new GamesPage ("plays", GAMES); if (navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('MSIE 9') == -1) { document.getElementById("nosvg").style.display = "block"; Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-22 07:34:03 UTC (rev 1493) +++ trunk/Toss/WebClient/Main.js 2011-06-22 22:37:37 UTC (rev 1494) @@ -45,6 +45,98 @@ PLAYS[CUR_PLAY_I].next_move (); } + +var GAMES = new Array( + /* "Concurrent-Tic-Tac-Toe" */ + "Breakthrough", + "Checkers", + "Chess", + "Connect4", + "Entanglement", + "Gomoku", + "Pawn-Whopping", + "Tic-Tac-Toe" +); + +var GAMESPAGE = undefined; + + +function GamesPage(id, games){ // html tag id + this.games = games; + this.paragraphs = new Object(); + this.container = document.getElementById(id); + for (var i = 0; i < this.games.length; i++) { + var game = this.games[i]; + + var paragraph = document.createElement("p"); + this.paragraphs[game] = paragraph; + paragraph.setAttribute("class", "game-par"); + + var button = document.createElement("button"); + paragraph.game_button = button; + button.setAttribute("class", "boldobt"); + button.setAttribute("onclick", "new_play('" + game + "')"); + button.innerHTML = game; + button.style.display = "block"; + this.container.appendChild(paragraph); + paragraph.appendChild(button); + + var open_play_list = document.createElement("ul"); + paragraph.open_play_list = open_play_list; + open_play_list.setAttribute("class", "plays-list"); + open_play_list.setAttribute("id", "a-plays-list-" + game); + paragraph.appendChild(open_play_list); + + var completed_bt = document.createElement("button"); + paragraph.completed_button = completed_bt; + completed_bt.setAttribute("class", "completedbt"); + completed_bt.setAttribute("onclick", + "GAMESPAGE.toggle_completed('" + game + "')"); + completed_bt.innerHTML = "Completed games (Show)"; + this.container.appendChild(paragraph); + paragraph.appendChild(completed_bt); + paragraph.completed_shown = false; + + var closed_play_list = document.createElement("ul"); + paragraph.closed_play_list = closed_play_list; + closed_play_list.setAttribute("class", "plays-list"); + closed_play_list.setAttribute("id", "d-plays-list-" + game); + closed_play_list.style.display = "none"; + paragraph.appendChild(closed_play_list); + } + return (this); +} + +GamesPage.prototype.show = function () { + this.container.style.display = "block"; +} + +GamesPage.prototype.hide = function () { + this.container.style.display = "none"; +} + +GamesPage.prototype.show_completed = function (game) { + this.paragraphs[game].closed_play_list.style.display = "block"; +} + +GamesPage.prototype.hide_completed = function (game) { + this.paragraphs[game].closed_play_list.style.display = "none"; +} + +GamesPage.prototype.toggle_completed = function (game) { + var par = this.paragraphs[game]; + if (par.completed_shown) { + par.closed_play_list.style.display = "none"; + par.completed_button.innerHTML = "Completed games (Show)"; + par.completed_shown = false; + } else { + par.closed_play_list.style.display = "block"; + par.completed_button.innerHTML = "Completed games (Hide)"; + par.completed_shown = true; + } +} + + function play_from_string (game, s) { var p = s.substring(game.length + 1); var lst = parse_list ('#', p); @@ -73,14 +165,18 @@ PLAYS = parse_list ('##', lst); var a_plist = document.getElementById("a-plays-list-" + game); var d_plist = document.getElementById("d-plays-list-" + game); - while (a_plist.childNodes.length > 0) { a_plist.removeChild(a_plist.firstChild); } - while (d_plist.childNodes.length > 0) { d_plist.removeChild(d_plist.firstChild); } + while (a_plist.childNodes.length > 0) { + a_plist.removeChild(a_plist.firstChild); + } + while (d_plist.childNodes.length > 0) { + d_plist.removeChild(d_plist.firstChild); + } for (var i = 0; i < PLAYS.length; i++) { PLAYS[i] = play_from_string (game, PLAYS[i]); - if (PLAYS[i].cur_state.payoff == "") a_plist.appendChild(new_play_item (game, i)); - else - { - d_plist.appendChild(new_play_item (game, i)); + if (PLAYS[i].cur_state.payoff == "") { + a_plist.appendChild(new_play_item (game, i)); + } else { + d_plist.appendChild(new_play_item (game, i)); } } if (PLAYS.length == 0) { Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-22 07:34:03 UTC (rev 1493) +++ trunk/Toss/WebClient/Style.css 2011-06-22 22:37:37 UTC (rev 1494) @@ -91,6 +91,23 @@ text-decoration: underline; } +.completedbt { + text-align: left; + border-color: #260314; + border-radius: 4px; + -moz-border-radius: 4px; + border-width: 0px; + color: #260314; + background-color: #fff1d4; + font-size: 0.8em; + font-family: Verdana, 'TeXGyreHerosRegular', sans; +} + +.completedbt:hover { + cursor: pointer; + text-decoration: underline; +} + .dbt { border-color: #fff1d4; border-radius: 4px; @@ -716,8 +733,8 @@ margin-left: 1em; padding-left: 0px; list-style: none; - margin-top: 0em; - border-top: 1px solid #260314; + margin: 0.5em; + border-bottom: 1px solid #260314; } .plays-list-elem { Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-06-22 07:34:03 UTC (rev 1493) +++ trunk/Toss/WebClient/index.html 2011-06-22 22:37:37 UTC (rev 1494) @@ -179,6 +179,7 @@ <div id="news"> <h3>News</h3> <ul id="welcome-list-news" class="welcome-list"> +<li><b>22/06/11</b> Better organized lists of plays</li> <li><b>19/06/11</b> News section on the front page of tPlay</li> <li><b>15/06/11</b> Bug with underscores in user names corrected</li> <li><b>10/06/11</b> New register site handles forgotten passwords</li> @@ -211,96 +212,6 @@ </div> <div id="plays"> - <p class="game-par"> - <button onclick="new_play('Breakthrough')" - class="boldobt">Breakthrough</button> - </p> - <ul class="plays-list" id="a-plays-list-Breakthrough"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Breakthrough"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Checkers')" - class="boldobt">Checkers</button> - </p> - <ul class="plays-list" id="a-plays-list-Checkers"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Checkers"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Chess')" - class="boldobt">Chess</button> - </p> - <ul class="plays-list" id="a-plays-list-Chess"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Chess"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Connect4')" - class="boldobt">Connect4</button> - </p> - <ul class="plays-list" id="a-plays-list-Connect4"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Connect4"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Entanglement')" - class="boldobt">Entanglement</button> - </p> - <ul class="plays-list" id="a-plays-list-Entanglement"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Entanglement"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Gomoku')" - class="boldobt">Gomoku</button> - </p> - <ul class="plays-list" id="a-plays-list-Gomoku"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Gomoku"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Pawn-Whopping')" - class="boldobt">Pawn-Whopping</button> - </p> - <ul class="plays-list" id="a-plays-list-Pawn-Whopping"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Pawn-Whopping"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Tic-Tac-Toe')" - class="boldobt">Tic-Tac-Toe</button> - </p> - <ul class="plays-list" id="a-plays-list-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> - <p class="game-par"> - <button onclick="new_play('Concurrent-Tic-Tac-Toe')" - class="boldobt">Concurrent-Tic-Tac-Toe</button> - </p> - <ul class="plays-list" id="a-plays-list-Concurrent-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> - <ul class="plays-list" id="d-plays-list-Concurrent-Tic-Tac-Toe"> - <li style="display: none;"/> - </ul> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-06-24 13:49:42
|
Revision: 1495 http://toss.svn.sourceforge.net/toss/?rev=1495&view=rev Author: lukaszkaiser Date: 2011-06-24 13:49:35 +0000 (Fri, 24 Jun 2011) Log Message: ----------- Plays list and stability corrections. Modified Paths: -------------- trunk/Toss/Server/DB.ml trunk/Toss/Server/ReqHandler.ml trunk/Toss/Server/Server.ml trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/register.html Modified: trunk/Toss/Server/DB.ml =================================================================== --- trunk/Toss/Server/DB.ml 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/Server/DB.ml 2011-06-24 13:49:35 UTC (rev 1495) @@ -7,7 +7,9 @@ let tID = ref "toss_id_05174_" -let dbFILE = ref ((Unix.getenv "HOME") ^ "/.tossdb.sqlite") +let dbFILE = ref + ( try (Unix.getenv "HOME") ^ "/.tossdb.sqlite" + with _ -> "/tossdb.sqlite" ) let tGAMES = ref ["Breakthrough"; "Checkers"; "Chess"; "Connect4"; "Entanglement"; "Gomoku"; "Pawn-Whopping"; "Tic-Tac-Toe"; @@ -106,7 +108,7 @@ Printf.printf "DB busy or locked, retrying %i\n%!" retried; ignore (Unix.select [] [] [] 0.1); apply_cmd ~retried:(retried+1) dbfile select cmd - | x -> raise (DBError (Sqlite3.Rc.to_string x)) + | x -> raise (DBError ((Sqlite3.Rc.to_string x) ^ ":" ^ select_s)) let get_table dbfile ?(select="") tbl = fst (apply_cmd dbfile select ("select * from " ^ tbl)) Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/Server/ReqHandler.ml 2011-06-24 13:49:35 UTC (rev 1495) @@ -693,7 +693,7 @@ if line_in = "" || line_in = "\r" then try nonempty () with End_of_file -> "" else line_in in - nonempty () in + try nonempty () with Sys_error _ -> "" in let line_in_len = String.length line_in in if line_in_len = 0 then ("", None) else (* TODO: who needs escaping? *) Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/Server/Server.ml 2011-06-24 13:49:35 UTC (rev 1495) @@ -42,6 +42,7 @@ try ignore (Unix.waitpid [Unix.WNOHANG] (-1)); ignore (Unix.waitpid [Unix.WNOHANG] (-1)); + ignore (Unix.waitpid [Unix.WNOHANG] (-1)); with Unix.Unix_error (e,_,_) -> if !debug_level > 1 then Printf.printf "UNIX WAITPID: %s\n%!" (Unix.error_message e); Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/WebClient/Main.js 2011-06-24 13:49:35 UTC (rev 1495) @@ -64,7 +64,7 @@ function GamesPage(id, games){ // html tag id this.games = games; this.paragraphs = new Object(); - this.container = document.getElementById(id); + this.container = document.getElementById (id); for (var i = 0; i < this.games.length; i++) { var game = this.games[i]; @@ -74,35 +74,42 @@ var button = document.createElement("button"); paragraph.game_button = button; - button.setAttribute("class", "boldobt"); + button.setAttribute("class", "gamebt"); button.setAttribute("onclick", "new_play('" + game + "')"); button.innerHTML = game; button.style.display = "block"; - this.container.appendChild(paragraph); - paragraph.appendChild(button); + this.container.appendChild (paragraph); + paragraph.appendChild (button); var open_play_list = document.createElement("ul"); paragraph.open_play_list = open_play_list; open_play_list.setAttribute("class", "plays-list"); open_play_list.setAttribute("id", "a-plays-list-" + game); - paragraph.appendChild(open_play_list); + paragraph.appendChild (open_play_list); + var closed_plays = document.createElement("div"); + paragraph.closed_plays = closed_plays; + closed_plays.setAttribute("id", "d-plays-div-" + game); + var completed_bt = document.createElement("button"); paragraph.completed_button = completed_bt; completed_bt.setAttribute("class", "completedbt"); completed_bt.setAttribute("onclick", - "GAMESPAGE.toggle_completed('" + game + "')"); + "GAMESPAGE.toggle_completed ('" + game + "')"); completed_bt.innerHTML = "Completed games (Show)"; - this.container.appendChild(paragraph); - paragraph.appendChild(completed_bt); - paragraph.completed_shown = false; + closed_plays.appendChild (completed_bt); var closed_play_list = document.createElement("ul"); paragraph.closed_play_list = closed_play_list; closed_play_list.setAttribute("class", "plays-list"); closed_play_list.setAttribute("id", "d-plays-list-" + game); closed_play_list.style.display = "none"; - paragraph.appendChild(closed_play_list); + closed_plays.appendChild (closed_play_list); + + closed_plays.style.display = "none"; + paragraph.appendChild (closed_plays); + paragraph.completed_shown = false; + this.container.appendChild (paragraph); } return (this); } @@ -116,11 +123,11 @@ } GamesPage.prototype.show_completed = function (game) { - this.paragraphs[game].closed_play_list.style.display = "block"; + this.paragraphs[game].closed_plays.style.display = "block"; } GamesPage.prototype.hide_completed = function (game) { - this.paragraphs[game].closed_play_list.style.display = "none"; + this.paragraphs[game].closed_plays.style.display = "none"; } GamesPage.prototype.toggle_completed = function (game) { @@ -163,27 +170,23 @@ function list_plays_string (game, lst) { PLAYS = parse_list ('##', lst); - var a_plist = document.getElementById("a-plays-list-" + game); - var d_plist = document.getElementById("d-plays-list-" + game); + var a_plist = document.getElementById ("a-plays-list-" + game); + var d_plist = document.getElementById ("d-plays-list-" + game); while (a_plist.childNodes.length > 0) { - a_plist.removeChild(a_plist.firstChild); + a_plist.removeChild (a_plist.firstChild); } while (d_plist.childNodes.length > 0) { - d_plist.removeChild(d_plist.firstChild); + d_plist.removeChild (d_plist.firstChild); } for (var i = 0; i < PLAYS.length; i++) { PLAYS[i] = play_from_string (game, PLAYS[i]); if (PLAYS[i].cur_state.payoff == "") { - a_plist.appendChild(new_play_item (game, i)); + a_plist.appendChild (new_play_item (game, i)); } else { - d_plist.appendChild(new_play_item (game, i)); + d_plist.appendChild (new_play_item (game, i)); } } - if (PLAYS.length == 0) { - document.getElementById("a-plays-list-" + game).style.display = "none"; - } else { - document.getElementById("a-plays-list-" + game).style.display = "block"; - } + if (d_plist.childNodes.length > 0) { GAMESPAGE.show_completed (game); } } function list_plays (game) { @@ -193,19 +196,19 @@ function play_click (game, play_id, pi) { - document.getElementById("opponents").style.display = "none"; + document.getElementById ("opponents").style.display = "none"; list_plays (game); - document.getElementById("welcome").style.display = "none"; - document.getElementById("game-disp").style.display = "none"; - document.getElementById("plays").style.display = "none"; + document.getElementById ("welcome").style.display = "none"; + document.getElementById ("game-disp").style.display = "none"; + document.getElementById ("plays").style.display = "none"; GAME_NAME = game; - var gd = document.getElementById("game-disp"); + var gd = document.getElementById ("game-disp"); gd.style.display = "block"; gd.setAttribute ("class", "Game-" + game); document.getElementById ("game-title").innerHTML = game; - document.getElementById("game-disp").style.display = "block"; - document.getElementById("play-number").innerHTML = "" + play_id; - document.getElementById("suggestions-toggle").style.display = "inline"; + document.getElementById ("game-disp").style.display = "block"; + document.getElementById ("play-number").innerHTML = "" + play_id; + document.getElementById ("suggestions-toggle").style.display = "inline"; CUR_PLAY_I = pi; PLAYS[CUR_PLAY_I].redraw (); } @@ -232,12 +235,12 @@ } function make_opnt_list () { - var o = document.getElementById("opponents-list"); + var o = document.getElementById ("opponents-list"); FULL_OPNT_LEN = FRIENDS.length + 1; CUR_OPNT_START = 0; - document.getElementById("opponents-prev").style.display = "none"; + document.getElementById ("opponents-prev").style.display = "none"; if (MAX_OPNT_LEN > FULL_OPNT_LEN) { - document.getElementById("opponents-next").style.display = "none" + document.getElementById ("opponents-next").style.display = "none" } var zeroli = document.createElement('li'); zeroli.setAttribute ("class", "opponents-list-elem"); @@ -250,55 +253,55 @@ if (i > MAX_OPNT_LEN - 2) { oi.style.display = "none"; } o.appendChild (oi); } - document.getElementById("opponents").style.display = "block"; + document.getElementById ("opponents").style.display = "block"; } function new_play (game) { if (UNAME == "") { alert ("Please log in to create plays"); return; } GAME_NAME = game; - var olist = document.getElementById("opponents-list"); - while (olist.childNodes.length > 0) { olist.removeChild(olist.firstChild); } + var olist = document.getElementById ("opponents-list"); + while (olist.childNodes.length > 0) { olist.removeChild (olist.firstChild); } make_opnt_list (); } function opponents_next () { for (var i = CUR_OPNT_START; i < CUR_OPNT_START + MAX_OPNT_LEN; i++) { - document.getElementById("opponent-" + "-" + i).style.display = "none"; + document.getElementById ("opponent-" + "-" + i).style.display = "none"; } CUR_OPNT_START += MAX_OPNT_LEN; for (var i = CUR_OPNT_START; i < CUR_OPNT_START + MAX_OPNT_LEN; i++) { if (i < FULL_OPNT_LEN) { - document.getElementById("opponent-" + "-" + i).style.display = "list-item"; + document.getElementById ("opponent-" + "-" + i).style.display = "list-item"; } } - document.getElementById("opponents-prev").style.display = "block" + document.getElementById ("opponents-prev").style.display = "block" if (CUR_OPNT_START + MAX_OPNT_LEN > FULL_OPNT_LEN) { - document.getElementById("opponents-next").style.display = "none" + document.getElementById ("opponents-next").style.display = "none" } } function opponents_prev () { for (var i = CUR_OPNT_START; i < CUR_OPNT_START + MAX_OPNT_LEN; i++) { if (i < FULL_OPNT_LEN) { - document.getElementById("opponent-" + "-" + i).style.display = "none"; + document.getElementById ("opponent-" + "-" + i).style.display = "none"; } } CUR_OPNT_START -= MAX_OPNT_LEN; for (var i = CUR_OPNT_START; i < CUR_OPNT_START + MAX_OPNT_LEN; i++) { - document.getElementById("opponent-" + "-" + i).style.display = "list-item"; + document.getElementById ("opponent-" + "-" + i).style.display = "list-item"; } - document.getElementById("opponents-next").style.display = "block" + document.getElementById ("opponents-next").style.display = "block" if (CUR_OPNT_START == 0) { - document.getElementById("opponents-prev").style.display = "none" + document.getElementById ("opponents-prev").style.display = "none" } } function show_chess_warning () { - document.getElementById("chess-level-warning").style.display = "block"; + document.getElementById ("chess-level-warning").style.display = "block"; } function hide_chess_warning () { - document.getElementById("chess-level-warning").style.display = "none"; + document.getElementById ("chess-level-warning").style.display = "none"; } function new_play_guest (game) { @@ -309,17 +312,17 @@ if (game == "Pawn-Whopping") { wgame = "Pawn_(chess)" }; if (game == "Entanglement") { wgame = "Entanglement_(graph_measure)" }; wiki = "http://en.wikipedia.org/wiki/" + wgame; - document.getElementById("topuser").innerHTML = + document.getElementById ("topuser").innerHTML = game + ' (<a href="' + wiki + '">Move Rules</a>)'; - if (SIMPLE_SET) { document.getElementById("topuser").innerHTML = game }; - document.getElementById("pdescBack").style.display = "inline"; - document.getElementById("game-title").style.display = "none"; - document.getElementById("game-info-par").style.paddingBottom = "1em"; - document.getElementById("loginform").style.display = "none"; - document.getElementById("topright-register").style.display = "none"; - document.getElementById("topright").style.display = "inline"; - document.getElementById("logoutbt").style.display = "none"; - document.getElementById("welcome").style.display = "none"; + if (SIMPLE_SET) { document.getElementById ("topuser").innerHTML = game }; + document.getElementById ("pdescBack").style.display = "inline"; + document.getElementById ("game-title").style.display = "none"; + document.getElementById ("game-info-par").style.paddingBottom = "1em"; + document.getElementById ("loginform").style.display = "none"; + document.getElementById ("topright-register").style.display = "none"; + document.getElementById ("topright").style.display = "inline"; + document.getElementById ("logoutbt").style.display = "none"; + document.getElementById ("welcome").style.display = "none"; if (game == "Chess") { show_chess_warning (); setTimeout("hide_chess_warning ()", 3000); @@ -329,35 +332,35 @@ function new_play_do (opp_uid) { list_plays (GAME_NAME); - document.getElementById("welcome").style.display = "none"; - document.getElementById("game-disp").style.display = "none"; - document.getElementById("plays").style.display = "none"; - var gd = document.getElementById("game-disp"); + document.getElementById ("welcome").style.display = "none"; + document.getElementById ("game-disp").style.display = "none"; + document.getElementById ("plays").style.display = "none"; + var gd = document.getElementById ("game-disp"); gd.style.display = "block"; gd.setAttribute ("class", "Game-" + GAME_NAME); document.getElementById ("game-title").innerHTML = GAME_NAME; - document.getElementById("opponents").style.display = "none"; - var olist = document.getElementById("opponents-list"); - while (olist.childNodes.length > 0) { olist.removeChild(olist.firstChild); } + document.getElementById ("opponents").style.display = "none"; + var olist = document.getElementById ("opponents-list"); + while (olist.childNodes.length > 0) { olist.removeChild (olist.firstChild); } if (opp_uid == -1) { opp_uid = UNAME; } if (opp_uid == 0 || UNAME == "") { return; } - //document.getElementById("plays-list-" + GAME_NAME).style.display = "block"; - document.getElementById("working").style.display = "block"; + //document.getElementById ("plays-list-" + GAME_NAME).style.display = "block"; + document.getElementById ("working").style.display = "block"; info_nbr = CONN.new_play (GAME_NAME, UNAME, opp_uid); - document.getElementById("working").style.display = "none"; - document.getElementById("suggestions-toggle").style.display = "inline"; + document.getElementById ("working").style.display = "none"; + document.getElementById ("suggestions-toggle").style.display = "inline"; info_idx = info_nbr.indexOf('$'); FREE_PLAY_NO = parseInt(info_nbr.substring(0, info_idx)); - document.getElementById("play-number").innerHTML = "" + FREE_PLAY_NO; + document.getElementById ("play-number").innerHTML = "" + FREE_PLAY_NO; CUR_PLAY_I = PLAYS.length; - document.getElementById("game-disp").style.display = "block"; - document.getElementById("plays").style.left = "30em"; + document.getElementById ("game-disp").style.display = "block"; + document.getElementById ("plays").style.left = "30em"; var p = new Play (GAME_NAME, [0,1], [UNAME, opp_uid], FREE_PLAY_NO, 0, info_nbr.substring(info_idx+1), UNAME); PLAYS.push(p); p.redraw (); //li = new_play_item (GAME_NAME, CUR_PLAY_I); - //document.getElementById("plays-list-" + GAME_NAME).appendChild(li); + //document.getElementById ("plays-list-" + GAME_NAME).appendChild (li); } function get_opponents () { @@ -366,16 +369,16 @@ } function play_anew (me_starts) { - document.getElementById('payoffs').innerHTML = "Not Finished Yet"; - document.getElementById('payoffs').style.display = "none"; - document.getElementById('new-play-par').style.display = "none"; + document.getElementById ('payoffs').innerHTML = "Not Finished Yet"; + document.getElementById ('payoffs').style.display = "none"; + document.getElementById ('new-play-par').style.display = "none"; if (UNAME == "guest") { - document.getElementById("game-info-par").style.paddingBottom = "1em"; + document.getElementById ("game-info-par").style.paddingBottom = "1em"; }; toggle_suggestions (); toggle_suggestions (); PLAYS[CUR_PLAY_I].clear (); - document.getElementById('cur-move').innerHTML = "none"; + document.getElementById ('cur-move').innerHTML = "none"; if (me_starts) { var opp = PLAYS[CUR_PLAY_I].players[1]; if (PLAYS[CUR_PLAY_I].players[0] != UNAME) { @@ -393,14 +396,14 @@ UNAME = me; PLAYS[CUR_PLAY_I].cur_player_uid = UNAME; if (opp == "computer") { - var mv_time = document.getElementById("speed").value; + var mv_time = document.getElementById ("speed").value; suggest_move_async (mv_time, make_move); } } } function decrease_moving (n) { - document.getElementById("working").innerHTML = "Moving in " + n + "s ..."; + document.getElementById ("working").innerHTML = "Moving in " + n + "s ..."; if (n > 0) { setTimeout("decrease_moving(" + (n-1) + ")", 1000); } @@ -408,8 +411,8 @@ function show_moving_msg (n) { if (n > 1) { - document.getElementById("working").innerHTML = "Moving in "+ n+ "s ..."; - document.getElementById("working").style.display = "block"; + document.getElementById ("working").innerHTML = "Moving in "+ n+ "s ..."; + document.getElementById ("working").style.display = "block"; setTimeout("decrease_moving(" + (n-1) + ")", 1000); } } @@ -417,8 +420,8 @@ function suggest_move_async (time, f) { show_moving_msg (time); var fm = function (m) { - document.getElementById("working").style.display = "none"; - document.getElementById("working").innerHTML = "Working..."; + document.getElementById ("working").style.display = "none"; + document.getElementById ("working").innerHTML = "Working..."; if (m != "") { PLAYS[CUR_PLAY_I].show_move (new Move (m)); f() } }; CONN.suggest (PLAYS[CUR_PLAY_I].cur_state.players[0]+1, time, @@ -426,26 +429,26 @@ } function suggest_move_click () { - var mv_time = document.getElementById("speed").value; + var mv_time = document.getElementById ("speed").value; suggest_move_async (mv_time, function () {}); } function toggle_suggestions () { - var txt = document.getElementById("suggestions-toggle").innerHTML; + var txt = document.getElementById ("suggestions-toggle").innerHTML; if (txt.indexOf ("Before") == -1) { SIMPLE_MOVES = true; - document.getElementById("play-nbr-info").style.display = "none"; - document.getElementById("board").style.paddingTop = "1em"; - document.getElementById("suggestions-toggle").innerHTML = + document.getElementById ("play-nbr-info").style.display = "none"; + document.getElementById ("board").style.paddingTop = "1em"; + document.getElementById ("suggestions-toggle").innerHTML = "Ask Before Move"; - document.getElementById("move-info-par").style.display = "none"; + document.getElementById ("move-info-par").style.display = "none"; } else { SIMPLE_MOVES = false; - document.getElementById("play-nbr-info").style.display = "inline"; - document.getElementById("board").style.paddingTop = "0em"; - document.getElementById("suggestions-toggle").innerHTML = + document.getElementById ("play-nbr-info").style.display = "inline"; + document.getElementById ("board").style.paddingTop = "0em"; + document.getElementById ("suggestions-toggle").innerHTML = "Move Without Asking"; - document.getElementById("move-info-par").style.display = "block"; + document.getElementById ("move-info-par").style.display = "block"; } } Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/WebClient/Style.css 2011-06-24 13:49:35 UTC (rev 1495) @@ -64,7 +64,7 @@ float: right; } -.obt, .boldobt { +.obt, .boldobt, .gamebt { text-align: left; border-color: #260314; border-radius: 4px; @@ -81,17 +81,25 @@ text-decoration: underline; } -.boldobt { +.boldobt, .gamebt { font-weight: bold; font-size: 1em; } -.boldobt:hover { +.boldobt:hover, .gamebt:hover { cursor: pointer; text-decoration: underline; } +.gamebt { + margin-bottom: 1em; + +} + .completedbt { + position: relative; + top: -1em; + left: 1em; text-align: left; border-color: #260314; border-radius: 4px; @@ -730,15 +738,17 @@ } .plays-list { - margin-left: 1em; - padding-left: 0px; list-style: none; margin: 0.5em; + margin-bottom: 0px; + margin-left: 0px; + padding-left: 0px; + padding-bottom: 1em; border-bottom: 1px solid #260314; } .plays-list-elem { - margin-left: 0em; + margin-left: 1em; margin-bottom: 0em; } Modified: trunk/Toss/WebClient/register.html =================================================================== --- trunk/Toss/WebClient/register.html 2011-06-22 22:37:37 UTC (rev 1494) +++ trunk/Toss/WebClient/register.html 2011-06-24 13:49:35 UTC (rev 1495) @@ -24,7 +24,7 @@ <h2>Register on tPlay</h2> -<form id="registerform" action=""> +<div id="registerform"> <p> <span class="reglabel">Email:</span> <input class="forminput" type="text" name="email" id="email" onchange="register_email_change()" /> @@ -50,7 +50,7 @@ <p> <span class="reglabel">Surname:</span> <input class="forminput" type="text" name="surname" id="surname" /> </p> -</form> +</div> <p> </p> <p> <span class="reglabel">Forgot your password?</span> <button class="bt" id="forgotbt" type="button" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |