[Toss-devel-svn] SF.net SVN: toss:[1701] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
From: <luk...@us...> - 2012-05-06 22:17:54
|
Revision: 1701 http://toss.svn.sourceforge.net/toss/?rev=1701&view=rev Author: lukaszkaiser Date: 2012-05-06 22:17:46 +0000 (Sun, 06 May 2012) Log Message: ----------- Animation in JS interface - Bounce example works. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/Arena.mli trunk/Toss/Arena/ContinuousRule.ml trunk/Toss/Client/JsHandler.ml trunk/Toss/Client/Main.js trunk/Toss/Client/Play.js trunk/Toss/Client/State.js trunk/Toss/Client/Style.css trunk/Toss/Client/index.html trunk/Toss/Solver/Structure.ml trunk/Toss/Solver/Structure.mli trunk/Toss/examples/Hnefatafl.toss Added Paths: ----------- trunk/Toss/Client/img/Bounce.png trunk/Toss/Client/img/Hnefatafl.png trunk/Toss/examples/Bounce.toss Removed Paths: ------------- trunk/Toss/examples/bounce.toss Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/Arena/Arena.ml 2012-05-06 22:17:46 UTC (rev 1701) @@ -654,8 +654,8 @@ let mtch = List.map (fun (v, e) -> v, Structure.elem_nbr state.struc e) mv.matching in Aux.map_option - (fun (model, time, _) -> (* ignoring shifts, i.e. animation steps *) - (mv, + (fun (model, time, shifts) -> + ((mv, shifts), {cur_loc = mv.next_loc; history = (mv, None) :: state.history; struc = model; @@ -667,9 +667,9 @@ let gen_models rules state time moves = let res = gen_models_list rules state time moves in let moves, states = List.split res in - Array.of_list moves, Array.of_list states + Array.of_list (List.map fst moves), Array.of_list states -let list_moves game s = +let list_moves_shifts game s = let select_moving a = let pls = Aux.array_argfind_all (fun l -> l.moves <> []) a in if pls = [] then [0] else pls in @@ -677,13 +677,14 @@ let moving = select_moving loc in let get_moves pl = let m = gen_moves cGRID_SIZE game.rules s.struc loc.(pl) in - (gen_models_list game.rules s s.time m) in + gen_models_list game.rules s s.time m in Array.of_list (List.concat ( List.map (fun p -> List.map (fun (a,b) -> (p,a,b)) (get_moves p)) moving)) +let list_moves game s = + Array.map (fun (p,a,b) -> (p, fst a, b)) (list_moves_shifts game s) - let apply_rule_int (state_game, state) (r_name, mtch, t, p) = (let try r = List.assoc r_name state_game.rules in ( match ContinuousRule.rewrite_single state.struc state.time mtch r t p with Modified: trunk/Toss/Arena/Arena.mli =================================================================== --- trunk/Toss/Arena/Arena.mli 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/Arena/Arena.mli 2012-05-06 22:17:46 UTC (rev 1701) @@ -188,6 +188,9 @@ the player together with a move. *) val list_moves : game -> game_state -> (int * move * game_state) array +(** As [list_moves] but with animation shifts for each move. *) +val list_moves_shifts : game -> game_state -> + (int * (move * ((string * string) * Term.term list) list) * game_state) array val apply_rule_int : game * game_state -> string * (string * int) list * float * (string * float) list -> Modified: trunk/Toss/Arena/ContinuousRule.ml =================================================================== --- trunk/Toss/Arena/ContinuousRule.ml 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/Arena/ContinuousRule.ml 2012-05-06 22:17:46 UTC (rev 1701) @@ -96,7 +96,7 @@ (* For now, we rewrite only single rules. Does not check postcondition. *) let rewrite_single_nocheck struc cur_time m r t params = let time = ref cur_time in - LOG 2 "current time: %f" !time; + LOG 1 "current time: %f" !time; let p_vars, p_vals = List.split params in let subst_params tm = List.hd @@ -130,11 +130,9 @@ let cur_vals = ref init_vals in let all_vals = ref [] in let end_time = !time +. t -. (0.01 *. !time_step) in (*TODO: 1% is decimals!*) - LOG 2 "end time: %f" end_time; + LOG 1 "end time: %f" end_time; let is_inv s = Solver.M.check s r.inv in - let lhs_to_model ((f, a), _) = - (* dynamics refer to elements by LHS matches *) - (f, List.assoc a m) in + let lhs_to_model ((f, a), _) = (f, List.assoc a m) in let upd_struct st = let vals = List.combine (List.map lhs_to_model dyn) @@ -154,13 +152,18 @@ ) else ( LOG 2 "Invariant failed.\n%s\n%s" (Structure.str !cur_struc) (Formula.sprint r.inv); - cur_vals := List.hd !all_vals; + if !all_vals = [] then + failwith "rewriting invariant failed in the first step; rule inapplicable" + else cur_vals := List.hd !all_vals; ); let lhs_to_model_str x = let (f, i) = lhs_to_model x in f, Structure.elem_str struc i in let all_vals_assoc = select_pos (List.map lhs_to_model_str dyn) (List.rev !all_vals) in + LOG 1 "%s" (String.concat "\n" (List.map (fun ((a, b), tl)-> a ^"("^ b ^")" ^ + (String.concat ", " (List.map ( + fun t -> string_of_float (Term.term_val t)) tl))) all_vals_assoc)); (* let val_map = if !cur_vals = [] then List.combine (List.map fst dyn) init_vals Modified: trunk/Toss/Client/JsHandler.ml =================================================================== --- trunk/Toss/Client/JsHandler.ml 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/Client/JsHandler.ml 2012-05-06 22:17:46 UTC (rev 1701) @@ -66,7 +66,9 @@ ("Gomoku", AuxIO.input_file "examples/Gomoku.toss"); ("Pawn-Whopping", AuxIO.input_file "examples/Pawn-Whopping.toss"); ("Tic-Tac-Toe", AuxIO.input_file "examples/Tic-Tac-Toe.toss"); + ("Hnefatafl", AuxIO.input_file "examples/Hnefatafl.toss"); ("Rewriting-Example", AuxIO.input_file "examples/Rewriting-Example.toss"); + ("Bounce", AuxIO.input_file "examples/Bounce.toss"); ] let gSel_games = ref [compile_game_data "Tic-Tac-Toe" @@ -108,8 +110,7 @@ Js.Unsafe.set js_handler (js name) (Js.wrap_callback f) (* In case the handler is used in the same thread: *) -let _ = - Js.Unsafe.set self (js"LOCAL") js_handler +let _ = Js.Unsafe.set self (js"LOCAL") js_handler (* In case the handler is used as Web Worker: *) let postMessage = Js.Unsafe.variable "postMessage" @@ -140,7 +141,7 @@ js ("Now " ^ of_js s ^ " tested") let _ = set_handle "test_handle" test_handle -let js_of_move game state move_id (player, move, _) = +let js_of_move game state move_id (player, (move, _), _) = let matched = Js.array (Aux.array_map_of_list (fun (_, e) -> js e) move.Arena.matching) in let js_move = jsnew js_object () in @@ -151,25 +152,30 @@ Js.Unsafe.set js_move (js"id") (Js.float (float_of_int move_id)); js_move -(* Translate current structure into an "info_obj" format. *) -let js_of_game_state ?(show_payoffs=true) game state = +(* Get dimensions of a structure (minx, maxx, miny, maxy). *) +let state_dim state = let struc = state.Arena.struc in - let get_pos e = - Structure.fun_val struc "x" e, Structure.fun_val struc "y" e in - LOG 1 "js_of_game_state: Preparing game elements..."; + let get_pos e= Structure.fun_val struc "x" e, Structure.fun_val struc "y" e in let elems = Structure.elements struc in let (posx, posy) = List.split (List.map get_pos elems) in let mkfl f l = List.fold_left f (List.hd l) (List.tl l) in let (minl, maxl, suml) = (mkfl min, mkfl max, mkfl (+.)) in - let minx, maxx, miny, maxy = minl posx, maxl posx, minl posy, maxl posy in + minl posx, maxl posx, minl posy, maxl posy + +(* Translate current structure into an "info_obj" format. *) +let js_of_game_state ?(show_payoffs=true) ?dims game state = + let struc = state.Arena.struc in + let elems = Structure.elements struc in + LOG 1 "js_of_game_state: Preparing game elements..."; + let get_pos e = Structure.fun_val struc "x" e,Structure.fun_val struc "y" e in + let minx, maxx, miny, maxy = match dims with + | None -> state_dim state | Some d -> d in (* elems are arrays of element name and position *) - let elems = Array.of_list - (List.map - (fun e -> - let e0 = js (Structure.elem_name struc e) in - let x, y = get_pos e in - Js.array [|js_any e0; js_any (Js.float x); js_any (Js.float y)|]) - elems) in + let elems = Array.of_list (List.map (fun e -> + let e0 = js (Structure.elem_name struc e) in + let x, y = get_pos e in + Js.array [|js_any e0; js_any (Js.float x); js_any (Js.float y)|] + ) elems) in (* rels are arrays of element names, with additional "name" field *) let num = Js.number_of_float in LOG 1 "js_of_game_state: Preparing game relations..."; @@ -197,7 +203,7 @@ if !cur_all_moves <> [||] then Js.Unsafe.set info_obj (js"moves") (Js.array (Array.mapi (js_of_move game state) !cur_all_moves)) - else if show_payoffs then ( (* find payoffs *) + else if show_payoffs then ( (* find payoffs *) let payoffs = Array.mapi (fun i v -> i, Solver.M.get_real_val v.Arena.payoff struc) game.Arena.graph.(state.Arena.cur_loc) in @@ -232,7 +238,7 @@ let game, state = game_data.game_state in cur_game := game_data; play_states := [state]; - cur_all_moves := Arena.list_moves game state; + cur_all_moves := Arena.list_moves_shifts game state; cur_move := 0; LOG 1 "new_play (%s): calling js_of_game_state." game_name; js_of_game_state game state @@ -248,17 +254,34 @@ let _ = set_handle "prev_move" preview_move +(* Compute all copies of [state] given by [shifts], including [state]. *) +let shifted_state state shifts = + if shifts = [] then [state] else + let len, res = List.length (snd (List.hd shifts)), ref [state] in + for i = 0 to len - 1 do + let new_struc = List.fold_left (fun struc ((fname, elem), ts) -> + let v = Term.term_val (List.nth ts i) in + Structure.change_fun struc fname elem v) state.Arena.struc shifts in + res := { state with Arena.struc = new_struc } :: !res; + done; + !res + let make_move move_id = let move_id = int_of_float (Js.to_float move_id) in LOG 1 "make_move: move_id=%d" move_id; if !play_states = [] then Js.null else - let (p, m, n_state) = !cur_all_moves.(move_id) in - let game, _ = !cur_game.game_state in + let (p, (_, shifts), n_state) = !cur_all_moves.(move_id) in + let game, old_state = !cur_game.game_state in play_states := n_state :: !play_states; - cur_all_moves := Arena.list_moves game n_state; + cur_all_moves := Arena.list_moves_shifts game n_state; cur_move := 0; - Js.some (js_of_game_state game n_state) + let states = List.rev (n_state :: (shifted_state old_state shifts)) in + let dims = List.fold_left (fun (a, b, c, d) s -> + let (x, y, z, v) = state_dim s in + (min a x, max b y, min c z, max d v)) (state_dim n_state) states in + Js.some (Js.array (Array.of_list (List.map + (js_of_game_state ~dims game) states))) let _ = set_handle "make_move" make_move @@ -301,7 +324,7 @@ let algo_iters = large_iters - !Play.latest_unfold_iters_left in LOG 0 "iters: %i" algo_iters; let move_id = Aux.array_argfind - (fun (_, m, _) -> m = move) !cur_all_moves in + (fun (_, (m, _), _) -> m = move) !cur_all_moves in let result = js_of_move game state move_id (!cur_all_moves.(move_id)) in Js.Unsafe.set result (js"comp_iters") @@ -321,7 +344,7 @@ let game, _ = !cur_game.game_state in let move_s, state = of_js move_js, List.hd !play_states in let move_id = Aux.array_argfind - (fun (_,m,_) -> Arena.game_move_str m = move_s) !cur_all_moves in + (fun (_, (m,_), _) -> Arena.game_move_str m = move_s) !cur_all_moves in let result = js_of_move game state move_id (!cur_all_moves.(move_id)) in Js.Unsafe.set result (js"comp_iters") Modified: trunk/Toss/Client/Main.js =================================================================== --- trunk/Toss/Client/Main.js 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/Client/Main.js 2012-05-06 22:17:46 UTC (rev 1701) @@ -278,10 +278,12 @@ var bt = document.getElementById ("more-games-bt"); if (bt.innerHTML.indexOf ("More") > -1) { bt.innerHTML = "Less Games"; - document.getElementById ("moregames").style.display = "block"; + document.getElementById ("moregames1").style.display = "block"; + document.getElementById ("moregames2").style.display = "block"; } else { bt.innerHTML = "More Games"; - document.getElementById ("moregames").style.display = "none"; + document.getElementById ("moregames1").style.display = "none"; + document.getElementById ("moregames2").style.display = "none"; } } Modified: trunk/Toss/Client/Play.js =================================================================== --- trunk/Toss/Client/Play.js 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/Client/Play.js 2012-05-06 22:17:46 UTC (rev 1701) @@ -149,13 +149,23 @@ function play_move_continue (info, suggest_f) { PlayDISP.free (); - this.new_state (info); - this.redraw (); - if (this.cur_state.players.length == 1 && - this.players[this.cur_state.players[0]] == "computer") { - var mv_time = document.getElementById("speed").value; - suggest_f (mv_time); + var TIMESTEP = 100; + for (var i = 1; i < info.length-1; i++) { + setTimeout (function (_this, cur_info) { + _this.cur_state = + new State (_this.game, cur_info, _this.cur_state.mirror); + _this.redraw (); + }, i*TIMESTEP, this, info[i]); } + setTimeout (function (_this, cur_info) { + _this.new_state (cur_info); + _this.redraw (); + if (_this.cur_state.players.length == 1 && + _this.players[_this.cur_state.players[0]] == "computer") { + var mv_time = document.getElementById("speed").value; + suggest_f (mv_time); + } + }, info.length*TIMESTEP, this, info[info.length - 1]) } Play.prototype.move_continue = play_move_continue; Modified: trunk/Toss/Client/State.js =================================================================== --- trunk/Toss/Client/State.js 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/Client/State.js 2012-05-06 22:17:46 UTC (rev 1701) @@ -197,6 +197,7 @@ function square_elements_game (game) { return (game !== "Connect4" && + game !== "Bounce" && game !== "Rewriting-Example") } @@ -442,12 +443,17 @@ 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 + default_rel["P"] = // Cross + '<g class="model-pred-P">' + '<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 + default_rel["X"] = default_rel["P"] // Cross + default_rel["Q"] = // Circle + '<circle class="model-pred-Q" cx="0" cy="0" r="17" />'; + default_rel["T"] = // Plus + '<g class="model-pred-T">' + + '<line x1="0" y1="-17" x2="0" y2="17" />' + + '<line x1="17" y1="0" x2="-17" y2="0" /></g>'; default_rel["IsFirst"] = '<circle class="model-pred-Q" cx="0" cy="0" r="0" />'; // Empty default_rel["IsSecond"] = Modified: trunk/Toss/Client/Style.css =================================================================== --- trunk/Toss/Client/Style.css 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/Client/Style.css 2012-05-06 22:17:46 UTC (rev 1701) @@ -175,9 +175,12 @@ width: 100%; } -#moregames { +#moregames1 { display: none; } +#moregames2 { + display: none; +} .game-picdiv1 { position: relative; @@ -1049,7 +1052,7 @@ } -.model-pred-P { +.model-pred-P, .model-pred-X, .model-pred-T { fill: #400827; stroke: #260314; stroke-width: 5px; @@ -1121,7 +1124,8 @@ stroke-width: 2px; } -.Game-Chess .chessW .chess-path-A, .Game-Pawn-Whopping .chessW .chess-path-A { +.Game-Chess .chessW .chess-path-A, .Game-Pawn-Whopping .chessW .chess-path-A, + .Game-Hnefatafl .chessW .chess-path-A { opacity: 1; fill: #fff1d4; fill-opacity: 1; @@ -1151,7 +1155,8 @@ stroke-opacity: 1; } -.Game-Chess .chessB .chess-path-A, .Game-Pawn-Whopping .chessB .chess-path-A { +.Game-Chess .chessB .chess-path-A, .Game-Pawn-Whopping .chessB .chess-path-A, + .Game-Hnefatafl .chessB .chess-path-A { opacity: 1; fill: #400827; fill-opacity: 1; @@ -1181,7 +1186,8 @@ stroke-opacity: 1; } -.Game-Chess .chessW .chess-path-B, .Game-Pawn-Whopping .chessW .chess-path-B { +.Game-Chess .chessW .chess-path-B, .Game-Pawn-Whopping .chessW .chess-path-B, + .Game-Hnefatafl .chessW .chess-path-B { opacity: 1; fill: #fff1d4; fill-opacity: 1; @@ -1209,7 +1215,8 @@ stroke-opacity: 1; } -.Game-Chess .chessB .chess-path-B, .Game-Pawn-Whopping .chessB .chess-path-B { +.Game-Chess .chessB .chess-path-B, .Game-Pawn-Whopping .chessB .chess-path-B, + .Game-Hnefatafl .chessB .chess-path-B { opacity: 1; fill: #400827; fill-opacity: 1; @@ -1238,7 +1245,8 @@ } -.Game-Chess .chessW .chess-path-Bx, .Game-Pawn-Whopping .chessW .chess-path-Bx { +.Game-Chess .chessW .chess-path-Bx, .Game-Pawn-Whopping .chessW .chess-path-Bx, + .Game-Hnefatafl .chessW .chess-path-Bx { opacity: 1; fill: #fff1d4; fill-opacity: 1; @@ -1266,7 +1274,8 @@ stroke-opacity: 1; } -.Game-Chess .chessB .chess-path-Bx, .Game-Pawn-Whopping .chessB .chess-path-Bx { +.Game-Chess .chessB .chess-path-Bx, .Game-Pawn-Whopping .chessB .chess-path-Bx, + .Game-Hnefatafl .chessB .chess-path-Bx { opacity: 1; fill: #fff1d4; fill-opacity: 1; @@ -1294,7 +1303,8 @@ stroke-opacity: 1; } -.Game-Chess .chessW .chess-path-C, .Game-Pawn-Whopping .chessW .chess-path-C { +.Game-Chess .chessW .chess-path-C, .Game-Pawn-Whopping .chessW .chess-path-C, + .Game-Hnefatafl .chessW .chess-path-C { opacity: 1; fill: #400827; fill-opacity: 1; @@ -1320,7 +1330,8 @@ stroke-opacity: 1; } -.Game-Chess .chessB .chess-path-C, .Game-Pawn-Whopping .chessB .chess-path-C { +.Game-Chess .chessB .chess-path-C, .Game-Pawn-Whopping .chessB .chess-path-C, + .Game-Hnefatafl .chessB .chess-path-C { opacity:1; fill: #fff1d4; fill-opacity: 1; @@ -1346,7 +1357,8 @@ stroke-opacity: 1; } -.Game-Chess .chessW .chess-path-D, .Game-Pawn-Whopping .chessW .chess-path-D { +.Game-Chess .chessW .chess-path-D, .Game-Pawn-Whopping .chessW .chess-path-D, + .Game-Hnefatafl .chessW .chess-path-D { fill: #fff1d4; fill-opacity: 0.75; fill-rule: evenodd; @@ -1372,7 +1384,8 @@ stroke-opacity: 1; } -.Game-Chess .chessB .chess-path-D, .Game-Pawn-Whopping .chessB .chess-path-D { +.Game-Chess .chessB .chess-path-D, .Game-Pawn-Whopping .chessB .chess-path-D, + .Game-Hnefatafl .chessB .chess-path-D { fill: #400827; fill-opacity: 0.75; fill-rule: evenodd; Added: trunk/Toss/Client/img/Bounce.png =================================================================== (Binary files differ) Property changes on: trunk/Toss/Client/img/Bounce.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/Toss/Client/img/Hnefatafl.png =================================================================== (Binary files differ) Property changes on: trunk/Toss/Client/img/Hnefatafl.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/Toss/Client/index.html =================================================================== --- trunk/Toss/Client/index.html 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/Client/index.html 2012-05-06 22:17:46 UTC (rev 1701) @@ -31,7 +31,8 @@ </span> <span id="appstorelink"> <a href="http://itunes.apple.com/us/app/tplay/id438620686" - ><img style="height: 24px; width: 69px;" src="img/appstore-small.png" /></a> + ><img style="height: 24px; width: 69px;" alt="App Store" + src="img/appstore-small.png" /></a> </span> <span id="speedtab" style="display: none;"> @@ -121,13 +122,13 @@ >More Games</button> </div> -<div id="moregames" class="game-line"> +<div id="moregames1" class="game-line"> <div class="game-picdiv1"> -<button onclick="new_play_click ('Entanglement')" class="game-picbt"> - <img class="game-picimg" src="img/Entanglement.png" - alt="Entanglement Graph" /> - <span id="pdescEntanglement" class="game-picspan"> - <span class="game-pictxt">Entanglement</span> +<button onclick="new_play_click ('Hnefatafl')" class="game-picbt"> + <img class="game-picimg" src="img/Hnefatafl.png" + alt="Hnefatafl" /> + <span id="pdescHnefatafl" class="game-picspan"> + <span class="game-pictxt">Hnefatafl</span> </span> </button> </div> @@ -141,15 +142,36 @@ </button> </div> <div class="game-picdiv3"> +<button onclick="new_play_click ('Entanglement')" class="game-picbt"> + <img class="game-picimg" src="img/Entanglement.png" + alt="Entanglement Graph" /> + <span id="pdescEntanglement" class="game-picspan"> + <span class="game-pictxt">Entanglement</span> + </span> +</button> +</div> +</div> + +<div id="moregames2" class="game-line"> +<div class="game-picdiv1"> <button onclick="new_play_click ('Rewriting-Example')" class="game-picbt"> <img class="game-picimg" src="img/Rewriting-Example.png" alt="Rewriting-Example" /> - <span id="pdescExample" class="game-picspan"> + <span id="pdescRewriting-Example" class="game-picspan"> <span class="game-pictxt">Rewriting-Example</span> </span> </button> </div> +<div class="game-picdiv2"> +<button onclick="new_play_click ('Bounce')" class="game-picbt"> + <img class="game-picimg" src="img/Bounce.png" + alt="Bounce" /> + <span id="pdescBounce" class="game-picspan"> + <span class="game-pictxt">Bounce</span> + </span> +</button> </div> +</div> <ul id="welcome-list-main" class="welcome-list"> <li>Play @@ -288,7 +310,7 @@ two bishops, and eight pawns. Pieces move in different assigned ways according to their type, and accordingly are used to attack and capture the opponent's pieces. The object of the game is to checkmate - the opponent's king. + the opponent's king.</p> <p><b>Moves.</b> The moves differ by figure. Please consult the chess link above for a complete explanation with examples.</p> <ul> @@ -314,7 +336,8 @@ diagonally in front of it on an adjacent file, capturing that piece. The pawn has two special moves: the en passant capture and pawn promotion. In the first it captures another pawn which has just made a - two-field move, in the other one it becomes a queen in the last row.</p> + two-field move, in the other one it becomes a queen in the last + row.</li> </ul> <p><b>Objective.</b> When a king is under immediate attack by one or more of the opponent's @@ -399,6 +422,37 @@ respective marks in a horizontal, vertical, or diagonal row wins the game.</p> </div> + <div class="game-desc" id="Hnefatafl-desc"> + <p><a href="http://hem.bredband.net/b512479/">Hnefatafl</a> is a strategic + board game of the Vikings. There are many variations, but the most + popular modern one is played on an 11×11 grid.</p> + <p><b>Warning!</b> The game is incomplete and very slow for now!</p> + <p><b>Moves.</b> Players move on free straight lines, + vertical or horizontal.</p> + <p><b>Capturing Pawns.</b> All pieces except the king are captured if they + are sandwiched between two enemy pieces, or between an enemy piece and a + hostile square, along a column or a row. A piece is only captured if + the trap is closed by a move of the opponent, and it is thus allowed to + move in between two enemy pieces. The king may take part in captures.</p> + <p><b>Capturing the King</b> The king himself is captured like all other + pieces, except when he is standing on the throne or on one of the four + squares next to the throne. When the king is standing on the throne, + the attackers must surround him in all four cardinal points. When he is + on a square next to the throne, the attackers must occupy all surrounding + squares in the four points of the compass except the throne.</p> + <p><b>Objective.</b> The objective for the king's side is to move the king + to any of the four corner squares. In that case, the king has escaped + and his side wins. The attackers win if they can capture the king before + he escapes.</p> + </div> + <div class="game-desc" id="Rewriting-Example-desc"> + <p><b>Rewriting Example</b> is the basic example we use to illustrate + the way discrete structure rewriting works.</p> + </div> + <div class="game-desc" id="Bounce-desc"> + <p><b>Bounce</b> is the basic example we use to illustrate + the way continuous dynamics works with structure rewriting.</p> + </div> </div> <div id="bottom"> Modified: trunk/Toss/Solver/Structure.ml =================================================================== --- trunk/Toss/Solver/Structure.ml 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/Solver/Structure.ml 2012-05-06 22:17:46 UTC (rev 1701) @@ -347,7 +347,13 @@ let add_funs struc fn assgns = List.fold_left (fun s a -> add_fun s fn a) struc assgns +(* Change function [fn] assignment for element [e] to [x] in [struc]. *) +let change_fun struc fn elem x = + let assgs, e = StringMap.find fn struc.functions, elem_nbr struc elem in + let new_functions = StringMap.add fn (IntMap.add e x assgs) struc.functions in + { struc with functions = new_functions } + (* ------------ GLOBAL FUNCTIONS TO CREATE STRUCTURES FROM LISTS ------------ *) (** Map a function over an array threading an accumulator. *) Modified: trunk/Toss/Solver/Structure.mli =================================================================== --- trunk/Toss/Solver/Structure.mli 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/Solver/Structure.mli 2012-05-06 22:17:46 UTC (rev 1701) @@ -227,7 +227,10 @@ (** Add function assignments [assgns] to [fn] in structure [struc]. *) val add_funs : structure -> string -> (int * float) list -> structure +(** Change function [fn] assignment for element [e] to [x] in [struc]. *) +val change_fun : structure -> string -> string -> float -> structure + (** {2 Global function to create structures from lists} *) val create_from_lists : ?struc:structure -> string list -> Copied: trunk/Toss/examples/Bounce.toss (from rev 1700, trunk/Toss/examples/bounce.toss) =================================================================== --- trunk/Toss/examples/Bounce.toss (rev 0) +++ trunk/Toss/examples/Bounce.toss 2012-05-06 22:17:46 UTC (rev 1701) @@ -0,0 +1,25 @@ +PLAYERS 1, 2 +RULE Move: + [ e1 | Q(e1) | vx { e1->0. }; vy { e1->0. }; x { e1->-10. }; y { e1->-60. } ] + -> + [ e1 | Q(e1) | vx { e1->0. }; vy { e1->0. }; x { e1->-10. }; y { e1->-30. } ] + emb Q + dynamics + :vy(e1)' = 50.; + :vx(e1)' = 0.; + :y(e1)' = :vy(e1); + :x(e1)' = :vx(e1) + update + :vy(e1) = (-1.) * :vy(e1); + :vx(e1) = :vx(e1); + :y(e1) = :y(e1); + :x(e1) = :x(e1) + inv ex x ((_lhs_e1(x) and ((((:y(x) + (-1. * 0.)) + + (-1. * 0.)) + (-1. * 0.)) < 0))) +LOC 0 { + PLAYER 1 { PAYOFF 0. MOVES [Move, t: 3. -- 3. -> 0] } + PLAYER 2 { PAYOFF 0. } +} +START [ e1, e2, e3 | Q(e1); E { (e2, e3); (e3, e2) } | + vx { e1->0., e2->0., e3->0. }; vy { e1->27., e2->0., e3->0. }; + x { e1->-140., e2->-160., e3->-120. }; y { e1->-40., e2->3.5, e3->3.5 } ] Modified: trunk/Toss/examples/Hnefatafl.toss =================================================================== --- trunk/Toss/examples/Hnefatafl.toss 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/examples/Hnefatafl.toss 2012-05-06 22:17:46 UTC (rev 1701) @@ -1,4 +1,6 @@ PLAYERS 1, 2 +SET Sum (x | wP(x) : 1) +SET Sum (x | bP(x) : 1) REL w(x) = wP(x) or wK(x) REL FreeC (x, y) = tc x, y ((C(x, y) or C(y, x)) and not w(y) and not bP(y)) REL FreeR (x, y) = tc x, y ((R(x, y) or R(y, x)) and not w(y) and not bP(y)) @@ -17,14 +19,16 @@ emb wP, wK, bP, X, T pre Line(a, b) and not WinWhite () LOC 0 { PLAYER 1 { + COND 1; -1 PAYOFF :(WinWhite()) MOVES [WhitePawn -> 1]; [WhiteKing -> 1] } - PLAYER 2 { PAYOFF -1 * :(WinWhite()) } + PLAYER 2 { COND -1; 1 PAYOFF -1 * :(WinWhite()) } } LOC 1 { - PLAYER 1 { PAYOFF :(WinWhite()) } + PLAYER 1 { COND 1; -1 PAYOFF :(WinWhite()) } PLAYER 2 { + COND -1; 1 PAYOFF -1 * :(WinWhite()) MOVES [BlackPawn -> 0] } @@ -49,7 +53,7 @@ ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... - ... ... ... ... ... ... - ... ... bP. ... ... + ... ... ...bP ... ... ... + ... ... ... ... ... X ... bP.bP bP.bP bP. ...X " Deleted: trunk/Toss/examples/bounce.toss =================================================================== --- trunk/Toss/examples/bounce.toss 2012-05-05 21:58:06 UTC (rev 1700) +++ trunk/Toss/examples/bounce.toss 2012-05-06 22:17:46 UTC (rev 1701) @@ -1,26 +0,0 @@ -PLAYERS 1, 2 -RULE Move: - [ 1 | | vx { 1->0. }; vy { 1->0. }; x { 1->-11. }; y { 1->-60.5 } ] - -> - [ 1 | | vx { 1->0. }; vy { 1->0. }; x { 1->-14.3 }; y { 1->-34.1 } ] - dynamics - :vy(1)' = 50.; - :vx(1)' = 0.; - :y(1)' = :vy(1); - :x(1)' = :vx(1) - update - :vy(1) = (-1.) * :vy(1); - :vx(1) = :vx(1); - :y(1) = :y(1); - :x(1) = :x(1) - pre true - inv ex x ((_lhs_1(x) and ((((:y(x) + (-1. * 0.)) + - (-1. * 0.)) + (-1. * 0.)) < 0))) - post true -LOC 0 { - PLAYER 1 { PAYOFF 0. MOVES [Move, t: 3. -- 3. -> 0] } - PLAYER 2 { PAYOFF 0. } -} -START [ 1, 2, 3 | G { (2, 3); (3, 2) } | - vx { 1->0., 2->0., 3->0. }; vy { 1->27., 2->0., 3->0. }; - x { 1->-140., 2->-160., 3->-120. }; y { 1->-40.2673662018, 2->3.5, 3->3.5 } ] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |