toss-devel-svn Mailing List for Toss (Page 12)
Status: Beta
Brought to you by:
lukaszkaiser
You can subscribe to this list here.
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(25) |
Dec
(62) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2011 |
Jan
(26) |
Feb
(38) |
Mar
(67) |
Apr
(22) |
May
(41) |
Jun
(30) |
Jul
(24) |
Aug
(32) |
Sep
(29) |
Oct
(34) |
Nov
(18) |
Dec
(2) |
2012 |
Jan
(19) |
Feb
(25) |
Mar
(16) |
Apr
(2) |
May
(18) |
Jun
(21) |
Jul
(11) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
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-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-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-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-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-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-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: <ch...@us...> - 2011-05-30 21:35:55
|
Revision: 1467 http://toss.svn.sourceforge.net/toss/?rev=1467&view=rev Author: chalmi Date: 2011-05-30 21:35:49 +0000 (Mon, 30 May 2011) Log Message: ----------- delete info Modified Paths: -------------- trunk/Toss/WebClient/index.html Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-05-30 20:31:01 UTC (rev 1466) +++ trunk/Toss/WebClient/index.html 2011-05-30 21:35:49 UTC (rev 1467) @@ -196,7 +196,6 @@ <p class="game-par"> <button onclick="new_play('Breakthrough')" class="boldobt">Breakthrough</button> - (<a href="http://en.wikipedia.org/wiki/Breakthrough_(board_game)">info</a>) </p> <ul class="plays-list" id="plays-list-Breakthrough"> <li style="display: none;"/> @@ -204,7 +203,6 @@ <p class="game-par"> <button onclick="new_play('Checkers')" class="boldobt">Checkers</button> - (<a href="http://en.wikipedia.org/wiki/English_draughts">info</a>) </p> <ul class="plays-list" id="plays-list-Checkers"> <li style="display: none;"/> @@ -212,7 +210,6 @@ <p class="game-par"> <button onclick="new_play('Chess')" class="boldobt">Chess</button> - (<a href="http://en.wikipedia.org/wiki/Chess">info</a>) </p> <ul class="plays-list" id="plays-list-Chess"> <li style="display: none;"/> @@ -220,7 +217,6 @@ <p class="game-par"> <button onclick="new_play('Connect4')" class="boldobt">Connect4</button> - (<a href="http://en.wikipedia.org/wiki/Connect4">info</a>) </p> <ul class="plays-list" id="plays-list-Connect4"> <li style="display: none;"/> @@ -228,8 +224,6 @@ <p class="game-par"> <button onclick="new_play('Entanglement')" class="boldobt">Entanglement</button> - (<a href="http://en.wikipedia.org/wiki/Entanglement_(graph_measure)" - >info</a>) </p> <ul class="plays-list" id="plays-list-Entanglement"> <li style="display: none;"/> @@ -237,7 +231,6 @@ <p class="game-par"> <button onclick="new_play('Gomoku')" class="boldobt">Gomoku</button> - (<a href="http://en.wikipedia.org/wiki/Gomoku">info</a>) </p> <ul class="plays-list" id="plays-list-Gomoku"> <li style="display: none;"/> @@ -245,7 +238,6 @@ <p class="game-par"> <button onclick="new_play('Pawn-Whopping')" class="boldobt">Pawn-Whopping</button> - (<a href="http://en.wikipedia.org/wiki/Pawn_(chess)">info</a>) </p> <ul class="plays-list" id="plays-list-Pawn-Whopping"> <li style="display: none;"/> @@ -253,7 +245,6 @@ <p class="game-par"> <button onclick="new_play('Tic-Tac-Toe')" class="boldobt">Tic-Tac-Toe</button> - (<a href="http://en.wikipedia.org/wiki/Tic-tac-toe">info</a>) </p> <ul class="plays-list" id="plays-list-Tic-Tac-Toe"> <li style="display: none;"/> @@ -261,7 +252,6 @@ <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;"/> 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-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-29 17:55:34
|
Revision: 1464 http://toss.svn.sourceforge.net/toss/?rev=1464&view=rev Author: lukaszkaiser Date: 2011-05-29 17:55:27 +0000 (Sun, 29 May 2011) Log Message: ----------- Cleaning JavaScript drawing code. Modified Paths: -------------- trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/State.js trunk/Toss/WebClient/index.html trunk/Toss/WebClient/profile.html Added Paths: ----------- trunk/Toss/WebClient/Drawing.js Removed Paths: ------------- trunk/Toss/WebClient/DefaultStyle.js Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-05-29 00:12:18 UTC (rev 1463) +++ trunk/Toss/WebClient/Connect.js 2011-05-29 17:55:27 UTC (rev 1464) @@ -1,16 +1,7 @@ // JavaScript Toss Module -- Connect (basic Toss Server connection routines) var UNAME = ""; - -var SVG_WIDTH = 500; -var SVG_HEIGHT = 500; -var SVG_MARGINX = 50; -var SVG_MARGINY = 50; -var VIEW_MIRROR = 0; - var GAME_NAME = ""; // name of current game, e.g. "Breakthrough" -var SUGGESTED_ELEM_SIZEX = 25; // suggested size of elements -var SUGGESTED_ELEM_SIZEY = 25; // suggested size of elements var ASYNC_ALL_REQ_PENDING = 0; var ASYNC_CMD_REQ_PENDING = {}; @@ -155,54 +146,3 @@ } var CONN = new Connect (); - - - -// ---- Two functions below are very basic and thus in this file. --- - -// 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); -} - -// 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]).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); - elem.setAttribute ("class", "svgelem"); - for (var i = 0; i < attributes.length; i++) { - elem.setAttribute (attributes[i][0], attributes[i][1].toString()); - } - document.getElementById("svg").appendChild(elem); -} Deleted: trunk/Toss/WebClient/DefaultStyle.js =================================================================== --- trunk/Toss/WebClient/DefaultStyle.js 2011-05-29 00:12:18 UTC (rev 1463) +++ trunk/Toss/WebClient/DefaultStyle.js 2011-05-29 17:55:27 UTC (rev 1464) @@ -1,339 +0,0 @@ -// JavaScript Toss Module -- DefaultStyle (requires TossConnect.js) - -// This module implements default drawing style for games. -// Functions expected from this module: -// - draw_background (game) -// - draw_elem (game, elem) -// - highlight_elem (elem) -// - unhighlight_elem (elem) -// - draw_rel (game, rel_name, args) - -// Helper function: sign of a number. -function sign (x) { - if (x > 0.01) { return (1); } - else if (x < -0.01) { return (-1); } - else { return (0); } -} - - -// Drawings - -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>'; - - -function is_int (s) { - 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"; - if (is_int (elem.substring(1))) { - var psum = elem.charCodeAt(0) + parseInt (elem.substring(1)); - elem_cl = "model-elem-" + (psum % 2); - }; - return (elem_cl); -} - -// Draw the element [elem]. -function draw_elem (game, elem) { - var pos = ST.elem_pos[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]. -function highlight_elem (elem) { - var e = document.getElementById ("elem_" + elem); - e.setAttribute ("class", "model-elem-highlight"); -} - -// Unhighlight the element [elem]. -function unhighlight_elem (elem) { - var e = document.getElementById ("elem_" + elem); - e.setAttribute ("class", elem_class(elem)); -} - -// Draw relation [rel_name] between elements [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 = ST.elem_pos[args[0]]; - if (rel_name == "P") { // Tic-tac-toe cross - 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], - ["id", "pred_" + args[0] + "_" + rel_name], - ["class", "model-pred-" + rel_name], - ["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>', []); - 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>', []); - 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>', []); - 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>', []); - 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>', []); - 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>', []); - 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>', []); - 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>', []); - 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>', []); - 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>', []); - 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>', []); - 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>', []); - document.getElementById("svg").appendChild(f); - } else { - add_svg ("circle", - [["cx", pos[0]], ["cy", pos[1]], ["r", SUGGESTED_ELEM_SIZEX - 12], - ["id", "pred_" + args[0] + "_" + rel_name], - ["class", "model-pred-" + rel_name], - ["stroke-width", (SUGGESTED_ELEM_SIZEX / 10) + 2], - ["onclick", ("handle_elem_click('" + args[0] + "')")]]); - } - } - if (args.length == 2) { - if (rel_name == "E") { - var pos1 = ST.elem_pos[args[0]]; - var pos2 = ST.elem_pos[args[1]]; - if (sign (pos1[0] - pos2[0]) == 0) { - var d = SUGGESTED_ELEM_SIZEY * sign (pos1[1] - pos2[1]); - add_svg ("line", [["x1", pos1[0]], ["y1", pos1[1] - d], - ["x2", pos2[0]], ["y2", pos2[1] + d], - ["class", "model-edge-E"]]); - } else if (sign (pos1[1] - pos2[1]) == 0) { - var d = SUGGESTED_ELEM_SIZEX * sign (pos1[0] - pos2[0]); - add_svg ("line", [["x1", pos1[0] - d], ["y1", pos1[1]], - ["x2", pos2[0] + d], ["y2", pos2[1]], - ["class", "model-edge-E"]]); - } - else { - var dx = SUGGESTED_ELEM_SIZEX * sign (pos1[0] - pos2[0]); - var dy = SUGGESTED_ELEM_SIZEY * sign (pos1[1] - pos2[1]); - add_svg ("line", [["x1", pos1[0] + dx], ["y1", pos1[1] + dy], - ["x2", pos2[0] - dx], ["y2", pos2[1] - dy], - ["class", "model-edge-E"]]); - } - } - } -} Copied: trunk/Toss/WebClient/Drawing.js (from rev 1463, trunk/Toss/WebClient/DefaultStyle.js) =================================================================== --- trunk/Toss/WebClient/Drawing.js (rev 0) +++ trunk/Toss/WebClient/Drawing.js 2011-05-29 17:55:27 UTC (rev 1464) @@ -0,0 +1,374 @@ +// JavaScript Toss Module -- Drawing + +var SVG_WIDTH = 500; +var SVG_HEIGHT = 500; +var SVG_MARGINX = 50; +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 + + + +// ------ Drawing functions ---- + +// 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); +} + +// 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)); + } else { + SUGGESTED_ELEM_SIZEX = SVG_WIDTH / 20; + SUGGESTED_ELEM_SIZEY = SVG_HEIGHT / 20; + } + draw_background (game); + for (var i = 0; i < state.elems.length; i++) { + draw_elem (game, state.elems[i]); + } + for (var i = 0; i < state.rels.length; i++) { + draw_rel (game, state.rels[i]); + } +} + +// 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); } +} + +// 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 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); + } 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); + } +} + +// Highlight the element [elem]. +function highlight_elem (elemid) { + var e = document.getElementById ("elem_" + elemid); + e.setAttribute ("class", "model-elem-highlight"); +} + +// Unhighlight the element [elem]. +function unhighlight_elem (elemid) { + var e = document.getElementById ("elem_" + elemid); + e.setAttribute ("class", elem_class(elemid)); +} + +// 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 () { + 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 (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 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 (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, + '<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 (x - w/2, y - w/2, SUGGESTED_ELEM_SIZEX - 10, + SUGGESTED_ELEM_SIZEY - 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 = SUGGESTED_ELEM_SIZEX * sign (x1 - x2); + var dy = SUGGESTED_ELEM_SIZEY * 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)); + } + 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)); + } + 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-29 00:12:18 UTC (rev 1463) +++ trunk/Toss/WebClient/Main.js 2011-05-29 17:55:27 UTC (rev 1464) @@ -21,33 +21,6 @@ var ST = undefined; -// Get model information from server. -function get_model_info () { - for (var i = 0; i < ST.elems.length; i++) { - ELEM_COUNTERS[ST.elems[i]] = 0; - } - var sqrt = Math.round (Math.sqrt (ST.elems.length)); - if (sqrt * sqrt == ST.elems.length) { // perhaps a grid - SUGGESTED_ELEM_SIZEX = SVG_WIDTH / (2.0 * (sqrt-1)); - SUGGESTED_ELEM_SIZEY = SVG_HEIGHT / (2.0 * (sqrt-1)); - } else { - SUGGESTED_ELEM_SIZEX = SVG_WIDTH / 20; - SUGGESTED_ELEM_SIZEY = SVG_HEIGHT / 20; - } -} - -// Draw the model using function from Toss[X]Style.js. -// WARNING: must call get_model_info first! -function draw_model (game) { - draw_background (game); - for (var i = 0; i < ST.elems.length; i++) { - draw_elem (game, ST.elems[i]); - } - for (var i = 0; i < ST.rels.length; i++) { - draw_rel (game, ST.rels[i][0], ST.rels[i][1]); - } -} - // Clear whole svg box. function clear_svg () { LAST_CLICKED_ELEM = ""; @@ -84,9 +57,11 @@ if (! SIMPLE_MOVES) { document.getElementById("working").style.display = "block"; } - get_model_info (); + 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); + draw_model (GAME_NAME, ST); if (ST.payoff == "") { document.getElementById('movebt').innerHTML = "Make move:"; document.getElementById('cur-move').innerHTML = "none"; Modified: trunk/Toss/WebClient/State.js =================================================================== --- trunk/Toss/WebClient/State.js 2011-05-29 00:12:18 UTC (rev 1463) +++ trunk/Toss/WebClient/State.js 2011-05-29 17:55:27 UTC (rev 1464) @@ -31,25 +31,36 @@ 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 ------ -// Translate position from Toss Model coordinates to SVG coordinates. -function translate_pos (pos) { - var x = ((pos[0] - this.minx) * SVG_WIDTH) / this.width; - if (VIEW_MIRROR == 0) { - var y = ((pos[1] - this.miny) * SVG_HEIGHT) / this.height; - } else { - var y = - ((this.height - (pos[1] - this.miny)) * SVG_WIDTH) / - this.height; - } - return ([x + SVG_MARGINX, y + SVG_MARGINY]) -} - // 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("$"); @@ -67,24 +78,34 @@ // The second component is the list of elements of the structure. var l = convert_python_list(',', res_arr[1]); this.elems = []; - // We directly compute element positions for svg. - this.elem_pos = {}; - this.translate_pos = translate_pos; for (var i = 0; i < l.length; i++) { var e = convert_python_list (';', l[i]); - this.elems.push (e[0]); - this.elem_pos[e[0]] = - this.translate_pos ([parseFloat(e[1]), parseFloat(e[2])]); + 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(']')); - if (rel_name[0] != "_" && args_s != "''") { - rels.push ([rel_name, convert_python_list (',', args_s)]); + 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; Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-05-29 00:12:18 UTC (rev 1463) +++ trunk/Toss/WebClient/index.html 2011-05-29 17:55:27 UTC (rev 1464) @@ -12,7 +12,7 @@ <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="DefaultStyle.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> </head> Modified: trunk/Toss/WebClient/profile.html =================================================================== --- trunk/Toss/WebClient/profile.html 2011-05-29 00:12:18 UTC (rev 1463) +++ trunk/Toss/WebClient/profile.html 2011-05-29 17:55:27 UTC (rev 1464) @@ -10,7 +10,7 @@ <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="DefaultStyle.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> </head> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-29 00:12:25
|
Revision: 1463 http://toss.svn.sourceforge.net/toss/?rev=1463&view=rev Author: lukaszkaiser Date: 2011-05-29 00:12:18 +0000 (Sun, 29 May 2011) Log Message: ----------- Cleanup in Javascript code. Modified Paths: -------------- trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/DefaultStyle.js trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/index.html trunk/Toss/WebClient/profile.html Added Paths: ----------- trunk/Toss/WebClient/State.js Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-05-27 22:09:16 UTC (rev 1462) +++ trunk/Toss/WebClient/Connect.js 2011-05-29 00:12:18 UTC (rev 1463) @@ -2,12 +2,6 @@ var UNAME = ""; -var MODEL_MAXX = 0.0; -var MODEL_MINX = 0.0; -var MODEL_MAXY = 0.0; -var MODEL_MINY = 0.0; -var MODEL_WIDTH = 0.0; -var MODEL_HEIGHT = 0.0; var SVG_WIDTH = 500; var SVG_HEIGHT = 500; var SVG_MARGINX = 50; @@ -15,121 +9,13 @@ var VIEW_MIRROR = 0; var GAME_NAME = ""; // name of current game, e.g. "Breakthrough" -var ELEMS = []; // used to store the list of elements -var ELEM_POS = {}; // positions of elements -var RELS = []; // relations var SUGGESTED_ELEM_SIZEX = 25; // suggested size of elements var SUGGESTED_ELEM_SIZEY = 25; // suggested size of elements -var DIM_STR = "" -var ELEM_STR = "" -var RELS_STR = "" -var MOVES_STR = "" -var PAYOFF_STR = "" -var PLAYER_STR = "" - var ASYNC_ALL_REQ_PENDING = 0; var ASYNC_CMD_REQ_PENDING = {}; -// Helper function: sign of a number. -function sign (x) { - if (x > 0.01) { return (1); } - else if (x < -0.01) { return (-1); } - else { return (0); } -} -function set_info (info) { - var res_arr = []; - res_arr = info.split("$"); - 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(2, 3) == "(") { - MOVES_STR = res_arr[3]; - PAYOFF_STR = ""; - } else { - MOVES_STR = ""; - PAYOFF_STR = res_arr[3]; - }; - PLAYER_STR = res_arr[4]; - var dim = strip('(', ')', DIM_STR).split(','); - MODEL_MAXX = parseFloat(strip(' ', ' ', dim[0])); - MODEL_MINX = parseFloat(strip(' ', ' ', dim[1])); - MODEL_MAXY = parseFloat(strip(' ', ' ', dim[2])); - MODEL_MINY = parseFloat(strip(' ', ' ', dim[3])); - MODEL_WIDTH = Math.max (SVG_WIDTH / 100, (MODEL_MAXX - MODEL_MINX)); - MODEL_HEIGHT = Math.max (SVG_HEIGHT / 100, (MODEL_MAXY - MODEL_MINY)); - return (true); -} - -// Send [msg] to server and return response text. -function sync_server_msg (msg) { - var xml_request = new XMLHttpRequest (); - xml_request.open ('POST', 'Handler', false); - xml_request.setRequestHeader ('Content-Type', - 'application/x-www-form-urlencoded; charset=UTF-8'); - xml_request.send (msg); - resp = xml_request.responseText; - if (resp.indexOf ("MOD_PYTHON ERROR") > -1) { - alert (resp.substring(resp.indexOf("Traceback"))); - return (""); - } - return (resp) -} - -// Send [msg] to server asynchronously, ignore response text. -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'); - 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) }; - } - } - }; - if (count) { ASYNC_ALL_REQ_PENDING += 1; } - xml_request.send (msg); -} - -// Send [msg] to server attaching prefix '[cmd]#' and return response text. -function srv (cmd, msg) { - return (sync_server_msg (cmd + '#' + msg)); -} - -// Send [msg] to server attaching prefix '[cmd]#' async., ignore response. -function async_srv_ignore (cmd, msg) { - 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) { - 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]. function strip (c1, c2, str) { if (str.length == 0) return (str); @@ -156,70 +42,122 @@ return (res_arr); } +function Connect () { + // Send [msg] to server and return response text. + var sync_server_msg = function (msg) { + var xml_request = new XMLHttpRequest (); + xml_request.open ('POST', 'Handler', false); + xml_request.setRequestHeader + ('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); + xml_request.send (msg); + resp = xml_request.responseText; + if (resp.indexOf ("MOD_PYTHON ERROR") > -1) { + alert (resp.substring(resp.indexOf("Traceback"))); + return (""); + } + return (resp) + } -// Get moves applicable to [elem] in a game. -function get_moves (elem, other) { - var all_moves = convert_python_list (';', MOVES_STR); - var elem_moves = [] - for (i = 0; i < all_moves.length; i++) { - var br = all_moves[i].indexOf(":"); - if (br < 0) { br = 0; }; - if (all_moves[i].indexOf(elem, br) > br) { - if (other == "") { - elem_moves.push(all_moves[i]) - } else if (all_moves[i].indexOf(other, br) > br) { - elem_moves.push(all_moves[i]) + // Send [msg] to server asynchronously, ignore response text. + var async_server_msg = function (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'); + 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) }; + } + } + }; + if (count) { ASYNC_ALL_REQ_PENDING += 1; } + xml_request.send (msg); } - return (elem_moves) -} -// Get relation tuples. -function get_rels () { - var r = convert_python_list(';', RELS_STR); - 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(']')); - if (rel_name[0] != "_" && args_s != "''") { - rels.push ([rel_name, convert_python_list (',', args_s)]); - } + // Send [msg] to server attaching prefix '[cmd]#' and return response text. + var srv = function (cmd, msg) { + return (sync_server_msg (cmd + '#' + msg)); } - return (rels) -} -// Translate position from Toss Model coordinates to SVG coordinates. -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; - } else { - var y = ((MODEL_HEIGHT - (pos[1] - MODEL_MINY))*SVG_WIDTH)/MODEL_HEIGHT; + // Send [msg] to server attaching prefix '[cmd]#' async., ignore response. + var async_srv_ignore = function (cmd, msg) { + async_server_msg (cmd + '#' + msg, false, function(x) { }); } - return ([x + SVG_MARGINX, y + SVG_MARGINY]) -} -// Get elements and positions. -function get_elems_with_pos () { - var l = convert_python_list(',', ELEM_STR); - ELEMS = []; - ELEM_POS = {}; - for (var i = 0; i < l.length; i++) { - var e = convert_python_list (';', l[i]); - ELEMS.push (e[0]); - ELEM_POS[e[0]] = translate_pos ([parseFloat(e[1]), parseFloat(e[2])]); + // Send [msg] to server attaching prefix '[cmd]#' async., run f on return. + var async_srv = function (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 (); + }; + async_server_msg (cmd + '#' + msg, true, f); } -} + this.get_name = function (uname) { return (srv ("GET_NAME", uname)); } + + this.list_plays = function (game, uname) { + return (srv ("LIST_PLAYS", "'" + game + "', '" + UNAME + "'")); + } -// Open [file_name] on Toss Server and get info. -function toss_open_db (file_name_params) { - var info = srv ("OPEN_DB", file_name_params); - set_info (info); + 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 +"'")); + } + this.make_move = function (move_s, pid, cont) { + async_srv("MOVE_PLAY", 'c, '+ 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); + } + + this.friends = function () { return (srv ("LIST_FRIENDS", "user")); } + this.allopnts = function () { return (srv ("LIST_FRIENDS", "**")); } + this.plays = function () { return (srv("USERPLAYS", "user")); } + this.username = function () { return (srv("USERNAME", "user")); } + this.addopp = function (opp) { return (srv("ADDOPP", opp)); } + + this.name = function (un) { return (srv("GET_NAME", un)); } + this.surname = function (un) { return (srv("GET_SURNAME", un)); } + this.email = function (un) { return (srv("GET_MAIL", un)); } + + this.login = function (un, chk, cpwd) { + return (srv ("LOGIN", un +"$"+ chk +"$"+ cpwd)); + } + this.logout = function () { return (srv("LOGOUT", "user")); } + this.register = function (data, cpwd) { + return (srv ("REGISTER", data + "$" + cpwd)); + } + this.change_data = function (name, surname, email) { + return (srv ("CHANGEUSR", name +"$"+ surname +"$"+ email)); + } + + return (this); } +var CONN = new Connect (); + + // ---- Two functions below are very basic and thus in this file. --- // Create basic svg box. Modified: trunk/Toss/WebClient/DefaultStyle.js =================================================================== --- trunk/Toss/WebClient/DefaultStyle.js 2011-05-27 22:09:16 UTC (rev 1462) +++ trunk/Toss/WebClient/DefaultStyle.js 2011-05-29 00:12:18 UTC (rev 1463) @@ -8,7 +8,16 @@ // - unhighlight_elem (elem) // - draw_rel (game, rel_name, args) +// Helper function: sign of a number. +function sign (x) { + if (x > 0.01) { return (1); } + else if (x < -0.01) { return (-1); } + else { return (0); } +} + +// Drawings + 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 " \ @@ -166,7 +175,7 @@ // Draw the element [elem]. function draw_elem (game, elem) { - var pos = ELEM_POS[elem]; + var pos = ST.elem_pos[elem]; if (game != "Connect4") { add_svg ("rect", [["x", pos[0] - SUGGESTED_ELEM_SIZEX], @@ -203,7 +212,7 @@ 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]]; + var pos = ST.elem_pos[args[0]]; if (rel_name == "P") { // Tic-tac-toe cross if (game != "Connect4") { var cs = 'class="' + "model-pred-" + rel_name + '" '; @@ -305,8 +314,8 @@ } if (args.length == 2) { if (rel_name == "E") { - var pos1 = ELEM_POS[args[0]]; - var pos2 = ELEM_POS[args[1]]; + var pos1 = ST.elem_pos[args[0]]; + var pos2 = ST.elem_pos[args[1]]; if (sign (pos1[0] - pos2[0]) == 0) { var d = SUGGESTED_ELEM_SIZEY * sign (pos1[1] - pos2[1]); add_svg ("line", [["x1", pos1[0]], ["y1", pos1[1] - d], Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-05-27 22:09:16 UTC (rev 1462) +++ trunk/Toss/WebClient/Login.js 2011-05-29 00:12:18 UTC (rev 1463) @@ -52,7 +52,7 @@ navigator.userAgent.indexOf('MSIE 9') == -1) { document.getElementById("nosvg").style.display = "block"; } else { - var udata = srv("USERPLAYS", "user"); + var udata = CONN.plays (); if (udata != "") { setup_user (udata.split("$")) }; } if (window.location.href.indexOf("?simple=true") > 0) { @@ -93,9 +93,9 @@ // Onload handler for the profile page function startup_profile () { - var un = srv("USERNAME", "user"); + var un = CONN.username (); if (un != "") { - UNAME = un + UNAME = un; document.getElementById("topuser").innerHTML = "Welcome " + disp_name(un); document.getElementById("loginform").style.display = "none"; @@ -103,9 +103,9 @@ document.getElementById("topright").style.display = "inline"; document.getElementById("welcome").style.display = "none"; document.getElementById("main-profile").style.display = "block"; - document.getElementById('name').value = srv("GET_NAME", un); - document.getElementById('surname').value = srv("GET_SURNAME", un); - document.getElementById('email').value = srv("GET_MAIL", un); + document.getElementById('name').value = CONN.name (un); + document.getElementById('surname').value = CONN.surname (un); + document.getElementById('email').value = CONN.email (un); get_opponents (); var o = document.getElementById("opponents-list"); for (var i = 0; i < FRIENDS.length; i++) { @@ -113,7 +113,7 @@ li.innerHTML = disp_name(FRIENDS[i]) + " (" + FRIENDS[i] + ")"; o.appendChild (li); } - var lst = srv ("LIST_FRIENDS", "**"); + var lst = CONN.allopnts (); var users = convert_python_list (',', lst); var u = document.getElementById("users-list"); for (var i = 0; i < users.length; i++) { @@ -133,7 +133,7 @@ var pwd = document.getElementById('password').value; var chk = "false"; if (document.getElementById('remember').checked) { chk = "true" }; - var resp = sync_server_msg("LOGIN#"+ un +"$"+ chk +"$"+ crypt(TSALT + pwd)); + var resp = CONN.login (un, chk, crypt(TSALT + pwd)); if (resp == "OK") { window.location.reload () } else { @@ -148,7 +148,7 @@ // Logout function logout () { clear_view (); - resp = sync_server_msg ("LOGOUT#user"); + resp = CONN.logout (); return; } @@ -159,7 +159,7 @@ document.getElementById("topuser").innerHTML = ""; document.getElementById("main-profile").style.display = "none"; document.getElementById("welcome").style.display = "block"; - resp = sync_server_msg ("LOGOUT#user"); + resp = CONN.logout (); return; } @@ -210,7 +210,7 @@ return; } var data = un + "$" + name + "$" + surname + "$" + email; - var resp = sync_server_msg ("REGISTER#" + data + "$" + crypt(TSALT + pwd)); + var resp = CONN.register (data, crypt(TSALT + pwd)); alert (resp); } @@ -236,14 +236,14 @@ alert ("Your data must not contain $, i.e. the dolar sign." + CORRMSG); return; } - var resp = sync_server_msg ("CHANGEUSR#" + name +"$"+ surname +"$"+ email); + var resp = CONN.change_data (name, surname, email); if (resp != "OK") { alert(resp); } window.location.reload (); } // Add opponent for the current user. function add_opponent (oppuname) { - var resp = sync_server_msg ("ADDOPP#" + oppuname); + var resp = CONN.addopp (oppuname); if (resp != "OK") { alert(resp); } window.location.reload (); } Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-05-27 22:09:16 UTC (rev 1462) +++ trunk/Toss/WebClient/Main.js 2011-05-29 00:12:18 UTC (rev 1463) @@ -19,15 +19,15 @@ var SIMPLE_MOVES = true; var SIMPLE_SET = false; +var ST = undefined; + // Get model information from server. function get_model_info () { - get_elems_with_pos (); - for (var i = 0; i < ELEMS.length; i++) { - ELEM_COUNTERS[ELEMS[i]] = 0; + for (var i = 0; i < ST.elems.length; i++) { + ELEM_COUNTERS[ST.elems[i]] = 0; } - RELS = get_rels (); - var sqrt = Math.round (Math.sqrt (ELEMS.length)); - if (sqrt * sqrt == ELEMS.length) { // perhaps a grid + var sqrt = Math.round (Math.sqrt (ST.elems.length)); + if (sqrt * sqrt == ST.elems.length) { // perhaps a grid SUGGESTED_ELEM_SIZEX = SVG_WIDTH / (2.0 * (sqrt-1)); SUGGESTED_ELEM_SIZEY = SVG_HEIGHT / (2.0 * (sqrt-1)); } else { @@ -40,11 +40,11 @@ // WARNING: must call get_model_info first! function draw_model (game) { draw_background (game); - for (var i = 0; i < ELEMS.length; i++) { - draw_elem (game, ELEMS[i]); + for (var i = 0; i < ST.elems.length; i++) { + draw_elem (game, ST.elems[i]); } - for (var i = 0; i < RELS.length; i++) { - draw_rel (game, RELS[i][0], RELS[i][1]); + for (var i = 0; i < ST.rels.length; i++) { + draw_rel (game, ST.rels[i][0], ST.rels[i][1]); } } @@ -87,7 +87,7 @@ get_model_info (); create_svg_box (SVG_MARGINX, SVG_MARGINY, "board"); draw_model (GAME_NAME); - if (PAYOFF_STR == "") { + if (ST.payoff == "") { document.getElementById('movebt').innerHTML = "Make move:"; document.getElementById('cur-move').innerHTML = "none"; } else { @@ -97,56 +97,38 @@ document.getElementById("move-info-par").style.display = "none"; document.getElementById("game-info-par").style.paddingBottom = "0em"; document.getElementById('payoffs').innerHTML = - "Result: " + subst_pl(PAYOFF_STR); + "Result: " + subst_pl(ST.payoff); document.getElementById('payoffs').style.display = "inline"; document.getElementById('new-play-par').style.display = "block"; } document.getElementById("working").style.display = "none"; } -// Helper function: get value elements from a move string [s]. -function get_move_elems (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))); - } - } - return (vals) -} - // Helper function: highlight move, unhighlight old, save current. function show_move (m) { - var m_act = get_move_elems (m); - m_act.sort (); - var m_rule = strip ("'", " ", - m.substring (m.indexOf("},")+3, m.lastIndexOf(','))); for (var i = 0; i < CUR_ELEMS.length; i++) { unhighlight_elem (CUR_ELEMS[i]); } - for (var i = 0; i < m_act.length; i++) { - highlight_elem (m_act[i]); + for (var i = 0; i < m.matched.length; i++) { + highlight_elem (m.matched[i]); } - var m_str = strip (' ', ' ', m_act.toString ()); - if (m_str == "") { + if (m.matched_str == "") { document.getElementById('cur-move').innerHTML = "none"; } else { document.getElementById('cur-move').innerHTML = - m_str.replace (/,/g, " — ") + " (" + m_rule + ")" + m.matched_str.replace (/,/g, " — ") + " (" + m.rule + ")" } - CUR_ELEMS = m_act; - CUR_MOVE = m.toString(); + CUR_ELEMS = m.matched; + CUR_MOVE = m.def_str; } // Handler for clicks on elements. function handle_elem_click (elem) { if (ASYNC_ALL_REQ_PENDING != 0) { return; } - var moves = get_moves (elem, LAST_CLICKED_ELEM); + var moves = ST.get_moves (elem, LAST_CLICKED_ELEM); if (moves.length == 0) { LAST_CLICKED_ELEM = ""; - moves = get_moves (elem, LAST_CLICKED_ELEM); + moves = ST.get_moves (elem, LAST_CLICKED_ELEM); }; if (moves.length == 0) { // still no moves, unhighlight for (var i = 0; i < CUR_ELEMS.length; i++) { @@ -160,12 +142,12 @@ 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) { + && moves.length == 2 && moves[0].length > moves[1].length) { 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) { + && moves.length == 2 && moves[1].length > moves[0].length) { show_move (moves[0]); ELEM_COUNTERS[elem] = 1; if (SIMPLE_MOVES) { make_move (); }; @@ -196,7 +178,7 @@ function disp_name (uname) { if (uname == "guest") { return ("You"); } if (UNAME_TO_NAME_MAP[uname]) { return (UNAME_TO_NAME_MAP[uname]); } - name = srv ("GET_NAME", uname); + name = CONN.get_name (uname); UNAME_TO_NAME_MAP[uname] = name; return (name); } @@ -234,7 +216,7 @@ } function list_plays (game) { - var lst = srv ("LIST_PLAYS", "'" + game + "', '" + UNAME + "'"); + var lst = CONN.list_plays (game, UNAME); list_plays_string (game, lst); } @@ -267,7 +249,8 @@ } document.getElementById("cur-player").innerHTML = disp_name(PLAYS[CUR_PLAY_I][PLAYS[CUR_PLAY_I][3]]); - toss_open_db (play_py_id(pi)); + var info = CONN.open_db (play_py_id (pi)); + ST = new State (info); document.getElementById("suggestions-toggle").style.display = "inline"; full_redraw (); } @@ -285,26 +268,25 @@ 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); + CONN.make_move (CUR_MOVE, play_py_id (CUR_PLAY_I), make_move_continue); } function make_move_continue (info) { - set_info (info); + ST = new State (info); CUR_MOVE = ""; CUR_ELEMS = []; ELEM_COUNTERS = {}; - PLAYS[CUR_PLAY_I][3] = PLAYER_STR; + PLAYS[CUR_PLAY_I][3] = ST.PLAYER_STR; document.getElementById("cur-player").innerHTML = - disp_name(PLAYS[CUR_PLAY_I][PLAYER_STR]); + disp_name(PLAYS[CUR_PLAY_I][ST.PLAYER_STR]); document.getElementById("working").style.display = "none"; full_redraw (); - async_srv_ignore ("UPD_SVG", play_py_id(CUR_PLAY_I) + ", " + svg_string()); + CONN.upd_svg (play_py_id(CUR_PLAY_I), svg_string()); var old_li = document.getElementById ("plays-list-" + GAME_NAME + "-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][PLAYER_STR] == "computer") { + if (PLAYS[CUR_PLAY_I][ST.PLAYER_STR] == "computer") { var mv_time = document.getElementById("speed").value; suggest_move_async (mv_time, make_move); } @@ -445,8 +427,7 @@ if (opp_uid == 0 || UNAME == "") { return; } document.getElementById("plays-list-" + GAME_NAME).style.display = "block"; document.getElementById("working").style.display = "block"; - info_nbr = srv ("NEW_PLAY", "c, '" + GAME_NAME + "', '" + UNAME + - "', '" + opp_uid + "'"); + 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('$'); @@ -459,15 +440,15 @@ document.getElementById("plays").style.left = "30em"; var p = [UNAME, opp_uid, FREE_PLAY_NO, 0]; PLAYS.push(p); - set_info(info_nbr.substring(info_idx+1)); + ST = new State (info_nbr.substring(info_idx+1)); full_redraw (); - async_srv_ignore ("UPD_SVG", play_py_id(CUR_PLAY_I) + ", " + svg_string()); + CONN.upd_svg (play_py_id(CUR_PLAY_I), svg_string()); li = new_play_item (GAME_NAME, CUR_PLAY_I); document.getElementById("plays-list-" + GAME_NAME).appendChild(li); } function get_opponents () { - var lst = srv ("LIST_FRIENDS", "user"); + var lst = CONN.friends (); FRIENDS = convert_python_list (',', lst); } @@ -520,9 +501,9 @@ var fm = function (m) { document.getElementById("working").style.display = "none"; document.getElementById("working").innerHTML = "Working..."; - if (m != "") { show_move (m); f() } + if (m != "") { show_move (new Move (m)); f() } }; - async_srv("SUGGEST", 'c, ' + time + ', '+ play_py_id (CUR_PLAY_I), fm); + CONN.suggest (time, play_py_id (CUR_PLAY_I), fm); } function suggest_move_click () { Added: trunk/Toss/WebClient/State.js =================================================================== --- trunk/Toss/WebClient/State.js (rev 0) +++ trunk/Toss/WebClient/State.js 2011-05-29 00:12:18 UTC (rev 1463) @@ -0,0 +1,127 @@ +// 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; + + + +// --------- State Object ------ + + +// Translate position from Toss Model coordinates to SVG coordinates. +function translate_pos (pos) { + var x = ((pos[0] - this.minx) * SVG_WIDTH) / this.width; + if (VIEW_MIRROR == 0) { + var y = ((pos[1] - this.miny) * SVG_HEIGHT) / this.height; + } else { + var y = + ((this.height - (pos[1] - this.miny)) * SVG_WIDTH) / + this.height; + } + return ([x + SVG_MARGINX, y + SVG_MARGINY]) +} + +// Object representing a state of the system (game). +function State (info_string) { + // 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 = []; + // We directly compute element positions for svg. + this.elem_pos = {}; + this.translate_pos = translate_pos; + for (var i = 0; i < l.length; i++) { + var e = convert_python_list (';', l[i]); + this.elems.push (e[0]); + this.elem_pos[e[0]] = + this.translate_pos ([parseFloat(e[1]), parseFloat(e[2])]); + } + + // 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(']')); + if (rel_name[0] != "_" && args_s != "''") { + rels.push ([rel_name, convert_python_list (',', args_s)]); + } + } + 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/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-05-27 22:09:16 UTC (rev 1462) +++ trunk/Toss/WebClient/index.html 2011-05-29 00:12:18 UTC (rev 1463) @@ -11,6 +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="State.js"> </script> <script type="text/javascript" src="DefaultStyle.js"> </script> <script type="text/javascript" src="Main.js"> </script> <script type="text/javascript" src="Login.js"> </script> Modified: trunk/Toss/WebClient/profile.html =================================================================== --- trunk/Toss/WebClient/profile.html 2011-05-27 22:09:16 UTC (rev 1462) +++ trunk/Toss/WebClient/profile.html 2011-05-29 00:12:18 UTC (rev 1463) @@ -9,6 +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="State.js"> </script> <script type="text/javascript" src="DefaultStyle.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-27 22:09:22
|
Revision: 1462 http://toss.svn.sourceforge.net/toss/?rev=1462&view=rev Author: lukaszkaiser Date: 2011-05-27 22:09:16 +0000 (Fri, 27 May 2011) Log Message: ----------- Corrections to subst_rels, tnf_fv over fixed-points and more tests. Modified Paths: -------------- trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Formula/FormulaOpsTest.ml Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2011-05-26 23:14:21 UTC (rev 1461) +++ trunk/Toss/Formula/FormulaOps.ml 2011-05-27 22:09:16 UTC (rev 1462) @@ -604,20 +604,7 @@ 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 = - let nx = f x in - if nx = x then x else - if n = 0 then - let msg = (print x) ^ " " ^ (print nx) in - failwith ("fixpoint not reached: " ^ msg) - else - fp_n print (n-1) f nx -(* 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 = @@ -650,27 +637,51 @@ 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 + (* Here we must replace a simultaneous least fixed-point with + single ones. In the future we should probably add simultaneous + fixed-points to our logic. For now we use the Bekic principle, cf + "Finite Model Theory and Descriptive Complexity", Lemma 3.3.41, + at www.logic.rwth-aachen.de/pub/graedel/FMTbook-Chapter3.pdf *) + let sovar vs n = + let m = if Array.length vs = 1 then n else "|" ^ n in + mso_or_so_var_of_string m in let sorels rels = function - | Rel (m, rvs) when List.mem m rels -> SO (sovar m, rvs) + | Rel (m, rvs) when List.mem m rels -> + let mv = (sovar rvs m :> var) in + if Array.length rvs = 1 then In (rvs.(0), to_mso mv) else + SO (to_so mv, 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 + (n, ([], vs, Lfp (sovar va n, 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 + if syntax_ok res_phi then + let simpfpvars = (* TODO: is it ok to simplify all these? name clashes? *) + List.concat (List.map (fun (n, _) -> [n; "|" ^ n]) cdefs) in + let rec simp_def_lfp acc fpvar fpvs fpdef = + if List.mem fpvar acc && List.mem (var_str fpvar) simpfpvars then + match mso_or_so_var_of_string (var_str fpvar) with + | `MSO v -> In (fpvs.(0), `MSO v) + | `SO v -> SO (`SO v, 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 + else failwith ("subst_defs: non-stratified recursion?\n" ^ (str res_phi)) +(* Substitute recursively in [r] relations defined in [defs]. *) +let rec subst_rels_expr defs = function + | RVar _ | Const _ | Fun _ as x -> x + | Times (r1, r2) -> Times (subst_rels_expr defs r1, subst_rels_expr defs r2) + | Plus (r1, r2) -> Plus (subst_rels_expr defs r1, subst_rels_expr defs r2) + | Char (phi) -> Char (subst_rels defs phi) + | Sum (vs, phi, r) -> Sum (vs, subst_rels defs phi, subst_rels_expr defs r) + + (* --- AType with variables over given relations, no repetition, equality --- *) let atp rels vars_in = @@ -1567,13 +1578,19 @@ let rec push_quant f = push_in_quant (flatten_sort (f)) -let tnf_fv ?sizes phi = +let tnf_fv_nofp ?sizes phi = let fv = free_vars phi in let psi = rename_quant_avoiding [] (Ex (fv, phi)) in match mso_last (flatten (del_vars_quant fv (tnf psi))) with | Or fl -> Or (List.map (order_by_fv_phi sizes []) fl) | f -> order_by_fv_phi sizes [] f +let tnf_fv ?sizes phi = + let tnf_lfp fprel fpvs fpdef = Lfp (fprel, fpvs, tnf_fv_nofp ?sizes fpdef) in + let psi = map_formula { identity_map with map_Lfp = tnf_lfp } phi in + tnf_fv_nofp ?sizes psi + + (* Assign emptyset to the MSO-variable v by replacing "x in X" with "false". *) let assign_emptyset v phi = let replace_by_emptyset v = function Modified: trunk/Toss/Formula/FormulaOpsTest.ml =================================================================== --- trunk/Toss/Formula/FormulaOpsTest.ml 2011-05-26 23:14:21 UTC (rev 1461) +++ trunk/Toss/Formula/FormulaOpsTest.ml 2011-05-27 22:09:16 UTC (rev 1462) @@ -332,6 +332,16 @@ " (|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))))"); + defs_eq + [("T", (["x"], formula_of_string "P(x) or ex y (E(x, y) and T(y))"))] + "T(x)" "lfp T(x) = (P(x) or ex y (E(x, y) and y in T))"; + defs_eq + [("R", (["x"], formula_of_string "S(x) or ex y (E(x, y) and R(y))")); + ("S", (["x"], formula_of_string "R(x) or ex y (F(x, y) and S(y))"))] + "R(x) and S(x)" + ("(lfp R(x) = ((lfp S(x) = (x in R or ex y (F(x, y) and y in S)) or "^ + " ex y (E(x, y) and y in R))) and lfp S(x) = ((lfp R(x)= (x in S"^ + " or ex y (E(x, y) and y in R)) or ex y (F(x, y) and y in S))))"); ); "atp, mintp" >:: 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-26 22:02:54
|
Revision: 1460 http://toss.svn.sourceforge.net/toss/?rev=1460&view=rev Author: lukstafi Date: 2011-05-26 22:02:48 +0000 (Thu, 26 May 2011) Log Message: ----------- Reference specification of GDL translation: {Concurrent Moves and Toss Locations}. Modified Paths: -------------- trunk/Toss/www/reference/reference.tex Modified: trunk/Toss/www/reference/reference.tex =================================================================== --- trunk/Toss/www/reference/reference.tex 2011-05-26 00:56:05 UTC (rev 1459) +++ trunk/Toss/www/reference/reference.tex 2011-05-26 22:02:48 UTC (rev 1460) @@ -1864,51 +1864,7 @@ 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 @@ -2087,6 +2043,92 @@ \end{align*} +\subsection{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. + +\subsubsection{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. + +\subsubsection{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. We translate using a +single-location game graph. The \texttt{next} clauses wihout +\texttt{does} atoms, are assigned to a special player, +``environment''. + +% The \texttt{next} clauses assigned to the ``environment'' player should +% ideally form rewrite rule(s) that has all its matchings applied, +% over all embeddings, at each state transition. + +To synchronize the play, we introduce an additional element, or use an +existing element singled-out by a stable singleton predicate, and we +introduce \emph{player marker} predicates $Player_{p_i}$ for each +player $p_i$. We require that the player marker be absent in the +corresponding player's rule left-hand-sides, and we add it over the +singled-out element by each rule. Finally, we build a rule for the +``environment'' player that expects player markers for all players, +and clears them all at once. + +The \texttt{next} clauses assigned to the ``environment'' player +together with the player marker clearing can form a single rewrite +rule, or these can be separate rewrite rules. + +If rewriting all matchings, as in the previous comment, is +implemented, then these should be separate rules for ``environment'', +otherwise having a single rewrite rule seems neat. + +\subsubsection{General Interaction Games} When some rule clause has +multiple \texttt{does} relations, we cannot use straightforward +translation of the previous section. Instead, we use the +``environment'' player to carry out state changes, and have the +players declare their moves by their rewrite rules. + +This mode of translation differs from the ``standard modes'' in the +way the \texttt{does} atoms are expanded by the \texttt{legal} +clauses. For each \texttt{legal} clause we introduce a fresh GDL +relation over the variables of the head of the \texttt{legal} +clause. Instead of fully substituting \texttt{does} atoms by +\texttt{legal} clause bodies in a \texttt{next} clause body, we now +substitute by applications of the freshly introduced relations. Later, +we translate the introduced relations coupled with \texttt{legal} +clause bodies as defined relations. But we will not add the +``\texttt{legal} defined relations'' to the Toss game definition, +instead we will use their defining formulas to derive rewrite rules +for players. The introduced ``\texttt{legal} defined relation names'' +will be the fluents added by the player rules, we will call them +\emph{move markers}. Unlike the game state fluents $Flu^s_p$, the move +markers will usually have arity higher than one. Due to the injective +nature of rewrite rules (the matchings are graph embeddings), we +generate additional rewrite rules where some arguments of move markers +are made equal and the right-hand-sides of the rules are +correspondingly smaller. + +Besides move markers, player rules also introduce player markers, as +in the previous section. The move and player markers are erased by the +game state transition rule of the ``environment'' player. + \section{Game Simplification in Toss} \label{sec-game-simpl} Games automatically translated from GDL, as described above, are verbose This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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-23 23:20:55
|
Revision: 1458 http://toss.svn.sourceforge.net/toss/?rev=1458&view=rev Author: lukaszkaiser Date: 2011-05-23 23:20:49 +0000 (Mon, 23 May 2011) Log Message: ----------- Merging some GIGA final version corrections. Modified Paths: -------------- trunk/Toss/www/pub/gdl_to_toss_translation.pdf trunk/Toss/www/reference/reference.tex Modified: trunk/Toss/www/pub/gdl_to_toss_translation.pdf =================================================================== (Binary files differ) Modified: trunk/Toss/www/reference/reference.tex =================================================================== --- trunk/Toss/www/reference/reference.tex 2011-05-23 16:48:44 UTC (rev 1457) +++ trunk/Toss/www/reference/reference.tex 2011-05-23 23:20:49 UTC (rev 1458) @@ -92,6 +92,8 @@ \newcommand{\tpos}{\downharpoonleft} \newcommand{\TrRels}{\ensuremath{\mathrm{TrRels}}} \newcommand{\TrST}{\ensuremath{\mathrm{TrST}}} +\newcommand{\lfp}{\mathrm{lfp}} +\newcommand{\gfp}{\mathrm{gfp}} % Theorem environments \theoremstyle{plain} @@ -167,8 +169,8 @@ $(a_1, \ldots, a_{r_i}) \in R^\frakA_i \Leftrightarrow (f(a_1), \ldots, f(a_{r_i})) \in R^\frakB_i$, and for $R_j \in \tau_{\mr{h}}$ it holds that - $(a_1, \ldots, a_{r_i}) \in R^\frakA_j \Rightarrow - (f(a_1), \ldots, f(a_{r_i})) \in R^\frakB_j$. + $(a_1, \ldots, a_{r_j}) \in R^\frakA_j \Rightarrow + (f(a_1), \ldots, f(a_{r_j})) \in R^\frakB_j$. A $(\tau_{\mr{e}}, \tau_{\mr{h}})$-\emph{match} of the rule $\frakL \to_s \frakR$ in another structure $\frakA$ is an $(\tau_{\mr{e}}, \tau_{\mr{h}})$-embedding $\sigma : \frakL \hookrightarrow \frakA$. @@ -372,18 +374,20 @@ In the syntax of our logic, we use first-order variables ($x_1, x_2, \ldots$) ranging over elements of the structure, second-order variables ($X_1, X_2, \ldots$) ranging over \emph{sets} of elements, +fixed-point second order relations ($\Xi_1,\Xi_2,\ldots$) ranging over relations and real-valued variables $(\alpha_1, \alpha_2, \ldots)$ ranging over $\bbR$, and we distinguish boolean formulas $\phi$ and real-valued terms $\rho$: \begin{eqnarray*} \phi := & \!\!\!\!\! R_i(x_1, \ldots, x_{r_i}) \, |\, x_i=x_j \, |\, - x_i \in X_j \, | \, \rho <_\epsilon \rho \, | \, \phi \land \phi \ | \\ - & \!\!\! \phi \lor \phi \, | \, \neg \phi \, | \, - \exists x_i \phi \, | \, \forall x_i \phi \, | \, + x_i \in X_j \, | \, \rho <_\epsilon \rho \, | \, \phi \land \phi \, | \, + \phi \lor \phi \, | \, \neg \phi \, | \\ + & \exists x_i \phi \, | \, \forall x_i \phi \, | \, \exists X_i \phi \, | \, \forall X_i \phi \, | \, - \exists \alpha_i \phi \, | \, \forall \alpha_i \phi, -\end{eqnarray*} -\vskip -1.1em -\begin{eqnarray*} + \exists \alpha_i \phi \, | \, \forall \alpha_i \phi \, | \, + \lfp \Xi_i \phi \, | \, \gfp \Xi_i \phi \\ +%\end{eqnarray*} +%\vskip -1.1em +%\begin{eqnarray*} \rho := & \!\!\!\! \alpha_i \: | \: f_i(x_j) \: | \: %\rho + \rho \ | \ \rho \dotplus \rho \: | \: \chi[\phi] \: | \: \min_{\alpha_i}\!\phi \: | \: \sum_{\ol{x} \mid \phi} \rho \: | \: \prod_{\ol{x} \mid \phi} \rho. @@ -392,7 +396,8 @@ Semantics of most of the above operators is defined in the well known way, \eg $\rho+\rho$ is the sum and $\rho \cdot \rho$ the product of real-valued terms, and $\exists X \phi(X)$ means that there exists a set of elements $S$ such -that $\phi(S)$ holds. Among less known operators, +that $\phi(S)$ holds, and $\lfp \, X\, \phi(X)$ is the least fixed-point of +the equation $X = \phi(X)$. Among less known operators, the term $\chi[\phi]$ denotes the characteristic function of $\phi$, \ie the real-valued term which is $1$ for all assignments for which $\phi$ holds and $0$ for all other. To evaluate $\min_{\alpha_i}\phi$ we take the minimal 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-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 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-22 14:52:07
|
Revision: 1454 http://toss.svn.sourceforge.net/toss/?rev=1454&view=rev Author: lukstafi Date: 2011-05-22 14:52:01 +0000 (Sun, 22 May 2011) Log Message: ----------- Reference specification of GDL translation: missing case of mask predicates. Modified Paths: -------------- trunk/Toss/www/reference/reference.tex Modified: trunk/Toss/www/reference/reference.tex =================================================================== --- trunk/Toss/www/reference/reference.tex 2011-05-22 13:40:35 UTC (rev 1453) +++ trunk/Toss/www/reference/reference.tex 2011-05-22 14:52:01 UTC (rev 1454) @@ -1489,7 +1489,8 @@ We say that a term $m$ is a \emph{mask term} if the paths to all variables of $m$ are contained in $\calP_m \cup \calP_f$ and for each $p \in \calP_m \cup \calP_f$ if $p$ exists in $m$ then $m \tpos_p$ is -a variable. We say that $m$ \emph{masks} a terms $t$ if there exists +a variable. We say that $m$ \emph{masks} a term $t$ if $m$ is a mask term +and there exists a substitution $\sigma$ such that $\sigma(m) = t$. For all mask terms $m \in \calS$ we introduce the \emph{mask predicate} $Mask_m$. Mask predicates are similar to the anchor predicates, but instead of @@ -1933,7 +1934,9 @@ & \Land \big\{ Flu^s_p(v) \; \big| \; v = \mathtt{BL}(t) \wedge p \in \calP_f \wedge t \tpos_p = s \wedge s \neq \mathtt{BLANK} - \big\} + \big\} \wedge \\ + & \Land \big\{ + Mask_m(v) \; \big| \; v = \mathtt{BL}(t) \wedge m \textit{ masks } t \big\} \end{align*} The case of $\TrRels$ for non-stable relations will be covered in the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-22 13:40:41
|
Revision: 1453 http://toss.svn.sourceforge.net/toss/?rev=1453&view=rev Author: lukaszkaiser Date: 2011-05-22 13:40:35 +0000 (Sun, 22 May 2011) Log Message: ----------- Very small TeX and compilation corrections. Modified Paths: -------------- trunk/Toss/www/reference/Makefile trunk/Toss/www/reference/reference.tex Modified: trunk/Toss/www/reference/Makefile =================================================================== --- trunk/Toss/www/reference/Makefile 2011-05-22 11:11:05 UTC (rev 1452) +++ trunk/Toss/www/reference/Makefile 2011-05-22 13:40:35 UTC (rev 1453) @@ -1,4 +1,4 @@ -all: reference.pdf index.html +all: reference.pdf #index.html reference.pdf: reference.tex reference.bib pdflatex reference.tex Modified: trunk/Toss/www/reference/reference.tex =================================================================== --- trunk/Toss/www/reference/reference.tex 2011-05-22 11:11:05 UTC (rev 1452) +++ trunk/Toss/www/reference/reference.tex 2011-05-22 13:40:35 UTC (rev 1453) @@ -1941,10 +1941,10 @@ \subsubsection{Introducing and Using Defined Relations} -Consider generating defined relation for relation $R$ with GDL -defining clauses $\mathtt{(<= (R \ t^1_1 \ldots t^1_n) \ b_1)}, -\ldots, \mathtt{(<= (R \ t^k_1 \ldots t^k_n) \ b_k)}$. For $i$th -argument of $R$ ($i \in \{1,\ldots,n\}$) we will find +Consider generating defined relation for relation $R$ with GDL defining clauses +\[ \mathtt{(<= (R \ t^1_1 \ldots t^1_n) \ b_1)}, + \ldots, \mathtt{(<= (R \ t^k_1 \ldots t^k_n) \ b_k)}.\] +For the $i$th argument of $R$ ($i \in \{1,\ldots,n\}$) we will find $\mathtt{ArgType}(R,i)$ with possible values $(\mathtt{DefSide},\calS_i,p_i)$ and $(\mathtt{CallSide},p_i)$, with a mapping $\calS_i$ into state terms corresponding to the argument in a given context and a path $p_i \in @@ -1988,11 +1988,11 @@ above, let \begin{align*} -$E_{j,l} = & +E_{j,l} = & \bigwedge \big\{v_i=s^i_{j,l} \big| i \in \calI\big\} \wedge \bigwedge\big\{v_i=\mathtt{BL}(p_i \ot t^j_i) \big| i \in \{1,\ldots,n\} \setminus \calI\big\} \\ -$S_{j,l} = & +S_{j,l} = & \bigwedge\big\{\mathtt{true}\big(\mathtt{BL}(p_i \ot t^j_i)\big) \big| i \in \{1,\ldots,n\} \setminus \calI\big\} \end{align*} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-05-22 11:11:12
|
Revision: 1452 http://toss.svn.sourceforge.net/toss/?rev=1452&view=rev Author: lukstafi Date: 2011-05-22 11:11:05 +0000 (Sun, 22 May 2011) Log Message: ----------- Reference specification of GDL translation: fixes and cleanup. Modified Paths: -------------- trunk/Toss/www/reference/reference.tex Modified: trunk/Toss/www/reference/reference.tex =================================================================== --- trunk/Toss/www/reference/reference.tex 2011-05-22 00:36:07 UTC (rev 1451) +++ trunk/Toss/www/reference/reference.tex 2011-05-22 11:11:05 UTC (rev 1452) @@ -1928,10 +1928,12 @@ \TrST (\phi_1) \vee \TrST(\phi_2) \\ \TrST (\mathtt{true}(t)) = & \Land \big\{ Anch^s_p(v) \; \big| \; v = \mathtt{BL}(t) \wedge - p \in \calP_m \wedge t \tpos_p = s \big\} \wedge \\ + p \in \calP_m \wedge t \tpos_p = s \wedge s \neq \mathtt{BLANK} + \big\} \wedge \\ & \Land \big\{ Flu^s_p(v) \; \big| \; v = \mathtt{BL}(t) \wedge - p \in \calP_f \wedge t \tpos_p = s \big\} + p \in \calP_f \wedge t \tpos_p = s \wedge s \neq \mathtt{BLANK} + \big\} \end{align*} The case of $\TrRels$ for non-stable relations will be covered in the @@ -2007,18 +2009,20 @@ \begin{align*} \TrRels (\pm R(t_1, \ldots, t_n), S_1, S_2) = & - \exists \{v_1,\ldots,v_n\} \ \pm R_{def}(v_1, \ldots, v_n) \wedge \\ & - \Land \big\{\exists \mathtt{BL}(p_{R,i}\ot t_i) \big( - v_i = \mathtt{BL}(p_{R,i}\ot t_i) \wedge \\ & - \ \ \ \TrRels (\mathtt{EQ}(t_i,t_i), - S_1 \cup \{\mathtt{BL}(p_{R,i}\ot t_i)\}, - \{\mathtt{BL}(p_{R,i}\ot t_i)\}) \big) \\ & - \ \ \big| \ i \in \calI_R \vee - \neg \exists s \in S_1 (s\tpos_{p_{R,i}} = t_i) \big\} \wedge \\ & - \Land \big\{v_i = s - \ \big| \ i \not\in \calI_R \wedge - \exists s \in S_1 (s\tpos_{p_{R,i}} = t_i) \big\} \\ & - \textit{(when $R$ is not a stable relation)} + \exists \{v_i \ | \ i \in \calJ \} \big( + \pm R_{def}(v_1, \ldots, v_n) \wedge \\ & + \Land \big\{ + \TrRels (\mathtt{EQ}(t_i,t_i), + S_1 \cup \{v_i\}, \{v_i\}) + \ \big| \ i \in \calJ \big\} \big) \\ & + \textit{(when $R$ is not a stable relation)} \\ + \textit{where} \\ + \calJ = & + \big\{i \ \big| \ i \in \calI_R \vee + \neg \exists s \in S_1 (s\tpos_{p_{R,i}} = t_i) \big\} \\ + v_i = \mathtt{BL}(p_{R,i}\ot t_i) & \textit{ if } i \in \calJ \\ + v_i = \mathtt{BL}(s) & \textit{ if } i \not\in \calJ + \textit{ where $s$ such that } s \in S_1 \wedge s\tpos_{p_{R,i}} = t_i \end{align*} 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-21 22:28:07
|
Revision: 1450 http://toss.svn.sourceforge.net/toss/?rev=1450&view=rev Author: lukstafi Date: 2011-05-21 22:28:01 +0000 (Sat, 21 May 2011) Log Message: ----------- Reference specification of GDL translation: minor correction. Modified Paths: -------------- trunk/Toss/www/reference/reference.tex Modified: trunk/Toss/www/reference/reference.tex =================================================================== --- trunk/Toss/www/reference/reference.tex 2011-05-21 14:32:28 UTC (rev 1449) +++ trunk/Toss/www/reference/reference.tex 2011-05-21 22:28:01 UTC (rev 1450) @@ -1315,15 +1315,13 @@ of all GDL state terms which are true at some game state reachable from the initial state of $G$. -For us, it is enough to approximate $\calS$ from above. To approximate $\calS$ -and determine the location structure of the Toss game, we currently perform -an \emph{aggregate playout}, \ie a symbolic play in where all players take -all their legal moves in a state. Since an approximation is sufficient, -we check only the positive part of the legality condition of each move. +For us, it is enough to approximate $\calS$ from above. To approximate +$\calS$, we currently perform an \emph{aggregate playout}, \ie a +symbolic play in where all players take all their legal moves in a +state. Since an approximation is sufficient, we check only the +positive part of the legality condition of each move. -%The \emph{noop move} of a player in a -%location is the only move available to her, determining them gives the -%player of a turn. In the future, instead of an aggregate playout we +%In the future, instead of an aggregate playout we %might use a form of type inference to approximate $\calS$. To construct the elements of the structure from state terms, @@ -1886,8 +1884,7 @@ equality relations $Eq_{p,q}$. The result of translation is the disjunction of translations of each -$\Phi_i$. Let $\mathtt{BL}(t)$ -be the term $t$ with fluent paths replaced with \texttt{BLANK}. A single $\Phi_i = G_i \wedge ST^{+}_i \wedge ST^{-}_i$ +$\Phi_i$. Let $\mathtt{BL}(t)=t\big[\calP_f \ot \mathtt{BLANK}\big]$. A single $\Phi_i = G_i \wedge ST^{+}_i \wedge ST^{-}_i$ is translated as: \begin{align*} @@ -1947,7 +1944,7 @@ \ldots, \mathtt{(<= (R \ t^k_1 \ldots t^k_n) \ b_k)}$. For $i$th argument of $R$ ($i \in \{1,\ldots,n\}$) we will find $\mathtt{ArgType}(R,i)$ with possible values -$(\mathtt{DefSide},\calS_i,p_i)$ and $(\mathtt{CallSide},\calS_i,p_i)$, with a mapping $\calS_i$ into state terms +$(\mathtt{DefSide},\calS_i,p_i)$ and $(\mathtt{CallSide},p_i)$, with a mapping $\calS_i$ into state terms corresponding to the argument in a given context and a path $p_i \in \calP_m$ corresponding to the subterm position selected to ``transfer'' the argument. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |