Thread: [Toss-devel-svn] SF.net SVN: toss:[1222] trunk/Toss (Page 2)
Status: Beta
Brought to you by:
lukaszkaiser
From: <luk...@us...> - 2010-12-05 16:26:50
|
Revision: 1222 http://toss.svn.sourceforge.net/toss/?rev=1222&view=rev Author: lukaszkaiser Date: 2010-12-05 16:26:44 +0000 (Sun, 05 Dec 2010) Log Message: ----------- Corrected additional TNF memoisation in Solver. Modified Paths: -------------- trunk/Toss/Play/GameTest.ml trunk/Toss/Solver/Assignments.ml trunk/Toss/Solver/Solver.ml trunk/Toss/Solver/SolverTest.ml Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2010-12-05 02:28:02 UTC (rev 1221) +++ trunk/Toss/Play/GameTest.ml 2010-12-05 16:26:44 UTC (rev 1222) @@ -1093,14 +1093,14 @@ ); ] -let a = +let a () = Aux.run_test_if_target "GameTest" tests let a () = run_test_tt ~verbose:true experiments (* The same content as in .toss files. *) -let a () = +let a = print_endline ("\n" ^ Arena.sprint_state (snd gomoku19x19_game)) let a () = Modified: trunk/Toss/Solver/Assignments.ml =================================================================== --- trunk/Toss/Solver/Assignments.ml 2010-12-05 02:28:02 UTC (rev 1221) +++ trunk/Toss/Solver/Assignments.ml 2010-12-05 16:26:44 UTC (rev 1222) @@ -74,7 +74,9 @@ valuations of two formulas, it computes one for the conjunction. *) let rec join aset1 aset2 = let fo_map v f m = let r = map_snd f m in if r = [] then Empty else FO(v,r) in - let mso_map v f m = let r = map_snd f m in if r=[] then Empty else MSO(v,r) in + let mso_map v f m = + let r = small_simp (map_snd f m) in + if r=[] then Empty else MSO(v,r) in match (aset1, aset2) with (Empty, _) | (_, Empty) -> Empty | (Any, a) -> a Modified: trunk/Toss/Solver/Solver.ml =================================================================== --- trunk/Toss/Solver/Solver.ml 2010-12-05 02:28:02 UTC (rev 1221) +++ trunk/Toss/Solver/Solver.ml 2010-12-05 16:26:44 UTC (rev 1222) @@ -31,14 +31,14 @@ formulas_check = Hashtbl.create 3 ; } -let register_formula solver phi = +let register_formula_do solver phi = let rec check_form = function Ex (vs, phi) -> check_form phi | phi -> phi in try let res = Hashtbl.find solver.reg_formulas phi in if !debug_level > 0 then print_endline ("Found " ^ (str phi)); - res + (Hashtbl.find solver.formulas_eval res, res) with Not_found -> let psi = FormulaOps.tnf_fv phi in if !debug_level > 0 then print_endline ("Entered " ^ (str phi)); @@ -47,8 +47,25 @@ Hashtbl.add solver.reg_formulas phi id; Hashtbl.add solver.formulas_eval id psi; Hashtbl.add solver.formulas_check id (check_form psi); - id + (psi, id) +let register_formula solver phi = + try + let res = Hashtbl.find solver.reg_formulas phi in + if !debug_level > 0 then print_endline ("DirectFound " ^ (str phi)); + res + with Not_found -> + match Formula.flatten phi with + | And fl -> + let rfl = List.map (fun f -> fst (register_formula_do solver f)) fl in + let id = Hashtbl.length solver.formulas_eval + 1 in + let psi = Formula.flatten (Or (FormulaOps.to_dnf (And rfl))) in + Hashtbl.add solver.reg_formulas phi id; + Hashtbl.add solver.formulas_eval id psi; + Hashtbl.add solver.formulas_check id psi; + id + | _ -> let (_, id) = register_formula_do solver phi in id + let get_formula solver i = Hashtbl.find solver.formulas_eval i @@ -118,7 +135,7 @@ let asg_s = AssignmentSet.str aset in let form_s = Formula.str (Ex (vl, phi)) in let msg_s = "solver: multiple vars?\n "^ asg_s ^ "\n "^ form_s in - failwith msg_s (* Any *) + (* failwith msg_s *) Any else aset in let phi_asgn = eval model elems in_aset phi in report (join aset (project_list elems phi_asgn vl)) @@ -129,7 +146,7 @@ let asg_s = AssignmentSet.str aset in let form_s = Formula.str (Ex (vl, phi)) in let msg_s = "solver: multiple vars?\n "^ asg_s ^ "\n "^ form_s in - failwith msg_s (* Any *) + (* failwith msg_s *) Any else aset in let phi_asgn = eval model elems in_aset phi in report (join aset (universal_list elems phi_asgn vl)) @@ -256,7 +273,7 @@ let phi_id = Hashtbl.find solver.reg_formulas phi in Hashtbl.find solver.formulas_eval phi_id with Not_found -> - Hashtbl.find solver.formulas_eval (register_formula solver phi) in + Hashtbl.find solver.formulas_eval (snd(register_formula_do solver phi)) in let eval_no_fv phi = if FormulaOps.free_vars phi = [] then ( if !debug_level > 1 then Modified: trunk/Toss/Solver/SolverTest.ml =================================================================== --- trunk/Toss/Solver/SolverTest.ml 2010-12-05 02:28:02 UTC (rev 1221) +++ trunk/Toss/Solver/SolverTest.ml 2010-12-05 16:26:44 UTC (rev 1222) @@ -156,7 +156,7 @@ ... wB. \"" diag_phi "{ y->3{ x->3 } , y->6{ x->3 } , y->8{ x->3 } , y->9{ x->3 } }"; - eval_eq "[ | | ] \" +(* eval_eq "[ | | ] \" ... ... ... ... ... ... ... ... ... @@ -171,7 +171,7 @@ ... wB. ... \"" diag_phi ("{ y->3{ x->3 } , y->8{ x->3 } , y->10{ x->3 } ," ^ - " y->13{ x->3 } , y->17{ x->3 } , y->24{ x->3 } }"); + " y->13{ x->3 } , y->17{ x->3 } , y->24{ x->3 } }"); *) ); "eval: with real values" >:: @@ -185,7 +185,7 @@ "{ x->3 }"; eval_eq "[ | R { (a, a); (a, b) } | ] " ":(all y (R (x, y))) > 0" "{ x->1 }"; - ); + ); "eval: game heuristic tests" >:: (fun () -> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-05 19:01:18
|
Revision: 1223 http://toss.svn.sourceforge.net/toss/?rev=1223&view=rev Author: lukaszkaiser Date: 2010-12-05 19:01:10 +0000 (Sun, 05 Dec 2010) Log Message: ----------- Diagonals defined directly in model in chess. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/Arena.mli trunk/Toss/Arena/ArenaParser.mly trunk/Toss/WebClient/TossMain.js trunk/Toss/WebClient/TossStyle.css trunk/Toss/WebClient/index.html trunk/Toss/examples/Chess.toss Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2010-12-05 16:26:44 UTC (rev 1222) +++ trunk/Toss/Arena/Arena.ml 2010-12-05 19:01:10 UTC (rev 1223) @@ -67,6 +67,19 @@ (* -------------------- PARSER HELPER ------------------------------ *) +(* Add a defined relation to a structure. *) +let add_def_rel_single struc (r_name, vars, def_phi) = + let def_asg = SolverIntf.M.evaluate struc + (SolverIntf.M.register_formula def_phi) in + match def_asg with + | AssignmentSet.Empty -> + Structure.add_rel_name r_name (List.length vars) struc + | _ -> + let tuples = AssignmentSet.tuples struc.Structure.elements 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 + (* The order of following entries matters: [DefPlayers] adds more players, with consecutive numbers starting from first available; later [StateStruc], [StateTime] and [StateLoc] entries override Modified: trunk/Toss/Arena/Arena.mli =================================================================== --- trunk/Toss/Arena/Arena.mli 2010-12-05 16:26:44 UTC (rev 1222) +++ trunk/Toss/Arena/Arena.mli 2010-12-05 19:01:10 UTC (rev 1223) @@ -43,6 +43,10 @@ val empty_state : game_state +val add_def_rels : Structure.structure -> + (string * string list * Formula.formula) list -> Structure.structure + + (* ------------------------ PRINTING FUNCTIONS ------------------------------ *) (* Print a label as a string. *) Modified: trunk/Toss/Arena/ArenaParser.mly =================================================================== --- trunk/Toss/Arena/ArenaParser.mly 2010-12-05 16:26:44 UTC (rev 1222) +++ trunk/Toss/Arena/ArenaParser.mly 2010-12-05 19:01:10 UTC (rev 1223) @@ -76,6 +76,9 @@ "Syntax error in location definition." } +rel_def_simple: + | rel = ID args = delimited (OPEN, separated_list (COMMA, ID), CLOSE) + EQ body = formula_expr { (rel, args, body) } game_defs: | RULE_SPEC rname = id_int COLON r = rule_expr @@ -95,6 +98,9 @@ { DefRel (rel, arg, body) } | MODEL_SPEC model = struct_expr { StateStruc model } + | MODEL_SPEC model = struct_expr WITH + defs = separated_list (SEMICOLON, rel_def_simple) + { StateStruc (Arena.add_def_rels model defs) } | TIME_MOD t = FLOAT { StateTime t } | STATE_SPEC LOC_MOD i = INT Modified: trunk/Toss/WebClient/TossMain.js =================================================================== --- trunk/Toss/WebClient/TossMain.js 2010-12-05 16:26:44 UTC (rev 1222) +++ trunk/Toss/WebClient/TossMain.js 2010-12-05 19:01:10 UTC (rev 1223) @@ -202,7 +202,9 @@ } else { create_svg_box ("19em", "19em", 40, 40, "board"); } + document.getElementById("opening").style.display = "block"; toss_open (GAMES_DIR + game + ".toss"); + document.getElementById("opening").style.display = "none"; list_plays (game); document.getElementById("game-disp").style.display = "block"; } Modified: trunk/Toss/WebClient/TossStyle.css =================================================================== --- trunk/Toss/WebClient/TossStyle.css 2010-12-05 16:26:44 UTC (rev 1222) +++ trunk/Toss/WebClient/TossStyle.css 2010-12-05 19:01:10 UTC (rev 1223) @@ -279,6 +279,19 @@ padding: 1em; } +#opening { + position: absolute; + left: 10em; + top: 7em; + width: 16em; + text-align: center; + font-weight: bold; + color: #ffe4aa; + background-color: #400827; + display: none; + padding: 1em; +} + #move { position: absolute; left: 0px; Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2010-12-05 16:26:44 UTC (rev 1222) +++ trunk/Toss/WebClient/index.html 2010-12-05 19:01:10 UTC (rev 1223) @@ -94,6 +94,8 @@ <div id="game-title"></div> +<div id="opening" style="display: none;">Opening may take some time ...</div> + <div id="game-disp"> <div id="game-desc" class="hyphenate"> <div id="Breakthrough-desc" style="display: none;"> Modified: trunk/Toss/examples/Chess.toss =================================================================== --- trunk/Toss/examples/Chess.toss 2010-12-05 16:26:44 UTC (rev 1222) +++ trunk/Toss/examples/Chess.toss 2010-12-05 19:01:10 UTC (rev 1223) @@ -10,8 +10,6 @@ REL KnightRCC(x, y) = ex z ((R(x, z) or R(z, x)) and DoubleC(z, y)) REL KnightCRR(x, y) = ex z ((C(x, z) or C(z, x)) and DoubleR(z, y)) REL Knight(x, y) = KnightRCC(x, y) or KnightCRR(x, y) -REL D1(x, y) = ex z ( (R(x, z) and C(z, y)) or (R(y, z) and C(z, x)) ) -REL D2(x, y) = ex z ( (R(x, z) and C(y, z)) or (R(y, z) and C(x, z)) ) REL FreeD1 (x, y) = tc 6 x, y (D1 (x, y) and not w(y) and not b(y)) REL FreeD2 (x, y) = tc 6 x, y (D2 (x, y) and not w(y) and not b(y)) REL Diag1 (x, y) = ex z (FreeD1 (x, z) and (z = y or D1 (z, y))) @@ -355,4 +353,6 @@ wP wP.wP wP.wP wP.wP wP. ... ... ... ... wR.wN wB.wQ wK.wB wN.wR -" +" with +D1(x, y) = ex z ( (R(x, z) and C(z, y)) or (R(y, z) and C(z, x)) ) ; +D2(x, y) = ex z ( (R(x, z) and C(y, z)) or (R(y, z) and C(x, z)) ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-05 21:51:56
|
Revision: 1225 http://toss.svn.sourceforge.net/toss/?rev=1225&view=rev Author: lukstafi Date: 2010-12-05 21:51:48 +0000 (Sun, 05 Dec 2010) Log Message: ----------- Better rule parsing error messages. More diagnostic logging. Small board handling fix (one pending). Endline comments syntax C++ style. Signature-related fixes in DiscreteRule. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/Arena.mli trunk/Toss/Arena/ArenaParser.mly trunk/Toss/Arena/ContinuousRule.ml trunk/Toss/Arena/ContinuousRuleParser.mly trunk/Toss/Arena/DiscreteRule.ml trunk/Toss/Arena/DiscreteRule.mli trunk/Toss/Formula/FFTNF.ml trunk/Toss/Formula/Lexer.mll trunk/Toss/Play/Game.ml trunk/Toss/Play/GameTest.ml trunk/Toss/Play/Heuristic.ml trunk/Toss/Solver/Structure.ml trunk/Toss/Solver/Structure.mli trunk/Toss/examples/Chess.toss Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Arena/Arena.ml 2010-12-05 21:51:48 UTC (rev 1225) @@ -1,5 +1,7 @@ (* Represent the game arena and operate on it. *) +let debug_level = ref 0 + (* The label's time interval defaults to this point. *) let cDEFAULT_TIMESTEP = 0.1 @@ -88,8 +90,10 @@ default location is 0, default time is 0.0, default data is empty. *) type definition = - | DefRule of string * ((string * int) list -> - (string * (string list * Formula.formula)) list -> ContinuousRule.rule) + | DefRule of string * ( + (string * int) list -> + (string * (string list * Formula.formula)) list -> string -> + ContinuousRule.rule) (* add a rule *) | DefLoc of ((string * int) list -> location) (* add location to graph *) @@ -145,6 +149,8 @@ payoffs = payoffs; payoffs_pp = payoffs_pp; moves = moves } +open Printf + (* Create a game state, possibly by extending an old state, from a list of definitions (usually corresponding to a ".toss" file.) *) let process_definition ?extend_state defs = @@ -161,37 +167,50 @@ state.game.defined_rels, state.struc, state.time, state.cur_loc, state.data in + (* {{{ log entry *) + if !debug_level > 2 then ( + printf "process_definition: %d old rules, %d old locs\n%!" + (List.length old_rules) (List.length old_locs); + ); + (* }}} *) let rules, locations, players, defined_rels, state, time, cur_loc, data = - List.fold_left (fun (rules, locations, players, defined_rels, - state, time, cur_loc, data) -> function - | DefRule (rname, r) -> - ((rname, r)::rules, locations, players, defined_rels, - state, time, cur_loc, data) - | DefLoc loc -> - (rules, loc::locations, players, defined_rels, - state, time, cur_loc, data) - | DefPlayers more_players -> - (rules, locations, players @ more_players, defined_rels, - state, time, cur_loc, data) - | DefRel (rel, args, body) -> - (rules, locations, players, - (rel, args, body)::defined_rels, - state, time, cur_loc, data) - | StateStruc struc -> - (rules, locations, players, defined_rels, - struc, time, cur_loc, data) - | StateTime ntime -> - (rules, locations, players, defined_rels, - state, ntime, cur_loc, data) - | StateLoc ncur_loc -> - (rules, locations, players, defined_rels, - state, time, ncur_loc, data) - | StateData more_data -> - (rules, locations, players, defined_rels, - state, time, cur_loc, data @ more_data) - ) ([], [], players, defined_rels, - state, time, cur_loc, data) defs in + List.fold_right (fun def (rules, locations, players, defined_rels, + state, time, cur_loc, data) -> + match def with + | DefRule (rname, r) -> + ((rname, r)::rules, locations, players, defined_rels, + state, time, cur_loc, data) + | DefLoc loc -> + (rules, loc::locations, players, defined_rels, + state, time, cur_loc, data) + | DefPlayers more_players -> + (rules, locations, players @ more_players, defined_rels, + state, time, cur_loc, data) + | DefRel (rel, args, body) -> + (rules, locations, players, + (rel, args, body)::defined_rels, + state, time, cur_loc, data) + | StateStruc struc -> + (rules, locations, players, defined_rels, + struc, time, cur_loc, data) + | StateTime ntime -> + (rules, locations, players, defined_rels, + state, ntime, cur_loc, data) + | StateLoc ncur_loc -> + (rules, locations, players, defined_rels, + state, time, ncur_loc, data) + | StateData more_data -> + (rules, locations, players, defined_rels, + state, time, cur_loc, data @ more_data) + ) defs ([], [], players, defined_rels, + state, time, cur_loc, data) in + (* {{{ log entry *) + if !debug_level > 2 then ( + printf "process_definition: %d new rules, %d defined rels\n%!" + (List.length rules) (List.length defined_rels); + ); + (* }}} *) let def_rels_pure = List.map (fun (rel, args, body) -> (rel, (args, body))) defined_rels in let defined_rels = @@ -204,9 +223,19 @@ let num_players = List.length player_names in let signature = Structure.StringMap.fold (fun rel ar si -> (rel, ar)::si) state.Structure.rel_signature [] in + (* {{{ log entry *) + if !debug_level > 2 then ( + printf "process_definition: parsing new rules...%!"; + ); + (* }}} *) let rules = old_rules @ List.map (fun (name, r) -> - name, r signature def_rels_pure) rules in + name, r signature def_rels_pure name) rules in + (* {{{ log entry *) + if !debug_level > 2 then ( + printf " parsed\n%!"; + ); + (* }}} *) let rules = List.sort (fun (rn1,_) (rn2,_)->String.compare rn1 rn2) rules in let updated_locs = @@ -228,8 +257,18 @@ let reg_ps = Array.map SolverIntf.M.register_real_expr ps in { loc with payoffs = ps; payoffs_pp = reg_ps } in + (* {{{ log entry *) + if !debug_level > 2 then ( + printf "process_definition: parsing locations (registering payoffs)...%!"; + ); + (* }}} *) let locations = updated_locs @ List.map (fun loc -> add_def_rel (loc player_names)) locations in + (* {{{ log entry *) + if !debug_level > 2 then ( + printf " parsed\n%!"; + ); + (* }}} *) let graph = try Aux.array_from_assoc @@ -313,11 +352,11 @@ if !equational_def_style then Format.fprintf ppf "@[<1>REL@ %s@,(@[<1>%a@])@ =@ @[<1>%a@]" drel (Aux.fprint_sep_list "," Format.pp_print_string) args - (Formula.fprint(* _nobra 0 *)) body + Formula.fprint body else Format.fprintf ppf "@[<1>REL@ %s@,(@[<1>%a@])@ {@,@[<1>%a@,@]}" drel (Aux.fprint_sep_list "," Format.pp_print_string) args - (Formula.fprint(* _nobra 0 *)) body; + Formula.fprint body; Format.fprintf ppf "@]@ "; ) defined_rels; Format.fprintf ppf "@[<1>PLAYERS@ %a@]@ " @@ -408,7 +447,8 @@ | EvalRealExpr of Formula.real_expr (* Evaluate real expr *) | SetRule of string * ((string * int) list -> - (string * (string list * Formula.formula)) list -> ContinuousRule.rule) + (string * (string list * Formula.formula)) list -> string -> + ContinuousRule.rule) (* Set a rule as given *) | GetRule of string (* Get a rule as string *) | SetRuleUpd of string*string *string *Term.term (* Set a rule update eq *) @@ -681,7 +721,7 @@ (fun (drel, (args, body, _)) -> drel,(args,body)) state.game.defined_rels in let new_rules = - Aux.replace_assoc r_name (r signat defs) + Aux.replace_assoc r_name (r signat defs r_name) state.game.rules in ({ state with game = {state.game with rules=new_rules} }, "SET RULE") with Modified: trunk/Toss/Arena/Arena.mli =================================================================== --- trunk/Toss/Arena/Arena.mli 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Arena/Arena.mli 2010-12-05 21:51:48 UTC (rev 1225) @@ -1,5 +1,7 @@ (* Represent the game arena and operate on it. *) +val debug_level : int ref + (* ------------------------ BASIC TYPE DEFINITIONS -------------------------- *) (* A single move consists of applying a rewrite rule for a time from the @@ -76,8 +78,10 @@ default location is 0, default time is 0.0, default data is empty. *) type definition = - | DefRule of string * ((string * int) list -> - (string * (string list * Formula.formula)) list -> ContinuousRule.rule) + | DefRule of string * ( + (string * int) list -> + (string * (string list * Formula.formula)) list -> string -> + ContinuousRule.rule) (* add a rule *) | DefLoc of ((string * int) list -> location) (* add location to graph *) @@ -155,7 +159,8 @@ | EvalRealExpr of Formula.real_expr (* Evaluate real expr *) | SetRule of string * ((string * int) list -> - (string * (string list * Formula.formula)) list -> ContinuousRule.rule) + (string * (string list * Formula.formula)) list -> string -> + ContinuousRule.rule) (* Set a rule as given *) | GetRule of string (* Get a rule as string *) | SetRuleUpd of string*string *string *Term.term (* Set a rule update eq *) Modified: trunk/Toss/Arena/ArenaParser.mly =================================================================== --- trunk/Toss/Arena/ArenaParser.mly 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Arena/ArenaParser.mly 2010-12-05 21:51:48 UTC (rev 1225) @@ -94,7 +94,7 @@ | REL_MOD rel = ID arg = delimited (OPEN, separated_list (COMMA, ID), CLOSE) EQ - body = formula_expr %prec COND + body = formula_expr { DefRel (rel, arg, body) } | MODEL_SPEC model = struct_expr { StateStruc model } Modified: trunk/Toss/Arena/ContinuousRule.ml =================================================================== --- trunk/Toss/Arena/ContinuousRule.ml 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Arena/ContinuousRule.ml 2010-12-05 21:51:48 UTC (rev 1225) @@ -32,7 +32,7 @@ let discrete = { discr with DiscreteRule.pre = cpre } in let defrels = List.map (fun (rel,(args,body)) -> rel, (args, body, SolverIntf.M.register_formula body)) defs in - let obj = DiscreteRule.compile_rule signat defrels discrete in + let obj = DiscreteRule.compile_rule signat defrels discr in { discrete = discrete; compiled = obj ; dynamics = dynamics ; Modified: trunk/Toss/Arena/ContinuousRuleParser.mly =================================================================== --- trunk/Toss/Arena/ContinuousRuleParser.mly 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Arena/ContinuousRuleParser.mly 2010-12-05 21:51:48 UTC (rev 1225) @@ -8,7 +8,7 @@ %start parse_rule %type < (string * int) list -> - (string * (string list * Formula.formula)) list -> + (string * (string list * Formula.formula)) list -> string -> ContinuousRule.rule> parse_rule rule_expr @@ -22,10 +22,15 @@ pre = option (preceded (PRE, formula_expr)) inv = option (preceded (INV, formula_expr)) post = option (preceded (POST, formula_expr)) - { fun signat defs -> + { fun signat defs rname -> (* no need to bother passing [pre] to [discr] *) - ContinuousRule.make_rule signat defs (discr signat (And [])) - dyn upd ?pre ?inv ?post () } + try + ContinuousRule.make_rule signat defs (discr signat (And [])) + dyn upd ?pre ?inv ?post () + with Failure s -> + report_parsing_error $startpos $endpos + ("Error in rule "^rname^": "^s) + } parse_rule: rule_expr EOF { $1 }; Modified: trunk/Toss/Arena/DiscreteRule.ml =================================================================== --- trunk/Toss/Arena/DiscreteRule.ml 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Arena/DiscreteRule.ml 2010-12-05 21:51:48 UTC (rev 1225) @@ -1,5 +1,7 @@ (* Discrete structure rewriting. *) +let debug_level = ref 0 + type matching = (int * int) list type matchings = Assignments.assignment_set @@ -123,8 +125,7 @@ r, negative_trace rel r.lhs_form, args_l) rel_prods) in let precond = match disjs with - | [] -> raise (Invalid_argument - ("fluent_preconds: not a fluent: "^rel)) + | [] -> failwith ("fluent_preconds: not a fluent: "^rel) | [phi] -> phi | _ -> Formula.Or disjs in rel, (nu_args, precond) in @@ -553,6 +554,12 @@ embedding condition). *) let compile_rule signat defined_rels rule_src = + (* TODO: but these shouldn't get into the signature in the first + place... See also [rhs_rels] -- empty defined relations appear in + RHS structure. *) + let signat = List.filter (fun (rel,_) -> + special_rel_of rel = None && + not (List.mem_assoc rel defined_rels)) signat in let expand_def_rels rel = if List.mem_assoc rel defined_rels then let args, _, rphi = List.assoc rel defined_rels in @@ -594,7 +601,13 @@ (* expand defined rels in embedding list *) let base_emb_rels = unique (=) (concat_map expand_def_rels rule_src.emb_rels) in - + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf "compile_rule: emb=%s -- base_emb_rels=%s\n%!" + (String.concat ", " rule_src.emb_rels) + (String.concat ", " base_emb_rels); + ); + (* }}} *) let tups_union ts1 ts2 = Aux.unique (=) (ts1 @ ts2) and tups_empty = [] and tups_diff ts1 ts2 = @@ -763,13 +776,19 @@ (* RHS *) let rhs_rels = SSMap.fold (fun rel tups rels -> - (rel, STups.elements tups) :: rels) + if STups.is_empty tups then rels + else (rel, STups.elements tups) :: rels) rule_src.rhs_struc.Structure.relations [] in let rhs_opt_rels, rhs_rels, _ = compile_opt_rels rhs_rels in if List.exists (fun (drel, _) -> List.mem_assoc drel rhs_rels) defined_rels - then failwith "Non-optional defined relation on RHS."; + then failwith + ("Non-optional defined relation(s) "^ + String.concat ", " (Aux.map_some (fun (drel,_) -> + if List.mem_assoc drel rhs_rels then Some drel else None) + defined_rels) + ^" on RHS."); (* if the rule is optimized for "nonstructural" rewriting, elements are already renamed; raises Not_found when adding elements *) let mapf_rn = if rlmap = None then fun x->x else @@ -934,20 +953,21 @@ let build_rule_s ?rule_s lhs rhs = let l_elem le = try Structure.find_elem lhs le - with Not_found -> raise (Invalid_argument ( - "\"with\" clause element "^le^" not found in LHS.")) in + with Not_found -> failwith + ("\"with\" clause element "^le^" not found in LHS.") in let r_elem re = try Structure.find_elem rhs re - with Not_found -> raise (Invalid_argument ( - "\"with\" clause element "^re^" not found in RHS.")) in + with Not_found -> failwith + ("\"with\" clause element "^re^" not found in RHS.") in let r_str re = Structure.elem_str rhs re in match rule_s with | None -> - if Structure.Elems.cardinal lhs.Structure.elements <> - Structure.Elems.cardinal rhs.Structure.elements - then raise (Invalid_argument - ("\"with\" clause not given but LHS and RHS "^ - "structures have different size")) + let lnum = Structure.Elems.cardinal lhs.Structure.elements in + let rnum = Structure.Elems.cardinal rhs.Structure.elements 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 [] Modified: trunk/Toss/Arena/DiscreteRule.mli =================================================================== --- trunk/Toss/Arena/DiscreteRule.mli 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Arena/DiscreteRule.mli 2010-12-05 21:51:48 UTC (rev 1225) @@ -1,5 +1,7 @@ (* Discrete Structure Rewriting Rules and Rewriting. *) +val debug_level : int ref + (* Single match of a rule, and a set of matches. *) type matching = (int * int) list type matchings = Assignments.assignment_set Modified: trunk/Toss/Formula/FFTNF.ml =================================================================== --- trunk/Toss/Formula/FFTNF.ml 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Formula/FFTNF.ml 2010-12-05 21:51:48 UTC (rev 1225) @@ -441,11 +441,11 @@ let location_str loc = sprintf "%s#[%s]" - (Formula.str (unpack_flat ( + (Formula.sprint (unpack_flat ( formula_of_tree (zip_nonflat {loc with n={ fvs=Vars.empty; t=TProc (-1,Rel("[HOLE]",[||]))}})))) - (Formula.str (unpack_flat (formula_of_tree loc.n))) + (Formula.sprint (unpack_flat (formula_of_tree loc.n))) (* Flatten and convert to a formula. *) (* While translating, also simplify constant truth values. *) @@ -618,7 +618,7 @@ | {t=TNot_subtask subt} -> Left subt, {loc with n={fvs=Vars.empty; t=TAnd[]}} | {fvs=lit_vs; t=TLit lit} -> - let _ = if !debug_level > 3 then + let _ = if !debug_level > 4 then printf "find_unprot: processing literal %s, loc %s\n" (Formula.str lit) (location_str loc) in let best_loc = (* store if first *) @@ -631,7 +631,7 @@ best_loc | _ -> let _ = if !debug_level > 3 then begin - printf "find_unprot: selecting it\n" end in + printf "find_unprot: selecting %s\n" (Formula.str lit) end in Some ((lit,lit_vs), {loc with n={fvs=Vars.empty; t=TAnd[]}}) in advance best_loc @@ -661,7 +661,7 @@ (* The rewriting steps. Uses a callback to process subtasks recursively before putting them in their final locations. *) let rec pull_out subproc (task_id, task_lit as task) loc = - let _ = if !debug_level > 2 then + let _ = if !debug_level > 4 then printf "\npull-out_step_location: %s\n" (location_str loc) in let lit_vs, put_result = match task_lit with @@ -878,19 +878,19 @@ let _ = if !debug_level > 2 then begin printf "\nfound_subtask-literal: %s\n" (match subt_lit with - | Left subt -> Formula.str (Not subt) + | Left subt -> Formula.sprint (Not subt) | Right (lit,_) -> Formula.str lit); printf "location: %s\n" (location_str loc) end in let phi = pull_out subproc (i, subt_lit) loc in if !debug_level > 2 then printf "\npull-out_result: %s\n" - (Formula.str (formula_of_tree phi)); + (Formula.sprint (formula_of_tree phi)); loop (i+1) {x=Top; n=phi} with Lit_not_found -> let result = zip loc in let _ = if !debug_level > 2 then begin printf "\nff_tnf-result: %s\n" - (Formula.str (formula_of_tree result)) end in + (Formula.sprint (formula_of_tree result)) end in result and subproc subt = @@ -903,10 +903,10 @@ let res = loop 0 loc in if !debug_level > 1 then - printf "ff_tnf: res=%s\n%!" (Formula.str (formula_of_tree res)); + printf "ff_tnf: res=%s\n%!" (Formula.sprint (formula_of_tree res)); let flat = flatten_tree_to_formula res in if !debug_level > 1 then - printf "ff_tnf: flat=%s\n%!" (Formula.str flat); + printf "ff_tnf: flat=%s\n%!" (Formula.sprint flat); flat Modified: trunk/Toss/Formula/Lexer.mll =================================================================== --- trunk/Toss/Formula/Lexer.mll 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Formula/Lexer.mll 2010-12-05 21:51:48 UTC (rev 1225) @@ -95,6 +95,19 @@ pos_bol = pos.Lexing.pos_cnum; } +let move_lines_by lexbuf s = + let nbrk = ref 0 in + for i = 0 to String.length s - 1 do + if s.[i] = '\n' then incr nbrk + done; + if !nbrk > 0 then + let pos = lexbuf.Lexing.lex_curr_p in + lexbuf.Lexing.lex_curr_p <- { pos with + Lexing.pos_lnum = pos.Lexing.pos_lnum + !nbrk; + pos_bol = pos.Lexing.pos_cnum; + } + + (* Parsing errors are about both syntax and semantics. *) exception Parsing_error of string @@ -195,16 +208,17 @@ | "STATE" { STATE_SPEC } | "LEFT" { LEFT_SPEC } | "RIGHT" { RIGHT_SPEC } - | ['0'-'9']+ as n { INT (int_of_string n) } - | '-' ['0'-'9']+ as n { INT (int_of_string n) } - | ['0'-'9']* '.' ['0'-'9']+ as x { FLOAT (float_of_string x) } - | ['0'-'9']+ '.' ['0'-'9']* as x { FLOAT (float_of_string x) } + | ['0'-'9']+ as n { INT (int_of_string n) } + | '-' ['0'-'9']+ as n { INT (int_of_string n) } + | ['0'-'9']* '.' ['0'-'9']+ as x { FLOAT (float_of_string x) } + | ['0'-'9']+ '.' ['0'-'9']* as x { FLOAT (float_of_string x) } | '-' ['0'-'9']* '.' ['0'-'9']+ as x { FLOAT (float_of_string x) } | '-' ['0'-'9']+ '.' ['0'-'9']* as x { FLOAT (float_of_string x) } | ['A'-'Z' 'a'-'z' '_']['0'-'9' 'A'-'Z' 'a'-'z' '_']* as s { ID (s) } | '"'(['0'-'9' 'A'-'Z' 'a'-'z' ' ' '.' '_' '\t' '\n' '*' '+' '-' '?' '#']+ - as s)'"' { BOARD_STRING (s) } + as s)'"' { move_lines_by lexbuf s; BOARD_STRING (s) } | '#' (['0'-'9' 'A'-'Z' 'a'-'z' ' ' '.' ':' '_' '\t' '*' '+' '-' '?' '/' '\\']+ - as s) '#' { reset_as_file lexbuf s; lex lexbuf } + as s) '#' { reset_as_file lexbuf s; lex lexbuf } + | "//" [^ '\n']* '\n' { incr_lineno lexbuf; lex lexbuf } | eof { EOF } Modified: trunk/Toss/Play/Game.ml =================================================================== --- trunk/Toss/Play/Game.ml 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Play/Game.ml 2010-12-05 21:51:48 UTC (rev 1225) @@ -249,10 +249,12 @@ Array.map (fun node -> Array.map (fun payoff -> (* {{{ log entry *) + if !debug_level > 3 then ( Printf.printf "default_hauristic: Computing of payoff %s...\n%!" - (Formula.real_str payoff); + (Formula.sprint_real payoff); ); + (* }}} *) Heuristic.of_payoff ?struc ?fluent_preconds advance_ratio (Aux.strings_of_list fluents) payoff) Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Play/GameTest.ml 2010-12-05 21:51:48 UTC (rev 1225) @@ -72,7 +72,7 @@ *) let emb_rels = Structure.StringMap.fold (fun rel arity acc -> - if arity = 1 && not (DiscreteRule.special_rel_of rel = Some "opt") + if arity = 1 && DiscreteRule.special_rel_of rel = None then rel::acc else acc) lhs_struc.Structure.rel_signature [] in let pre = formula_of_str precond in @@ -565,11 +565,11 @@ "play: chess suggest first move" >:: (fun () -> - todo "Payoff too difficult for heuristic generation."; + (* todo "Payoff too difficult for heuristic generation."; *) let state = chess_game in Game.set_debug_level 7; Heuristic.debug_level := 7; - FFTNF.debug_level := 7; + FFTNF.debug_level := 4; let move_opt = (let p,ps = Game.initialize_default (snd state) ~heur_adv_ratio:(fst state) ~loc:0 ~effort:2 @@ -1101,7 +1101,7 @@ (* The same content as in .toss files. *) let a = - print_endline ("\n" ^ Arena.sprint_state (snd gomoku19x19_game)) + print_endline ("\n" ^ Arena.sprint_state (snd chess_game)) let a () = Game.set_debug_level 7 Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Play/Heuristic.ml 2010-12-05 21:51:48 UTC (rev 1225) @@ -592,7 +592,7 @@ let substs = trunc_to_vars vars substs in if !debug_level > 2 then ( printf "expanded_descritpion: phi=%s; aset=%s\nsubsts=%s\n%!" - (Formula.str phi) + (Formula.sprint phi) (AssignmentSet.str aset) (String.concat "; " (List.map (fun sb->String.concat ", " @@ -628,7 +628,7 @@ if !debug_level > 3 then ( Printf.printf "Heuristic: computing expanded description for %s...\n%!" - (Formula.str phi) + (Formula.sprint phi) ); (* }}} *) let substs = @@ -818,7 +818,7 @@ if !debug_level > 2 then ( Printf.printf "Heuristic: for expanding, get ff-tnf of %s...\n%!" - (Formula.str phi); + (Formula.sprint phi); ); (* }}} *) let phi'' = @@ -827,7 +827,7 @@ if !debug_level > 2 then ( Printf.printf "Heuristic: computing expanded form of %s...\n%!" - (Formula.str phi''); + (Formula.sprint phi''); ); (* }}} *) expanded_form max_alt_descr frels struc phi'' @@ -836,7 +836,7 @@ if !debug_level > 2 then ( Printf.printf "Heuristic: computing for (expanded) formula %s...\n%!" - (Formula.str phi') + (Formula.sprint phi') ); (* }}} *) of_formula adv_ratio @@ -847,7 +847,7 @@ if !debug_level > 2 then ( Printf.printf "Heuristic: computing monotonic for %s...\n%!" - (Formula.str phi); + (Formula.sprint phi); ); (* }}} *) (* FIXME: shouldn't be expanding? *) Modified: trunk/Toss/Solver/Structure.ml =================================================================== --- trunk/Toss/Solver/Structure.ml 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Solver/Structure.ml 2010-12-05 21:51:48 UTC (rev 1225) @@ -4,6 +4,8 @@ let cBOARD_DX = 15.0 let cBOARD_DY = -15.0 +let debug_level = ref 0 + (* ------------------------- TYPE DEFINITIONS -------------------------- *) module IntMap = Map.Make (* Maps from int to 'alpha *) @@ -141,6 +143,9 @@ if Elems.mem e struc.elements then e else raise Not_found +(* Add an element by name, return the updated structure and the + element. Search for an element with the given name in the + structure, and if not found, add new element with this name. *) let find_or_new_elem struc name = if StringMap.mem name struc.names then struc, StringMap.find name struc.names @@ -564,52 +569,61 @@ (* Ignore special relations. *) let find_unique all_preds = + (* FIXME: don't force prefix-free *) let all_preds = List.filter (fun r -> r.[0] <> '_') all_preds in (* build a fixed depth trie *) - let trie1 = List.fold_left (fun trie rel -> - if List.mem_assoc rel.[0] trie then - let rels, trie = Aux.pop_assoc rel.[0] trie in - (rel.[0], rel::rels)::trie - else (rel.[0], [rel])::trie + let trie1 = List.fold_left (fun trie pred -> + if List.mem_assoc pred.[0] trie then + let preds, trie = Aux.pop_assoc pred.[0] trie in + (pred.[0], pred::preds)::trie + else (pred.[0], [pred])::trie ) [] all_preds in + let trie1 = List.map (fun (k,preds) -> + let trunc = + List.filter (fun r -> String.length r = 1) preds in + if trunc = [] then k, preds else k, trunc) trie1 in let uniq1, trie1 = Aux.partition_map - (function (k,[rel]) -> Aux.Left (rel, Char.escaped k) + (function (k,[pred]) -> Aux.Left (pred, Char.escaped k) | subt -> Aux.Right subt) trie1 in let trie1 = List.map - (fun (k, rels) -> k, List.filter - (fun rel -> String.length rel > 1) rels) trie1 in + (fun (k, preds) -> k, List.filter + (fun pred -> String.length pred > 1) preds) trie1 in let trie2 = Aux.concat_map (fun (key, preds) -> let trie2 = - List.fold_left (fun trie rel -> - if List.mem_assoc rel.[1] trie then - let rels, trie = Aux.pop_assoc rel.[1] trie in - (rel.[1], rel::rels)::trie - else (rel.[1], [rel])::trie + List.fold_left (fun trie pred -> + if List.mem_assoc pred.[1] trie then + let preds, trie = Aux.pop_assoc pred.[1] trie in + (pred.[1], pred::preds)::trie + else (pred.[1], [pred])::trie ) [] preds in List.map (fun (key2, preds) -> Char.escaped key ^ Char.escaped key2, preds) trie2 ) trie1 in + let trie2 = List.map (fun (k,preds) -> + let trunc = + List.filter (fun r -> String.length r = 2) preds in + if trunc = [] then k, preds else k, trunc) trie2 in let uniq2, trie2 = Aux.partition_map - (function (k,[rel]) -> Aux.Left (rel, k) + (function (k,[pred]) -> Aux.Left (pred, k) | subt -> Aux.Right subt) trie2 in let trie2 = List.map - (fun (k, rels) -> k, List.filter - (fun rel -> String.length rel > 2) rels) trie2 in + (fun (k, preds) -> k, List.filter + (fun pred -> String.length pred > 2) preds) trie2 in let trie3 = Aux.concat_map (fun (key, preds) -> let trie3 = - List.fold_left (fun trie rel -> - if List.mem_assoc rel.[2] trie then - let rels, trie = Aux.pop_assoc rel.[2] trie in - (rel.[2], rel::rels)::trie - else (rel.[2], [rel])::trie + List.fold_left (fun trie pred -> + if List.mem_assoc pred.[2] trie then + let preds, trie = Aux.pop_assoc pred.[2] trie in + (pred.[2], pred::preds)::trie + else (pred.[2], [pred])::trie ) [] preds in List.map (fun (key2, preds) -> key ^ Char.escaped key2, preds) trie3 ) trie2 in let uniq3 = Aux.map_some - (function (k,[rel]) -> Some (rel,k) | _ -> None) trie3 in + (function (k,[pred]) -> Some (pred,k) | _ -> None) trie3 in uniq1, uniq2, uniq3 @@ -710,7 +724,16 @@ inferred parameters (row / column relations and position increments), and the structure with information already extracted into the string removed. *) -let board_to_string struc = +let rec board_to_string struc = + (* {{{ log entry *) + if !debug_level > 1 then ( + let old_level = !debug_level in + debug_level := 0; + let bstr,_ = board_to_string struc in + Printf.printf "board_to_string: printing of %s\n%!" bstr; + debug_level := old_level; + ); + (* }}} *) let col_index = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" in (* find the spanning rectangle *) @@ -833,10 +856,22 @@ StringMap.fold (fun rel arity predicates -> if arity = 1 then rel::predicates else predicates) struc.rel_signature [] in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf "board_to_string: all_predicates=%s\n%!" + (String.concat ", " all_predicates); + ); + (* }}} *) let uniq1, uniq2, uniq3 = find_unique all_predicates in let uniq_long = uniq1 @ uniq2 @ uniq3 in let uniq_short = uniq1 @ uniq2 in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf "board_to_string: uniq_long=%s\n%!" + (String.concat ", " (List.map fst uniq_long)); + ); + (* }}} *) let ret = ref struc in for c=1 to c_max do for r=1 to r_max do @@ -850,7 +885,7 @@ c_max*3*(r_max - r)*2 + c_max*3 + 2*(r_max - r)*2 + (c-1)*3 + 3 in if elem = -1 then board.[lower_left] <- '*' else begin - (* collect the predicates *) + (* collect the predicates *) let tup = [|elem|] in let predicates = List.filter (fun pred -> @@ -858,12 +893,12 @@ try StringMap.find pred !ret.relations with Not_found -> Tuples.empty in Tuples.mem tup tmap && - let rmap = - try StringMap.find pred !ret.incidence - with Not_found -> IntMap.empty in - not (Tuples.is_empty ( - try IntMap.find elem rmap - with Not_found -> Tuples.empty))) + let rmap = + try StringMap.find pred !ret.incidence + with Not_found -> IntMap.empty in + not (Tuples.is_empty ( + try IntMap.find elem rmap + with Not_found -> Tuples.empty))) all_predicates in let up_line = String.make 3 ' ' and lo_line = String.make 3 ' ' in @@ -902,18 +937,18 @@ init_pos_x +. float_of_int (c - 1) *. pos_dx in let pos_y = init_pos_y +. float_of_int (r - 1) *. pos_dy in - if try fun_val !ret "x" elem = pos_x - with Not_found -> false then - ret := del_fun !ret "x" elem; - if try fun_val !ret "y" elem = pos_y - with Not_found -> false then - ret := del_fun !ret "y" elem; - if try fun_val !ret "vx" elem = 0.0 - with Not_found -> false then - ret := del_fun !ret "vx" elem; - if try fun_val !ret "vy" elem = 0.0 - with Not_found -> false then - ret := del_fun !ret "vy" elem; + if (try fun_val !ret "x" elem = pos_x + with Not_found -> false) + then ret := del_fun !ret "x" elem; + if (try fun_val !ret "y" elem = pos_y + with Not_found -> false) + then ret := del_fun !ret "y" elem; + if (try fun_val !ret "vx" elem = 0.0 + with Not_found -> false) + then ret := del_fun !ret "vx" elem; + if (try fun_val !ret "vy" elem = 0.0 + with Not_found -> false) + then ret := del_fun !ret "vy" elem; end done done; @@ -936,8 +971,8 @@ else struc with Not_found -> struc in ret := List.fold_left clear_empty !ret ["x"; "y"; "vx"; "vy"]; - (* relations that are in the structure for the sake of - signature, i.e. they're empty *) + (* relations that are in the structure for the sake of + signature, i.e. they're empty *) let signat_rels = StringMap.fold (fun rel tups acc -> if Tuples.is_empty tups then rel::acc else acc) @@ -1100,7 +1135,7 @@ then ( let elname = Char.escaped col_index.[c-1] ^ string_of_int r in let nstruc, elem = - add_new_elem !struc ~name:elname () in + find_or_new_elem !struc elname in board_els.(c-1).(r-1) <- elem; struc := nstruc; let tup = [|elem|] in Modified: trunk/Toss/Solver/Structure.mli =================================================================== --- trunk/Toss/Solver/Structure.mli 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/Solver/Structure.mli 2010-12-05 21:51:48 UTC (rev 1225) @@ -1,5 +1,6 @@ (* Representing Structures *) +val debug_level : int ref module IntMap : Map.S with type key = int (* Maps from int to 'alpha *) Modified: trunk/Toss/examples/Chess.toss =================================================================== --- trunk/Toss/examples/Chess.toss 2010-12-05 20:52:32 UTC (rev 1224) +++ trunk/Toss/examples/Chess.toss 2010-12-05 21:51:48 UTC (rev 1225) @@ -327,7 +327,7 @@ [ a, b | bK { b } | vx {a->0.,b->10.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] emb w, b pre Near(a, b) post not CheckB() -LOC 0 { # both can castle # +LOC 0 { // both can castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -349,7 +349,7 @@ [WhiteQueen -> 1]; [WhiteKing -> 7] } -LOC 1 { # both can castle # +LOC 1 { // both can castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -371,7 +371,7 @@ [BlackQueen -> 0]; [BlackKing -> 24] } -LOC 2 { # w left, b can castle # +LOC 2 { // w left, b can castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -393,7 +393,7 @@ [WhiteQueen -> 3]; [WhiteKing -> 7] } -LOC 3 { # w left, b can castle # +LOC 3 { // w left, b can castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -415,7 +415,7 @@ [BlackQueen -> 2]; [BlackKing -> 26] } -LOC 4 { # w right, b can castle # +LOC 4 { // w right, b can castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -437,7 +437,7 @@ [WhiteQueen -> 5]; [WhiteKing -> 7] } -LOC 5 { # w right, b can castle # +LOC 5 { // w right, b can castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -459,7 +459,7 @@ [BlackQueen -> 4]; [BlackKing -> 28] } -LOC 6 { # w no, b can castle # +LOC 6 { // w no, b can castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -481,7 +481,7 @@ [WhiteQueen -> 7]; [WhiteKing -> 7] } -LOC 7 { # w no, b can castle # +LOC 7 { // w no, b can castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -503,7 +503,7 @@ [BlackQueen -> 6]; [BlackKing -> 30] } -LOC 8 { # w can, b left castle # +LOC 8 { // w can, b left castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -525,7 +525,7 @@ [WhiteQueen -> 9]; [WhiteKing -> 15] } -LOC 9 { # w can, b left castle # +LOC 9 { // w can, b left castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -547,7 +547,7 @@ [BlackQueen -> 8]; [BlackKing -> 24] } -LOC 10 { # w left, b left castle # +LOC 10 { // w left, b left castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -569,7 +569,7 @@ [WhiteQueen -> 11]; [WhiteKing -> 15] } -LOC 11 { # w left, b left castle # +LOC 11 { // w left, b left castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -591,7 +591,7 @@ [BlackQueen -> 10]; [BlackKing -> 26] } -LOC 12 { # w right, b left castle # +LOC 12 { // w right, b left castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -613,7 +613,7 @@ [WhiteQueen -> 13]; [WhiteKing -> 15] } -LOC 13 { # w right, b left castle # +LOC 13 { // w right, b left castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -635,7 +635,7 @@ [BlackQueen -> 12]; [BlackKing -> 28] } -LOC 14 { # w no, b left castle # +LOC 14 { // w no, b left castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -657,7 +657,7 @@ [WhiteQueen -> 15]; [WhiteKing -> 15] } -LOC 15 { # w no, b left castle # +LOC 15 { // w no, b left castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -679,7 +679,7 @@ [BlackQueen -> 14]; [BlackKing -> 30] } -LOC 16 { # w can, b right castle # +LOC 16 { // w can, b right castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -701,7 +701,7 @@ [WhiteQueen -> 17]; [WhiteKing -> 23] } -LOC 17 { # w can, b right castle # +LOC 17 { // w can, b right castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -723,7 +723,7 @@ [BlackQueen -> 16]; [BlackKing -> 24] } -LOC 18 { # w left, b right castle # +LOC 18 { // w left, b right castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -745,7 +745,7 @@ [WhiteQueen -> 19]; [WhiteKing -> 23] } -LOC 19 { # w left, b right castle # +LOC 19 { // w left, b right castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -767,7 +767,7 @@ [BlackQueen -> 18]; [BlackKing -> 26] } -LOC 20 { # w right, b right castle # +LOC 20 { // w right, b right castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -789,7 +789,7 @@ [WhiteQueen -> 21]; [WhiteKing -> 23] } -LOC 21 { # w right, b right castle # +LOC 21 { // w right, b right castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -811,7 +811,7 @@ [BlackQueen -> 20]; [BlackKing -> 28] } -LOC 22 { # w no, b right castle # +LOC 22 { // w no, b right castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -833,7 +833,7 @@ [WhiteQueen -> 23]; [WhiteKing -> 23] } -LOC 23 { # w no, b right castle # +LOC 23 { // w no, b right castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -855,7 +855,7 @@ [BlackQueen -> 22]; [BlackKing -> 30] } - LOC 24 { # w can, b no castle # + LOC 24 { // w can, b no castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -877,7 +877,7 @@ [WhiteQueen -> 25]; [WhiteKing -> 31] } -LOC 25 { # w can, b no castle # +LOC 25 { // w can, b no castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -899,7 +899,7 @@ [BlackQueen -> 24]; [BlackKing -> 24] } -LOC 26 { # w left, b no castle # +LOC 26 { // w left, b no castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -921,7 +921,7 @@ [WhiteQueen -> 27]; [WhiteKing -> 31] } -LOC 27 { # w left, b no castle # +LOC 27 { // w left, b no castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -943,7 +943,7 @@ [BlackQueen -> 26]; [BlackKing -> 26] } -LOC 28 { # w right, b no castle # +LOC 28 { // w right, b no castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -965,7 +965,7 @@ [WhiteQueen -> 29]; [WhiteKing -> 31] } -LOC 29 { # w right, b no castle # +LOC 29 { // w right, b no castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -987,7 +987,7 @@ [BlackQueen -> 28]; [BlackKing -> 28] } -LOC 30 { # w no, b no castle # +LOC 30 { // w no, b no castle PLAYER 1 PAYOFF { 1: :(CheckB()) - :(CheckW()); @@ -1009,7 +1009,7 @@ [WhiteQueen -> 31]; [WhiteKing -> 31] } -LOC 31 { # w no, b no castle # +LOC 31 { // w no, b no castle PLAYER 2 PAYOFF { 1: :(CheckB()) - :(CheckW()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-06 00:34:39
|
Revision: 1228 http://toss.svn.sourceforge.net/toss/?rev=1228&view=rev Author: lukaszkaiser Date: 2010-12-06 00:34:31 +0000 (Mon, 06 Dec 2010) Log Message: ----------- Documentation corrections, removing SolverIntf. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/Arena.mli trunk/Toss/Arena/ContinuousRule.ml trunk/Toss/Arena/ContinuousRule.mli trunk/Toss/Arena/DiscreteRule.ml trunk/Toss/Arena/DiscreteRule.mli trunk/Toss/Arena/DiscreteRuleTest.ml trunk/Toss/Arena/Term.mli trunk/Toss/Formula/BoolFormula.ml trunk/Toss/Formula/BoolFormula.mli trunk/Toss/Formula/Formula.mli trunk/Toss/Formula/FormulaOps.mli trunk/Toss/Play/Game.ml trunk/Toss/Play/GameTest.ml trunk/Toss/Play/Heuristic.ml trunk/Toss/Solver/AssignmentSet.mli trunk/Toss/Solver/Assignments.mli trunk/Toss/Solver/Class.mli trunk/Toss/Solver/Solver.ml trunk/Toss/Solver/Solver.mli trunk/Toss/Toss.odocl Removed Paths: ------------- trunk/Toss/Solver/SolverIntf.ml trunk/Toss/Solver/SolverIntf.mli Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Arena/Arena.ml 2010-12-06 00:34:31 UTC (rev 1228) @@ -22,7 +22,7 @@ id : int ; player : int ; payoffs : Formula.real_expr array ; - payoffs_pp : SolverIntf.M.registered_real_expr array ; + payoffs_pp : Solver.M.registered_real_expr array ; moves : (label * int) list ; } @@ -33,7 +33,7 @@ num_players : int; player_names : (string * int) list ; defined_rels : (string * (string list * Formula.formula * - SolverIntf.M.registered_formula)) list ; + Solver.M.registered_formula)) list ; } (* State of the game and additional information. *) @@ -54,7 +54,7 @@ graph=Array.make 1 { id = 0; player = 0; payoffs = [|zero|]; payoffs_pp = - [|SolverIntf.M.register_real_expr zero|]; + [|Solver.M.register_real_expr zero|]; moves = [] }; player_names = ["1", 0] ; defined_rels = [] ; @@ -71,8 +71,8 @@ (* Add a defined relation to a structure. *) let add_def_rel_single struc (r_name, vars, def_phi) = - let def_asg = SolverIntf.M.evaluate struc - (SolverIntf.M.register_formula def_phi) in + let def_asg = Solver.M.evaluate struc + (Solver.M.register_formula def_phi) in match def_asg with | AssignmentSet.Empty -> Structure.add_rel_name r_name (List.length vars) struc @@ -144,7 +144,7 @@ let payoffs = array_of_players zero player_names payoffs in let payoffs_pp = - Array.map SolverIntf.M.register_real_expr payoffs in + Array.map Solver.M.register_real_expr payoffs in { id = id; player = player; payoffs = payoffs; payoffs_pp = payoffs_pp; moves = moves } @@ -215,7 +215,7 @@ List.map (fun (rel, args, body) -> (rel, (args, body))) defined_rels in let defined_rels = List.map (fun (rel, args, body) -> - rel, (args, body, SolverIntf.M.register_formula body)) + rel, (args, body, Solver.M.register_formula body)) defined_rels in let player_names = Array.to_list (Array.mapi (fun i pname->pname, i) @@ -242,7 +242,7 @@ if old_locs = [] then old_locs else let zero = Formula.Const 0.0 in - let pp_zero = SolverIntf.M.register_real_expr zero in + let pp_zero = Solver.M.register_real_expr zero in let add_payoffs loc = let more = num_players - Array.length loc.payoffs in {loc with @@ -255,7 +255,7 @@ let add_def_rel loc = let ps = Array.map (FormulaOps.subst_rels_expr def_rels_pure) loc.payoffs in let reg_ps = - Array.map SolverIntf.M.register_real_expr ps in + Array.map Solver.M.register_real_expr ps in { loc with payoffs = ps; payoffs_pp = reg_ps } in (* {{{ log entry *) if !debug_level > 2 then ( @@ -389,7 +389,7 @@ let add_new_player state pname = let player = state.game.num_players in let zero = Formula.Const 0.0 in - let pp_zero = SolverIntf.M.register_real_expr zero in + let pp_zero = Solver.M.register_real_expr zero in let add_payoff loc = {loc with payoffs = Array.append loc.payoffs [|zero|]; @@ -694,7 +694,7 @@ (Array.mapi (fun i v->string_of_int i,v) state.game.graph.(state.cur_loc).payoffs_pp) in let ev (p,e) = - p^": "^(string_of_float (SolverIntf.M.get_real_val e struc)) in + p^": "^(string_of_float (Solver.M.get_real_val e struc)) in (state, String.concat ", " (List.sort compare (List.map ev payoffs))) | SetLocMoves (i, moves) -> if i < 0 || i > Array.length state.game.graph then Modified: trunk/Toss/Arena/Arena.mli =================================================================== --- trunk/Toss/Arena/Arena.mli 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Arena/Arena.mli 2010-12-06 00:34:31 UTC (rev 1228) @@ -1,10 +1,8 @@ -(* Represent the game arena and operate on it. *) +(** Represent the game arena and operate on it. *) val debug_level : int ref -(* ------------------------ BASIC TYPE DEFINITIONS -------------------------- *) - -(* A single move consists of applying a rewrite rule for a time from the +(** A single move consists of applying a rewrite rule for a time from the [time_in] interval, and parameters from the interval list. *) type label = { rule : string ; @@ -12,29 +10,29 @@ parameters_in : (string * (float * float)) list ; } -(* A game has locations from which a player (single for now) can move, +(** A game has locations from which a player (single for now) can move, with a label, to one of the next positions, or get a payoff. Players are indexed continuously starting from 0. *) type location = { id : int ; player : int ; payoffs : Formula.real_expr array ; - payoffs_pp : SolverIntf.M.registered_real_expr array ; + payoffs_pp : Solver.M.registered_real_expr array ; moves : (label * int) list ; } -(* The basic type of Arena. *) +(** The basic type of Arena. *) type game = { rules : (string * ContinuousRule.rule) list; graph : location array; num_players : int; player_names : (string * int) list ; defined_rels : (string * (string list * Formula.formula * - SolverIntf.M.registered_formula)) list ; + Solver.M.registered_formula)) list ; } -(* State of the game. *) +(** State of the game. *) type game_state = { game : game ; struc : Structure.structure ; @@ -49,18 +47,16 @@ (string * string list * Formula.formula) list -> Structure.structure -(* ------------------------ PRINTING FUNCTIONS ------------------------------ *) - -(* Print a label as a string. *) +(** Print a label as a string. *) val label_str : label -> string val move_str : (label * int) -> string -(* Print a game as a string. *) +(** Print a game as a string. *) val str : game -> string -(* Print the whole state: the game, structure, time and aux data. *) +(** Print the whole state: the game, structure, time and aux data. *) val state_str : game_state -> string -(* Whether to print relation definitions as equations, or using the C +(** Whether to print relation definitions as equations, or using the C syntax. Defaults to [true]. *) val equational_def_style : bool ref @@ -68,9 +64,7 @@ val print_state : game_state -> unit val sprint_state : game_state -> string -(* -------------------- PARSER HELPER ------------------------------ *) - -(* The order of following entries matters: [DefPlayers] adds more +(** The order of following entries matters: [DefPlayers] adds more players, with consecutive numbers starting from first available; later [StateStruc], [StateTime] and [StateLoc] entries override earlier ones; later [DefLoc] with already existing location ID @@ -82,16 +76,16 @@ (string * int) list -> (string * (string list * Formula.formula)) list -> string -> ContinuousRule.rule) - (* add a rule *) + (** add a rule *) | DefLoc of ((string * int) list -> location) - (* add location to graph *) - | DefPlayers of string list (* add players (fresh numbers) *) + (** add location to graph *) + | DefPlayers of string list (** add players (fresh numbers) *) | DefRel of string * string list * Formula.formula - (* add a defined relation *) - | StateStruc of Structure.structure (* initial/saved state *) - | StateTime of float (* initial/saved time *) - | StateLoc of int (* initial/saved location *) - | StateData of (string * string) list (* saved data *) + (** add a defined relation *) + | StateStruc of Structure.structure (** initial/saved state *) + | StateTime of float (** initial/saved time *) + | StateLoc of int (** initial/saved location *) + | StateData of (string * string) list (** saved data *) exception Arena_definition_error of string @@ -109,45 +103,45 @@ | `PlayerName of string ] list -> (string * int) list -> location -(* Create a game state, possibly by extending an old state, from a +(** Create a game state, possibly by extending an old state, from a list of definitions (usually corresponding to a ".toss" file.) *) val process_definition : ?extend_state:game_state -> definition list -> game_state -(* ------------------ REQUESTS TO THE ARENA USED IN OPERATION --------------- *) +(** ------------------ REQUESTS TO THE ARENA USED IN OPERATION --------------- *) -(* Location of a structure: either arena or left or right-hand side of a rule *) +(** Location of a structure: either arena or left or right-hand side of a rule *) type struct_loc = Struct | Left of string | Right of string -(* Requests which we handle. *) +(** Requests which we handle. *) type request = - AddElem of struct_loc (* Add element to location *) - | AddRel of struct_loc * string * string list (* Add relation tuple *) - | DelElem of struct_loc * string (* Del element at location *) - | DelRel of struct_loc * string * string list (* Del relation tuple *) - | GetRelSignature of struct_loc (* List rel names and arities *) - | GetFunSignature of struct_loc (* List function names *) - | GetAllTuples of struct_loc * string (* Get all tuples in relation *) - | GetAllElems of struct_loc (* List all elements *) - | SetFun of struct_loc * string * string * float (* Set function value *) - | GetFun of struct_loc * string * string (* Get function value *) - | SetData of string * string (* Set data under a name *) - | GetData of string (* Get data *) - | SetArity of string * int (* Set arity of a relation *) - | GetArity of string (* Get arity of a relation *) - | RenamePlayer of string * string (* Replace player name *) - | SetLoc of int (* Set current location *) - | GetLoc (* Get current and # locs. *) - | SetLocPlayer of int * string (* Set player at location *) - | GetLocPlayer of int (* Get player at location *) - | SetLocPayoff of int * string * Formula.real_expr(* Set payoff for player *) - | GetLocPayoff of int * string (* Get payoff for player *) - | GetCurPayoffs (* Payoffs in current loc *) - | SetLocMoves of int * (label * int) list (* Set moves at location *) - | GetLocMoves of int (* Get moves at location *) + AddElem of struct_loc (** Add element to location *) + | AddRel of struct_loc * string * string list (** Add relation tuple *) + | DelElem of struct_loc * string (** Del element at location *) + | DelRel of struct_loc * string * string list (** Del relation tuple *) + | GetRelSignature of struct_loc (** List rel names and arities *) + | GetFunSignature of struct_loc (** List function names *) + | GetAllTuples of struct_loc * string (** Get all tuples in relation *) + | GetAllElems of struct_loc (** List all elements *) + | SetFun of struct_loc * string * string * float (** Set function value *) + | GetFun of struct_loc * string * string (** Get function value *) + | SetData of string * string (** Set data under a name *) + | GetData of string (** Get data *) + | SetArity of string * int (** Set arity of a relation *) + | GetArity of string (** Get arity of a relation *) + | RenamePlayer of string * string (** Replace player name *) + | SetLoc of int (** Set current location *) + | GetLoc (** Get current and # locs. *) + | SetLocPlayer of int * string (** Set player at location *) + | GetLocPlayer of int (** Get player at location *) + | SetLocPayoff of int * string * Formula.real_expr(** Set payoff for player *) + | GetLocPayoff of int * string (** Get payoff for player *) + | GetCurPayoffs (** Payoffs in current loc *) + | SetLocMoves of int * (label * int) list (** Set moves at location *) + | GetLocMoves of int (** Get moves at location *) | SuggestLocMoves of int * int * int * string * int option * (string * Formula.real_expr) list array option * float option - (* Suggested moves at loc, with timeout in so many seconds, for so + (** Suggested moves at loc, with timeout in so many seconds, for so much computational effort if possible before timeout, using given search method ("maximax", "alpha_beta", "alpha_beta_ord", "uct_random_playouts", @@ -155,32 +149,32 @@ "uct_no_playouts"), with optional horizon for playouts, with location-dependent heuristics, with advancement ratio for generating heuristics if they're not given *) - | EvalFormula of Formula.formula (* Evaluate formula *) - | EvalRealExpr of Formula.real_expr (* Evaluate real expr *) + | EvalFormula of Formula.formula (** Evaluate formula *) + | EvalRealExpr of Formula.real_expr (** Evaluate real expr *) | SetRule of string * ((string * int) list -> (string * (string list * Formula.formula)) list -> string -> ContinuousRule.rule) - (* Set a rule as given *) - | GetRule of string (* Get a rule as string *) - | SetRuleUpd of string*string *string *Term.term (* Set a rule update eq *) - | GetRuleUpd of string * string * string (* Get a rule update eq *) - | SetRuleDyn of string*string *string *Term.term (* Set a rule dynamics eq *) - | GetRuleDyn of string * string * string (* Get a rule dynamics eq *) + (** Set a rule as given *) + | GetRule of string (** Get a rule as string *) + | SetRuleUpd of string*string *string *Term.term (** Set a rule update eq *) + | GetRuleUpd of string * string * string (** Get a rule update eq *) + | SetRuleDyn of string*string *string *Term.term (** Set a rule dynamics eq *) + | GetRuleDyn of string * string * string (** Get a rule dynamics eq *) | SetRuleCond of string * Formula.formula * Formula.formula * Formula.formula - (* Set a rule's precondition, invariant and postconsition *) - | GetRuleCond of string (* Get a rule conditions *) - | SetRuleEmb of string * string list (* Set relations to embed *) - | GetRuleEmb of string (* Get relations to embed *) - | SetRuleAssoc of string * string * string list (* Set an association *) - | GetRuleAssoc of string * string (* Get an association *) - | GetRuleMatches of string (* Get matches of a rule *) + (** Set a rule's precondition, invariant and postconsition *) + | GetRuleCond of string (** Get a rule conditions *) + | SetRuleEmb of string * string list (** Set relations to embed *) + | GetRuleEmb of string (** Get relations to embed *) + | SetRuleAssoc of string * string * string list (** Set an association *) + | GetRuleAssoc of string * string (** Get an association *) + | GetRuleMatches of string (** Get matches of a rule *) | ApplyRule of string * (string * string) list * float * (string * float) list - (* Apply rule at match for given time and with params *) - | GetRuleNames (* Get names of rules *) - | SetTime of float * float (* Set time step and time *) - | GetTime (* Get time step and time *) - | SetState of game_state (* Set the full state *) - | GetState (* Return the state *) + (** Apply rule at match for given time and with params *) + | GetRuleNames (** Get names of rules *) + | SetTime of float * float (** Set time step and time *) + | GetTime (** Get time step and time *) + | SetState of game_state (** Set the full state *) + | GetState (** Return the state *) val handle_request : game_state -> request -> game_state * string Modified: trunk/Toss/Arena/ContinuousRule.ml =================================================================== --- trunk/Toss/Arena/ContinuousRule.ml 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Arena/ContinuousRule.ml 2010-12-06 00:34:31 UTC (rev 1228) @@ -15,10 +15,10 @@ update : ((string * string) * Term.term) list; (* Update equations calT *) (* Note that, for efficiency, the precondition is part of DiscreteRule. *) inv : Formula.formula; (* Invariant for the evolution *) - inv_pp : SolverIntf.M.registered_formula; + inv_pp : Solver.M.registered_formula; (* Optimized invariant *) post : Formula.formula; (* Postcondition for application *) - post_pp : SolverIntf.M.registered_formula; + post_pp : Solver.M.registered_formula; (* Optimized postcondition *) } @@ -31,16 +31,16 @@ let cpost = FormulaOps.subst_rels defs post in let discrete = { discr with DiscreteRule.pre = cpre } in let defrels = List.map (fun (rel,(args,body)) -> - rel, (args, body, SolverIntf.M.register_formula body)) defs in + rel, (args, body, Solver.M.register_formula body)) defs in let obj = DiscreteRule.compile_rule signat defrels discr in { discrete = discrete; compiled = obj ; dynamics = dynamics ; update = update ; inv = cinv ; - inv_pp = SolverIntf.M.register_formula cinv; + inv_pp = Solver.M.register_formula cinv; post = cpost ; - post_pp = SolverIntf.M.register_formula cpost; + post_pp = Solver.M.register_formula cpost; } @@ -108,7 +108,7 @@ 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!*) - let is_inv s = SolverIntf.M.check_formula s r.inv_pp in + let is_inv s = Solver.M.check_formula s r.inv_pp in let lhs_to_model ((f, a), _) = (* dynamics refer to elements by LHS matches *) let e = Structure.find_elem r.discrete.DiscreteRule.lhs_struc a in @@ -164,7 +164,7 @@ let is_ok m = let (res_struc, _, _) = rewrite_single_nocheck struc cur_time m r 1. [] in - SolverIntf.M.check_formula res_struc r.post_pp in + Solver.M.check_formula res_struc r.post_pp in if r.post = Formula.And [] then matches struc r else List.filter is_ok (matches struc r) @@ -174,7 +174,7 @@ let (res_struc, _, _ as res_struc_n_shifts) = rewrite_single_nocheck struc cur_time m r t params in if r.post = Formula.And [] || - SolverIntf.M.check_formula res_struc r.post_pp + Solver.M.check_formula res_struc r.post_pp then Some res_struc_n_shifts else None Modified: trunk/Toss/Arena/ContinuousRule.mli =================================================================== --- trunk/Toss/Arena/ContinuousRule.mli 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Arena/ContinuousRule.mli 2010-12-06 00:34:31 UTC (rev 1228) @@ -1,40 +1,41 @@ -(* Structure rewriting with continuous dynamics. *) +(** Structure rewriting with continuous dynamics. *) val get_time_step : unit -> float val set_time_step : float -> unit -(* ---------------- BASIC TYPE DEFINITION AND CONSTRUCTOR ------------------- *) +(** {2 Basic Type Definition} *) -(* Specification of a continuous rewriting rule, as in modelling document. +(** Specification of a continuous rewriting rule, as in modelling document. Function named foo on element i is, in a term, given by variable foo_i. *) type rule = { - discrete : DiscreteRule.rule; (* The discrete part *) - compiled : DiscreteRule.rule_obj ; (* Compiled discrete part *) - dynamics : ((string * string) * Term.term) list; (* Equation system calD *) - update : ((string * string) * Term.term) list; (* Update equations calT *) - (* Note that, for efficiency, the precondition is part of DiscreteRule. *) - inv : Formula.formula; (* Invariant for the evolution *) - inv_pp : SolverIntf.M.registered_formula; - (* Optimized invariant *) - post : Formula.formula; (* Postcondition for application *) - post_pp : SolverIntf.M.registered_formula; -(* Optimized postcondition *) + discrete : DiscreteRule.rule; (** The discrete part *) + compiled : DiscreteRule.rule_obj ; (** Compiled discrete part *) + dynamics : ((string * string) * Term.term) list; (** Equation system calD *) + update : ((string * string) * Term.term) list; (** Update equations calT *) + (** Note that, for efficiency, the precondition is part of DiscreteRule. *) + inv : Formula.formula; (** Invariant for the evolution *) + inv_pp : Solver.M.registered_formula; + (** Optimized invariant *) + post : Formula.formula; (** Postcondition for application *) + post_pp : Solver.M.registered_formula; + (** Optimized postcondition *) } -(* Create a continuous rule given a named discrete rule and other params. *) +(** Create a continuous rule given a named discrete rule and other params. *) val make_rule : - (string * int) list -> (* signature *) - (string * (string list * Formula.formula)) list -> (* defined rels *) + (string * int) list -> (** signature *) + (string * (string list * Formula.formula)) list -> (** defined rels *) (DiscreteRule.rule) -> Term.eq_sys -> Term.eq_sys -> ?pre:Formula.formula -> ?inv:Formula.formula -> ?post:Formula.formula -> unit -> rule -(* -------------------------- PRINTING FUNCTION ----------------------------- *) +(** {2 Printing function} *) -(* Print a rule to string. *) + +(** Print a rule to string. *) val str : rule -> string val fprint : Format.formatter -> rule -> unit @@ -42,32 +43,35 @@ val sprint : rule -> string -(* ------------------ APPLYING FUNCTIONS TO SIDE STRUCTURES ----------------- *) +(** {2 Applying function to side structures} *) -(* Apply [f] to left (if [to_left]) or right side of the given rule. + +(** Apply [f] to left (if [to_left]) or right side of the given rule. Return the new rule and an additional result which [f] returns. *) val apply_to_side : bool -> (Structure.structure -> Structure.structure * 'a) -> - (string * int) list -> (* signature *) - (string * (string list * Formula.formula)) list -> (* defined rels *) + (string * int) list -> (** signature *) + (string * (string list * Formula.formula)) list -> (** defined rels *) rule -> rule * 'a val lhs : rule -> Structure.structure val rhs : rule -> Structure.structure -(* ---------------------- FINDING APPLICABLE MATCHES ------------------------ *) -(* Find all matches of [r] in [struc] which satisfy [r]'s precondition. *) +(** {2 Finding applicable matches} *) + + +(** Find all matches of [r] in [struc] which satisfy [r]'s precondition. *) val matches : Structure.structure -> rule -> (int * int) list list -(* Matches which satisfy postcondition with time 1 and empty params *) +(** Matches which satisfy postcondition with time 1 and empty params *) val matches_post : Structure.structure -> rule -> float -> (int * int) list list -(* --------------------------- REWRITING ------------------------------------ *) +(** {2 Rewriting} *) -(* For now, we rewrite only single rules. +(** For now, we rewrite only single rules. [rewrite_single struc cur_time m r t params def_rels] rewrites [struc] for the period [t] (unless invariant stops holding earlier) starting in [cur_time], at matching [m], and returns the rewritten @@ -78,8 +82,7 @@ (int * int) list -> rule -> float -> (string * float) list -> Structure.structure * float * ((string * string) * Term.term list) list -(* For now, we rewrite only single rules. - +(** For now, we rewrite only single rules. Same as {!ContinuousRule.rewrite_single_nocheck}, but check if the postcondition holds. Returns [None] if rewriting fails. *) val rewrite_single : Modified: trunk/Toss/Arena/DiscreteRule.ml =================================================================== --- trunk/Toss/Arena/DiscreteRule.ml 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Arena/DiscreteRule.ml 2010-12-06 00:34:31 UTC (rev 1228) @@ -36,7 +36,7 @@ lhs_elem_inv_names : elem_inv_names; lhs_elem_vars : string list; lhs_form : Formula.formula; - lhs_form_pp : SolverIntf.M.registered_formula; + lhs_form_pp : Solver.M.registered_formula; (* gets instantiated in the model *) (* the precondition [pre] is compiled as part of [lhs_form] *) rhs_elem_names : elem_names; @@ -165,7 +165,7 @@ (* Find all embeddings of a rule. Does not guarantee that rewriting will succeed for all of them. *) let find_matchings model rule_obj = - SolverIntf.M.evaluate model rule_obj.lhs_form_pp + Solver.M.evaluate model rule_obj.lhs_form_pp (* Convert assignment to an embedding of the LHS structure. *) let assignment_to_embedding rule_obj assgn = @@ -564,7 +564,7 @@ if List.mem_assoc rel defined_rels then let args, _, rphi = List.assoc rel defined_rels in List.map fst (List.filter (fun (rel, ar) -> - SolverIntf.M.check_formula (Structure.free_for_rel rel ar) rphi + Solver.M.check_formula (Structure.free_for_rel rel ar) rphi ) signat) else [rel] in let expand_defrel_tups (drel, tups) = @@ -575,7 +575,7 @@ map_some (fun (brel, ar) -> let selector = Structure.free_for_rel brel ar in let assgn = - SolverIntf.M.evaluate selector rphi in + Solver.M.evaluate selector rphi in let btup = Array.init ar (fun i->i+1) in (* [selector] has only [btup] with its elements *) let selvars = @@ -836,7 +836,7 @@ rhs_neg_tuples in (* Optimizing the embedding formula. *) let lhs_form_pp = - SolverIntf.M.register_formula emb in + Solver.M.register_formula emb in { lhs_elem_names = lhs_elem_names; lhs_elem_inv_names = lhs_elem_inv_names; @@ -913,7 +913,7 @@ List.map (fun tup->Not (Rel (r,Array.map (fun v->`FO v) tup))) tups) obj.rhs_neg_tuples in - SolverIntf.M.formula_str obj.lhs_form_pp ^ "-> " ^ + Solver.M.formula_str obj.lhs_form_pp ^ "-> " ^ Formula.str (And (plits @ nlits)) Modified: trunk/Toss/Arena/DiscreteRule.mli =================================================================== --- trunk/Toss/Arena/DiscreteRule.mli 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Arena/DiscreteRule.mli 2010-12-06 00:34:31 UTC (rev 1228) @@ -31,7 +31,7 @@ lhs_elem_inv_names : elem_inv_names; lhs_elem_vars : string list; lhs_form : Formula.formula; - lhs_form_pp : SolverIntf.M.registered_formula; + lhs_form_pp : Solver.M.registered_formula; (* gets instantiated in the model *) (* the precondition [pre] is compiled as part of [lhs_form] *) rhs_elem_names : elem_names; @@ -104,7 +104,7 @@ val compile_rule : (string * int) list -> (string * - (string list * Formula.formula * SolverIntf.M.registered_formula)) + (string list * Formula.formula * Solver.M.registered_formula)) list -> rule -> rule_obj (** Relations that can explicitly change state by rewriting (i.e. not Modified: trunk/Toss/Arena/DiscreteRuleTest.ml =================================================================== --- trunk/Toss/Arena/DiscreteRuleTest.ml 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Arena/DiscreteRuleTest.ml 2010-12-06 00:34:31 UTC (rev 1228) @@ -520,7 +520,7 @@ let signat = ["O", 1; "P", 1; "Q", 1] in let defrels = ["D", (["a"], formula_of_str "P(a) or Q(a)")] in let defrels = List.map (fun (rel,(args,body)) -> - rel, (args, body, SolverIntf.M.register_formula body)) defrels in + rel, (args, body, Solver.M.register_formula body)) defrels in let rule_obj = compile_rule signat defrels {lhs_struc = lhs_struc; rhs_struc = rhs_struc; @@ -536,7 +536,7 @@ let signat = ["O", 1; "P", 1; "Q", 1] in let defrels = ["D", (["a"], formula_of_str "P(a) or Q(a)")] in let defrels = List.map (fun (rel,(args,body)) -> - rel, (args, body, SolverIntf.M.register_formula body)) defrels in + rel, (args, body, Solver.M.register_formula body)) defrels in let rule_obj = compile_rule signat defrels {lhs_struc = lhs_struc; rhs_struc = rhs_struc; @@ -552,7 +552,7 @@ let signat = ["O", 1; "P", 1; "Q", 1] in let defrels = ["D", (["a"], formula_of_str "P(a) or Q(a)")] in let defrels = List.map (fun (rel,(args,body)) -> - rel, (args, body, SolverIntf.M.register_formula body)) defrels in + rel, (args, body, Solver.M.register_formula body)) defrels in let rule_obj = compile_rule signat defrels {lhs_struc = lhs_struc; rhs_struc = rhs_struc; @@ -568,7 +568,7 @@ let signat = ["O", 1; "P", 1; "Q", 1] in let defrels = ["D", (["a"], formula_of_str "P(a) or Q(a)")] in let defrels = List.map (fun (rel,(args,body)) -> - rel, (args, body, SolverIntf.M.register_formula body)) defrels in + rel, (args, body, Solver.M.register_formula body)) defrels in let rule_obj = compile_rule signat defrels {lhs_struc = lhs_struc; rhs_struc = rhs_struc; @@ -589,7 +589,7 @@ let signat = ["O", 1; "P", 1; "Q", 1] in let defrels = ["D", (["a"], formula_of_str "P(a) or Q(a)")] in let defrels = List.map (fun (rel,(args,body)) -> - rel, (args, body, SolverIntf.M.register_formula body)) defrels in + rel, (args, body, Solver.M.register_formula body)) defrels in let rule_obj = compile_rule signat defrels {lhs_struc = lhs_struc; rhs_struc = rhs_struc; @@ -605,7 +605,7 @@ let signat = ["O", 1; "P", 1; "Q", 1] in let defrels = ["D", (["a"], formula_of_str "P(a) or Q(a)")] in let defrels = List.map (fun (rel,(args,body)) -> - rel, (args, body, SolverIntf.M.register_formula body)) defrels in + rel, (args, body, Solver.M.register_formula body)) defrels in let rule_obj = compile_rule signat defrels {lhs_struc = lhs_struc; rhs_struc = rhs_struc; @@ -621,7 +621,7 @@ let signat = ["O", 1; "P", 1; "Q", 1] in let defrels = ["D", (["a"], formula_of_str "P(a) or Q(a)")] in let defrels = List.map (fun (rel,(args,body)) -> - rel, (args, body, SolverIntf.M.register_formula body)) defrels in + rel, (args, body, Solver.M.register_formula body)) defrels in let rule_obj = compile_rule signat defrels {lhs_struc = lhs_struc; rhs_struc = rhs_struc; Modified: trunk/Toss/Arena/Term.mli =================================================================== --- trunk/Toss/Arena/Term.mli 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Arena/Term.mli 2010-12-06 00:34:31 UTC (rev 1228) @@ -1,6 +1,6 @@ -(* Represent terms and their operations. *) +(** Represent terms and their operations. *) -(* ---------------------- BASIC TYPE DEFINITION ----------------------------- *) +(** {2 Basic Type Definition.} *) type term = Var of string @@ -13,12 +13,13 @@ type eq_sys = ((string * string) * term) list -(* ------------------------ BASIC FUNCTIONS -------------------------------- *) +(** {2 Basic functions.} *) -(* Print a term as a string. *) + +(** Print a term as a string. *) val str : term -> string -(* Print an equation system as a string. *) +(** Print an equation system as a string. *) val eq_str : ?diff : bool -> eq_sys -> string val fprint : @@ -32,20 +33,20 @@ val sprint_eqs : ?diff : bool -> eq_sys -> string -(* Power function used in parser. *) +(** Power function used in parser. *) val pow : term -> int -> term -(* Basic simplification, reduces constant terms to floats. *) +(** Basic simplification, reduces constant terms to floats. *) val simp_const : term -> term -(* Convert a term to float, fail on non-constant term. *) +(** Convert a term to float, fail on non-constant term. *) val term_val : term -> float -(* Convert an equation system to float assciation list, fail on non-consts. *) +(** Convert an equation system to float assciation list, fail on non-consts. *) val eq_vals : eq_sys -> ((string * string) * float) list -(* ----------------------- SIMPLE OPERATIONS ------------------------------- *) +(** {2 Simple operations.} *) val add : term -> term -> term val ladd1 : term -> term list -> term list @@ -56,27 +57,28 @@ val lmul : term list -> term list -> term list -(* ------------------ SUBSTITUTION FOR VARIABLES --------------------------- *) +(** {2 Substitution for variables.} *) -(* Substitute term [t] for variable [v] in the given term. *) +(** Substitute term [t] for variable [v] in the given term. *) val subst : string * term -> term -> term -(* Substitute [vals] for [vars] in [terms] and simplify. *) +(** Substitute [vals] for [vars] in [terms] and simplify. *) val subst_simp : string list -> term list -> term list -> term list -(* Substitute term [t] for function variable [f, a] in the given term. *) +(** Substitute term [t] for function variable [f, a] in the given term. *) val subst_f : (string * string) * term -> term -> term -(* Substitute [vals] for function [vars] in [terms] and simplify. *) +(** Substitute [vals] for function [vars] in [terms] and simplify. *) val subst_simp_f : (string * string) list -> term list -> term list -> term list -(* Substitute variables and function vals in an equation system and simplify. *) +(** Substitute variables and function vals in an eq. system and simplify. *) val subst_simp_eq : (string * term) list -> ((string * string) * term) list -> eq_sys -> eq_sys -(* ---------------- RUNGE - KUTTA METHOD FOR TERM EQUATIONS ---------------- *) +(** {2 Runge-Kutta Method for Term Equations *) -(* Perform a Runge-Kutta (RK4) step for [vars] with [vals_init] and right-hand + +(** Perform a Runge-Kutta (RK4) step for [vars] with [vals_init] and right-hand side [eq_terms]. Time variable [tvar] starts at [tinit] and moves [tstep]. *) val rk4_step : string -> term -> term -> eq_sys -> term list -> term list Modified: trunk/Toss/Formula/BoolFormula.ml =================================================================== --- trunk/Toss/Formula/BoolFormula.ml 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Formula/BoolFormula.ml 2010-12-06 00:34:31 UTC (rev 1228) @@ -38,10 +38,10 @@ (* ----------------------- PRINTING FUNCTIONS ------------------------------- *) -(* Print a variable as a string. *) +(** Print a variable as a string. *) let var_str = string_of_int -(* Print a Boolean formula as a string. *) +(** Print a Boolean formula as a string. *) let rec str = function BVar v -> var_str v | BNot phi -> "(not " ^ (str phi) ^ ")" @@ -58,7 +58,7 @@ (* ------------------------ ORDER ON FORMULAS ------------------------------- *) -(* Compare two variables. We assume that FO < MSO < Real. *) +(** Compare two variables. We assume that FO < MSO < Real. *) let compare_vars x y = let abs lit = if lit < 0 then (-lit) else lit in (abs x) - (abs y) Modified: trunk/Toss/Formula/BoolFormula.mli =================================================================== --- trunk/Toss/Formula/BoolFormula.mli 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Formula/BoolFormula.mli 2010-12-06 00:34:31 UTC (rev 1228) @@ -1,8 +1,8 @@ -(* Represent Boolean combinations of integer literals. *) +(** Represent Boolean combinations of integer literals. *) -(* ----------------------- BASIC TYPE DEFINITIONS -------------------------- *) +(** {2 Basic type definitions.} *) -(* This type describes formulas of relational logic with equality. +(** This type describes formulas of relational logic with equality. We allow only simple boolean junctors, other are resolved during parsing. *) type bool_formula = BVar of int @@ -10,58 +10,55 @@ | BAnd of bool_formula list | BOr of bool_formula list -(* ---------------------- PRINTING FUNCTIONS ------------------------------- *) +(** {2 Printing functions.} *) -(* Print a variable as a string. *) +(** Print a variable as a string. *) val var_str : int -> string -(* Print a formula as a string. *) +(** Print a formula as a string. *) val str : bool_formula -> string - -(* Helper function to flatten multiple or's and and's. *) +(** Helper function to flatten multiple or's and and's. *) val flatten_sort : bool_formula -> bool_formula -(* ------------------------- Boolean Formulas ------------------------------ *) +(** {3 Boolean Formulas.} *) -(* Convert an arbitrary formula to a Boolean combination of literals *) +(** Convert an arbitrary formula to a Boolean combination of literals *) val bool_formula_of_formula : Formula.formula -> bool_formula -(* Convert a Boolean combination back to a formula *) -(*val formula_of_bool_formula : bool_formula -> Formula.formula*) - +(** Convert a Boolean combination back to a formula *) val formula_of_bool_formula_arg : bool_formula -> (Formula.formula, int) Hashtbl.t * (int, Formula.formula) Hashtbl.t * int ref -> Formula.formula val bool_formula_of_formula_arg : Formula.formula -> (Formula.formula, int) Hashtbl.t * (int, Formula.formula) Hashtbl.t * int ref -> bool_formula -(* Simplify a Boolean combination *) +(** Simplify a Boolean combination *) val simplify : bool_formula -> bool_formula -(* Sort a Boolean combination *) +(** Sort a Boolean combination *) val sort : bool_formula -> bool_formula -(* Convert a reduced Boolean combination into a CNF with auxiliary variables *) +(** Convert a reduced Boolean combination into a CNF with auxiliary variables *) val auxcnf_of_bool_formula : bool_formula -> int * bool_formula val pg_auxcnf_of_bool_formula : bool_formula -> int * bool_formula -(* Convert a Boolean combination into reduced form (over 'not' and 'or') *) +(** Convert a Boolean combination into reduced form (over 'not' and 'or') *) val to_reduced_form : ?neg:bool -> bool_formula -> bool_formula -(* Convert a Boolean formula to NNF and additionally negate if [neg] is set. *) +(** Convert a Boolean formula to NNF and additionally negate if [neg] is set. *) val to_nnf : ?neg : bool -> bool_formula -> bool_formula val convert : bool_formula -> int list list -(* Convert an arbitrary formula to CNF via Boolean combinations. *) +(** Convert an arbitrary formula to CNF via Boolean combinations. *) val formula_to_cnf : Formula.formula -> Formula.formula -(* ------------------------- DEBUGGING ------------------------------------- *) +(** {2 Debugging.} *) -(* Debugging information. At level 0 nothing is printed out. *) +(** Debugging information. At level 0 nothing is printed out. *) val set_debug_level : int -> unit Modified: trunk/Toss/Formula/Formula.mli =================================================================== --- trunk/Toss/Formula/Formula.mli 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Formula/Formula.mli 2010-12-06 00:34:31 UTC (rev 1228) @@ -1,46 +1,46 @@ -(* Represent formulas with first-order, mso, and real variables. *) +(** Represent formulas with first-order, mso, and real variables. *) -(* ----------------------- BASIC TYPE DEFINITIONS -------------------------- *) +(** {2 Basic Type Definitions.} *) -(* Our variables can be first-order, monadic second-order or reals. *) +(** Our variables can be first-order, monadic second-order or reals. *) type var = [ `FO of string | `MSO of string | `Real of string ] ;; type fo_var = [ `FO of string ];; type mso_var = [ `MSO of string ];; type real_var = [ `Real of string ];; -(* We recognize if the variable is FO (x, y) or MSO (X, Y) or Real (r1, r2). *) +(** We recognize if the variable is FO (x, y) or MSO (X, Y) or Real (r1, r2). *) val var_of_string : string -> var val fo_var_of_string : string -> fo_var val mso_var_of_string : string -> mso_var val real_var_of_string : string -> real_var -(* Check variable type. *) +(** Check variable type. *) val is_fo : var -> bool val is_mso : var -> bool val is_real : var -> bool -(* Casts to particular variable types. *) +(** Casts to particular variable types. *) val to_fo : var -> fo_var val to_mso : var -> mso_var val to_real : var -> real_var val var_tup : [< var] array -> var array -(* Compare two variables. We assume FO < MSO < Real. *) +(** Compare two variables. We assume FO < MSO < Real. *) val compare_vars : ([< var ] as 'a) -> 'a -> int val compare_var_lists : ([< var ] as 'a) list -> 'a list -> int val compare_var_tups : ([< var ] as 'a) array -> 'a array -> int -(* Sign operands. *) +(** Sign operands. *) type sign_op = EQZero | GZero | LZero | GEQZero | LEQZero | NEQZero -(* Print a sign_op as string. *) +(** Print a sign_op as string. *) val sign_op_str : sign_op -> string -(* This type describes formulas of relational logic with equality. +(** This type describes formulas of relational logic with equality. We allow only simple boolean junctors, other are resolved during parsing. *) type formula = Rel of string * fo_var array @@ -68,23 +68,23 @@ val compare : formula -> formula -> int -(* ---------------------- PRINTING FUNCTIONS ------------------------------- *) +(** {2 Printing Functions} *) -(* Print a variable as a string. *) +(** Print a variable as a string. *) val var_str : [< `FO of string | `MSO of string | `Real of string ] -> string -(* Print a variable list as a string. *) +(** Print a variable list as a string. *) val var_list_str: [< `FO of string | `MSO of string | `Real of string ] list -> string -(* Print a formula as a string. *) +(** Print a formula as a string. *) val str : formula -> string val mona_str : formula -> string val print : formula -> unit val sprint : formula -> string val fprint : Format.formatter -> formula -> unit -(* Print a real_expr as a string. *) +(** Print a real_expr as a string. *) val real_str : real_expr -> string val print_real : real_expr -> unit val sprint_real : real_expr -> string @@ -93,13 +93,13 @@ val fprint_prec : int -> Format.formatter -> formula -> unit val fprint_real_prec : int -> Format.formatter -> real_expr -> unit -(* --------------- BASIC HELPER FUNCTIONS USED IN PARSER ------------------- *) +(** {2 Basic flattening functions.} *) -(* Only flatten the formula. *) +(** Only flatten the formula. *) val flatten : formula -> formula val flatten_re : real_expr -> real_expr -(* Flatten and sort multiple or's and and's. *) +(** Flatten and sort multiple or's and and's. *) val flatten_sort : formula -> formula val flatten_sort_re : real_expr -> real_expr Modified: trunk/Toss/Formula/FormulaOps.mli =================================================================== --- trunk/Toss/Formula/FormulaOps.mli 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Formula/FormulaOps.mli 2010-12-06 00:34:31 UTC (rev 1228) @@ -1,35 +1,35 @@ -(* Operations on formulas. *) +(** Operations on formulas. *) open Formula -(* ------------------------------- NNF ------------------------------------ *) +(** {2 NNF} *) -(* Convert formula to NNF and additionally negate if [neg] is set. *) +(** Convert formula to NNF and additionally negate if [neg] is set. *) val nnf : ?neg : bool -> formula -> formula -(* ------------------------------- VARS ------------------------------------ *) +(** {2 Vars} *) val all_vars : formula -> var list val free_vars : formula -> var list -(* Delete top-most quantification of [vs] in the formula. *) +(** Delete top-most quantification of [vs] in the formula. *) val del_vars_quant : var list -> formula -> formula -(* ----------------- MAPPING TO ATOMS AND VAR SUBSTITUTION ------------------ *) +(** {2 Mapping to atoms and variable substitution.} *) -(* Map [f] to all literals (i.e. atoms or not(atom)'s) in the given +(** Map [f] to all literals (i.e. atoms or not(atom)'s) in the given formula. Preserves order of subformulas. *) val map_to_literals : (formula -> formula) -> formula -> formula val map_to_literals_expr : (formula -> formula) -> real_expr -> real_expr -(* Map [f] to all atoms in the given formula. *) +(** Map [f] to all atoms in the given formula. *) val map_to_atoms : (formula -> formula) -> formula -> formula val map_to_atoms_expr : (formula -> formula) -> real_expr -> real_expr -(** Map [f] to all variables occurring in the formula. - Preserves order of subformulas. *) +(** Map @param f to all variables occurring in the formula. + Preserves order of subformulas. @param phi The formula to substitute in. *) val map_to_all_vars : (var -> var) -> formula -> formula (** Apply substitution [subst] to all free variables in the given formula @@ -41,59 +41,59 @@ and the above-quantified ones. Does not go into real_expr. *) val rename_quant_avoiding : var list -> formula -> formula -(* Substitute once relations in [defs] by corresponding subformulas +(** Substitute once relations in [defs] by corresponding subformulas (with instantiated parameters). *) val subst_once_rels : (string * (string list * formula)) list -> formula -> formula val subst_once_rels_expr : (string * (string list * formula)) list -> real_expr -> real_expr -(* Substitute recursively relations defined in [defs] by their definitions. *) +(** Substitute recursively relations defined in [defs] by their definitions. *) val subst_rels : (string * (string list * formula)) list -> formula -> formula val subst_rels_expr : (string * (string list * formula)) list -> real_expr -> real_expr -(* Assign emptyset to an MSO-variable. *) +(** Assign emptyset to an MSO-variable. *) val assign_emptyset : string -> formula -> formula -(* ------------------------ Transitive Closure ---------------------------- *) +(** {2 Transitive Closure} *) -(* Transitive closure of phi(x, y, z) over x and y, an MSO formula. *) +(** Transitive closure of phi(x, y, z) over x and y, an MSO formula. *) val make_tc : string -> string -> formula -> formula -(* First-order [k]-step refl. transitive closure of [phi] over [x] and [y]. *) +(** First-order [k]-step refl. transitive closure of [phi] over [x] and [y]. *) val make_fo_tc_conj : int -> string -> string -> formula -> formula val make_fo_tc_disj : int -> string -> string -> formula -> formula -(* -------------------------- Simplification ------------------------------ *) +(** {2 Simplification} *) -(* Recursively simplify a formula *) +(** Recursively simplify a formula *) val simplify : ?do_pnf : bool -> formula -> formula val pnf : formula -> formula -(* Flatten "and"s and "or"s in a formula -- i.e. associativity. *) +(** Flatten "and"s and "or"s in a formula -- i.e. associativity. *) val flatten_formula : formula -> formula -(* ------------------------------- TNF ------------------------------------ *) +(** {2 TNF} *) -(* Convert formula to TNF; or negTNF when [neg] is set. Type normal form +(** Convert formula to TNF; or negTNF when [neg] is set. Type normal form in a NNF form which pushes quantifiers inside as strongly as possible. *) val tnf : formula -> formula val tnf_re : real_expr -> real_expr val tnf_fv : formula -> formula (** first existentially quantifies free vars *) -(* ----------------------------- CNF/DNF ---------------------------------- *) +(** {2 Convert to CNF or DNF} *) -(* Convert an arbitrary boolean combination to DNF. *) +(** Convert an arbitrary boolean combination to DNF. *) val to_dnf : formula -> formula list -(* Convert an arbitrary boolean combination to CNF. *) +(** Convert an arbitrary boolean combination to CNF. *) val to_cnf : formula -> formula list -(* ------------------------- DEBUGGING ------------------------------------- *) +(** {2 Debugging} *) -(* Debugging information. At level 0 nothing is printed out. *) +(** Debugging information. At level 0 nothing is printed out. *) val set_debug_level : int -> unit Modified: trunk/Toss/Play/Game.ml =================================================================== --- trunk/Toss/Play/Game.ml 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Play/Game.ml 2010-12-06 00:34:31 UTC (rev 1228) @@ -612,7 +612,7 @@ let subloc = evgame.ev_game.Arena.graph.(evgame.ev_location) in if subloc.Arena.moves = [] then (* optimization *) Array.map (fun expr -> - SolverIntf.M.get_real_val expr model) subloc.Arena.payoffs_pp + Solver.M.get_real_val expr model) subloc.Arena.payoffs_pp else let state = {game_state={loc=evgame.ev_location; struc=model; time=time}; @@ -650,7 +650,7 @@ if moves = [| |] then let payoff = Array.map (fun expr -> - SolverIntf.M.get_real_val expr state.struc) + Solver.M.get_real_val expr state.struc) loc.Arena.payoffs_pp in Aux.Right payoff else @@ -1015,7 +1015,7 @@ if moves = [| |] then let payoff = Array.map (fun expr -> - SolverIntf.M.get_real_val expr state.struc) + Solver.M.get_real_val expr state.struc) location.Arena.payoffs_pp in let upscore = score_payoff payoff in upscore, Terminal (state, upscore, heuristic, payoff) @@ -1085,7 +1085,7 @@ | None -> default_heuristic ~struc heur_adv_ratio game in let heuristics_pp = - Array.map (Array.map SolverIntf.M.register_real_expr) heuristics in + Array.map (Array.map Solver.M.register_real_expr) heuristics in let evgame gloc = {ev_game = {Arena.rules = []; @@ -1132,7 +1132,7 @@ | None -> default_heuristic ~struc heur_adv_ratio game in let heuristics_pp = - Array.map (Array.map SolverIntf.M.register_real_expr) heuristics in + Array.map (Array.map Solver.M.register_real_expr) heuristics in let agents = Array.map (fun loc -> {ev_game = @@ -1158,7 +1158,7 @@ | None -> default_heuristic ~struc default_adv_ratio orig_game in let heuristics_pp = - Array.map (Array.map SolverIntf.M.register_real_expr) heuristics in + Array.map (Array.map Solver.M.register_real_expr) heuristics in let evgame gloc = {ev_game = {Arena.rules=[]; Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Play/GameTest.ml 2010-12-06 00:34:31 UTC (rev 1228) @@ -124,7 +124,7 @@ player = 0; payoffs = payoffs; payoffs_pp = - Array.map SolverIntf.M.register_real_expr payoffs; + Array.map Solver.M.register_real_expr payoffs; moves = Array.to_list (Array.map (fun (rname, rule) -> {Arena.rule = rname; time_in = 0.1, 0.1; parameters_in = []}, 1) rules1); @@ -134,7 +134,7 @@ player = 1; payoffs = payoffs; payoffs_pp = - Array.map SolverIntf.M.register_real_expr payoffs; + Array.map Solver.M.register_real_expr payoffs; moves = Array.to_list (Array.map (fun (rname, rule) -> {Arena.rule = rname; time_in = 0.1, 0.1; parameters_in = []}, 0) rules2); @@ -620,7 +620,7 @@ in let ev (p,e) = p^": "^(string_of_float - (SolverIntf.M.get_real_val e state.Arena.struc)) in + (Solver.M.get_real_val e state.Arena.struc)) in let answ = String.concat ", " (List.sort compare (List.map ev payoffs)) in assert_equal ~msg:"black wins: direct" ~printer:(fun x->x) Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Play/Heuristic.ml 2010-12-06 00:34:31 UTC (rev 1228) @@ -584,8 +584,8 @@ List.map Formula.to_fo (FormulaOps.free_vars phi) in if vars = [] then Or [] else - let aset = SolverIntf.M.evaluate struc - (SolverIntf.M.register_formula phi) in + let aset = Solver.M.evaluate struc + (Solver.M.register_formula phi) in let substs = AssignmentSet.fo_assgn_to_list elems vars aset in (* sort substitutions; TODO: optimizable *) @@ -633,8 +633,8 @@ (* }}} *) let substs = AssignmentSet.fo_assgn_to_list elems vars - (SolverIntf.M.evaluate struc - (SolverIntf.M.register_formula phi)) in + (Solver.M.evaluate struc + (Solver.M.register_formula phi)) in (* sort substitutions; TODO: optimizable *) let substs = trunc_to_vars vars substs in let all_vars = add_strings (List.map var_str vars) all_vars in Modified: trunk/Toss/Solver/AssignmentSet.mli =================================================================== --- trunk/Toss/Solver/AssignmentSet.mli 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Solver/AssignmentSet.mli 2010-12-06 00:34:31 UTC (rev 1228) @@ -1,9 +1,9 @@ -(* This module contains the main type for partial assignments of +(** This module contains the main type for partial assignments of values to variables. *) -(* ------------------------- BASIC TYPE DEFINITION -------------------------- *) +(** {2 Basic type definition.} *) -(* We represent assignment sets as trees. Below a variable we keep a +(** We represent assignment sets as trees. Below a variable we keep a tree of all assignments which assign this variable the same value. For an MSO variable X, we keep a list of elements which must be and which must not be in X. For real-valued variables, we keep @@ -18,32 +18,32 @@ | Real of (Poly.polynomial * Formula.sign_op) list list -(* --------------------- PRINTING AND HELPER FUNCTIONS --------------------- *) +(** {2 Printing and small helper functions.} *) -(* Variables assigned in an assignement set. *) +(** Variables assigned in an assignement set. *) val assigned_vars : Formula.var list -> assignment_set -> Formula.var list -(* Print the given assignment as string. *) +(** Print the given assignment as string. *) val str : assignment_set -> string -(* Print the given assignment as string, using element names. *) +(** Print the given assignment as string, using element names. *) val named_str : Structure.structure -> assignment_set -> string -(* Select an arbitrary assignment for first-order variables with the +(** Select an arbitrary assignment for first-order variables with the given names and default values. Raise [Not_found] if the assignment set is empty. *) val choose_fo : (string * int) list -> assignment_set -> (string * int) list -(* List all tuples the first-order assignment [asg] assigns to [vars] +(** List all tuples the first-order assignment [asg] assigns to [vars] in order in which [vars] are given. [elems] are are all elements. *) val tuples : Structure.Elems.t -> string list -> assignment_set -> int array list -(* Check if a variable is actually present in the assignments tree. *) +(** Check if a variable is actually present in the assignments tree. *) val mem_assoc : [< Formula.var ] -> assignment_set -> bool -(* Convert the FO part of an assingment set into a list of substitutions. *) +(** Convert the FO part of an assingment set into a list of substitutions. *) val fo_assgn_to_list : int list -> Formula.fo_var list -> assignment_set -> (Formula.fo_var * Structure.Elems.elt) list list Modified: trunk/Toss/Solver/Assignments.mli =================================================================== --- trunk/Toss/Solver/Assignments.mli 2010-12-05 22:48:17 UTC (rev 1227) +++ trunk/Toss/Solver/Assignments.mli 2010-12-06 00:34:31 UTC (rev 1228) @@ -1,61 +1,69 @@ -(* This module contains functions for handling partial assignments of +(** This module contains functions for handling partial assignments of values to variables. The main type [assignmnent_set] represents a set of assignments of values to variables and the main functions are [join], [sum], [project] and [complement] with natural meanings. *) -(* ------------------------- BASIC TYPE DEFINITION -------------------------- *) -(* We represent assignment sets as trees. +(** {2 Basic Type Definition} *) + + +(** We represent assignment sets as trees. Variables must occur in order and below a variable we keep a table of all assignments which assign this variable the same value. If an assignment set is not Empty, then it cannot contain Empty leafs. *) type assignment_set = AssignmentSet.assignment_set -(* ------------------------------ LIST SET ---------------------------------- *) +(** {2 List or Set Type} *) -(* Helper type to represent a set or a list of elements with length. *) + +(** Helper type to represent a set or a list of elements with length. *) type set_list = List of int * int list | Set of int * Structure.Elems.t -(* List a set or list ref; changes from set to list if required. *) +(** List a set or list ref; changes from set to list if required. *) val slist : set_list ref -> int list val sllen : set_list ref -> int -(* -------------------------------- JOIN ------------------------------------ *) +(** {2 Join} *) -(* This function joins two assignment sets, i.e. if these represent + +(** This function joins two assignment sets, i.e. if these represent valuations of two formulas, it computes one for the conjunction. *) val join : assignment_set -> assignment_set -> assignment_set -(* -------------------------------- EQUAL ----------------------------------- *) +(** {2 Equality} *) -(* Enforce that in [aset] the variable [u] is equal to [w]. *) + +(** Enforce that in [aset] the variable [u] is equal to [w]. *) val equal_vars : set_list ref -> Formula.fo_var -> Formula.fo_var -> assignment_set -> assignment_set -(* -------------------------------- SUM ------------------------------------- *) +(** {2 Sum} *) -(* Sum of two assignments, assuming that [elems] are all assignable elements. + +(** Sum of two assignments, assuming that [elems] are all assignable elements. We assume that [elems] are sorted. Corresponds to disjunction of formulas. *) val sum : set_list ref -> assignment_set -> assignment_set -> assignment_set -(* ----------------------------- PROJECTION --------------------------------- *) +(** {2 Projection} *) -(* Project assignments on a given variable. We assume that [elems] are all + +(** Project assignments on a given variable. We assume that [elems] are all elements and are sorted. C... [truncated message content] |
From: <luk...@us...> - 2010-12-06 00:46:11
|
Revision: 1229 http://toss.svn.sourceforge.net/toss/?rev=1229&view=rev Author: lukstafi Date: 2010-12-06 00:46:05 +0000 (Mon, 06 Dec 2010) Log Message: ----------- Modified shortcut selection for board predicates (fixed single-character case). Revert to test suite in GameTest. Modified Paths: -------------- trunk/Toss/Play/GameTest.ml trunk/Toss/Solver/Structure.ml trunk/Toss/Solver/StructureTest.ml Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2010-12-06 00:34:31 UTC (rev 1228) +++ trunk/Toss/Play/GameTest.ml 2010-12-06 00:46:05 UTC (rev 1229) @@ -565,7 +565,7 @@ "play: chess suggest first move" >:: (fun () -> - (* todo "Payoff too difficult for heuristic generation."; *) + todo "Payoff too difficult for heuristic generation."; let state = chess_game in Game.set_debug_level 7; Heuristic.debug_level := 7; @@ -1093,14 +1093,14 @@ ); ] -let a () = +let a = Aux.run_test_if_target "GameTest" tests let a () = run_test_tt ~verbose:true experiments (* The same content as in .toss files. *) -let a = +let a () = print_endline ("\n" ^ Arena.sprint_state (snd chess_game)) let a () = Modified: trunk/Toss/Solver/Structure.ml =================================================================== --- trunk/Toss/Solver/Structure.ml 2010-12-06 00:34:31 UTC (rev 1228) +++ trunk/Toss/Solver/Structure.ml 2010-12-06 00:46:05 UTC (rev 1229) @@ -544,10 +544,13 @@ - when there is no element in a position, the upper line is changed to " " and the lower line to "* " - - the predicates on an element are expressed using the least - amount of chars and the parsing/printing rules and written over - the default lower, then upper, line, remaining predicates are - stored to print separately + - the predicates on an element longer than one character are + expressed using two characters for relations with unique two + character prefix, and using three characters for unique three + character prefix (but 3 chars only for cases without + modifiers), and the parsing/printing rules, and written over the + default lower, then upper, line, remaining predicates are stored + to print separately - the row and column relations are determined such that they hold for all (existing) elements as required (they need not be @@ -569,25 +572,17 @@ (* Ignore special relations. *) let find_unique all_preds = - (* FIXME: don't force prefix-free *) let all_preds = List.filter (fun r -> r.[0] <> '_') all_preds in (* build a fixed depth trie *) + let uniq1, more_preds = + List.partition (fun r -> String.length r = 1) all_preds in + let uniq1 = List.map (fun p -> p,p) uniq1 in let trie1 = List.fold_left (fun trie pred -> if List.mem_assoc pred.[0] trie then let preds, trie = Aux.pop_assoc pred.[0] trie in (pred.[0], pred::preds)::trie else (pred.[0], [pred])::trie - ) [] all_preds in - let trie1 = List.map (fun (k,preds) -> - let trunc = - List.filter (fun r -> String.length r = 1) preds in - if trunc = [] then k, preds else k, trunc) trie1 in - let uniq1, trie1 = Aux.partition_map - (function (k,[pred]) -> Aux.Left (pred, Char.escaped k) - | subt -> Aux.Right subt) trie1 in - let trie1 = List.map - (fun (k, preds) -> k, List.filter - (fun pred -> String.length pred > 1) preds) trie1 in + ) [] more_preds in let trie2 = Aux.concat_map (fun (key, preds) -> let trie2 = @@ -600,13 +595,11 @@ List.map (fun (key2, preds) -> Char.escaped key ^ Char.escaped key2, preds) trie2 ) trie1 in - let trie2 = List.map (fun (k,preds) -> - let trunc = - List.filter (fun r -> String.length r = 2) preds in - if trunc = [] then k, preds else k, trunc) trie2 in let uniq2, trie2 = Aux.partition_map (function (k,[pred]) -> Aux.Left (pred, k) | subt -> Aux.Right subt) trie2 in + (* deliberately losing two-char long predicates that are not + prefix-unique: they might be confusing *) let trie2 = List.map (fun (k, preds) -> k, List.filter (fun pred -> String.length pred > 2) preds) trie2 in Modified: trunk/Toss/Solver/StructureTest.ml =================================================================== --- trunk/Toss/Solver/StructureTest.ml 2010-12-06 00:34:31 UTC (rev 1228) +++ trunk/Toss/Solver/StructureTest.ml 2010-12-06 00:46:05 UTC (rev 1229) @@ -221,10 +221,25 @@ test_parse ~msg:"Unique by 1 character" "[ | Alpha:1 {}; Beta:1 {} | ] \" - A B + Al Be + Al + . Be +\""; + (* "A" not in signature, because its name is recoverable from board *) + test_parse ~msg:"Single character + unique by 1 character" +"[ | Alpha:1 {}; Beta:1 {} | ] \" + + Al Be A - . B + . Be \""; + test_parse ~msg:"Single character + unique by 2 characters" +"[ | Alpha:1 {}; Ampr:1 {} | ] \" + + Al Am + A + . Am +\""; test_parse ~msg:"Unique by 3 characters" "[ | Aleph:1 {}; Alpha:1 {} | ] \" @@ -240,16 +255,16 @@ test_parse ~msg:"3 predicates" "[ | Alpha:1 {}; Beta:1 {}; Gamma:1 {} | ] \" - ? ?B + ? ?Be - #A B? + #AlBe? \""; test_parse ~msg:"2 predicates" "[ | Alpha:1 {}; Beta:1 {} | ] \" - ? ?B + ? ?Be - #A B? + #AlBe? \""; ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-07 00:26:46
|
Revision: 1231 http://toss.svn.sourceforge.net/toss/?rev=1231&view=rev Author: lukaszkaiser Date: 2010-12-07 00:26:40 +0000 (Tue, 07 Dec 2010) Log Message: ----------- Correct bounce, add debugging info. Modified Paths: -------------- trunk/Toss/Arena/ContinuousRule.ml trunk/Toss/Arena/DiscreteRule.ml trunk/Toss/examples/bounce.toss Modified: trunk/Toss/Arena/ContinuousRule.ml =================================================================== --- trunk/Toss/Arena/ContinuousRule.ml 2010-12-06 22:12:51 UTC (rev 1230) +++ trunk/Toss/Arena/ContinuousRule.ml 2010-12-07 00:26:40 UTC (rev 1231) @@ -4,7 +4,9 @@ let get_time_step () = !time_step let set_time_step x = (time_step := x) +let debug_level = ref 0; + (* ---------------- BASIC TYPE DEFINITION AND CONSTRUCTOR ------------------- *) (* Specification of a continuous rewriting rule, as in modelling document. *) @@ -82,6 +84,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 + if !debug_level > 1 then print_endline ("ct: " ^ (string_of_float !time)); let left_elname le = Structure.elem_str r.discrete.DiscreteRule.lhs_struc le in let subst_params tm = @@ -108,6 +111,7 @@ 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!*) + if !debug_level > 1 then print_endline ("et: " ^ (string_of_float end_time)); let is_inv s = Solver.M.check_formula s r.inv_pp in let lhs_to_model ((f, a), _) = (* dynamics refer to elements by LHS matches *) @@ -129,8 +133,14 @@ if (is_inv !cur_struc) then ( all_vals := !cur_vals :: !all_vals ; last_struc := !cur_struc - ) else - cur_vals := List.hd !all_vals ; + ) else ( + if (!debug_level > 1) then ( + print_endline "Invariant failed."; + print_endline (Structure.str !cur_struc); + print_endline (Formula.sprint r.inv); + ) ; + 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 Modified: trunk/Toss/Arena/DiscreteRule.ml =================================================================== --- trunk/Toss/Arena/DiscreteRule.ml 2010-12-06 22:12:51 UTC (rev 1230) +++ trunk/Toss/Arena/DiscreteRule.ml 2010-12-07 00:26:40 UTC (rev 1231) @@ -458,12 +458,16 @@ check invariants nor postconditions. *) let rewrite_single model (matching : matching) rule_obj : Structure.structure = - let ldmap = - try - List.map (fun (l,d)-> - SIMap.find l rule_obj.lhs_elem_inv_names, d) matching - with _ -> - failwith "rewrite_single: rule_obj inconsistent with matching" in + let find_fst_name simap (name, x) = + try (SIMap.find name simap, x) with Not_found -> + let mtch_str (a, b) = (string_of_int a) ^ " <- " ^ (string_of_int b) in + let m_s = "{ "^ String.concat ", " (List.map mtch_str matching) ^ " }" in + let bd_add_str a b acc = acc ^ ", " ^ (string_of_int a) ^ ": " ^ b in + let map_s = SIMap.fold bd_add_str simap "" in + let general_s = "rewrite_single: rule_obj inconsistent with matching " in + let name_s = string_of_int name in + failwith (general_s ^ m_s ^"; missing "^ name_s ^ " in: "^ map_s ^ ".") in + let ldmap = List.map (find_fst_name rule_obj.lhs_elem_inv_names) matching in rewrite_single_aux model ldmap rule_obj Modified: trunk/Toss/examples/bounce.toss =================================================================== --- trunk/Toss/examples/bounce.toss 2010-12-06 22:12:51 UTC (rev 1230) +++ trunk/Toss/examples/bounce.toss 2010-12-07 00:26:40 UTC (rev 1231) @@ -14,7 +14,7 @@ y(1) = y(1); x(1) = x(1) pre true - inv ex x ((lhs_1(x) and ((((:y(x) + (-1. * 0.)) + + inv ex x ((_lhs_1(x) and ((((:y(x) + (-1. * 0.)) + (-1. * 0.)) + (-1. * 0.)) < 0))) post true LOC 0 { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-07 16:19:26
|
Revision: 1233 http://toss.svn.sourceforge.net/toss/?rev=1233&view=rev Author: lukstafi Date: 2010-12-07 16:19:19 +0000 (Tue, 07 Dec 2010) Log Message: ----------- Simple test fixes (mostly adjustments to new FFTNF). Modified Paths: -------------- trunk/Toss/Arena/ArenaTest.ml trunk/Toss/Arena/ContinuousRuleTest.ml trunk/Toss/Arena/DiscreteRuleTest.ml trunk/Toss/Play/Game.ml trunk/Toss/Play/GameTest.ml trunk/Toss/Play/HeuristicTest.ml trunk/Toss/Solver/FFSolverTest.ml Modified: trunk/Toss/Arena/ArenaTest.ml =================================================================== --- trunk/Toss/Arena/ArenaTest.ml 2010-12-07 14:35:28 UTC (rev 1232) +++ trunk/Toss/Arena/ArenaTest.ml 2010-12-07 16:19:19 UTC (rev 1233) @@ -71,8 +71,8 @@ PLAYER black PAYOFF {white: 0.3; black: :(ex x Q(x))} } STATE LOC 1" in - let res1 = "REL Q(x) {ex y R(y, x)} -REL P(x) {ex y R(x, y)} + let res1 = "REL P(x) {ex y R(x, y)} +REL Q(x) {ex y R(y, x)} PLAYERS white, black RULE finish: [a, b | R (a, b) | ] -> [a, c, b | R {(a, c); (c, b)} | ] emb R @@ -90,8 +90,8 @@ Arena.equational_def_style := false; assert_equal ~printer:(fun x->x) ~msg:"curly braces style" res1 (Arena.sprint_state gs); - let res2 = "REL Q(x) = ex y R(y, x) -REL P(x) = ex y R(x, y) + let res2 = "REL P(x) = ex y R(x, y) +REL Q(x) = ex y R(y, x) PLAYERS white, black RULE finish: [a, b | R (a, b) | ] -> [a, c, b | R {(a, c); (c, b)} | ] emb R Modified: trunk/Toss/Arena/ContinuousRuleTest.ml =================================================================== --- trunk/Toss/Arena/ContinuousRuleTest.ml 2010-12-07 14:35:28 UTC (rev 1232) +++ trunk/Toss/Arena/ContinuousRuleTest.ml 2010-12-07 16:19:19 UTC (rev 1233) @@ -26,24 +26,24 @@ "[a, b | R (a, b) | ] -> [c, d | R (c, d) | ] emb R with [c <- a, d <- b] " in let s = discr ^ " pre true inv true post true" in let signat = ["R", 2] in - let r = rule_of_str s signat [] in + let r = rule_of_str s signat [] "rule1" in assert_equal ~msg:"1. no continuous" ~printer:(fun x->x) s (str r); let upd_eq = " f(c) = 2. * f(a);\n f(d) = f(b)\n" in let s = discr ^ "\nupdate\n" ^ upd_eq ^ " pre true inv true post true" in - let r = rule_of_str s signat [] in + let r = rule_of_str s signat [] "rule2" in assert_equal ~msg:"2. update" ~printer:(fun x->x) s (str r); let dyn_eq = " f(a)' = (2. * f(a)) + t;\n f(b)' = f(b)" in let s = discr ^ "\ndynamics\n" ^ dyn_eq ^ " pre true inv true post true" in - let r = rule_of_str s signat [] in + let r = rule_of_str s signat [] "rule3" in assert_equal ~msg:"3. dynamics" ~printer:(fun x->x) s (str r); let dyn_eq = " f(a)' = (2. * f(a)) + t;\n f(b)' = f(b)" in let upd_eq = " f(c) = 2. * f(a);\n f(d) = f(b)\n" in let s = discr ^ "\ndynamics\n" ^ dyn_eq ^ "\nupdate\n" ^ upd_eq ^ " pre true inv true post true" in - let r = rule_of_str s signat [] in + let r = rule_of_str s signat [] "rule4" in assert_equal ~msg:"4. dynamics+update" ~printer:(fun x->x) s (str r); ); @@ -53,25 +53,25 @@ "[a, b | R (a, b) | ] -> [c, d | R (c, d) | ] emb R with [c <- a, d <- b]" in let s = discr in let signat = ["R", 2] in - let r = rule_of_str s signat [] in + let r = rule_of_str s signat [] "rule1" in assert_equal ~msg:"1. no continuous" ~printer:(fun x->x) s (sprint r); let upd_eq1 = " f(c) = 2. * f(a);" and upd_eq2 = " f(d) = f(b)" in let upd_eq = upd_eq1 ^ upd_eq2 in let s = discr ^ "\n update" ^ upd_eq in - let r = rule_of_str s signat [] in + let r = rule_of_str s signat [] "rule2" in assert_equal ~msg:"2. update" ~printer:(fun x->x) s (sprint r); let dyn_eq1 = " f(a)' = 2. * f(a) + t;" and dyn_eq2 = " f(b)' = f(b)" in let dyn_eq = dyn_eq1 ^ dyn_eq2 in let s = discr ^ "\n dynamics" ^ dyn_eq in - let r = rule_of_str s signat [] in + let r = rule_of_str s signat [] "rule3" in assert_equal ~msg:"3. dynamics" ~printer:(fun x->x) s (sprint r); let s = discr ^ "\n dynamics" ^ dyn_eq ^ "\n update" ^ upd_eq in - let r = rule_of_str s signat [] in + let r = rule_of_str s signat [] "rule4" in assert_equal ~msg:"4. dynamics+update" ~printer:(fun x->x) s (sprint r); let dyn_eq = dyn_eq1 ^ "\n" ^ dyn_eq2 ^ ";\n" ^ dyn_eq1 ^ "\n" ^ dyn_eq2 @@ -79,7 +79,7 @@ let upd_eq = upd_eq1 ^ "\n" ^ upd_eq2 ^ ";\n" ^ upd_eq1 ^ "\n" ^ upd_eq2 ^ ";\n" ^ upd_eq1 ^ "\n" ^ upd_eq2 in let s = discr ^ "\n dynamics\n" ^ dyn_eq ^ "\n update\n" ^ upd_eq in - let r = rule_of_str s signat [] in + let r = rule_of_str s signat [] "rule5" in assert_equal ~msg:"5. many equations" ~printer:(fun x->x) s (sprint r); ); @@ -93,7 +93,7 @@ let s = dr ^ " dynamics " ^ dyn_eq ^ " update " ^ upd_eq ^ " pre true inv true post true " in let struc = struc_of_str "[ | P {a}; Q:1{} | x { a -> 0.0 } ]" in - let r = rule_of_str s signat [] in + let r = rule_of_str s signat [] "rule1" in let m = List.hd (matches struc r) in let res, _, _ = Aux.unsome (rewrite_single struc 0.0 m r 1. []) in @@ -113,7 +113,7 @@ " pre true inv true post true " in let signat = ["P", 1; "Q", 1] in let struc = struc_of_str "[ | P {a}; Q:1{} | x { a -> 0.0 } ]" in - let r = rule_of_str s signat [] in + let r = rule_of_str s signat [] "rule1" in let m = List.hd (matches struc r) in let res, _, _ = Aux.unsome (rewrite_single struc 0.0 m r 1. []) in Modified: trunk/Toss/Arena/DiscreteRuleTest.ml =================================================================== --- trunk/Toss/Arena/DiscreteRuleTest.ml 2010-12-07 14:35:28 UTC (rev 1232) +++ trunk/Toss/Arena/DiscreteRuleTest.ml 2010-12-07 16:19:19 UTC (rev 1233) @@ -613,7 +613,7 @@ pre = Formula.And []; rule_s = [1,1]} in assert_one_of ~msg:"del defrel" - ["(O(b) and (not P(b)) and (not Q(b)) and (_del_P(b) or _del_Q(b)))-> (P(b) and (not O(b)))";"((_del_Q(b) or _del_P(b)) and O(b) and (not P(b)) and (not Q(b)))-> (P(b) and (not O(b)))"] + ["(O(b) and (not P(b)) and (not Q(b)) and (_del_P(b) or _del_Q(b)))-> (P(b) and (not O(b)))";"((_del_Q(b) or _del_P(b)) and O(b) and (not P(b)) and (not Q(b)))-> (P(b) and (not O(b)))";"((_del_P(b) and O(b) and (not P(b)) and (not Q(b))) or (_del_Q(b) and O(b) and (not P(b)) and (not Q(b))))-> (P(b) and (not O(b)))"] (rule_obj_str rule_obj); let lhs_struc = struc_of_str "[ e | _opt_D (e); _diffthan_P(e) | ]" in Modified: trunk/Toss/Play/Game.ml =================================================================== --- trunk/Toss/Play/Game.ml 2010-12-07 14:35:28 UTC (rev 1232) +++ trunk/Toss/Play/Game.ml 2010-12-07 16:19:19 UTC (rev 1233) @@ -251,7 +251,7 @@ (* {{{ log entry *) if !debug_level > 3 then ( - Printf.printf "default_hauristic: Computing of payoff %s...\n%!" + Printf.printf "default_heuristic: Computing of payoff %s...\n%!" (Formula.sprint_real payoff); ); Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2010-12-07 14:35:28 UTC (rev 1232) +++ trunk/Toss/Play/GameTest.ml 2010-12-07 16:19:19 UTC (rev 1233) @@ -467,9 +467,12 @@ let breakthrough_heur = breakthrough_heur_adv 1.5 -let chess_game = +let chess_game () = 2.0, state_of_file "./examples/Chess.toss" +let breakthrough_file_game = + 2.0, state_of_file "./examples/Breakthrough.toss" + let check_loc_random = function | Game.Tree_search (_,_,_,evgames) -> if @@ -566,7 +569,7 @@ "play: chess suggest first move" >:: (fun () -> todo "Payoff too difficult for heuristic generation."; - let state = chess_game in + let state = chess_game () in Game.set_debug_level 7; Heuristic.debug_level := 7; FFTNF.debug_level := 4; @@ -581,7 +584,7 @@ "breakthrough payoff" >:: (fun () -> - let state = update_game breakthrough_game + let state = update_game breakthrough_file_game "[ | | ] \" ... ... ... ... B ...B ...B B..B B.. @@ -596,16 +599,16 @@ ... ... ... ... ... B.. ... B.. ... ... ... ... - -B ... ...W ...W ... - ...B ... ... ... - W..+B W..W W..W W..W -\"" 1 in + ... ...W ...W ... + ... ... ... ... + W..B W..W W..W W..W +\"" 0 in (* Game.set_debug_level 5; *) let move_opt = (let p,ps = Game.initialize_default (snd state) ~heur_adv_ratio:(fst state) - ~loc:0 ~effort:5 + ~loc:0 ~effort:2 ~heuristic:breakthrough_heur - ~search_method:"uct_greedy_playouts" () in + ~search_method:"alpha_beta_ord" () in Game.toss ~grid_size:Game.cGRID_SIZE p ps) in assert_equal ~msg:"black wins: suggest" ~printer:(function | Aux.Left (bpos, moves, _, _) -> @@ -1093,7 +1096,7 @@ ); ] -let a = +let a () = Aux.run_test_if_target "GameTest" tests let a () = run_test_tt ~verbose:true experiments @@ -1101,14 +1104,14 @@ (* The same content as in .toss files. *) let a () = - print_endline ("\n" ^ Arena.sprint_state (snd chess_game)) + print_endline ("\n" ^ Arena.sprint_state (snd (chess_game ()))) let a () = Game.set_debug_level 7 -let a () = +let a = match test_filter - ["Game:0:misc:0:play: chess suggest first move"] + ["Game:0:misc:2:breakthrough payoff"] tests with | Some tests -> ignore (run_test_tt ~verbose:true tests) Modified: trunk/Toss/Play/HeuristicTest.ml =================================================================== --- trunk/Toss/Play/HeuristicTest.ml 2010-12-07 14:35:28 UTC (rev 1232) +++ trunk/Toss/Play/HeuristicTest.ml 2010-12-07 16:19:19 UTC (rev 1233) @@ -288,7 +288,7 @@ "of_payoff: tic-tac-toe non monotonic" >:: (fun () -> backtrace ( assert_equal ~printer:(fun x->x) ~msg:"adv_ratio=1.5" - "(Sum (z | P(z) : ((((0.64 + Sum (y | (R(y, z) and P(y)) : (0.96 + Sum (x | (R(x, y) and P(x)) : 1.44)))) + Sum (y | (C(y, z) and P(y)) : (0.96 + Sum (x | (C(x, y) and P(x)) : 1.44)))) + Sum (u | C(z, u) : (0.29 + Sum (y | (R(y, u) and P(y)) : (0.44 + Sum (v | C(y, v) : (0.66 + Sum (x | (R(x, v) and P(x)) : 1.)))))))) + Sum (u0 | C(u0, z) : (0.29 + Sum (y | (R(y, u0) and P(y)) : (0.44 + Sum (v0 | C(v0, y) : (0.66 + Sum (x | (R(x, v0) and P(x)) : 1.))))))))) + (-1. * Sum (z | Q(z) : ((((0.64 + Sum (y | (R(y, z) and Q(y)) : (0.96 + Sum (x | (R(x, y) and Q(x)) : 1.44)))) + Sum (y | (C(y, z) and Q(y)) : (0.96 + Sum (x | (C(x, y) and Q(x)) : 1.44)))) + Sum (u | C(z, u) : (0.29 + Sum (y | (R(y, u) and Q(y)) : (0.44 + Sum (v | C(y, v) : (0.66 + Sum (x | (R(x, v) and Q(x)) : 1.)))))))) + Sum (u0 | C(u0, z) : (0.29 + Sum (y | (R(y, u0) and Q(y)) : (0.44 + Sum (v0 | C(v0, y) : (0.66 + Sum (x | (R(x, v0) and Q(x)) : 1.)))))))))))" + "(Sum (x | P(x) : ((((0.64 + Sum (y | (R(x, y) and P(y)) : (0.96 + Sum (z | (R(y, z) and P(z)) : 1.44)))) + Sum (y | (C(x, y) and P(y)) : (0.96 + Sum (z | (C(y, z) and P(z)) : 1.44)))) + Sum (v0 | R(x, v0) : (0.29 + Sum (y | (C(v0, y) and P(y)) : (0.44 + Sum (u0 | R(y, u0) : (0.66 + Sum (z | (C(u0, z) and P(z)) : 1.)))))))) + Sum (v | R(x, v) : (0.29 + Sum (y | (C(y, v) and P(y)) : (0.44 + Sum (u | R(y, u) : (0.66 + Sum (z | (C(z, u) and P(z)) : 1.))))))))) + (-1. * Sum (x | Q(x) : ((((0.64 + Sum (y | (R(x, y) and Q(y)) : (0.96 + Sum (z | (R(y, z) and Q(z)) : 1.44)))) + Sum (y | (C(x, y) and Q(y)) : (0.96 + Sum (z | (C(y, z) and Q(z)) : 1.44)))) + Sum (v0 | R(x, v0) : (0.29 + Sum (y | (C(v0, y) and Q(y)) : (0.44 + Sum (u0 | R(y, u0) : (0.66 + Sum (z | (C(u0, z) and Q(z)) : 1.)))))))) + Sum (v | R(x, v) : (0.29 + Sum (y | (C(y, v) and Q(y)) : (0.44 + Sum (u | R(y, u) : (0.66 + Sum (z | (C(z, u) and Q(z)) : 1.)))))))))))" (Formula.real_str (Heuristic.map_constants (fun c->(floor (c*.100.))/.100.) (Heuristic.of_payoff 1.5 @@ -296,7 +296,7 @@ (real_of_str (":("^winPxyz^") - :("^winQxyz^")"))))); assert_equal ~printer:(fun x->x) ~msg:"adv_ratio=10" - "(Sum (z | P(z) : ((((0.0101 + Sum (y | (R(y, z) and P(y)) : (0.101 + Sum (x | (R(x, y) and P(x)) : 1.01)))) + Sum (y | (C(y, z) and P(y)) : (0.101 + Sum (x | (C(x, y) and P(x)) : 1.01)))) + Sum (u | C(z, u) : (0.001 + Sum (y | (R(y, u) and P(y)) : (0.01 + Sum (v | C(y, v) : (0.1 + Sum (x | (R(x, v) and P(x)) : 1.)))))))) + Sum (u0 | C(u0, z) : (0.001 + Sum (y | (R(y, u0) and P(y)) : (0.01 + Sum (v0 | C(v0, y) : (0.1 + Sum (x | (R(x, v0) and P(x)) : 1.))))))))) + (-1. * Sum (z | Q(z) : ((((0.0101 + Sum (y | (R(y, z) and Q(y)) : (0.101 + Sum (x | (R(x, y) and Q(x)) : 1.01)))) + Sum (y | (C(y, z) and Q(y)) : (0.101 + Sum (x | (C(x, y) and Q(x)) : 1.01)))) + Sum (u | C(z, u) : (0.001 + Sum (y | (R(y, u) and Q(y)) : (0.01 + Sum (v | C(y, v) : (0.1 + Sum (x | (R(x, v) and Q(x)) : 1.)))))))) + Sum (u0 | C(u0, z) : (0.001 + Sum (y | (R(y, u0) and Q(y)) : (0.01 + Sum (v0 | C(v0, y) : (0.1 + Sum (x | (R(x, v0) and Q(x)) : 1.)))))))))))" + "(Sum (x | P(x) : ((((0.0101 + Sum (y | (R(x, y) and P(y)) : (0.101 + Sum (z | (R(y, z) and P(z)) : 1.01)))) + Sum (y | (C(x, y) and P(y)) : (0.101 + Sum (z | (C(y, z) and P(z)) : 1.01)))) + Sum (v0 | R(x, v0) : (0.001 + Sum (y | (C(v0, y) and P(y)) : (0.01 + Sum (u0 | R(y, u0) : (0.1 + Sum (z | (C(u0, z) and P(z)) : 1.)))))))) + Sum (v | R(x, v) : (0.001 + Sum (y | (C(y, v) and P(y)) : (0.01 + Sum (u | R(y, u) : (0.1 + Sum (z | (C(z, u) and P(z)) : 1.))))))))) + (-1. * Sum (x | Q(x) : ((((0.0101 + Sum (y | (R(x, y) and Q(y)) : (0.101 + Sum (z | (R(y, z) and Q(z)) : 1.01)))) + Sum (y | (C(x, y) and Q(y)) : (0.101 + Sum (z | (C(y, z) and Q(z)) : 1.01)))) + Sum (v0 | R(x, v0) : (0.001 + Sum (y | (C(v0, y) and Q(y)) : (0.01 + Sum (u0 | R(y, u0) : (0.1 + Sum (z | (C(u0, z) and Q(z)) : 1.)))))))) + Sum (v | R(x, v) : (0.001 + Sum (y | (C(y, v) and Q(y)) : (0.01 + Sum (u | R(y, u) : (0.1 + Sum (z | (C(z, u) and Q(z)) : 1.)))))))))))" (Formula.real_str (Heuristic.map_constants (fun c->(floor (c*.10000.))/.10000.) (Heuristic.of_payoff 10. Modified: trunk/Toss/Solver/FFSolverTest.ml =================================================================== --- trunk/Toss/Solver/FFSolverTest.ml 2010-12-07 14:35:28 UTC (rev 1232) +++ trunk/Toss/Solver/FFSolverTest.ml 2010-12-07 16:19:19 UTC (rev 1233) @@ -91,7 +91,7 @@ "eval: first-order quantifier free more" >:: (fun () -> eval_eq "[ | R {(a, b); (c, d)}; P {a; b}; Q{a; c} | ]" "P(x) or Q(x)" - "{ x->b, x->a, x->c }"; + "{ x->c, x->a, x->b }"; ); "eval: first-order with quantifiers more" >:: @@ -177,11 +177,12 @@ . Q . \"" heur_phi - "{ y->b1{ z->c1{ x->a1 } } , y->a2{ z->a3{ x->a1 } } }"; + "{ z->a3{ y->a2{ x->a1 } } , z->c1{ y->b1{ x->a1 } } }"; ); "eval: gomoku heuristic from SolverTest.ml" >:: (fun () -> + todo "Problem: uneliminated Empty inside assignment set"; let heur_phi = "(((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u ((C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) @@ -215,6 +216,26 @@ \"" heur_phi "{ y->d6{ z->e7{ x->c5{ w->b4{ v->a3 } } } } , y->e1{ x->d1{ v->b1{ z->f1{ w->c1 } } } } , y->f1{ x->e1{ v->c1{ z->g1{ w->d1 } } } } , y->g1{ x->f1{ v->d1{ w->e1{ z->h1 } } } } , y->d2{ x->c3{ v->a5{ z->e1{ w->b4 } } } } , y->g5{ x->f6{ v->d8{ w->e7{ z->h4 } } } } , y->g6{ x->f6{ v->d6{ w->e6{ z->h6 } } } } , y->b7{ x->b6{ v->b4{ w->b5{ z->b8 } } } } , y->e7{ x->d6{ z->f8{ w->c5{ v->b4 } } } } , y->f7{ x->e6{ z->g8{ w->d5{ v->c4 } } } } }"); + (* + + { + w->f6{} , + w->e6{ v->d6{ x->f6{ y->g6{ z->h6 } } } } , + w->d6{} , + w->d5{ x->e6{ v->c4{ y->f7{ z->g8 } } } } , + w->c5{ x->d6{ v->b4{ y->e7{ z->f8 } } } } , + w->b5{ v->b4{ x->b6{ y->b7{ z->b8 } } } } , + w->e4{} , + w->c4{} , + w->b4{ x->c5{ v->a3{ y->d6{ z->e7 } } } , x->c3{ v->a5{ y->d2{ z->e1 } } } } , + w->c3{} , + w->f1{} , + w->c1{ x->d1{ y->e1{ v->b1{ z->f1 } } } } , + w->d1{ x->e1{ y->f1{ z->g1{ v->c1 } } } } , + w->e1{ x->f1{ y->g1{ v->d1{ z->h1 } } } } , + w->e7{ x->f6{ y->g5{ z->h4{ v->d8 } } } } } + *) + "get_real_val: tic-tac-toe winning" >:: (fun () -> let heur = real_of_str @@ -271,7 +292,7 @@ W..W W..W W..W W..W \"" in assert_equal ~printer:(fun x->x) - "((not ex x ((B(x) and all y ((not C(y, x)))))) and (W(b1) and (not B(b1)) and (C(b1, b2) and (not (b2 = b1)) and (R(a1, b1) and (not (b1 = a1)) and (not (b2 = a1)) and ((not (b1 = a2)) and R(a2, b2) and (not (b2 = a2)) and C(a1, a2) and (not (a2 = a1)) and (not W(a2)))))))" + "((not ex x ((B(x) and all y ((not C(y, x)))))) and (W(b1) and (not B(b1)) and (R(a1, b1) and (not (b1 = a1)) and (C(b1, b2) and (not (b2 = b1)) and (not (b2 = a1)) and ((not (b1 = a2)) and C(a1, a2) and (not (a2 = a1)) and R(a2, b2) and (not (b2 = a2)) and (not W(a2)))))))" (Formula.str (FFSolver.normalize_for_model brkthr_init brkthr_LHS)); ); @@ -290,7 +311,7 @@ . . . \"" in assert_equal ~printer:(fun x->x) - "((not ex x ((Q(x) and (ex y ((C(x, y) and Q(y) and ex z ((C(y, z) and Q(z))))) or ex y ((R(x, y) and Q(y) and ex z ((R(y, z) and Q(z))))) or ex v0 ((R(x, v0) and ex y ((C(y, v0) and Q(y) and ex u0 ((R(y, u0) and ex z ((C(z, u0) and Q(z))))))))) or ex v ((R(x, v) and ex y ((C(v, y) and Q(y) and ex u ((R(y, u) and ex z ((C(u, z) and Q(z))))))))))))) and ((not P(a1)) and (not Q(a1))))" + "((not ex z ((Q(z) and (ex y ((C(y, z) and Q(y) and ex x ((C(x, y) and Q(x))))) or ex u0 ((C(z, u0) and ex y ((R(y, u0) and Q(y) and ex v0 ((C(y, v0) and ex x ((R(x, v0) and Q(x))))))))) or ex y ((R(y, z) and Q(y) and ex x ((R(x, y) and Q(x))))) or ex u ((C(u, z) and ex y ((R(y, u) and Q(y) and ex v ((C(v, y) and ex x ((R(x, v) and Q(x))))))))))))) and ((not P(a1)) and (not Q(a1))))" (Formula.str (FFSolver.normalize_for_model tictactoe_init tictactoe_LHS)); ); @@ -311,8 +332,9 @@ . . . \"" in + (* not quite completely reviewed, but looks good... *) assert_equal ~printer:(fun x->x) -"((not ex z0 ((P(z0) and (ex y0 ((R(y0, z0) and P(y0) and ex x0 ((R(x0, y0) and P(x0))))) or ex y0 ((C(y0, z0) and P(y0) and ex x0 ((C(x0, y0) and P(x0))))) or ex u ((C(z0, u) and ex y0 ((R(y0, u) and P(y0) and ex v ((C(y0, v) and ex x0 ((R(x0, v) and P(x0))))))))) or ex u0 ((C(u0, z0) and ex y0 ((R(y0, u0) and P(y0) and ex v0 ((C(v0, y0) and ex x0 ((R(x0, v0) and P(x0))))))))))))) and ((P(z) and (not Q(z)) and (C(y, z) and (not Q(y)) and (C(x, y) and (not Q(x))))) or (P(y) and (not Q(y)) and (C(y, z) and (not Q(z)) and (C(x, y) and (not Q(x))))) or (P(z) and (not Q(z)) and (R(y, z) and (not Q(y)) and (R(x, y) and (not Q(x))))) or (P(y) and (not Q(y)) and (R(y, z) and (not Q(z)) and (R(x, y) and (not Q(x))))) or (P(x) and (not Q(x)) and (R(x, y) and (not Q(y)) and (R(y, z) and (not Q(z))))) or (P(x) and (not Q(x)) and (C(x, y) and (not Q(y)) and (C(y, z) and (not Q(z))))) or ((not Q(z)) and ex u ((C(u, z) and (R(y, u) and P(y) and (not Q(y)) and ex v ((C(v, y) and (R(x, v) and (not Q(x))))))))) or (P(x) and (not Q(x)) and ex v0 ((R(x, v0) and (C(y, v0) and (not Q(y)) and ex u0 ((R(y, u0) and (C(z, u0) and (not Q(z))))))))) or (P(z) and (not Q(z)) and ex u0 ((C(z, u0) and (R(y, u0) and (not Q(y)) and ex v0 ((C(y, v0) and (R(x, v0) and (not Q(x))))))))) or (P(x) and (not Q(x)) and ex v ((R(x, v) and (C(v, y) and (not Q(y)) and ex u ((R(y, u) and (C(u, z) and (not Q(z))))))))) or (P(z) and (not Q(z)) and ex u ((C(u, z) and (R(y, u) and (not Q(y)) and ex v ((C(v, y) and (R(x, v) and (not Q(x))))))))) or (P(y) and (not Q(y)) and ex u0 ((R(y, u0) and ex v0 ((C(y, v0) and (C(z, u0) and (not Q(z)) and (R(x, v0) and (not Q(x)))))))))))" +"((not ex x0 ((P(x0) and (ex y0 ((R(x0, y0) and P(y0) and ex z0 ((R(y0, z0) and P(z0))))) or ex y0 ((C(x0, y0) and P(y0) and ex z0 ((C(y0, z0) and P(z0))))) or ex v0 ((R(x0, v0) and ex y0 ((C(v0, y0) and P(y0) and ex u0 ((R(y0, u0) and ex z0 ((C(u0, z0) and P(z0))))))))) or ex v ((R(x0, v) and ex y0 ((C(y0, v) and P(y0) and ex u ((R(y0, u) and ex z0 ((C(z0, u) and P(z0))))))))))))) and ((P(z) and (not Q(z)) and (R(y, z) and (not Q(y)) and (R(x, y) and (not Q(x))))) or (P(x) and (not Q(x)) and (R(x, y) and (not Q(y)) and (R(y, z) and (not Q(z))))) or (P(y) and (not Q(y)) and (R(x, y) and (not Q(x)) and (R(y, z) and (not Q(z))))) or (P(z) and (not Q(z)) and (C(y, z) and (not Q(y)) and (C(x, y) and (not Q(x))))) or (P(x) and (not Q(x)) and (C(x, y) and (not Q(y)) and (C(y, z) and (not Q(z))))) or (P(y) and (not Q(y)) and (C(x, y) and (not Q(x)) and (C(y, z) and (not Q(z))))) or (P(z) and (not Q(z)) and ex u0 ((C(z, u0) and (R(y, u0) and (not Q(y)) and ex v0 ((C(y, v0) and (R(x, v0) and (not Q(x))))))))) or (P(x) and (not Q(x)) and ex v0 ((R(x, v0) and (C(y, v0) and (not Q(y)) and ex u0 ((R(y, u0) and (C(z, u0) and (not Q(z))))))))) or (P(y) and (not Q(y)) and ex v0 ((C(y, v0) and ex u0 ((R(y, u0) and (R(x, v0) and (not Q(x)) and (C(z, u0) and (not Q(z))))))))) or (P(z) and (not Q(z)) and ex u ((C(u, z) and (R(y, u) and (not Q(y)) and ex v ((C(v, y) and (R(x, v) and (not Q(x))))))))) or (P(x) and (not Q(x)) and ex v ((R(x, v) and (C(v, y) and (not Q(y)) and ex u ((R(y, u) and (C(u, z) and (not Q(z))))))))) or (P(y) and (not Q(y)) and ex u ((R(y, u) and ex v ((C(v, y) and (C(u, z) and (not Q(z)) and (R(x, v) and (not Q(x)))))))))))" (* old variant: "((not ex z0 ((P(z0) and (ex y0 ((R(y0, z0) and P(y0) and ex x0 ((R(x0, y0) and P(x0))))) or ex y0 ((C(y0, z0) and P(y0) and ex x0 ((C(x0, y0) and P(x0))))) or ex y0 ((P(y0) and ex x0 ((P(x0) and (ex u ((C(z0, u) and R(y0, u) and ex v ((C(y0, v) and R(x0, v))))) or ex u0 ((C(u0, z0) and R(y0, u0) and ex v0 ((C(v0, y0) and R(x0, v0)))))))))))))) and ((P(z) and (not Q(z)) and (C(y, z) and (not Q(y)) and (C(x, y) and (not Q(x))))) or (P(y) and (not Q(y)) and (C(y, z) and (not Q(z)) and (C(x, y) and (not Q(x))))) or (P(z) and (not Q(z)) and (R(y, z) and (not Q(y)) and (R(x, y) and (not Q(x))))) or (P(y) and (not Q(y)) and (R(y, z) and (not Q(z)) and (R(x, y) and (not Q(x))))) or (P(x) and (not Q(x)) and (R(x, y) and (not Q(y)) and (R(y, z) and (not Q(z))))) or (P(x) and (not Q(x)) and (C(x, y) and (not Q(y)) and (C(y, z) and (not Q(z))))) or ((not Q(z)) and ex u ((C(u, z) and (R(y, u) and P(y) and (not Q(y)) and ex v ((C(v, y) and (R(x, v) and (not Q(x))))))))) or (P(x) and (not Q(x)) and ex v0 ((R(x, v0) and (C(y, v0) and (not Q(y)) and ex u0 ((R(y, u0) and (C(z, u0) and (not Q(z))))))))) or (P(z) and (not Q(z)) and ex u0 ((C(z, u0) and (R(y, u0) and (not Q(y)) and ex v0 ((C(y, v0) and (R(x, v0) and (not Q(x))))))))) or (P(x) and (not Q(x)) and ex v ((R(x, v) and (C(v, y) and (not Q(y)) and ex u ((R(y, u) and (C(u, z) and (not Q(z))))))))) or (P(z) and (not Q(z)) and ex u ((C(u, z) and (R(y, u) and (not Q(y)) and ex v ((C(v, y) and (R(x, v) and (not Q(x))))))))) or (P(y) and (not Q(y)) and ex u0 ((R(y, u0) and ex v0 ((C(y, v0) and (C(z, u0) and (not Q(z)) and (R(x, v0) and (not Q(x)))))))))))"*) (Formula.str (FFSolver.normalize_for_model This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-07 17:50:00
|
Revision: 1234 http://toss.svn.sourceforge.net/toss/?rev=1234&view=rev Author: lukstafi Date: 2010-12-07 17:49:54 +0000 (Tue, 07 Dec 2010) Log Message: ----------- Recent make_rule bug fixed. Modified Paths: -------------- trunk/Toss/Arena/ContinuousRule.ml trunk/Toss/Play/GameTest.ml Modified: trunk/Toss/Arena/ContinuousRule.ml =================================================================== --- trunk/Toss/Arena/ContinuousRule.ml 2010-12-07 16:19:19 UTC (rev 1233) +++ trunk/Toss/Arena/ContinuousRule.ml 2010-12-07 17:49:54 UTC (rev 1234) @@ -34,7 +34,9 @@ let discrete = { discr with DiscreteRule.pre = cpre } in let defrels = List.map (fun (rel,(args,body)) -> rel, (args, body, Solver.M.register_formula body)) defs in - let obj = DiscreteRule.compile_rule signat defrels discr in + (* we use [discrete] instead of [discr] because parser does not + insert precondition into discr! *) + let obj = DiscreteRule.compile_rule signat defrels discrete in { discrete = discrete; compiled = obj ; dynamics = dynamics ; Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2010-12-07 16:19:19 UTC (rev 1233) +++ trunk/Toss/Play/GameTest.ml 2010-12-07 17:49:54 UTC (rev 1234) @@ -1096,7 +1096,7 @@ ); ] -let a () = +let a = Aux.run_test_if_target "GameTest" tests let a () = run_test_tt ~verbose:true experiments @@ -1109,7 +1109,7 @@ let a () = Game.set_debug_level 7 -let a = +let a () = match test_filter ["Game:0:misc:2:breakthrough payoff"] tests This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-07 22:14:51
|
Revision: 1235 http://toss.svn.sourceforge.net/toss/?rev=1235&view=rev Author: lukstafi Date: 2010-12-07 22:14:45 +0000 (Tue, 07 Dec 2010) Log Message: ----------- DiscreteRule: streamlining rewrite_single, tests with integer-named elements. Examples: adapting rewriting_example for Arena test. Modified Paths: -------------- trunk/Toss/Arena/ArenaTest.ml trunk/Toss/Arena/DiscreteRule.ml trunk/Toss/Arena/DiscreteRule.mli trunk/Toss/Arena/DiscreteRuleTest.ml trunk/Toss/examples/rewriting_example.toss Modified: trunk/Toss/Arena/ArenaTest.ml =================================================================== --- trunk/Toss/Arena/ArenaTest.ml 2010-12-07 17:49:54 UTC (rev 1234) +++ trunk/Toss/Arena/ArenaTest.ml 2010-12-07 22:14:45 UTC (rev 1235) @@ -113,8 +113,8 @@ "setting states from examples dir" >:: (fun () -> backtrace ( - skip_if true "Change to simpler and stable example."; - let fname = "./examples/Breakthrough.toss" in + (* skip_if true "Change to simpler and stable example."; *) + let fname = "./examples/rewriting_example.toss" in let file = open_in fname in let contents = String.make 4000 '$' in input_file file contents 0 4000; @@ -126,20 +126,6 @@ Arena.handle_request gs (req_of_str "GET STATE") in assert_equal ~msg:("Set "^fname) ~printer:(fun x->x) contents msg; - (* - let fname = "../examples/Gomoku19x19.toss" in - let file = open_in fname in - let contents = String.make 10000 '$' in - let _ = input_file file contents 0 10000 in - let contents = - String.sub contents 0 (String.index contents '$') in - let s = "SET STATE #" ^ fname ^ "#" ^ contents in - let (gs,_) = Arena.handle_request Arena.empty_state (req_of_str s) in - let (_, msg) = - Arena.handle_request gs (req_of_str "GET STATE") in - assert_equal ~msg:("Set "^fname) ~printer:(fun x->x) - contents msg; - *) )); (* Modified: trunk/Toss/Arena/DiscreteRule.ml =================================================================== --- trunk/Toss/Arena/DiscreteRule.ml 2010-12-07 17:49:54 UTC (rev 1234) +++ trunk/Toss/Arena/DiscreteRule.ml 2010-12-07 22:14:45 UTC (rev 1235) @@ -443,8 +443,12 @@ end else model) model ctups) model neg_tuples -let rewrite_single_aux model ldmap - ({rlmap=rlmap} as rule_obj) = +(* Rewrite the model using the rule at the given matching. Does not + check invariants nor postconditions. *) +let rewrite_single model matching ({rlmap=rlmap} as rule_obj) = + let find_fst_name (name, x) = + elemvar_of_elem rule_obj.lhs_elem_inv_names name, x in + let ldmap = List.map find_fst_name matching in match rlmap with | None -> (* [ldmap = rmmap] *) @@ -454,23 +458,6 @@ rewrite_emb model ldmap rlmap rule_obj -(* Rewrite the model using the rule at the given matching. Does not - check invariants nor postconditions. *) -let rewrite_single model (matching : matching) rule_obj - : Structure.structure = - let find_fst_name simap (name, x) = - try (SIMap.find name simap, x) with Not_found -> - let mtch_str (a, b) = (string_of_int a) ^ " <- " ^ (string_of_int b) in - let m_s = "{ "^ String.concat ", " (List.map mtch_str matching) ^ " }" in - let bd_add_str a b acc = acc ^ ", " ^ (string_of_int a) ^ ": " ^ b in - let map_s = SIMap.fold bd_add_str simap "" in - let general_s = "rewrite_single: rule_obj inconsistent with matching " in - let name_s = string_of_int name in - failwith (general_s ^ m_s ^"; missing "^ name_s ^ " in: "^ map_s ^ ".") in - let ldmap = List.map (find_fst_name rule_obj.lhs_elem_inv_names) matching in - rewrite_single_aux model ldmap rule_obj - - (** {2 Building a rule.} *) open Formula Modified: trunk/Toss/Arena/DiscreteRule.mli =================================================================== --- trunk/Toss/Arena/DiscreteRule.mli 2010-12-07 17:49:54 UTC (rev 1234) +++ trunk/Toss/Arena/DiscreteRule.mli 2010-12-07 22:14:45 UTC (rev 1235) @@ -85,9 +85,9 @@ Rewriting introduces the following form of trace: - +R(tup) = R(tup) and not R_old(tup) - -R(tup) = not R(tup) and R_old(tup) - __right_e(emb[e]) + _new_R(tup) = +R(tup) = R(tup) and not R_old(tup) + _del_R(tup) = -R(tup) = not R(tup) and R_old(tup) + _right_e(emb[e]) where emb[e] is the model element corresponding to a RHS rule element e, or, when LHS and RHS structures have the same Modified: trunk/Toss/Arena/DiscreteRuleTest.ml =================================================================== --- trunk/Toss/Arena/DiscreteRuleTest.ml 2010-12-07 17:49:54 UTC (rev 1234) +++ trunk/Toss/Arena/DiscreteRuleTest.ml 2010-12-07 22:14:45 UTC (rev 1235) @@ -143,6 +143,94 @@ (Structure.str nmodel); ); + + "rewrite: compile_rule integers" >:: + (fun () -> + + let model = + struc_of_str "[ | P:1 {}; R:2 {}; Q{1} | ]" in + let lhs_struc = struc_of_str "[ 1 | | ]" in + let rhs_struc = struc_of_str "[ 1, 2 | P{ (1) } | ]" in + let signat = Structure.StringMap.fold + (fun r ar si -> (r,ar)::si) model.Structure.rel_signature [] in + let rule_obj = compile_rule signat [] + {lhs_struc = lhs_struc; + rhs_struc = rhs_struc; + emb_rels = []; + pre = Formula.And []; + rule_s = [1,1; 2,1]} in + let embs = find_matchings model rule_obj in + let emb = choose_match model rule_obj embs in + let nmodel = + rewrite_single model emb rule_obj in + assert_equal ~printer:(fun x->x) ~msg:"clone, add to twin" + "[1, 2 | P (1); Q {1; 2}; R:2 {}; _new_P (1); _right_1 (1); _right_2 (2) | ]" + (Structure.str nmodel); + + let model = + struc_of_str "[ | P{2}; Q{1} | ]" in + let lhs_struc = struc_of_str "[ | Q{1} | ]" in + let rhs_struc = struc_of_str "[ 1, 2 | Q:1{}; _opt_Q{2}; P{1} | ]" in + let signat = Structure.StringMap.fold + (fun r ar si -> (r,ar)::si) model.Structure.rel_signature [] in + let rule_obj = compile_rule signat [] + {lhs_struc = lhs_struc; + rhs_struc = rhs_struc; + emb_rels = ["P";"Q"]; + pre = Formula.And []; + rule_s = [1,1; 2,1]} in + let embs = find_matchings model rule_obj in + let emb = choose_match model rule_obj embs in + let nmodel = + rewrite_single model emb rule_obj in + assert_equal ~printer:(fun x->x) ~msg:"clone, remove from twin" + "[1, 2, 3 | P {1; 2}; Q (3); _del_Q (1); _new_P (1); _right_1 (1); _right_2 (3) | ]" + (Structure.str nmodel); + + let model = + struc_of_str "[ | R{1}; Q{1}; P:1{ } | ]" in + + let lhs_struc = struc_of_str "[ | Q{1} | ]" in + let rhs_struc = struc_of_str "[ 1, 2 | Q:1{}; P{1} | ]" in + let signat = Structure.StringMap.fold + (fun r ar si -> (r,ar)::si) model.Structure.rel_signature [] in + let rule_obj = compile_rule signat [] + {lhs_struc = lhs_struc; + rhs_struc = rhs_struc; + emb_rels = ["P";"Q"]; + pre = Formula.And []; + rule_s = [1,1; 2,1]} in + let embs = find_matchings model rule_obj in + let emb = choose_match model rule_obj embs in + let nmodel = + rewrite_single model emb rule_obj in + assert_equal ~printer:(fun x->x) ~msg:"clone, remove, add to twin" + "[1, 2 | P (1); Q:1 {}; R {1; 2}; _del_Q {1; 2}; _new_P (1); _right_1 (1); _right_2 (2) | ]" + (Structure.str nmodel); + + let model = + struc_of_str "[ | P:1{ }; R{(1,2)}; C{(2,3)}; D{(1,3)} | ]" in + let lhs_struc = struc_of_str "[ 1,2 | R{ (2,1) } | ]" in + let rhs_struc = struc_of_str "[ 1,2,3 | P{ (2) }; R:2{}; _opt_R { (1,1); (1,2); (1,3); (2,2); (2,3); (3,2); (3,3) } | ]" in + let signat = Structure.StringMap.fold + (fun r ar si -> (r,ar)::si) model.Structure.rel_signature [] in + let rule_obj = compile_rule signat [] + {lhs_struc = lhs_struc; + rhs_struc = rhs_struc; + emb_rels = ["P";"R"]; + pre = Formula.And []; + rule_s = [1,1; 2,2; 3,2]} in + let embs = find_matchings model rule_obj in + let emb = choose_match model rule_obj embs in + let nmodel = + rewrite_single model emb rule_obj in + assert_equal ~printer:(fun x->x) + ~msg:"clone, copy rels, remove, add to twin" + "[1, 2, 3, 4 | C (1, 3); D {(2, 3); (4, 3)}; P (2); R:2 {}; _del_R {(2, 1); (4, 1)}; _new_P (2); _right_1 (1); _right_2 (2); _right_3 (4) | ]" + (Structure.str nmodel); + + ); + "rewrite: compile_rule no change" >:: (fun () -> @@ -638,7 +726,9 @@ let a = Aux.run_test_if_target "DiscreteRuleTest" tests +let a () = DiscreteRule.debug_level := 7 + let a () = - match (test_filter ["DiscreteRule:11:rewrite: compile_rule adding and deleting elements"] tests) with + match (test_filter ["DiscreteRule:4:rewrite: compile_rule integers"] tests) with | Some tests -> ignore (run_test_tt ~verbose:true tests) | None -> () Modified: trunk/Toss/examples/rewriting_example.toss =================================================================== --- trunk/Toss/examples/rewriting_example.toss 2010-12-07 17:49:54 UTC (rev 1234) +++ trunk/Toss/examples/rewriting_example.toss 2010-12-07 22:14:45 UTC (rev 1235) @@ -1,51 +1,59 @@ PLAYERS 1, 2 RULE Rewrite: - [ 1, 2 | R { (1, 2) } | - vx { 1->0., 2->0. }; vy { 1->0., 2->0. }; - x { 1->-56.1, 2->12.1 }; y { 1->-19.8, 2->-16.5 } ] - -> - [ 1, 2, 3, 4 | R { (2, 4) }; S { (2, 1); (2, 3) } | - vx { 1->0., 2->0., 3->0., 4->0. }; vy { 1->0., 2->0., 3->0., 4->0. }; - x { 1->-53.9, 2->-13.2, 3->24.2, 4->-15.4 }; - y { 1->-28.6, 2->-30.8, 3->-29.7, 4->14.3 } ] - emb R with [ 3 <- 2, 2 <- 2, 1 <- 1 ] + [1, 2 | R (1, 2); S:2 {} | + vx {2->0., 1->0.}; vy {2->0., 1->0.}; x {2->12.1, 1->-56.1}; + y {2->-16.5, 1->-19.8} + ] -> + [1, 2, 3, 4 | R (2, 4); S {(2, 1); (2, 3)} | + vx {4->0., 3->0., 2->0., 1->0.}; vy {4->0., 3->0., 2->0., 1->0.}; + x {4->-15.4, 3->24.2, 2->-13.2, 1->-53.9}; + y {4->14.3, 3->-29.7, 2->-30.8, 1->-28.6} + ] emb R with [3 <- 2, 2 <- 2, 1 <- 1] dynamics - vy(2)' = 0.; - vy(1)' = 0.; - vx(2)' = 0.; - vx(1)' = 0.; - y(2)' = 0.; - y(1)' = 0.; - x(2)' = 0.; - x(1)' = 0. + vy(2)' = 0.; + vy(1)' = 0.; + vx(2)' = 0.; + vx(1)' = 0.; + y(2)' = 0.; + y(1)' = 0.; + x(2)' = 0.; + x(1)' = 0. update - vy(4) = 0.; - vy(3) = 0.; - vy(2) = 0.; - vy(1) = 0.; - vx(4) = 0.; - vx(3) = 0.; - vx(2) = 0.; - vx(1) = 0.; - y(4) = (0.5)*(y(2)); - y(3) = y(2); - y(2) = y(2); - y(1) = y(1); - x(4) = x(2); - x(3) = ((2.)*(x(2))) + ((-1.)*(x(1))); - x(2) = x(2); - x(1) = x(1) - pre true inv true post true - LOC 0 { - PLAYER 1 - PAYOFF { - 1: 0.; - 2: 0. - } - MOVES - [Rewrite, t: 1. -- 1. -> 0] - } + vy(4) = 0.; + vy(3) = 0.; + vy(2) = 0.; + vy(1) = 0.; + vx(4) = 0.; + vx(3) = 0.; + vx(2) = 0.; + vx(1) = 0.; + y(4) = 0.5 * y(2); + y(3) = y(2); + y(2) = y(2); + y(1) = y(1); + x(4) = x(2); + x(3) = 2. * x(2) - x(1); + x(2) = x(2); + x(1) = x(1) +LOC 0 {PLAYER 1 PAYOFF {1: 0.; 2: 0.} MOVES [Rewrite, t: 1. -- 1. -> 0]} MODEL - [ 1, 2, 3, 4, 5, 6, 7, 9, 10, 11 | - R { (1, 2) }; S { (1, 4); (1, 11); (2, 6); (2, 10); (3, 1); (5, 2); (7, 1); (9, 2) } | - vx { 1->0., 2->0., 3->0., 4->0., 5->0., 6->0., 7->0., 9->0., 10->0., 11->0. }; vy { 1->0., 2->0., 3->0., 4->0., 5->0., 6->0., 7->0., 9->0., 10->0., 11->0. }; x { 1->-146.255462055, 2->21.302749004, 3->-258.32323745, 4->-120.686436849, 5->-18.5442846716, 6->90.6508710148, 7->-232.262151394, 9->-9.62456175299, 10->103.945266932, 11->-125.119302789 }; y { 1->-198.131474104, 2->-199.490916335, 3->-389.602259761, 4->-388.668637651, 5->-373.881488196, 6->-383.007253961, 7->-11.1358565737, 9->-40.4231593625, 10->-39.0902989992, 11->-22.4325180255 } ] + [1, 2, 3, 4, 5, 6, 7, 9, 10, 11 | + R (1, 2); + S {(1, 4); (1, 11); (2, 6); (2, 10); (3, 1); (5, 2); (7, 1); (9, 2)} + | + vx { + 11->0., 10->0., 9->0., 7->0., 6->0., 5->0., 4->0., 3->0., 2->0., 1->0.}; + vy { + 11->0., 10->0., 9->0., 7->0., 6->0., 5->0., 4->0., 3->0., 2->0., 1->0.}; + x { + 11->-125.119302789, 10->103.945266932, 9->-9.62456175299, + 7->-232.262151394, 6->90.6508710148, 5->-18.5442846716, + 4->-120.686436849, 3->-258.32323745, 2->21.302749004, 1->-146.255462055 + }; + y { + 11->-22.4325180255, 10->-39.0902989992, 9->-40.4231593625, + 7->-11.1358565737, 6->-383.007253961, 5->-373.881488196, + 4->-388.668637651, 3->-389.602259761, 2->-199.490916335, + 1->-198.131474104 + } + ] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-08 00:23:56
|
Revision: 1236 http://toss.svn.sourceforge.net/toss/?rev=1236&view=rev Author: lukstafi Date: 2010-12-08 00:23:46 +0000 (Wed, 08 Dec 2010) Log Message: ----------- Parsimony model in Heuristic. Modified Paths: -------------- trunk/Toss/Formula/FFTNF.mli trunk/Toss/Play/Game.ml trunk/Toss/Play/GameTest.ml trunk/Toss/Play/Heuristic.ml trunk/Toss/Play/Heuristic.mli Modified: trunk/Toss/Formula/FFTNF.mli =================================================================== --- trunk/Toss/Formula/FFTNF.mli 2010-12-07 22:14:45 UTC (rev 1235) +++ trunk/Toss/Formula/FFTNF.mli 2010-12-08 00:23:46 UTC (rev 1236) @@ -14,6 +14,8 @@ *) +val parsimony_threshold_1 : int ref +val parsimony_threshold_2 : int ref val debug_level : int ref Modified: trunk/Toss/Play/Game.ml =================================================================== --- trunk/Toss/Play/Game.ml 2010-12-07 22:14:45 UTC (rev 1235) +++ trunk/Toss/Play/Game.ml 2010-12-08 00:23:46 UTC (rev 1236) @@ -246,15 +246,18 @@ if monotonic then Some (DiscreteRule.fluent_preconds drules signat fluents) else None in - Array.map (fun node -> Array.map + Array.mapi (fun i node -> Array.map (fun payoff -> (* {{{ log entry *) - - if !debug_level > 3 then ( - Printf.printf "default_heuristic: Computing of payoff %s...\n%!" - (Formula.sprint_real payoff); + if !debug_level > 4 then ( + Printf.printf + "default_heuristic: Computing for loc %d of payoff %s...\n%!" + i (Formula.sprint_real payoff); ); - + if !debug_level = 4 then ( + Printf.printf + "default_heuristic: Computing for loc %d\n%!" i; + ); (* }}} *) Heuristic.of_payoff ?struc ?fluent_preconds advance_ratio (Aux.strings_of_list fluents) payoff) Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2010-12-07 22:14:45 UTC (rev 1235) +++ trunk/Toss/Play/GameTest.ml 2010-12-08 00:23:46 UTC (rev 1236) @@ -568,11 +568,11 @@ "play: chess suggest first move" >:: (fun () -> - todo "Payoff too difficult for heuristic generation."; + (* todo "Payoff too difficult for heuristic generation."; *) let state = chess_game () in - Game.set_debug_level 7; - Heuristic.debug_level := 7; - FFTNF.debug_level := 4; + Game.set_debug_level 3; + (* Heuristic.debug_level := 7; *) + (* FFTNF.debug_level := 7; *) let move_opt = (let p,ps = Game.initialize_default (snd state) ~heur_adv_ratio:(fst state) ~loc:0 ~effort:2 @@ -1096,7 +1096,7 @@ ); ] -let a = +let a () = Aux.run_test_if_target "GameTest" tests let a () = run_test_tt ~verbose:true experiments @@ -1109,9 +1109,9 @@ let a () = Game.set_debug_level 7 -let a () = +let a = match test_filter - ["Game:0:misc:2:breakthrough payoff"] + ["Game:0:misc:1:play: chess suggest first move"] tests with | Some tests -> ignore (run_test_tt ~verbose:true tests) Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2010-12-07 22:14:45 UTC (rev 1235) +++ trunk/Toss/Play/Heuristic.ml 2010-12-08 00:23:46 UTC (rev 1236) @@ -14,6 +14,19 @@ H(Phi) = Alg(FFTNF(promote relations F) of Phi', True) where Phi' = ExpandedForm(F, S, FFTNF(promote relations F) of Phi) + Since formula transformations involved in generating the heuristic + are costly, we use the parsimony model from FFTNF: + + (1) at parsimony level 1 (PARL1), we do not compute FFTNF prior to + expanding the formula: + + H(Phi) = Alg(FFTNF(promote relations F) of Phi', True) + where Phi' = ExpandedForm(F, S, Phi) + + (2) at parsimony level 2 (PARL2), we do not expand the formula: + + H(Phi) = Alg(FFTNF(promote relations F) of Phi, True) + Monotonic case (see also the definition of FFSEP(F) in {!FFTNF} module): @@ -800,8 +813,8 @@ ) guards in sum_exprs parts -let of_payoff ?(max_alt_descr=5) ?struc ?fluent_preconds adv_ratio frels expr = - (* FIXME: what [gds] should be doing? it's not doing anything *) +let of_payoff ?force_parsimony + ?(max_alt_descr=5) ?struc ?fluent_preconds adv_ratio frels expr = let rec aux gds = function | RVar _ | Const _ @@ -809,29 +822,40 @@ | Times (a, b) -> Times (aux gds a, aux gds b) | Plus (a, b) -> Plus (aux gds a, aux gds b) | Char phi -> + let parsimony_level = + match force_parsimony with + | Some parl -> parl + | None -> + let size = FormulaOps.size phi in + if size < !FFTNF.parsimony_threshold_1 then 0 + else if size < !FFTNF.parsimony_threshold_2 then 1 + else 2 in (match fluent_preconds with | None -> (* not monotonic *) - let phi' = match struc with - | Some struc -> - (* guards are currently ignored *) - (* {{{ log entry *) - if !debug_level > 2 then ( - Printf.printf - "Heuristic: for expanding, get ff-tnf of %s...\n%!" - (Formula.sprint phi); - ); - (* }}} *) - let phi'' = - FFTNF.ff_tnf (FFTNF.promote_rels frels) phi in - (* {{{ log entry *) - if !debug_level > 2 then ( - Printf.printf - "Heuristic: computing expanded form of %s...\n%!" - (Formula.sprint phi''); - ); - (* }}} *) - expanded_form max_alt_descr frels struc phi'' - | None -> phi in + let phi' = + if parsimony_level > 1 then phi + else match struc with + | Some struc -> + (* TODO: summation guards [gds] are currently ignored *) + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf + "Heuristic: for expanding, get ff-tnf of %s...\n%!" + (Formula.sprint phi); + ); + (* }}} *) + let phi'' = + if parsimony_level > 0 then phi + else FFTNF.ff_tnf (FFTNF.promote_rels frels) phi in + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf + "Heuristic: computing expanded form of %s...\n%!" + (Formula.sprint phi''); + ); + (* }}} *) + expanded_form max_alt_descr frels struc phi'' + | None -> phi in (* {{{ log entry *) if !debug_level > 2 then ( Printf.printf Modified: trunk/Toss/Play/Heuristic.mli =================================================================== --- trunk/Toss/Play/Heuristic.mli 2010-12-07 22:14:45 UTC (rev 1235) +++ trunk/Toss/Play/Heuristic.mli 2010-12-08 00:23:46 UTC (rev 1236) @@ -82,7 +82,8 @@ *) (** Heuristic of payoff expression. *) -val of_payoff : ?max_alt_descr:int -> ?struc:Structure.structure -> +val of_payoff : ?force_parsimony:int -> + ?max_alt_descr:int -> ?struc:Structure.structure -> ?fluent_preconds:(string * (string list * Formula.formula)) list -> float -> Aux.Strings.t -> Formula.real_expr -> Formula.real_expr This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-08 17:33:24
|
Revision: 1240 http://toss.svn.sourceforge.net/toss/?rev=1240&view=rev Author: lukaszkaiser Date: 2010-12-08 17:33:16 +0000 (Wed, 08 Dec 2010) Log Message: ----------- Final release changes. Modified Paths: -------------- trunk/Toss/Client/TossMainWindow.py trunk/Toss/Makefile trunk/Toss/README trunk/Toss/Solver/Structure.mli trunk/Toss/examples/Chess.toss Modified: trunk/Toss/Client/TossMainWindow.py =================================================================== --- trunk/Toss/Client/TossMainWindow.py 2010-12-08 15:17:50 UTC (rev 1239) +++ trunk/Toss/Client/TossMainWindow.py 2010-12-08 17:33:16 UTC (rev 1240) @@ -202,7 +202,7 @@ def about (self): about_text = ' \ - <h2>Toss 0.4</h2> \ + <h2>Toss 0.5</h2> \ <p>Visit Toss website at \ <a href="http://toss.sourceforge.net/">toss.sourceforge.net</a> \ for more information.</p> \ @@ -211,10 +211,6 @@ <li>Lukasz Kaiser</li> \ <li>Tobias Ganzow</li> \ <li>Lukasz Stafiniak</li> \ - <li>Dietmar Berwanger</li> \ - <li>Matko Botincan</li> \ - <li>Diana Fischer</li> \ - <li>Michal Wojcik</li> \ </ul> \ <p>Other contributors are listed on our \ <a href="http://toss.sourceforge.net/contact.html">\ Modified: trunk/Toss/Makefile =================================================================== --- trunk/Toss/Makefile 2010-12-08 15:17:50 UTC (rev 1239) +++ trunk/Toss/Makefile 2010-12-08 17:33:16 UTC (rev 1240) @@ -6,7 +6,19 @@ Server: Play/Server.native cp _build/Play/Server.native Server +Release: + make -C . clean + make -C . Client + make -C . Server + make -C . doc + mkdir ../toss_0.5 + cp -r * ../toss_0.5 + find ../toss_0.5 -name '.svn' -exec rm -rf {} \; + rm -rf ../toss_0.5/_build ../toss_0.5/gmon.out + zip -r toss_0.5.zip ../toss_0.5 + rm -rf ../toss_0.5 + # ------ NON OCAMLBUILD DEPENDENCIES -------- caml_extensions/pa_let_try.cmo: caml_extensions/pa_let_try.ml Modified: trunk/Toss/README =================================================================== --- trunk/Toss/README 2010-12-08 15:17:50 UTC (rev 1239) +++ trunk/Toss/README 2010-12-08 17:33:16 UTC (rev 1240) @@ -2,26 +2,16 @@ * RUNNING TOSS To run Toss you need python, Qt4 (>=4.6 recommended) and PyQt4. -(As a developer, you additionally need ocaml, menhir, ounit and pyqt4-dev-tools.) +Under Ubuntu do "sudo apt-get install python-qt4". +When you have these, just run "./Toss.py" or click on it. -When you have these, just run "python Toss.py". - * COMPILING TOSS -- Installing dependencies under Ubuntu Run the following in terminal: - sudo apt-get install python-qt4 python-dev pyqt4-dev-tools ocaml-findlib menhir -You will also need oUnit: starting from Lucid Lynx just - sudo apt-get install libounit-ocaml-dev -else, and *only if the above failed* do - # wget http://www.xs4all.nl/~mmzeeman/ocaml/ounit-1.0.3.tar.gz - # tar xzf ounit-1.0.3.tar.gz - # cd ounit-1.0.3 - # make allopt - # sudo make install - # cd ..; rm -rf ounit-1.0.3; rm ounit-1.0.3.tar.gz + sudo apt-get install python-qt4 python-dev pyqt4-dev-tools ocaml-findlib menhir libounit-ocaml-dev Finally to compile Toss just type make @@ -32,7 +22,7 @@ * AUTHORS The current version of Toss is developed by -- Łukasz Kaiser (ka...@lo...) +- Łukasz Kaiser (ka...@li...) - Tobias Ganzow - Łukasz Stafiniak Modified: trunk/Toss/Solver/Structure.mli =================================================================== --- trunk/Toss/Solver/Structure.mli 2010-12-08 15:17:50 UTC (rev 1239) +++ trunk/Toss/Solver/Structure.mli 2010-12-08 17:33:16 UTC (rev 1240) @@ -1,24 +1,24 @@ -(* Representing Structures *) +(** Representing Structures *) val debug_level : int ref -module IntMap : Map.S with type key = int (* Maps from int to 'alpha *) +module IntMap : Map.S with type key = int (** Maps from int to 'alpha *) -module StringMap : Map.S with type key = string (* Maps from string to 'alpha*) +module StringMap : Map.S with type key = string (** Maps from string to 'alpha*) -module Elems : Set.S with type elt = int (* Sets of integers *) +module Elems : Set.S with type elt = int (** Sets of integers *) val add_elems : int list -> Elems.t -> Elems.t val elems_of_list : int list -> Elems.t module Tuples : Set.S with type elt = int array -(* No element is named by a decimal numeral other than its +(** 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. *) + 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 ; @@ -31,59 +31,60 @@ val equal : structure -> structure -> bool -(* ----------------------- BASIC HELPER FUNCTIONS --------------------------- *) +(** {2 Basic helper functions} *) -(* Reverse a map: make a string IntMap from an int StringMap. *) + +(** Reverse a map: make a string IntMap from an int StringMap. *) val rev_string_to_int_map : int StringMap.t -> string IntMap.t -(* Reverse a map: make an int StringMap from a string IntMap. *) +(** Reverse a map: make an int StringMap from a string IntMap. *) val rev_int_to_string_map : string IntMap.t -> int StringMap.t -(* Return the empty structure (with empty signature). *) +(** Return the empty structure (with empty signature). *) val empty_structure : unit -> structure -(* Return the empty structure with given relational signature. *) +(** Return the empty structure with given relational signature. *) val empty_with_signat : (string * int) list -> structure -(* Return the list of relation tuples incident to an element [e] in [struc]. *) +(** Return the list of relation tuples incident to an element [e] in [struc]. *) val incident : structure -> int -> (string * int array list) list -(* Check if a relation holds for a tuple. *) +(** Check if a relation holds for a tuple. *) val check_rel : structure -> string -> int array -> bool -(* Return the value of function [f] on [e] in [struc]. *) +(** Return the value of function [f] on [e] in [struc]. *) val fun_val : structure -> string -> int -> float -(* Return the list of functions. *) +(** Return the list of functions. *) val f_signature : structure -> string list -(* ------------------------ PRINTING STRUCTURES ----------------------------- *) +(** {2 Printing structures} *) -(* Print the elements [e] as string. *) +(** Print the elements [e] as string. *) val elem_str : structure -> int -> string -(* Print the tuple [tp] as string. When [with_paren] is set to false, +(** Print the tuple [tp] as string. When [with_paren] is set to false, avoid printing parentheses around one-element tuple. *) val tuple_str : ?with_paren:bool -> structure -> int array -> string -(* Print the relation named [rel_name] with tuples [ts] as +(** Print the relation named [rel_name] with tuples [ts] as string. Unless [print_arity] is false, print the arity if [ts] is empty. *) val rel_str : ?print_arity:bool -> structure -> string -> Tuples.t -> string -(* Print the function named [fun_name] with values [vals] as string. *) +(** Print the function named [fun_name] with values [vals] as string. *) val fun_str : structure -> string -> float IntMap.t -> string -(* Print relational signature. *) +(** Print relational signature. *) val sig_str : structure -> string -(* Print the structure [struc] as string, in extensive form (not using +(** Print the structure [struc] as string, in extensive form (not using condensed representations like boards). *) val ext_str : structure -> string -(* Print the structure [struc] as string. *) +(** Print the structure [struc] as string. *) val str : structure -> string @@ -105,89 +106,94 @@ val sprint : structure -> string -(* ---------- ADDING ELEMENTS POSSIBLY WITH STRING NAMES ---------- *) +(** {2 Adding elements possibly with string names} *) -(* Nonexisting elements or relations, signature mismatch, etc. *) + +(** Nonexisting elements or relations, signature mismatch, etc. *) exception Structure_mismatch of string -(* Add element [e] to [struc] if it is not yet there. Return new structure. *) +(** Add element [e] to [struc] if it is not yet there. Return new structure. *) val add_elem : structure -> ?name:string -> int -> structure -(* Add new element to [struc], return the updated structure and the +(** Add new element to [struc], return the updated structure and the element. *) val add_new_elem : structure -> ?name:string -> unit -> structure * int val find_elem : structure -> string -> int -(* Find an element in the structure, and if not present, add new one. *) +(** Find an element in the structure, and if not present, add new one. *) val find_or_new_elem : structure -> string -> structure * int -(* --------- ADDING RELATION TUPLES POSSIBLY WITH NAMED ELEMENTS ---------- *) -(* Ensure relation named [rn] exists in [struc], add if needed. *) +(** {2 Adding relation tuples possibly with named elements} *) + + +(** 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 +(** 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]. *) +(** Add tuple [tp] to relation [rn] in structure [struc]. *) val add_rel : structure -> string -> int array -> structure -(* Add tuples [tps] to relation [rn] in structure [struc]. *) +(** Add tuples [tps] to relation [rn] in structure [struc]. *) val add_rels : structure -> string -> int array list -> structure -(* Return a structure with a single relation of given arity, over a +(** Return a structure with a single relation of given arity, over a single tuple, of different elements. *) val free_for_rel : string -> int -> structure -(* --------- ADDING FUNCTION ASSINGMENTS POSSIBLY TO NAMED ELEMENTS --------- *) -(* Add function assignment [e] -> [x] to function [fn] in structure [struc]. *) +(** {2 Adding function assignments possibly to named elements} *) + + +(** Add function assignment [e] -> [x] to function [fn] in structure [struc]. *) val add_fun : structure -> string -> int * float -> structure -(* Add function assignments [assgns] to [fn] in structure [struc]. *) +(** Add function assignments [assgns] to [fn] in structure [struc]. *) val add_funs : structure -> string -> (int * float) list -> structure -(* ------------ GLOBAL FUNCTION TO CREATE STRUCTURES FROM LISTS ------------ *) +(** {2 Global function to create structures from lists} *) val create_from_lists : ?struc:structure -> string list -> (string * int option * string array list) list -> (string * (string * float) list) list -> structure -(* ---------- REMOVING RELATION TUPLES AND ELEMENTS FROM A STRUCTURE -------- *) +(** {2 Removing relation tuples and elements from a structure} *) -(* Remove the tuple [tp] from relation [rn] in structure [struc]. May +(** 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). *) val del_rel : structure -> string -> int array -> structure -(* Remove the tuples [tps] from relation [rn] in structure [struc]. May +(** 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). *) val del_rels : structure -> string -> int array list -> structure -(* Remove all relations matching the predicate. By default, also remove +(** 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 -(* Remove the element [e] and all incident relation tuples from [struc]. *) +(** Remove the element [e] and all incident relation tuples from [struc]. *) val del_elem : structure -> int -> structure -(* Remove elements [es] and all incident relation tuples from +(** Remove elements [es] and all incident relation tuples from [struc]. Return the resulting structure and deleted relation tuples. *) val del_elems : structure -> int list -> structure * (string * int array list) list -(* Remove the elements that are not incident to any relation (and have +(** Remove the elements that are not incident to any relation (and have no defined properties, unless [ignore_funs] is given). *) val gc_elems : ?ignore_funs:bool -> structure -> structure -(* -------------------- PARSER HELPERS -------------------- *) +(** {2 Parser Helpers} *) exception Board_parse_error of string Modified: trunk/Toss/examples/Chess.toss =================================================================== --- trunk/Toss/examples/Chess.toss 2010-12-08 15:17:50 UTC (rev 1239) +++ trunk/Toss/examples/Chess.toss 2010-12-08 17:33:16 UTC (rev 1240) @@ -1,4 +1,5 @@ PLAYERS 1, 2 +DATA depth: 1 REL IsFirst(x) = not ex z C(z, x) REL IsSecond(x) = ex y (C(y, x) and IsFirst(y)) REL IsEight(x) = not ex z C(x, z) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-10 14:21:14
|
Revision: 1243 http://toss.svn.sourceforge.net/toss/?rev=1243&view=rev Author: lukstafi Date: 2010-12-10 14:21:08 +0000 (Fri, 10 Dec 2010) Log Message: ----------- input_file reads a file returning a string. Handle reported parse errors in Server. Server test suite invoked by GameTest. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/ArenaTest.ml trunk/Toss/Formula/Aux.ml trunk/Toss/Formula/Aux.mli trunk/Toss/Play/GameTest.ml trunk/Toss/Play/Server.ml Added Paths: ----------- trunk/Toss/Play/ServerTest.in trunk/Toss/Play/ServerTest.out Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2010-12-09 20:05:14 UTC (rev 1242) +++ trunk/Toss/Arena/Arena.ml 2010-12-10 14:21:08 UTC (rev 1243) @@ -561,8 +561,6 @@ AddElem loc -> apply_to_loc add_new_elem loc state "add elem" | AddRel (loc, rel, tp) -> - (* FIXME: remove this note if AddRel needs to add new - elements, otherwise simplify *) let add_rel struc = let struc, tp = List.fold_right (fun n (struc, tp) -> Modified: trunk/Toss/Arena/ArenaTest.ml =================================================================== --- trunk/Toss/Arena/ArenaTest.ml 2010-12-09 20:05:14 UTC (rev 1242) +++ trunk/Toss/Arena/ArenaTest.ml 2010-12-10 14:21:08 UTC (rev 1243) @@ -8,11 +8,6 @@ let gs_of_str s = ArenaParser.parse_game_state Lexer.lex (Lexing.from_string s) -let rec input_file file buf begpos buflen = - let nread = input file buf begpos buflen in - if nread > 0 && buflen - nread > 0 then - input_file file buf (begpos+nread) (buflen-nread) - let apply_rule gs rname match_str = let s = "SET RULE " ^ rname ^ " MODEL " ^ match_str ^ " 0.1" in snd (Arena.handle_request Arena.empty_state (req_of_str s)) @@ -116,10 +111,7 @@ (* skip_if true "Change to simpler and stable example."; *) let fname = "./examples/rewriting_example.toss" in let file = open_in fname in - let contents = String.make 4000 '$' in - input_file file contents 0 4000; - let contents = - String.sub contents 0 (String.index contents '$') in + let contents = Aux.input_file file in let s = "SET STATE #" ^ fname ^ "#" ^ contents in let (gs,_) = Arena.handle_request Arena.empty_state (req_of_str s) in let (_, msg) = @@ -128,21 +120,6 @@ contents msg; )); -(* - "Chess taking a pawn and moving" >:: - (fun () -> backtrace ( - let fname = "./examples/Chess.toss" in - let file = open_in fname in - let contents = String.make 10000 '$' in - input_file file contents 0 10000; - let contents = - String.sub contents 0 (String.index contents '$') in - let s = "SET STATE #" ^ fname ^ "#" ^ contents in - let (gs,_) = - Arena.handle_request Arena.empty_state (req_of_str s) in - let gs = apply_rule "WhitePawnDbl" "a1: " - )); -*) ] let a = Modified: trunk/Toss/Formula/Aux.ml =================================================================== --- trunk/Toss/Formula/Aux.ml 2010-12-09 20:05:14 UTC (rev 1242) +++ trunk/Toss/Formula/Aux.ml 2010-12-10 14:21:08 UTC (rev 1243) @@ -390,3 +390,10 @@ (* So that the tests are not run twice while building TossTest. *) if test_fname then ignore (OUnit.run_test_tt ~verbose:true tests) + +let rec input_file file = + let buf = Buffer.create 256 in + (try + while true do Buffer.add_channel buf file 1 done + with End_of_file -> ()); + Buffer.contents buf Modified: trunk/Toss/Formula/Aux.mli =================================================================== --- trunk/Toss/Formula/Aux.mli 2010-12-09 20:05:14 UTC (rev 1242) +++ trunk/Toss/Formula/Aux.mli 2010-12-10 14:21:08 UTC (rev 1243) @@ -182,3 +182,6 @@ (** Run a test suite if the executable name matches the given prefix. *) val run_test_if_target : string -> OUnit.test -> unit + +(** Input a file to a string. *) +val input_file : in_channel -> string Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2010-12-09 20:05:14 UTC (rev 1242) +++ trunk/Toss/Play/GameTest.ml 2010-12-10 14:21:08 UTC (rev 1243) @@ -545,6 +545,22 @@ let misc_tests = "misc" >::: [ + + "server: check ServerTest.in response" >:: + (fun () -> + let in_ch = open_in "./Play/ServerTest.in" in + let out_ch = open_out "./Play/ServerTest.temp" in + (try while true do + Server.req_handle in_ch out_ch done + with End_of_file -> ()); + close_in in_ch; close_out out_ch; + let result = + Aux.input_file (open_in "./Play/ServerTest.temp") in + let target = + Aux.input_file (open_in "./Play/ServerTest.out") in + Sys.remove "./Play/ServerTest.temp"; + assert_equal ~printer:(fun x->x) target result + ); "play: breakthrough suggest in game" >:: (fun () -> @@ -1107,10 +1123,10 @@ ); ] -let a () = +let a = Aux.run_test_if_target "GameTest" tests -let a = run_test_tt ~verbose:true experiments +let a () = run_test_tt ~verbose:true experiments (* The same content as in .toss files. *) @@ -1122,7 +1138,7 @@ let a () = match test_filter - ["Game:1:alpha_beta_ord:11:gomoku8x8 avoid endgame"] + ["Game:0:misc:0:server: check ServerTest.in response"] tests with | Some tests -> ignore (run_test_tt ~verbose:true tests) Modified: trunk/Toss/Play/Server.ml =================================================================== --- trunk/Toss/Play/Server.ml 2010-12-09 20:05:14 UTC (rev 1242) +++ trunk/Toss/Play/Server.ml 2010-12-10 14:21:08 UTC (rev 1243) @@ -140,117 +140,124 @@ !state.Arena.game.Arena.player_names) heur) in let p, ps = match !game_modified, !play, !play_state with - | false, Some play, Some play_state -> - play, play_state - | _ -> - let p, ps = Game.initialize_default - !state ~loc ~effort ~search_method:how - ?horizon ?heuristic ?heur_adv_ratio () in - game_modified := false; - play := Some p; play_state := Some ps; - p, ps in - ignore (Unix.alarm timer); - let res = Game.suggest ~effort p ps in - Game.cancel_timeout (); - match res with - | Some (move, new_state) -> - play_state := Some new_state; - Game.move_gs_str !state move - | None -> "None" - ) + | false, Some play, Some play_state -> + play, play_state + | _ -> + let p, ps = Game.initialize_default + !state ~loc ~effort ~search_method:how + ?horizon ?heuristic ?heur_adv_ratio () in + game_modified := false; + play := Some p; play_state := Some ps; + p, ps in + ignore (Unix.alarm timer); + let res = Game.suggest ~effort p ps in + Game.cancel_timeout (); + match res with + | Some (move, new_state) -> + play_state := Some new_state; + Game.move_gs_str !state move + | None -> "None" + ) | Arena.ApplyRule (r_name, mtch, t, p) -> ( - if !game_modified then - let (new_state, resp) = Arena.handle_request !state req in - state := new_state; resp - else + if !game_modified then + let (new_state, resp) = Arena.handle_request !state req in + state := new_state; resp + else (* trying to restore [Server.play_state] so as to avoid reinitialization *) - let {Arena.rules=rules; graph=graph} = !state.Arena.game in - let struc = !state.Arena.struc in - let fn s n = Structure.find_elem s n in - let r = List.assoc r_name rules in - let lhs = - r.ContinuousRule.discrete.DiscreteRule.lhs_struc in - let m = - List.map (fun (l, s) -> (fn lhs l, fn struc s)) mtch in - let moves = - Game.gen_moves Game.cGRID_SIZE rules - !state.Arena.struc graph.(!state.Arena.cur_loc) in - try - for i = 0 to Array.length moves - 1 do + let {Arena.rules=rules; graph=graph} = !state.Arena.game in + let struc = !state.Arena.struc in + let fn s n = Structure.find_elem s n in + let r = List.assoc r_name rules in + let lhs = + r.ContinuousRule.discrete.DiscreteRule.lhs_struc in + let m = + List.map (fun (l, s) -> (fn lhs l, fn struc s)) mtch in + let moves = + Game.gen_moves Game.cGRID_SIZE rules + !state.Arena.struc graph.(!state.Arena.cur_loc) in + try + for i = 0 to Array.length moves - 1 do (* FIXME: handle time and params! *) - let mov = moves.(i) in - if - r_name = mov.Game.rule && + let mov = moves.(i) in + if + r_name = mov.Game.rule && (* t = mov.Game.time && *) (* something wrong with this: List.for_all (fun (pn, pv) -> pv = List.assoc pn mov.Game.parameters) p && *) - List.for_all (fun (e, f) -> - f = List.assoc e mov.Game.embedding) m - (* TODO: handle location matching *) - then ( - expected_location := mov.Game.next_loc; - let _ = if !debug_level > 2 then + List.for_all (fun (e, f) -> + f = List.assoc e mov.Game.embedding) m + (* TODO: handle location matching *) + then ( + expected_location := mov.Game.next_loc; + let _ = if !debug_level > 2 then Printf.printf "expected_location = %d\n%!" !expected_location in - raise (Found i)) - done; + raise (Found i)) + done; (* TODO: if not due to only time or params mismatch, block or warn about invalid rule application *) - let (new_state, resp) = - Arena.handle_request !state req in - if !debug_level > 0 then - Printf.printf "ApplyRule: mismatched with play state!\n%!"; - state := new_state; resp - with Found pos -> - let old_struc = !state.Arena.struc in - let (new_state, resp) = Arena.handle_request !state req in - let memory = match !play, !play_state with - | Some play, Some {Game.memory=memory; game_state=pstate} -> - Game.update_memory - ~num_players:play.Game.game.Arena.num_players - {Game.struc=old_struc; - time = !state.Arena.time; - loc = !state.Arena.cur_loc} pos memory - | _ -> failwith "req_handle: impossible" in - state := new_state; + let (new_state, resp) = + Arena.handle_request !state req in + if !debug_level > 0 then + Printf.printf "ApplyRule: mismatched with play state!\n%!"; + state := new_state; resp + with Found pos -> + let old_struc = !state.Arena.struc in + let (new_state, resp) = Arena.handle_request !state req in + let memory = match !play, !play_state with + | Some play, Some {Game.memory=memory; game_state=pstate} -> + Game.update_memory + ~num_players:play.Game.game.Arena.num_players + {Game.struc=old_struc; + time = !state.Arena.time; + loc = !state.Arena.cur_loc} pos memory + | _ -> failwith "req_handle: impossible" in + state := new_state; (* Rewriting doesn't handle location update. *) - let new_game_state = { - Game.struc = new_state.Arena.struc; - loc = moves.(pos).Game.next_loc; - time = new_state.Arena.time; - } in - play_state := Some { - Game.game_state = new_game_state; - memory = memory; - }; - resp - ) + let new_game_state = { + Game.struc = new_state.Arena.struc; + loc = moves.(pos).Game.next_loc; + time = new_state.Arena.time; + } in + play_state := Some { + Game.game_state = new_game_state; + memory = memory; + }; + resp + ) | _ -> - game_modified := !game_modified || - possibly_modifies_game req; - let (new_state, resp) = Arena.handle_request !state req in - state := new_state; resp in + game_modified := !game_modified || + possibly_modifies_game req; + let (new_state, resp) = Arena.handle_request !state req in + state := new_state; resp in if !debug_level > 0 then print_endline ("Repl: " ^ resp ^ "\n"); output_string out_ch (resp ^ "\n"); flush out_ch; with - Parsing.Parse_error -> - Printf.printf "Toss Server: parse error\n%!"; - output_string out_ch ("ERR could not parse\n"); - flush out_ch + | Parsing.Parse_error -> + Printf.printf "Toss Server: parse error\n%!"; + output_string out_ch ("ERR could not parse\n"); + flush out_ch + | Lexer.Parsing_error msg -> + Printf.printf "Toss Server: parse error: %s\n%!" msg; + output_string out_ch ("ERR could not parse\n"); + flush out_ch + | End_of_file -> + output_string out_ch ("ERR processing completed -- EOF\n"); + flush out_ch; raise End_of_file | exn -> - Printf.printf "Toss Server: error -- exception %s\n%!" - (Printexc.to_string exn); - Printf.printf "Exception backtrace: %s\n%!" - (Printexc.get_backtrace ()); - output_string out_ch ("ERR internal error -- see server stdout\n") + Printf.printf "Toss Server: error -- exception %s\n%!" + (Printexc.to_string exn); + Printf.printf "Exception backtrace: %s\n%!" + (Printexc.get_backtrace ()); + output_string out_ch ("ERR internal error -- see server stdout\n") (* ----------------------- START SERVER WHEN CALLED ------------------------- *) -let _ = +let main () = Gc.set { (Gc.get()) with Gc.space_overhead = 300; (* 300% instead of 80% std *) Gc.minor_heap_size = 64*1024; (* 2*std, opt ~= L2 cache/proc *) @@ -268,3 +275,16 @@ start_server req_handle !port !server with Host_not_found -> print_endline "The host you specified was not found." ;; + +let _ = + (* Test against being called from GameTest... *) + let target_name = "GameTest" in + let file_from_path p = + String.sub p (String.rindex p '/'+1) + (String.length p - String.rindex p '/' - 1) in + let test_fname = + let fname = file_from_path Sys.executable_name in + String.length fname >= String.length target_name && + String.sub fname 0 (String.length target_name) = target_name in + (* so that the server is not started by the test suite. *) + if not test_fname then main ();; Added: trunk/Toss/Play/ServerTest.in =================================================================== --- trunk/Toss/Play/ServerTest.in (rev 0) +++ trunk/Toss/Play/ServerTest.in 2010-12-10 14:21:08 UTC (rev 1243) @@ -0,0 +1,2 @@ +ADD REL MODEL R(a,b) +GET ALLOF REL MODEL R Added: trunk/Toss/Play/ServerTest.out =================================================================== --- trunk/Toss/Play/ServerTest.out (rev 0) +++ trunk/Toss/Play/ServerTest.out 2010-12-10 14:21:08 UTC (rev 1243) @@ -0,0 +1,3 @@ +REL ADDED +R (a, b) +ERR processing completed -- EOF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-18 00:52:34
|
Revision: 1253 http://toss.svn.sourceforge.net/toss/?rev=1253&view=rev Author: lukaszkaiser Date: 2010-12-18 00:52:28 +0000 (Sat, 18 Dec 2010) Log Message: ----------- Store only models in WebClient plays, each game only once. Chess works reasonably now. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/Arena.mli trunk/Toss/Arena/ArenaParser.mly trunk/Toss/Play/Server.ml trunk/Toss/WebClient/README trunk/Toss/WebClient/TossDefaultStyle.js trunk/Toss/WebClient/TossHandler.py trunk/Toss/WebClient/TossMain.js trunk/Toss/WebClient/TossStyle.css trunk/Toss/WebClient/Wrapper.py trunk/Toss/WebClient/index.html Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/Arena/Arena.ml 2010-12-18 00:52:28 UTC (rev 1253) @@ -173,6 +173,9 @@ (List.length old_rules) (List.length old_locs); ); (* }}} *) + let rev_models_at_end l = + let m, n = List.partition (function StateStruc _ -> true | _ -> false) l in + n @ (List.rev m) in let rules, locations, players, defined_rels, state, time, cur_loc, data = List.fold_right (fun def (rules, locations, players, defined_rels, @@ -203,7 +206,7 @@ | StateData more_data -> (rules, locations, players, defined_rels, state, time, cur_loc, data @ more_data) - ) defs ([], [], players, defined_rels, + ) (rev_models_at_end defs) ([], [], players, defined_rels, state, time, cur_loc, data) in (* {{{ log entry *) if !debug_level > 2 then ( @@ -469,6 +472,7 @@ | SetTime of float * float (* Set time step and time *) | GetTime (* Get time step and time *) | SetState of game_state (* Set the full state *) + | GetModel (* Return the current model*) | GetState (* Return the state *) @@ -870,4 +874,5 @@ (state, string_of_float (ts) ^ " / " ^ string_of_float (t)) | SetState s -> (s, "STATE SET") + | GetModel -> (state, Structure.sprint state.struc) | GetState -> (state, state_str state) Modified: trunk/Toss/Arena/Arena.mli =================================================================== --- trunk/Toss/Arena/Arena.mli 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/Arena/Arena.mli 2010-12-18 00:52:28 UTC (rev 1253) @@ -175,6 +175,7 @@ | SetTime of float * float (** Set time step and time *) | GetTime (** Get time step and time *) | SetState of game_state (** Set the full state *) + | GetModel (** Return the model *) | GetState (** Return the state *) val handle_request : game_state -> request -> game_state * string Modified: trunk/Toss/Arena/ArenaParser.mly =================================================================== --- trunk/Toss/Arena/ArenaParser.mly 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/Arena/ArenaParser.mly 2010-12-18 00:52:28 UTC (rev 1253) @@ -135,6 +135,7 @@ | GET_CMD SIG_MOD id_int { GetArity ($3) } | SET_CMD STATE_SPEC gs=game_state { SetState gs } | GET_CMD STATE_SPEC { GetState } + | GET_CMD MODEL_SPEC { GetModel } | ADD_CMD ELEM_MOD struct_location { AddElem ($3) } | ADD_CMD REL_MOD Modified: trunk/Toss/Play/Server.ml =================================================================== --- trunk/Toss/Play/Server.ml 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/Play/Server.ml 2010-12-18 00:52:28 UTC (rev 1253) @@ -117,6 +117,7 @@ | Arena.SetTime _ -> false (* TODO: rethink when working on dyns *) | Arena.GetTime -> false | Arena.SetState _ -> true + | Arena.GetModel -> false | Arena.GetState -> false exception Found of int Modified: trunk/Toss/WebClient/README =================================================================== --- trunk/Toss/WebClient/README 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/README 2010-12-18 00:52:28 UTC (rev 1253) @@ -19,12 +19,11 @@ TODO: - - better register html - - back button handler (reload), enter for login - - enable google (or other) analytics - - refresh (async?) plays in which the other player moves + - better register html and user table - move interface: first click all, second click toggle, if one - confirm msg - after the above: remove left-of-board div, confirm in the middle - after the above: show game result in the middle / instead of move - - option to give up game and offer a draw - sort plays by who's turn it is + - option to give up game and offer a draw + - enable google (or other) analytics + - refresh (async?) plays in which the other player moves Modified: trunk/Toss/WebClient/TossDefaultStyle.js =================================================================== --- trunk/Toss/WebClient/TossDefaultStyle.js 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/TossDefaultStyle.js 2010-12-18 00:52:28 UTC (rev 1253) @@ -38,14 +38,14 @@ 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" /> \ + style="stroke-linecap:butt;" class="chess-path-Bx" /> \ <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-B" /> \ + 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" /> \ @@ -63,10 +63,10 @@ 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-B" /> \ + 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" /> \ + style="stroke-linecap:butt;" class="chess-path-Bx" /> \ <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" /> \ @@ -78,7 +78,7 @@ 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" /> \ + class="chess-path-Bx" /> \ <path \ d="M 11,14 L 34,14" \ class="chess-path-D" /> \ Modified: trunk/Toss/WebClient/TossHandler.py =================================================================== --- trunk/Toss/WebClient/TossHandler.py 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/TossHandler.py 2010-12-18 00:52:28 UTC (rev 1253) @@ -10,7 +10,7 @@ TUID = "toss_id_05174_" def tmp_log (str): - file = open ("/tmp/th.log", 'w') + file = open ("/tmp/th.log", 'a') file.write (str) file.close() @@ -27,23 +27,37 @@ time.sleep (0.1) return (port) +def get_global_lock (db): + cur = db.cursor () + cur.execute ("update lock set locked='true' " + + " where locked='false' and tid='" + str(TUID) + "'") + db.commit () + if cur.rowcount == 1: + return + time.sleep (0.1) + get_global_lock (db) + +def release_global_lock (db): + db.execute ("update lock set locked='false' " + + " where locked='true' and tid='" + str(TUID) + "'") + db.commit () + def get_toss_port (db): + get_global_lock (db) free_ports = get_all_from_db (db, "ports", "locked='false'") if len(free_ports) == 0: fid = 0 for f in db.execute ("select count(*) from ports"): fid = int(f[0]) port = 8110+fid+1 - # WARNING: two proc can get same fid! Avoid by sqlite write-atomicity! db.execute ("insert into ports(port, locked) values (?, ?)", (port, 'true')) - db.commit () + release_global_lock (db) open_toss_server (port) return (port) (port, _) = free_ports[0] db.execute ("update ports set locked='true' where port=" + str(port)) - # This could give same port to 2 proc (1st line). Avoid by sql-write! - db.commit () + release_global_lock (db) return (port) def release_toss_port (db, port): @@ -84,7 +98,8 @@ (_, toss) = res[0] client.open_from_str (toss) info = get_game_info (client) - db_cur_insert (db, game, p1, p2, pid, move, toss, info, "") + model = client.get_model () + db_cur_insert (db, game, p1, p2, pid, move, model, info, "") return (info) def game_select_s (g, p1, p2, pid, m): @@ -102,10 +117,12 @@ select_s = game_select_s (g, p1, p2, pid, m) old_res = get_all_from_db (db, "cur_states", select_s) (_, _, _, _, _, old_toss, old_info, old_svg) = old_res[0] - client.open_from_str (old_toss) + res = get_all_from_db (db, "games", "game='" + g + "'") + (_, game_toss) = res[0] + client.open_from_str (game_toss + "\n MODEL " + old_toss) (move1, move2, move3) = move_tup client.make_move (move1, move2, move3) - new_toss = client.get_state () + new_toss = client.get_model () new_info = get_game_info (client) db.execute ("delete from cur_states where " + select_s) db_old_insert (db, g, p1, p2, pid, m, old_toss, old_info, old_svg) Modified: trunk/Toss/WebClient/TossMain.js =================================================================== --- trunk/Toss/WebClient/TossMain.js 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/TossMain.js 2010-12-18 00:52:28 UTC (rev 1253) @@ -161,8 +161,8 @@ } function play_click (game, play_id, pi) { - list_plays (game) - game_click (game) + 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; @@ -324,6 +324,8 @@ UNAME = un document.getElementById("topuser").innerHTML = "Welcome " + un; document.getElementById("loginform").style.display = "none"; + document.getElementById("topright-register").style.display = "none"; + document.getElementById("topright").style.display = "inline"; document.getElementById("welcome").style.display = "none"; document.getElementById("plays").style.display = "block"; list_plays ("Breakthrough"); @@ -333,6 +335,18 @@ list_plays ("Tic-Tac-Toe"); } +// Clear view +function clear_view () { + document.getElementById("loginform").style.display = "inline"; + document.getElementById("topright-register").style.display = "inline"; + document.getElementById("topright").style.display = "none"; + document.getElementById("topuser").innerHTML = ""; + document.getElementById("plays").style.display = "none"; + document.getElementById("game-title").style.display = "none"; + document.getElementById("game-disp").style.display = "none"; + document.getElementById("welcome").style.display = "block"; +} + function startup () { if (navigator.userAgent.indexOf('MSIE') !=-1) { document.getElementById("nosvg").style.display = "block"; @@ -357,10 +371,5 @@ // Logout function logout () { - document.getElementById("loginform").style.display = "inline"; - document.getElementById("topuser").innerHTML = ""; - document.getElementById("plays").style.display = "none"; - document.getElementById("game-title").style.display = "none"; - document.getElementById("game-disp").style.display = "none"; - document.getElementById("welcome").style.display = "block"; + clear_view (); } Modified: trunk/Toss/WebClient/TossStyle.css =================================================================== --- trunk/Toss/WebClient/TossStyle.css 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/TossStyle.css 2010-12-18 00:52:28 UTC (rev 1253) @@ -58,8 +58,14 @@ #topright { float: right; margin-right: 0em; + display: none; } +#topright-register { + float: right; + margin-right: 0em; +} + #bottom { position: relative; bottom: 0px; @@ -410,7 +416,7 @@ .chessB .chess-path-B { opacity:1; - fill:#400827; + fill: #400827; fill-opacity:1; fill-rule:evenodd; stroke:#260314; @@ -422,6 +428,34 @@ stroke-opacity:1; } +.chessW .chess-path-Bx { + opacity:1; + fill:#ffe4aa; + fill-opacity:1; + fill-rule:evenodd; + stroke:#260314; + stroke-width:1.5; + stroke-linecap:round; + stroke-linejoin:round; + stroke-miterlimit:4; + stroke-dasharray:none; + stroke-opacity:1; +} + +.chessB .chess-path-Bx { + opacity:1; + fill: #ffe4aa; + fill-opacity:1; + fill-rule:evenodd; + stroke: #400827; + stroke-width:1.5; + stroke-linecap:round; + stroke-linejoin:round; + stroke-miterlimit:4; + stroke-dasharray:none; + stroke-opacity:1; +} + .chessW .chess-path-C { opacity:1; fill:#400827; Modified: trunk/Toss/WebClient/Wrapper.py =================================================================== --- trunk/Toss/WebClient/Wrapper.py 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/Wrapper.py 2010-12-18 00:52:28 UTC (rev 1253) @@ -117,6 +117,9 @@ def get_state (self): return (self.msg ("GET STATE")) + def get_model (self): + return (self.msg ("GET MODEL")) + def set_state (self, state): m = self.msg ("SET STATE " + state) return (m) Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/index.html 2010-12-18 00:52:28 UTC (rev 1253) @@ -21,15 +21,17 @@ <form id="loginform" style="display: inline;"> Username: <input type="text" name="username" id="username" /> -Password: <input type="password" name="password" id="password" /> +Password: <input type="password" name="password" id="password" + onkeypress="if (window.event && window.event.keyCode == 13) { login () }" /> <a id="login" href="#" onclick="login()">Login</a> - -(<a href="register.html">Register</a>) </form> <span id="topright"> <a id="logout" href="#" onclick="logout()">Logout</a> </span> +<span id="topright-register"> + <a href="register.html">Register</a> +</span> </div> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-19 14:31:22
|
Revision: 1260 http://toss.svn.sourceforge.net/toss/?rev=1260&view=rev Author: lukstafi Date: 2010-12-19 14:31:15 +0000 (Sun, 19 Dec 2010) Log Message: ----------- GDL parsing: initial commit, in progress. Modified Paths: -------------- trunk/Toss/Formula/Aux.ml trunk/Toss/Formula/Aux.mli trunk/Toss/Play/GDL.ml trunk/Toss/Play/GDL.mli trunk/Toss/Play/GameTest.ml trunk/Toss/Play/Server.ml Added Paths: ----------- trunk/Toss/Play/ServerGDLTest.in trunk/Toss/Play/ServerGDLTest.out Modified: trunk/Toss/Formula/Aux.ml =================================================================== --- trunk/Toss/Formula/Aux.ml 2010-12-19 12:26:22 UTC (rev 1259) +++ trunk/Toss/Formula/Aux.ml 2010-12-19 14:31:15 UTC (rev 1260) @@ -397,3 +397,17 @@ while true do Buffer.add_channel buf file 1 done with End_of_file -> ()); Buffer.contents buf + +let rec input_http_message file = + let buf = Buffer.create 256 in + let line = ref "POST / HTTP" in + let msg_len = ref 0 in + while !line <> "" && !line <> "\r" do + line := input_line file; + let line_len = String.length !line in + if line_len > 16 && String.sub !line 0 15 = "Content-length:" then + msg_len := int_of_string + (String.sub !line 16 (line_len - 16)); + done; + Buffer.add_channel buf file !msg_len; + Buffer.contents buf Modified: trunk/Toss/Formula/Aux.mli =================================================================== --- trunk/Toss/Formula/Aux.mli 2010-12-19 12:26:22 UTC (rev 1259) +++ trunk/Toss/Formula/Aux.mli 2010-12-19 14:31:15 UTC (rev 1260) @@ -185,3 +185,7 @@ (** Input a file to a string. *) val input_file : in_channel -> string + +(** Skip the header extracting the [Content-length] field and input the + content of an HTTP message. *) +val input_http_message : in_channel -> string Modified: trunk/Toss/Play/GDL.ml =================================================================== --- trunk/Toss/Play/GDL.ml 2010-12-19 12:26:22 UTC (rev 1259) +++ trunk/Toss/Play/GDL.ml 2010-12-19 14:31:15 UTC (rev 1260) @@ -41,3 +41,19 @@ (* game ends here: match id, actions on previous step *) let compile_game_descr entries = entries + +let client_player = ref (Const "uninitialized") +let game_description = ref [] + +let initialize_game player game_descr startcl = + client_player := player; + game_description := game_descr; + let effort, horizon, heur_adv_ratio = + 2, 100, 4.0 in + effort, horizon, heur_adv_ratio + +let translate_last_action actions = + "1", ["1","1"] + +let translate_move move new_state = + "NOOP" Modified: trunk/Toss/Play/GDL.mli =================================================================== --- trunk/Toss/Play/GDL.mli 2010-12-19 12:26:22 UTC (rev 1259) +++ trunk/Toss/Play/GDL.mli 2010-12-19 14:31:15 UTC (rev 1260) @@ -39,3 +39,13 @@ val compile_game_descr : game_descr_entry list -> game_description + +val initialize_game : + term -> game_description -> int -> int * int * float + +val translate_last_action : + term list -> string * (string * string) list + +(* FIXME: remove dependency on Game? *) +val translate_move : + Game.move -> Game.play_state -> string Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2010-12-19 12:26:22 UTC (rev 1259) +++ trunk/Toss/Play/GameTest.ml 2010-12-19 14:31:15 UTC (rev 1260) @@ -561,6 +561,22 @@ Sys.remove "./Play/ServerTest.temp"; assert_equal ~printer:(fun x->x) target result ); + + "server: ServerGDLTest.in GDL Tic-Tac-Toe" >:: + (fun () -> + let in_ch = open_in "./Play/ServerGDLTest.in" in + let out_ch = open_out "./Play/ServerGDLTest.temp" in + (try while true do + Server.req_handle in_ch out_ch done + with End_of_file -> ()); + close_in in_ch; close_out out_ch; + let result = + Aux.input_file (open_in "./Play/ServerGDLTest.temp") in + let target = + Aux.input_file (open_in "./Play/ServerGDLTest.out") in + Sys.remove "./Play/ServerTest.temp"; + assert_equal ~printer:(fun x->x) target result + ); "play: breakthrough suggest in game" >:: (fun () -> Modified: trunk/Toss/Play/Server.ml =================================================================== --- trunk/Toss/Play/Server.ml 2010-12-19 12:26:22 UTC (rev 1259) +++ trunk/Toss/Play/Server.ml 2010-12-19 14:31:15 UTC (rev 1260) @@ -19,9 +19,9 @@ let play_state = ref (None : Game.play_state option) (* Timeout. *) -let dtimeout = ref (-1); +let dtimeout = ref (-1) +let playclock = ref 0 - (* -------------------- GENERAL SERVER AND REQUEST HANDLER ------------------ *) exception Host_not_found @@ -53,23 +53,21 @@ done let req_of_str s = - let http_beg = "POST / HTTP/" in - let http_beg_l = String.length http_beg in let s_len = String.length s in - if s_len > http_beg_l && String.sub s 0 http_beg_l = http_beg + if s_len > 4 && String.sub s 0 4 = "GDL " then - if Str.string_match (Str.regexp "\r?\n\r?\n") s 0 - then - let m_beg = Str.match_end () in - Aux.Right (GDLParser.parse_request KIFLexer.lex - (Lexing.from_string (String.sub s m_beg (s_len-m_beg)))) - else - raise (Lexer.Parsing_error "Empty HTTP message") + Aux.Right (GDLParser.parse_request KIFLexer.lex + (Lexing.from_string (String.sub s 4 (s_len-4)))) else Aux.Left (ArenaParser.parse_request Lexer.lex (Lexing.from_string s)) let rec read_in_line in_ch = - let line_in = input_line in_ch in + let line_in = + let rec nonempty () = + let line_in = input_line in_ch in + if line_in = "" || line_in = "\r" then nonempty () + else line_in in + nonempty () in let line_in_len = String.length line_in in (* TODO: who needs escaping? *) let line_in = @@ -77,12 +75,19 @@ (* String.escaped *) line_in else (* String.escaped *) (String.sub line_in 0 (line_in_len-1)) in - (* We put endlines, encoded by '$', back into the message. *) - let line = - String.concat "\n" - (Str.split (Str.regexp "\\$") line_in) in - if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" line; - line + let http_beg = "POST / HTTP/" in + let http_beg_l = String.length http_beg in + if line_in_len > http_beg_l && String.sub line_in 0 http_beg_l = http_beg + then + "GDL " ^ Aux.input_http_message in_ch + else + (* We put endlines, encoded by '$', back into the message. + TODO: perhaps a "better" solution now that HTTP has one? *) + let line = + String.concat "\n" + (Str.split (Str.regexp "\\$") line_in) in + if !debug_level > 0 then Printf.printf "Rcvd: %s\n%!" line; + line let possibly_modifies_game = function Arena.AddElem _ -> true @@ -142,8 +147,8 @@ let resp = match req with | Aux.Left (Arena.SuggestLocMoves - (loc, timer, effort, how, horizon, heuristic, - heur_adv_ratio)) -> ( + (loc, timer, effort, how, horizon, heuristic, + heur_adv_ratio)) -> ( Random.self_init (); (* TODO: should be in idle time, not now *) Gc.full_major (); @@ -173,13 +178,14 @@ Game.move_gs_str !state move | None -> "None" ) + | Aux.Left (Arena.ApplyRule (r_name, mtch, t, p) as req) -> ( if !game_modified then let (new_state, resp) = Arena.handle_request !state req in state := new_state; resp else - (* trying to restore [Server.play_state] so as to avoid - reinitialization *) + (* trying to restore [Server.play_state] so as to avoid + reinitialization *) let {Arena.rules=rules; graph=graph} = !state.Arena.game in let struc = !state.Arena.struc in let fn s n = Structure.find_elem s n in @@ -193,17 +199,17 @@ !state.Arena.struc graph.(!state.Arena.cur_loc) in try for i = 0 to Array.length moves - 1 do - (* FIXME: handle time and params! *) + (* FIXME: handle time and params! *) let mov = moves.(i) in if r_name = mov.Game.rule && - (* t = mov.Game.time && *) - (* something wrong with this: - List.for_all (fun (pn, pv) -> - pv = List.assoc pn mov.Game.parameters) p && *) + (* t = mov.Game.time && *) + (* something wrong with this: + List.for_all (fun (pn, pv) -> + pv = List.assoc pn mov.Game.parameters) p && *) List.for_all (fun (e, f) -> f = List.assoc e mov.Game.embedding) m - (* TODO: handle location matching *) + (* TODO: handle location matching *) then ( expected_location := mov.Game.next_loc; let _ = if !debug_level > 2 then @@ -211,8 +217,8 @@ !expected_location in raise (Found i)) done; - (* TODO: if not due to only time or params mismatch, - block or warn about invalid rule application *) + (* TODO: if not due to only time or params mismatch, + block or warn about invalid rule application *) let (new_state, resp) = Arena.handle_request !state req in if !debug_level > 0 then @@ -230,7 +236,7 @@ loc = !state.Arena.cur_loc} pos memory | _ -> failwith "req_handle: impossible" in state := new_state; - (* Rewriting doesn't handle location update. *) + (* Rewriting doesn't handle location update. *) let new_game_state = { Game.struc = new_state.Arena.struc; loc = moves.(pos).Game.next_loc; @@ -242,13 +248,179 @@ }; resp ) + | Aux.Left req -> game_modified := !game_modified || possibly_modifies_game req; let (new_state, resp) = Arena.handle_request !state req in state := new_state; resp - | Aux.Right req -> - failwith "GDL request parsed but handler not implemented yet" + + | Aux.Right (GDL.Start (_, player, game_descr, startcl, playcl)) -> + (* GDL will store the player and the game in its state. *) + let effort, horizon, heur_adv_ratio = + GDL.initialize_game player game_descr startcl in + (* TODO: handle timer (startclock) in Game.initialize_default*) + let p, ps = Game.initialize_default + !state ~effort ~search_method:"alpha_beta_ord" + ~horizon ~heur_adv_ratio () in + game_modified := false; + play := Some p; play_state := Some ps; + playclock := playcl; + "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: 5" + ^ "\r\n\r\nREADY" + + + | Aux.Right (GDL.Play (_, actions)) -> + let time_started = int_of_float (Sys.time ()) in + let r_name, mtch = + GDL.translate_last_action actions in + + let {Arena.rules=rules; graph=graph} = !state.Arena.game in + let struc = !state.Arena.struc in + let fn s n = Structure.find_elem s n in + let r = List.assoc r_name rules in + let lhs = + r.ContinuousRule.discrete.DiscreteRule.lhs_struc in + let m = + List.map (fun (l, s) -> (fn lhs l, fn struc s)) mtch in + let moves = + Game.gen_moves Game.cGRID_SIZE rules + !state.Arena.struc graph.(!state.Arena.cur_loc) in + let pos = + (try + for i = 0 to Array.length moves - 1 do + (* FIXME: handle time and params! *) + let mov = moves.(i) in + if + r_name = mov.Game.rule && + (* t = mov.Game.time && *) + (* something wrong with this: + List.for_all (fun (pn, pv) -> + pv = List.assoc pn mov.Game.parameters) p && *) + List.for_all (fun (e, f) -> + f = List.assoc e mov.Game.embedding) m + (* TODO: handle location matching *) + then ( + expected_location := mov.Game.next_loc; + let _ = if !debug_level > 2 then + Printf.printf "expected_location = %d\n%!" + !expected_location in + raise (Found i)) + done; + (* TODO: if not due to only time or params mismatch, + block or warn about invalid rule application *) + failwith + "Server GDL Play request: action mismatched with play state" + with Found pos -> pos) in + let old_struc = !state.Arena.struc in + let req = Arena.ApplyRule (r_name, mtch, 0.1, []) in + let (new_state, resp) = Arena.handle_request !state req in + let memory = match !play, !play_state with + | Some play, Some {Game.memory=memory; game_state=pstate} -> + Game.update_memory + ~num_players:play.Game.game.Arena.num_players + {Game.struc=old_struc; + time = !state.Arena.time; + loc = !state.Arena.cur_loc} pos memory + | _ -> failwith "req_handle: impossible" in + state := new_state; + (* Rewriting doesn't handle location update. *) + let new_game_state = { + Game.struc = new_state.Arena.struc; + loc = moves.(pos).Game.next_loc; + time = new_state.Arena.time; + } in + play_state := Some { + Game.game_state = new_game_state; + memory = memory; + }; + + let time_used = + time_started - (int_of_float (ceil (Sys.time ()))) in + let p, ps = + match !play, !play_state with + | Some play, Some play_state -> + play, play_state + | _ -> assert false in + ignore (Unix.alarm (!playclock - time_used)); + let res = Game.suggest p ps in + Game.cancel_timeout (); + let mov_msg = + match res with + | Some (move, new_state) -> + play_state := Some new_state; + GDL.translate_move move new_state + | None -> "NOOP" in + let msg_len = String.length mov_msg in + "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: " + ^ string_of_int msg_len ^ "\r\n\r\n" ^ mov_msg + + | Aux.Right (GDL.Stop (_, actions)) -> + let r_name, mtch = + GDL.translate_last_action actions in + + let {Arena.rules=rules; graph=graph} = !state.Arena.game in + let struc = !state.Arena.struc in + let fn s n = Structure.find_elem s n in + let r = List.assoc r_name rules in + let lhs = + r.ContinuousRule.discrete.DiscreteRule.lhs_struc in + let m = + List.map (fun (l, s) -> (fn lhs l, fn struc s)) mtch in + let moves = + Game.gen_moves Game.cGRID_SIZE rules + !state.Arena.struc graph.(!state.Arena.cur_loc) in + let pos = + (try + for i = 0 to Array.length moves - 1 do + (* FIXME: handle time and params! *) + let mov = moves.(i) in + if + r_name = mov.Game.rule && + (* t = mov.Game.time && *) + (* something wrong with this: + List.for_all (fun (pn, pv) -> + pv = List.assoc pn mov.Game.parameters) p && *) + List.for_all (fun (e, f) -> + f = List.assoc e mov.Game.embedding) m + (* TODO: handle location matching *) + then ( + expected_location := mov.Game.next_loc; + let _ = if !debug_level > 2 then + Printf.printf "expected_location = %d\n%!" + !expected_location in + raise (Found i)) + done; + (* TODO: if not due to only time or params mismatch, + block or warn about invalid rule application *) + failwith + "Server GDL Play request: action mismatched with play state" + with Found pos -> pos) in + let old_struc = !state.Arena.struc in + let req = Arena.ApplyRule (r_name, mtch, 0.1, []) in + let (new_state, resp) = Arena.handle_request !state req in + let memory = match !play, !play_state with + | Some play, Some {Game.memory=memory; game_state=pstate} -> + Game.update_memory + ~num_players:play.Game.game.Arena.num_players + {Game.struc=old_struc; + time = !state.Arena.time; + loc = !state.Arena.cur_loc} pos memory + | _ -> failwith "req_handle: impossible" in + state := new_state; + (* Rewriting doesn't handle location update. *) + let new_game_state = { + Game.struc = new_state.Arena.struc; + loc = moves.(pos).Game.next_loc; + time = new_state.Arena.time; + } in + play_state := Some { + Game.game_state = new_game_state; + memory = memory; + }; + "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: 4" + ^ "\r\n\r\nDONE" + in if !debug_level > 0 then print_endline ("Repl: " ^ resp ^ "\n"); output_string out_ch (resp ^ "\n"); Added: trunk/Toss/Play/ServerGDLTest.in =================================================================== --- trunk/Toss/Play/ServerGDLTest.in (rev 0) +++ trunk/Toss/Play/ServerGDLTest.in 2010-12-19 14:31:15 UTC (rev 1260) @@ -0,0 +1,62 @@ +POST / HTTP/1.0 +Accept: text/delim +Sender: GAMEMASTER +Receiver: GAMEPLAYER +Content-type: text/acl +Content-length: 1587 + +(START MATCH.3316980891 X (ROLE X) (ROLE O) (INIT (CELL 1 1 B)) (INIT (CELL 1 2 B)) (INIT (CELL 1 3 B)) (INIT (CELL 2 1 B)) (INIT (CELL 2 2 B)) (INIT (CELL 2 3 B)) (INIT (CELL 3 1 B)) (INIT (CELL 3 2 B)) (INIT (CELL 3 3 B)) (INIT (CONTROL X)) (<= (NEXT (CELL ?X ?Y ?PLAYER)) (DOES ?PLAYER (MARK ?X ?Y))) (<= (NEXT (CELL ?X ?Y ?MARK)) (TRUE (CELL ?X ?Y ?MARK)) (DOES ?PLAYER (MARK ?M ?N)) (DISTINCTCELL ?X ?Y ?M ?N)) (<= (NEXT (CONTROL X)) (TRUE (CONTROL O))) (<= (NEXT (CONTROL O)) (TRUE (CONTROL X))) (<= (ROW ?X ?PLAYER) (TRUE (CELL ?X 1 ?PLAYER)) (TRUE (CELL ?X 2 ?PLAYER)) (TRUE (CELL ?X 3 ?PLAYER))) (<= (COLUMN ?Y ?PLAYER) (TRUE (CELL 1 ?Y ?PLAYER)) (TRUE (CELL 2 ?Y ?PLAYER)) (TRUE (CELL 3 ?Y ?PLAYER))) (<= (DIAGONAL ?PLAYER) (TRUE (CELL 1 1 ?PLAYER)) (TRUE (CELL 2 2 ?PLAYER)) (TRUE (CELL 3 3 ?PLAYER))) (<= (DIAGONAL ?PLAYER) (TRUE (CELL 1 3 ?PLAYER)) (TRUE (CELL 2 2 ?PLAYER)) (TRUE (CELL 3 1 ?PLAYER))) (<= (LINE ?PLAYER) (ROW ?X ?PLAYER)) (<= (LINE ?PLAYER) (COLUMN ?Y ?PLAYER)) (<= (LINE ?PLAYER) (DIAGONAL ?PLAYER)) (<= OPEN (TRUE (CELL ?X ?Y B))) (<= (DISTINCTCELL ?X ?Y ?M ?N) (DISTINCT ?X ?M)) (<= (DISTINCTCELL ?X ?Y ?M ?N) (DISTINCT ?Y ?N)) (<= (LEGAL ?PLAYER (MARK ?X ?Y)) (TRUE (CELL ?X ?Y B)) (TRUE (CONTROL ?PLAYER))) (<= (LEGAL ?PLAYER NOOP) (NOT (TRUE (CONTROL ?PLAYER)))) (<= (GOAL ?PLAYER 100) (LINE ?PLAYER)) (<= (GOAL ?PLAYER 50) (NOT (LINE X)) (NOT (LINE O)) (NOT OPEN)) (<= (GOAL ?PLAYER1 0) (LINE ?PLAYER2) (DISTINCT ?PLAYER1 ?PLAYER2)) (<= (GOAL ?PLAYER 0) (NOT (LINE X)) (NOT (LINE O)) OPEN) (<= TERMINAL (LINE ?PLAYER)) (<= TERMINAL (NOT OPEN)) 30 30) + +POST / HTTP/1.0 +Accept: text/delim +Sender: GAMEMASTER +Receiver: GAMEPLAYER +Content-type: text/acl +Content-length: 27 + +(PLAY MATCH.3316980891 NIL) + +POST / HTTP/1.0 +Accept: text/delim +Sender: GAMEMASTER +Receiver: GAMEPLAYER +Content-type: text/acl +Content-length: 41 + +(PLAY MATCH.3316980891 ((MARK 3 3) NOOP)) + +POST / HTTP/1.0 +Accept: text/delim +Sender: GAMEMASTER +Receiver: GAMEPLAYER +Content-type: text/acl +Content-length: 41 + +(PLAY MATCH.3316980891 (NOOP (MARK 1 3))) + +POST / HTTP/1.0 +Accept: text/delim +Sender: GAMEMASTER +Receiver: GAMEPLAYER +Content-type: text/acl +Content-length: 41 + +(PLAY MATCH.3316980891 ((MARK 2 2) NOOP)) + +POST / HTTP/1.0 +Accept: text/delim +Sender: GAMEMASTER +Receiver: GAMEPLAYER +Content-type: text/acl +Content-length: 41 + +(PLAY MATCH.3316980891 (NOOP (MARK 1 2))) + +POST / HTTP/1.0 +Accept: text/delim +Sender: GAMEMASTER +Receiver: GAMEPLAYER +Content-type: text/acl +Content-length: 41 + +(STOP MATCH.3316980891 ((MARK 1 1) NOOP)) Added: trunk/Toss/Play/ServerGDLTest.out =================================================================== --- trunk/Toss/Play/ServerGDLTest.out (rev 0) +++ trunk/Toss/Play/ServerGDLTest.out 2010-12-19 14:31:15 UTC (rev 1260) @@ -0,0 +1,36 @@ +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 5 + +READY +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 10 + +(MARK 3 3) +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 4 + +NOOP +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 10 + +(MARK 2 2) +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 4 + +NOOP +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 10 + +(MARK 1 1) +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 4 + +DONE +ERR processing completed -- EOF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-19 20:42:14
|
Revision: 1262 http://toss.svn.sourceforge.net/toss/?rev=1262&view=rev Author: lukstafi Date: 2010-12-19 20:42:04 +0000 (Sun, 19 Dec 2010) Log Message: ----------- Arena definition parsing bug fix. GDL parsing bug fix. Board elements <-> coordinates helpers. GDL test example: in progress. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Play/GDL.ml trunk/Toss/Play/GDL.mli trunk/Toss/Play/GDLParser.mly trunk/Toss/Play/GameTest.ml trunk/Toss/Play/Server.ml trunk/Toss/Play/ServerGDLTest.in trunk/Toss/Play/ServerGDLTest.out trunk/Toss/Solver/Structure.ml trunk/Toss/Solver/Structure.mli Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2010-12-19 17:35:10 UTC (rev 1261) +++ trunk/Toss/Arena/Arena.ml 2010-12-19 20:42:04 UTC (rev 1262) @@ -154,7 +154,7 @@ (* Create a game state, possibly by extending an old state, from a list of definitions (usually corresponding to a ".toss" file.) *) let process_definition ?extend_state defs = - let (old_rules, old_locs, players, defined_rels, + let (old_rules, old_locs, players, old_defined_rels, state, time, cur_loc, data) = match extend_state with | None -> @@ -173,13 +173,10 @@ (List.length old_rules) (List.length old_locs); ); (* }}} *) - let rev_models_at_end l = - let m, n = List.partition (function StateStruc _ -> true | _ -> false) l in - n @ (List.rev m) in let rules, locations, players, defined_rels, state, time, cur_loc, data = - List.fold_right (fun def (rules, locations, players, defined_rels, - state, time, cur_loc, data) -> + List.fold_left (fun (rules, locations, players, defined_rels, + state, time, cur_loc, data) def -> match def with | DefRule (rname, r) -> ((rname, r)::rules, locations, players, defined_rels, @@ -206,14 +203,15 @@ | StateData more_data -> (rules, locations, players, defined_rels, state, time, cur_loc, data @ more_data) - ) (rev_models_at_end defs) ([], [], players, defined_rels, - state, time, cur_loc, data) in + ) ([], [], players, [], + state, time, cur_loc, data) defs in (* {{{ log entry *) if !debug_level > 2 then ( - printf "process_definition: %d new rules, %d defined rels\n%!" + printf "process_definition: %d new rules, %d new defined rels\n%!" (List.length rules) (List.length defined_rels); ); (* }}} *) + let defined_rels = old_defined_rels @ List.rev defined_rels in let def_rels_pure = List.map (fun (rel, args, body) -> (rel, (args, body))) defined_rels in let defined_rels = Modified: trunk/Toss/Play/GDL.ml =================================================================== --- trunk/Toss/Play/GDL.ml 2010-12-19 17:35:10 UTC (rev 1261) +++ trunk/Toss/Play/GDL.ml 2010-12-19 20:42:04 UTC (rev 1262) @@ -44,8 +44,22 @@ let client_player = ref (Const "uninitialized") let game_description = ref [] +let game_state = ref (ref Arena.empty_state) -let initialize_game player game_descr startcl = +let state_of_file s = + Printf.printf "GDL: Loading file %s...\n%!" s; + let f = open_in s in + let res = + ArenaParser.parse_game_state Lexer.lex + (Lexing.from_channel f) in + Printf.printf "GDL: File %s loaded.\n%!" s; + res + +let initialize_game state player game_descr startcl = + game_state := state; + + state := state_of_file "./examples/Tic-Tac-Toe.toss"; + client_player := player; game_description := game_descr; let effort, horizon, heur_adv_ratio = @@ -53,7 +67,20 @@ effort, horizon, heur_adv_ratio let translate_last_action actions = - "1", ["1","1"] + if actions = [] then + (* start of game -- Server will handle this answer as NOOP *) + "", [] + else + (* FIXME: really translate *) + "Cross", ["a1","a1"] -let translate_move move new_state = - "NOOP" +let translate_move rule emb new_state = + let struc = new_state.Arena.struc in + let elem = snd (List.hd emb) in + let c, r = + Structure.board_elem_coords (Structure.elem_str struc elem) in + let mark = Printf.sprintf "(MARK %d %d)" c r in + match rule with + | "Cross" -> "(" ^ mark ^ " NOOP)" + | "Circle" -> "(NOOP " ^ mark ^ ")" + | _ -> assert false Modified: trunk/Toss/Play/GDL.mli =================================================================== --- trunk/Toss/Play/GDL.mli 2010-12-19 17:35:10 UTC (rev 1261) +++ trunk/Toss/Play/GDL.mli 2010-12-19 20:42:04 UTC (rev 1262) @@ -41,11 +41,11 @@ game_descr_entry list -> game_description val initialize_game : - term -> game_description -> int -> int * int * float + Arena.game_state ref -> term -> game_description -> int -> int * int * float val translate_last_action : term list -> string * (string * string) list -(* FIXME: remove dependency on Game? *) +(* Rule name, embedding, game state. *) val translate_move : - Game.move -> Game.play_state -> string + string -> (int * int) list -> Arena.game_state -> string Modified: trunk/Toss/Play/GDLParser.mly =================================================================== --- trunk/Toss/Play/GDLParser.mly 2010-12-19 17:35:10 UTC (rev 1261) +++ trunk/Toss/Play/GDLParser.mly 2010-12-19 20:42:04 UTC (rev 1262) @@ -30,6 +30,9 @@ | Const c::args -> Func (c, args) | _ -> raise (Lexer.Parsing_error "GDL term: not a constant head") } +| error { + Lexer.report_parsing_error $startpos $endpos + "GDL: Syntax error in term." } atom: | r=WORD { Rel (r, []) } @@ -41,6 +44,9 @@ | Const r::args -> Rel (r, args) | _ -> raise (Lexer.Parsing_error "GDL atom: not a constant head") } +| error { + Lexer.report_parsing_error $startpos $endpos + "GDL: Syntax error in atom." } literal: | a=atom { Pos a } @@ -92,13 +98,17 @@ "GDL atomic entry: not init, role nor fact") } + %public game_description: - OPEN descr=list(game_descr_entry) CLOSE +| OPEN descr=list(game_descr_entry) CLOSE { compile_game_descr descr } +| error { + Lexer.report_parsing_error $startpos $endpos + "GDL: Syntax error in game description." } %public request: | OPEN start=WORD id=WORD role=term descr=game_description - startclock=WORD playclock=WORD + startclock=WORD playclock=WORD CLOSE { if start <> "START" && start <> "start" then raise (Lexer.Parsing_error "GDL request: start request expected") @@ -110,7 +120,8 @@ with Failure _ | Invalid_argument _ -> raise (Lexer.Parsing_error "GDL start: clock not a constant int") } -| OPEN command=WORD id=WORD actions=delimited (OPEN, list(term), CLOSE) +| OPEN command=WORD id=WORD + actions=delimited (OPEN, list(term), CLOSE) CLOSE { if command = "PLAY" || command = "play" then Play (id, actions) @@ -120,7 +131,7 @@ (Lexer.Parsing_error "GDL request: play or stop request expected") } -| OPEN command=WORD id=WORD actions=WORD +| OPEN command=WORD id=WORD actions=WORD CLOSE { if actions = "nil" || actions = "NIL" then ( if command = "PLAY" || command = "play" then @@ -132,6 +143,9 @@ ) else raise (Lexer.Parsing_error "GDL request: action list expected") } +| error { + Lexer.report_parsing_error $startpos $endpos + "GDL: Syntax error in request." } parse_game_description: | game_description EOF { $1 } Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2010-12-19 17:35:10 UTC (rev 1261) +++ trunk/Toss/Play/GameTest.ml 2010-12-19 20:42:04 UTC (rev 1262) @@ -1205,11 +1205,11 @@ let a () = run_test_tt ~verbose:true experiments let a () = - Game.set_debug_level 3 + Server.set_debug_level 3 let a () = match test_filter - ["Game:0:misc:5:chess draw"] + ["Game:0:misc:1:server: ServerGDLTest.in GDL Tic-Tac-Toe"] tests with | Some tests -> ignore (run_test_tt ~verbose:true tests) Modified: trunk/Toss/Play/Server.ml =================================================================== --- trunk/Toss/Play/Server.ml 2010-12-19 17:35:10 UTC (rev 1261) +++ trunk/Toss/Play/Server.ml 2010-12-19 20:42:04 UTC (rev 1262) @@ -55,9 +55,15 @@ let req_of_str s = let s_len = String.length s in if s_len > 4 && String.sub s 0 4 = "GDL " - then + then ( + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf "req_of_str-GDL:\n%s\n%!" (String.sub s 4 (s_len-4)); + ); + (* }}} *) Aux.Right (GDLParser.parse_request KIFLexer.lex (Lexing.from_string (String.sub s 4 (s_len-4)))) + ) else Aux.Left (ArenaParser.parse_request Lexer.lex (Lexing.from_string s)) @@ -258,7 +264,7 @@ | Aux.Right (GDL.Start (_, player, game_descr, startcl, playcl)) -> (* GDL will store the player and the game in its state. *) let effort, horizon, heur_adv_ratio = - GDL.initialize_game player game_descr startcl in + GDL.initialize_game state player game_descr startcl in (* TODO: handle timer (startclock) in Game.initialize_default*) let p, ps = Game.initialize_default !state ~effort ~search_method:"alpha_beta_ord" @@ -275,6 +281,7 @@ let r_name, mtch = GDL.translate_last_action actions in + if r_name <> "" then ( let {Arena.rules=rules; graph=graph} = !state.Arena.game in let struc = !state.Arena.struc in let fn s n = Structure.find_elem s n in @@ -291,6 +298,12 @@ for i = 0 to Array.length moves - 1 do (* FIXME: handle time and params! *) let mov = moves.(i) in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf "GDL: considering move %s\n%!" + (Game.move_gs_str !state mov) + ); + (* }}} *) if r_name = mov.Game.rule && (* t = mov.Game.time && *) @@ -309,6 +322,7 @@ done; (* TODO: if not due to only time or params mismatch, block or warn about invalid rule application *) + failwith "Server GDL Play request: action mismatched with play state" with Found pos -> pos) in @@ -333,8 +347,8 @@ play_state := Some { Game.game_state = new_game_state; memory = memory; - }; - + }); + let time_used = time_started - (int_of_float (ceil (Sys.time ()))) in let p, ps = @@ -349,7 +363,8 @@ match res with | Some (move, new_state) -> play_state := Some new_state; - GDL.translate_move move new_state + GDL.translate_move move.Game.rule move.Game.embedding + !state | None -> "NOOP" in let msg_len = String.length mov_msg in "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: " Modified: trunk/Toss/Play/ServerGDLTest.in =================================================================== --- trunk/Toss/Play/ServerGDLTest.in 2010-12-19 17:35:10 UTC (rev 1261) +++ trunk/Toss/Play/ServerGDLTest.in 2010-12-19 20:42:04 UTC (rev 1262) @@ -3,9 +3,9 @@ Sender: GAMEMASTER Receiver: GAMEPLAYER Content-type: text/acl -Content-length: 1587 +Content-length: 1589 -(START MATCH.3316980891 X (ROLE X) (ROLE O) (INIT (CELL 1 1 B)) (INIT (CELL 1 2 B)) (INIT (CELL 1 3 B)) (INIT (CELL 2 1 B)) (INIT (CELL 2 2 B)) (INIT (CELL 2 3 B)) (INIT (CELL 3 1 B)) (INIT (CELL 3 2 B)) (INIT (CELL 3 3 B)) (INIT (CONTROL X)) (<= (NEXT (CELL ?X ?Y ?PLAYER)) (DOES ?PLAYER (MARK ?X ?Y))) (<= (NEXT (CELL ?X ?Y ?MARK)) (TRUE (CELL ?X ?Y ?MARK)) (DOES ?PLAYER (MARK ?M ?N)) (DISTINCTCELL ?X ?Y ?M ?N)) (<= (NEXT (CONTROL X)) (TRUE (CONTROL O))) (<= (NEXT (CONTROL O)) (TRUE (CONTROL X))) (<= (ROW ?X ?PLAYER) (TRUE (CELL ?X 1 ?PLAYER)) (TRUE (CELL ?X 2 ?PLAYER)) (TRUE (CELL ?X 3 ?PLAYER))) (<= (COLUMN ?Y ?PLAYER) (TRUE (CELL 1 ?Y ?PLAYER)) (TRUE (CELL 2 ?Y ?PLAYER)) (TRUE (CELL 3 ?Y ?PLAYER))) (<= (DIAGONAL ?PLAYER) (TRUE (CELL 1 1 ?PLAYER)) (TRUE (CELL 2 2 ?PLAYER)) (TRUE (CELL 3 3 ?PLAYER))) (<= (DIAGONAL ?PLAYER) (TRUE (CELL 1 3 ?PLAYER)) (TRUE (CELL 2 2 ?PLAYER)) (TRUE (CELL 3 1 ?PLAYER))) (<= (LINE ?PLAYER) (ROW ?X ?PLAYER)) (<= (LINE ?PLAYER) (COLUMN ?Y ?PLAYER)) (<= (LINE ?PLAYER) (DIAGONAL ?PLAYER)) (<= OPEN (TRUE (CELL ?X ?Y B))) (<= (DISTINCTCELL ?X ?Y ?M ?N) (DISTINCT ?X ?M)) (<= (DISTINCTCELL ?X ?Y ?M ?N) (DISTINCT ?Y ?N)) (<= (LEGAL ?PLAYER (MARK ?X ?Y)) (TRUE (CELL ?X ?Y B)) (TRUE (CONTROL ?PLAYER))) (<= (LEGAL ?PLAYER NOOP) (NOT (TRUE (CONTROL ?PLAYER)))) (<= (GOAL ?PLAYER 100) (LINE ?PLAYER)) (<= (GOAL ?PLAYER 50) (NOT (LINE X)) (NOT (LINE O)) (NOT OPEN)) (<= (GOAL ?PLAYER1 0) (LINE ?PLAYER2) (DISTINCT ?PLAYER1 ?PLAYER2)) (<= (GOAL ?PLAYER 0) (NOT (LINE X)) (NOT (LINE O)) OPEN) (<= TERMINAL (LINE ?PLAYER)) (<= TERMINAL (NOT OPEN)) 30 30) +(START MATCH.3316980891 X ((ROLE X) (ROLE O) (INIT (CELL 1 1 B)) (INIT (CELL 1 2 B)) (INIT (CELL 1 3 B)) (INIT (CELL 2 1 B)) (INIT (CELL 2 2 B)) (INIT (CELL 2 3 B)) (INIT (CELL 3 1 B)) (INIT (CELL 3 2 B)) (INIT (CELL 3 3 B)) (INIT (CONTROL X)) (<= (NEXT (CELL ?X ?Y ?PLAYER)) (DOES ?PLAYER (MARK ?X ?Y))) (<= (NEXT (CELL ?X ?Y ?MARK)) (TRUE (CELL ?X ?Y ?MARK)) (DOES ?PLAYER (MARK ?M ?N)) (DISTINCTCELL ?X ?Y ?M ?N)) (<= (NEXT (CONTROL X)) (TRUE (CONTROL O))) (<= (NEXT (CONTROL O)) (TRUE (CONTROL X))) (<= (ROW ?X ?PLAYER) (TRUE (CELL ?X 1 ?PLAYER)) (TRUE (CELL ?X 2 ?PLAYER)) (TRUE (CELL ?X 3 ?PLAYER))) (<= (COLUMN ?Y ?PLAYER) (TRUE (CELL 1 ?Y ?PLAYER)) (TRUE (CELL 2 ?Y ?PLAYER)) (TRUE (CELL 3 ?Y ?PLAYER))) (<= (DIAGONAL ?PLAYER) (TRUE (CELL 1 1 ?PLAYER)) (TRUE (CELL 2 2 ?PLAYER)) (TRUE (CELL 3 3 ?PLAYER))) (<= (DIAGONAL ?PLAYER) (TRUE (CELL 1 3 ?PLAYER)) (TRUE (CELL 2 2 ?PLAYER)) (TRUE (CELL 3 1 ?PLAYER))) (<= (LINE ?PLAYER) (ROW ?X ?PLAYER)) (<= (LINE ?PLAYER) (COLUMN ?Y ?PLAYER)) (<= (LINE ?PLAYER) (DIAGONAL ?PLAYER)) (<= OPEN (TRUE (CELL ?X ?Y B))) (<= (DISTINCTCELL ?X ?Y ?M ?N) (DISTINCT ?X ?M)) (<= (DISTINCTCELL ?X ?Y ?M ?N) (DISTINCT ?Y ?N)) (<= (LEGAL ?PLAYER (MARK ?X ?Y)) (TRUE (CELL ?X ?Y B)) (TRUE (CONTROL ?PLAYER))) (<= (LEGAL ?PLAYER NOOP) (NOT (TRUE (CONTROL ?PLAYER)))) (<= (GOAL ?PLAYER 100) (LINE ?PLAYER)) (<= (GOAL ?PLAYER 50) (NOT (LINE X)) (NOT (LINE O)) (NOT OPEN)) (<= (GOAL ?PLAYER1 0) (LINE ?PLAYER2) (DISTINCT ?PLAYER1 ?PLAYER2)) (<= (GOAL ?PLAYER 0) (NOT (LINE X)) (NOT (LINE O)) OPEN) (<= TERMINAL (LINE ?PLAYER)) (<= TERMINAL (NOT OPEN))) 30 30) POST / HTTP/1.0 Accept: text/delim @@ -23,7 +23,7 @@ Content-type: text/acl Content-length: 41 -(PLAY MATCH.3316980891 ((MARK 3 3) NOOP)) +(PLAY MATCH.3316980891 ((MARK 2 2) NOOP)) POST / HTTP/1.0 Accept: text/delim @@ -32,7 +32,7 @@ Content-type: text/acl Content-length: 41 -(PLAY MATCH.3316980891 (NOOP (MARK 1 3))) +(PLAY MATCH.3316980891 (NOOP (MARK 1 1))) POST / HTTP/1.0 Accept: text/delim Modified: trunk/Toss/Play/ServerGDLTest.out =================================================================== --- trunk/Toss/Play/ServerGDLTest.out 2010-12-19 17:35:10 UTC (rev 1261) +++ trunk/Toss/Play/ServerGDLTest.out 2010-12-19 20:42:04 UTC (rev 1262) @@ -7,7 +7,7 @@ Content-type: text/acl Content-length: 10 -(MARK 3 3) +(MARK 2 2) HTTP/1.0 200 OK Content-type: text/acl Content-length: 4 Modified: trunk/Toss/Solver/Structure.ml =================================================================== --- trunk/Toss/Solver/Structure.ml 2010-12-19 17:35:10 UTC (rev 1261) +++ trunk/Toss/Solver/Structure.ml 2010-12-19 20:42:04 UTC (rev 1262) @@ -1033,6 +1033,19 @@ Format.fprintf Format.str_formatter "%a" fprint struc; Format.flush_str_formatter () +let board_elem_coords name = + let col_index = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" in + let col = String.index col_index name.[0] + 1 in + try col, int_of_string (String.sub name 1 (String.length name - 1)) + with Failure _ | Invalid_argument _ -> + raise Not_found + +let board_coords_name (col, row) = + if col < 1 || col > 52 || row < 1 then raise Not_found; + let col_index = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" in + Char.escaped col_index.[col-1] ^ string_of_int row (* -------------------- PARSER HELPERS -------------------- *) Modified: trunk/Toss/Solver/Structure.mli =================================================================== --- trunk/Toss/Solver/Structure.mli 2010-12-19 17:35:10 UTC (rev 1261) +++ trunk/Toss/Solver/Structure.mli 2010-12-19 20:42:04 UTC (rev 1262) @@ -105,7 +105,14 @@ val sprint : structure -> string +(** Coordinates, column first, of a board element name. Raises + [Not_found] if the name is not of proper format. *) +val board_elem_coords : string -> int * int +(** Board element name under given coordinates, column first. Raises + [Not_found] if the coordinates are out of bounds. *) +val board_coords_name : int * int -> string + (** {2 Adding elements possibly with string names} *) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-19 22:43:16
|
Revision: 1263 http://toss.svn.sourceforge.net/toss/?rev=1263&view=rev Author: lukaszkaiser Date: 2010-12-19 22:43:09 +0000 (Sun, 19 Dec 2010) Log Message: ----------- Move suggestions and computer play in WebClient. Modified Paths: -------------- trunk/Toss/WebClient/Handler.py trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/MakeDB.py trunk/Toss/WebClient/README trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/Wrapper.py trunk/Toss/WebClient/index.html trunk/Toss/WebClient/profile.html trunk/Toss/WebClient/register.html trunk/Toss/examples/Breakthrough.toss trunk/Toss/examples/Chess.toss trunk/Toss/examples/Gomoku.toss trunk/Toss/examples/Tic-Tac-Toe.toss Added Paths: ----------- trunk/Toss/WebClient/contact.html Modified: trunk/Toss/WebClient/Handler.py =================================================================== --- trunk/Toss/WebClient/Handler.py 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/WebClient/Handler.py 2010-12-19 22:43:09 UTC (rev 1263) @@ -69,7 +69,7 @@ or_s = "(player1='" + player_id + "' or player2='" + player_id + "')" plays = get_all_from_db (db, "cur_states", "game='"+ game + "' and " + or_s) def play_name (p): - (pid, g, p1, p2, move, _, _, _) = p + (pid, g, p1, p2, move, _, _, _, _) = p return ("/plays/" + str(g) + "_" + str(p1) + "_" + str(p2) + "_" + str(pid) + "_" + str(move)) return (str([play_name (p) for p in plays])) @@ -78,14 +78,14 @@ friends = get_all_from_db (db, "friends", "id='"+ uid + "'") return (str([str(f) for (_, f) in friends])) -def db_cur_insert (db, game, p1, p2, pid, move, toss, info, svg_str): - db.execute ("insert into cur_states(playid, game, player1, player2, move, toss, info, svg) values (?, ?, ?, ?, ?, ?, ?, ?)", - (pid, game, p1, p2, move, toss, info, svg_str)) +def db_cur_insert (db, game, p1, p2, pid, move, toss, loc, info, svg_str): + db.execute ("insert into cur_states(playid, game, player1, player2, move, toss, loc, info, svg) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", + (pid, game, p1, p2, move, toss, str(loc), info, svg_str)) db.commit () -def db_old_insert (db, game, p1, p2, pid, move, toss, info, svg_str): - db.execute ("insert into old_states(playid, game, player1, player2, move, toss, info, svg) values (?, ?, ?, ?, ?, ?, ?, ?)", - (pid, game, p1, p2, move, toss, info, svg_str)) +def db_old_insert (db, game, p1, p2, pid, move, toss, loc, info, svg_str): + db.execute ("insert into old_states(playid, game, player1, player2, move, toss, loc, info, svg) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", + (pid, game, p1, p2, move, toss, str(loc), info, svg_str)) db.commit () def get_game_info (client): @@ -107,9 +107,10 @@ client.open_from_str (toss) info = get_game_info (client) model = client.get_model () + loc = client.get_cur_loc () get_global_lock (db) pid = get_free_id (db) - db_cur_insert (db, game, p1, p2, pid, move, model, info, "") + db_cur_insert (db, game, p1, p2, pid, move, model, loc, info, "") release_global_lock (db) return (str(pid) + "$" + info) @@ -120,7 +121,7 @@ def open_db (db, game, p1, p2, pid, move): select_s = game_select_s (game, p1, p2, pid, move) res = get_all_from_db (db, "cur_states", select_s) - (_, _, _, _, _, _, info, _) = res[0] + (_, _, _, _, _, _, _, info, _) = res[0] return (info) def db_escape (s): @@ -129,10 +130,11 @@ def move_play (db, client, move_tup, g, p1, p2, pid, m): sel_s = game_select_s (g, p1, p2, pid, m) old_res = get_all_from_db (db, "cur_states", sel_s) - (_, _, _, _, _, old_toss, old_info, old_svg) = old_res[0] + (_, _, _, _, _, old_toss, old_loc, old_info, old_svg) = old_res[0] res = get_all_from_db (db, "games", "game='" + g + "'") (_, game_toss) = res[0] client.open_from_str (game_toss + "\n MODEL " + old_toss) + client.set_cur_loc (old_loc) (move1, move2, move3) = move_tup client.make_move (move1, move2, move3) new_toss = db_escape (client.get_model ()) @@ -140,8 +142,9 @@ new_info_db = db_escape (new_info) db.execute ("update cur_states set toss='" + new_toss + "' where " + sel_s) db.execute ("update cur_states set info='"+ new_info_db +"' where "+ sel_s) + db.execute ("update cur_states set loc='"+ str(move3) +"' where "+ sel_s) db.execute ("update cur_states set move=" + str(int(m)+1) +" where "+ sel_s) - db_old_insert (db, g, p1, p2, pid, m, old_toss, old_info, old_svg) + db_old_insert (db, g, p1, p2, pid, m, old_toss, old_loc, old_info, old_svg) return (new_info) def upd_svg (db, g, p1, p2, pid, m, svg_s): @@ -187,6 +190,7 @@ if passwd_from_db (db, uid): return (False) db.execute ("insert into users(id, name, surname, email, passwd) " + "values (?, ?, ?, ?, ?)", (uid, name, surname, email, pwd)) + db.execute ("insert into friends(id, fid) values (?, ?)", (uid, "computer")) db.commit () return (True) @@ -236,6 +240,26 @@ plays += "$" + list_plays (db, g, usr) return (usr + "$" + name + plays) +def suggest_offset (offset, db, client, g, p1, p2, pid, m): + sel_s = game_select_s (g, p1, p2, pid, m) + res = get_all_from_db (db, "cur_states", sel_s) + (_, _, _, _, _, toss, loc, _, _) = res[0] + game_res = get_all_from_db (db, "games", "game='" + g + "'") + (_, game_toss) = game_res[0] + client.open_from_str (game_toss + "\n MODEL " + toss) + client.set_cur_loc (loc) + depth = client.get_data ("depth") + if depth == "none": depth = 2 + adv_ratio = client.get_data ("adv_ratio") + if adv_ratio == "none": adv_ratio = 2 + return (client.suggest (int(depth) + offset, adv_ratio)) + +def suggest (db, client, g, p1, p2, pid, m): + return (suggest_offset (0, db, client, g, p1, p2, pid, m)) + +def suggestx (db, client, g, p1, p2, pid, m): + return (suggest_offset (1, db, client, g, p1, p2, pid, m)) + def handler(req): req.content_type = "text/plain" db = sqlite3.connect(MakeDB.DB_FILE) @@ -300,7 +324,8 @@ res = eval (cmd.lower() + "(db, " + data + ")") req.write(str(res)) return apache.OK - if (cmd == "NEW_PLAY") or (cmd == "MOVE_PLAY"): + if ((cmd == "NEW_PLAY") or (cmd == "MOVE_PLAY") or + (cmd == "SUGGEST") or (cmd == "SUGGESTX")): port = get_toss_port (db) c = SystemClient ("localhost", port) res = eval (cmd.lower() + "(db, " + data + ")") Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/WebClient/Main.js 2010-12-19 22:43:09 UTC (rev 1263) @@ -191,9 +191,9 @@ function make_move () { if (CUR_MOVE == "") return; var m = PLAYS[CUR_PLAY_I][3] % 2; - if (PLAYS[CUR_PLAY_I][m] != UNAME) { - alert ("It is your Opponent's turn"); - return; + if (PLAYS[CUR_PLAY_I][m] != UNAME && PLAYS[CUR_PLAY_I][m] != "computer") { + alert ("It is your Opponent's turn"); + return; } document.getElementById("working").style.display = "block"; var info = srv("MOVE_PLAY", 'c, '+ CUR_MOVE +', '+ play_py_id (CUR_PLAY_I)); @@ -209,9 +209,14 @@ full_redraw (); PLAYS[CUR_PLAY_I][3] = parseInt(PLAYS[CUR_PLAY_I][3]) + 1; async_srv ("UPD_SVG", play_py_id(CUR_PLAY_I) + ", " + svg_string()); - var old_li = document.getElementById ("plays-list-" + GAME_NAME + "-elem-" + CUR_PLAY_I); + 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][(m + 1) % 2] == "computer") { + suggest_move (); + make_move (); + } } @@ -337,3 +342,26 @@ var lst = srv ("LIST_FRIENDS", "user"); FRIENDS = convert_python_list (',', lst); } + +function suggest_move () { + var m = srv("SUGGEST", 'c, '+ play_py_id (CUR_PLAY_I)); + show_move (m); +} + +function suggest_move_better () { + var m = srv("SUGGESTX", 'c, '+ play_py_id (CUR_PLAY_I)); + show_move (m); +} + +function toggle_suggestions () { + var txt = document.getElementById("suggestions-toggle").innerHTML; + if (txt.indexOf ("Show") == -1) { + document.getElementById("suggestions-toggle").innerHTML = + "Show Move Suggestions"; + document.getElementById("player-info-par").style.display = "none"; + } else { + document.getElementById("suggestions-toggle").innerHTML = + "Hide Move Suggestions"; + document.getElementById("player-info-par").style.display = "block"; + } +} \ No newline at end of file Modified: trunk/Toss/WebClient/MakeDB.py =================================================================== --- trunk/Toss/WebClient/MakeDB.py 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/WebClient/MakeDB.py 2010-12-19 22:43:09 UTC (rev 1263) @@ -20,10 +20,10 @@ " name string, surname string, email string, passwd string)") conn.execute("create table cur_states(playid int primary key," + " game string, player1 string, player2 string," + - " move int, toss string, info string, svg string)") + " move int, toss string, loc string, info string, svg string)") conn.execute("create table old_states(playid int," + " game string, player1 string, player2 string," + - " move int, toss string, info string, svg string)") + " move int, toss string, loc string, info string, svg string)") conn.execute("create table games(game string primary key, toss string)") conn.execute("create table ports(port int primary key, locked bool)") conn.execute("create table lock(tid int primary key, locked bool)") @@ -31,6 +31,9 @@ conn.commit () conn.execute ("insert into lock(tid, locked) values (?, ?)", (TUID, 'false')) + conn.execute ("insert into users(id, name, surname, email, passwd) values"+ + " (?, ?, ?, ?, ?)", + ("computer", "Computer", "tPlay", "co...@tp...", "xxx")) for g in games: f = open(games_path + "/" + g + ".toss") toss = f.read() Modified: trunk/Toss/WebClient/README =================================================================== --- trunk/Toss/WebClient/README 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/WebClient/README 2010-12-19 22:43:09 UTC (rev 1263) @@ -14,13 +14,13 @@ The main handler script is called Hander.py (server side) and corresponding JavaScript functions are in *.js. To start client open index.html, but first make sure that WebClient is linked in /var/www (ln -s should suffice). -Then run "./make_db" from WebClient and make sure Handler entry (above) is ok. +Then run "./MakeDB.py" from WebClient and make sure Handler entry (above) is ok. Also copy Server from main Toss dir as TossServer to the WebClient directory. TODO: - move interface: first click all, second click toggle, if one - confirm msg - - move suggestions and play against computer + - display results, prevent suggestion bug when game has already ended - sort plays by who's turn it is - option to give up game and offer a draw - enable google (or other) analytics Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/WebClient/Style.css 2010-12-19 22:43:09 UTC (rev 1263) @@ -35,6 +35,7 @@ #plays .bt { width: 7em; + font-size: 0.75em; position: absolute; right: 2px; } @@ -248,7 +249,9 @@ padding: 0px; margin: 0px; height: 1.3em; - text-align: right; + text-align: center; + font-size: 0.9em; + font-weight: bold; color: #ffe4aa; background-color: #400827; border-color: #260314; @@ -256,6 +259,47 @@ border-width: 5px 0px 0px 0px; } +#bottom a, #bottom a:link, #bottom a:active, #bottom a:visited { + color: #ffe4aa; + text-decoration: none; +} + +#bottom a:hover { + color: #ffffff; + text-decoration: underline; + cursor: pointer; +} + +/* Bottom styles. */ + +#contact { + position: absolute; + top: 0px; + right: 0.5em; +} + +#suggestions-toggle { + position: absolute; + margin: 0px; + padding: 0px; + top: 0px; + left: 0.5em; + border: 0px; + background-color: #400827; + color: #ffe4aa; + font-family: Verdana, 'TeXGyreHerosRegular', sans; + font-size: 1em; + font-weight: bold; +} + +#suggestions-toggle:hover { + color: #ffffff; + text-decoration: underline; + cursor: pointer; +} + +/* Menu styles. */ + #menu-top-par { margin-top: 0.5em; margin-bottom: 0em; @@ -321,13 +365,27 @@ text-decoration: underline; } +#register-content { + position: relative; + top: 2.5em; + left: 1em; +} +#main-profile { + position: relative; + left: 1em; +} + #opponents { display: none; position: absolute; - left: 6em; - top: 3.5em; + left: 0px; + right: 0px; + top: 4em; min-width: 20em; + width: 20em; + margin-left: auto; + margin-right: auto; color: #ffe4aa; background-color: #400827; font-weight: bold; @@ -383,7 +441,8 @@ #welcome { text-align: justify; - margin-top: 1em; + margin-top: 3.5em; + margin-left: 1em; } #welcome-top { @@ -410,6 +469,12 @@ padding: 0px; } +#player-info-par { + display: none; + margin-top: 0.5em; + padding: 0px; +} + #move-info-par { margin-top: 0.5em; padding: 0px; @@ -461,7 +526,8 @@ .game-par { padding: 0px; - border-top: 0px solid #260314; + padding-bottom: 0.2em; + border-bottom: 1px solid #260314; } #plays { @@ -500,7 +566,6 @@ } - /* SVG styling */ #svg { min-width: 10em; Modified: trunk/Toss/WebClient/Wrapper.py =================================================================== --- trunk/Toss/WebClient/Wrapper.py 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/WebClient/Wrapper.py 2010-12-19 22:43:09 UTC (rev 1263) @@ -197,3 +197,33 @@ self.apply_rule (r, m, 1.0, []) self.set_cur_loc (endp) return ("move ok") + + def get_data (self, did): + m = self.msg ("GET DATA " + did) + if len(m) < 3: return (m) + if m[0:3] == "ERR": return ("none") + return (m) + + def set_time (self, tstep, t): + m = self.msg ("SET dynamics " + repr(tstep) + " " + repr(t)) + return (m) + + def get_time (self): + m = self.msg ("GET dynamics") + t = [s.strip() for s in m.split('/')] + return ((float(t[0]), float(t[1]))) + + def suggest (self, depth, adv_ratio): + loc = self.get_cur_loc () + (ts, t) = self.get_time () + m = self.msg ("EVAL LOC MOVES " + str(adv_ratio) + ".0 " + + str(loc) +" TIMEOUT 1200 "+ str(depth) + + " alpha_beta_ord") + self.set_time (ts, t) + msg = [s.strip() for s in m.split(';')] + emb = dict() + for s in msg[1].split(','): + es = [x.strip() for x in s.split(':')] + emb[es[0]] = es[1] + # we ignore params in html for now + return ((emb, msg[0], int(msg[3]))) Added: trunk/Toss/WebClient/contact.html =================================================================== --- trunk/Toss/WebClient/contact.html (rev 0) +++ trunk/Toss/WebClient/contact.html 2010-12-19 22:43:09 UTC (rev 1263) @@ -0,0 +1,35 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/xhtml+xml; charset=UTF-8" /> + <title>tPlay — Contact</title> + <meta http-equiv="X-UA-Compatible" content="chrome=1"> + <link rel="icon" type="image/vnd.microsoft.icon" href="/favicon.ico" /> + <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> + <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> +</head> + +<body> +<div id="top"> +<div id="logo"><a href="index.html">tPlay</a></div> +</div> + +<div id="main"> + +<div id="register-content"> + +<h2>Contact tPlay</h2> + +Just write us an email! + +</div> + +</div> + +<div id="bottom"> +<a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a> +<a href="contact.html" id="contact">Contact and Info</a> +</div> + +</body> +</html> Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/WebClient/index.html 2010-12-19 22:43:09 UTC (rev 1263) @@ -129,8 +129,7 @@ <div id="game-disp"> <p id="game-info-par"> <span id="game-title"></span> - game <span id="play-number">?</span>, - <span id="cur-player"></span> moving + game <span id="play-number">?</span> </p> <p id="move-info-par"> @@ -138,13 +137,27 @@ <span id="cur-move">none</span> </p> + <p id="player-info-par"> + Moving: <span id="cur-player">?</span> + <button id="sugbt" class="bt" onclick="suggest_move()"> + Suggest (weak, fast) + </button> + <button id="sugbt" class="bt" onclick="suggest_move_better()"> + Suggest (stronger, slow) + </button> + </p> + <div id="board"><div id="working">Working...</div></div> </div> </div> <div id="bottom"> -<div style="margin-right: 0em; display: none;">Disclaimer</div> +<button id="suggestions-toggle" onclick="toggle_suggestions()"> + Show Move Suggestions +</button> +<a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a> +<a href="contact.html" id="contact">Contact and Info</a> </div> </body> Modified: trunk/Toss/WebClient/profile.html =================================================================== --- trunk/Toss/WebClient/profile.html 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/WebClient/profile.html 2010-12-19 22:43:09 UTC (rev 1263) @@ -94,7 +94,8 @@ </div> <div id="bottom"> -<div style="margin-right: 0em; display: none;">Disclaimer</div> +<a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a> +<a href="contact.html" id="contact">Contact and Info</a> </div> </body> Modified: trunk/Toss/WebClient/register.html =================================================================== --- trunk/Toss/WebClient/register.html 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/WebClient/register.html 2010-12-19 22:43:09 UTC (rev 1263) @@ -19,6 +19,8 @@ <div id="main"> +<div id="register-content"> + <h2>Register on tPlay</h2> <form id="registerform"> @@ -45,8 +47,11 @@ </div> +</div> + <div id="bottom"> -<div style="margin-right: 0em; display: none;">Disclaimer</div> +<a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a> +<a href="contact.html" id="contact">Contact and Info</a> </div> </body> Modified: trunk/Toss/examples/Breakthrough.toss =================================================================== --- trunk/Toss/examples/Breakthrough.toss 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/examples/Breakthrough.toss 2010-12-19 22:43:09 UTC (rev 1263) @@ -1,19 +1,14 @@ PLAYERS 1, 2 -DATA depth: 3 -RULE WhiteLeft: - [ | B:1 {} | ] " - - ?B ? - - ? W -" -> [ | B:1 {} | - ] " - - W ? - - ? . -" emb W, B - pre not ex x (B(x) and not ex y C(y, x)) +DATA depth: 2, adv_ratio: 2 +REL DiagW (x, y) = ex z (C(x, z) and (R(y, z) or R(z, y))) +REL DiagB (x, y) = ex z (C(z, x) and (R(y, z) or R(z, y))) +RULE WhiteDiag: + [ a, b | W { a }; _opt_B { b } | + vx {a->0.,b->10.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + -> + [ a, b | W { b } | + vx {a->0.,b->10.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + emb W, B pre DiagW(a, b) and not ex x (B(x) and not ex y C(y, x)) RULE WhiteStraight: [ | B:1 {}; R:2 {} | ] " @@ -27,34 +22,13 @@ . " emb W, B pre not ex x (B(x) and not ex y C(y, x)) -RULE WhiteRight: - [ | B:1 {} | ] " - - ? ?B - - W ? -" -> [ | B:1 {} | - ] " - - ? W - - . ? -" emb W, B - pre not ex x (B(x) and not ex y C(y, x)) -RULE BlackLeft: - [ | W:1 {} | ] " - - B ? - - ? ?W -" -> [ | W:1 {} | - ] " - - . ? - - ? B -" emb W, B - pre not ex x (W(x) and not ex y C(x, y)) +RULE BlackDiag: + [ a, b | B { a }; _opt_W { b } | + vx {a->0.,b->10.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + -> + [ a, b | B { b } | + vx {a->0.,b->10.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + emb W, B pre DiagB(a, b) and not ex x (W(x) and not ex y C(x, y)) RULE BlackStraight: [ | R:2 {}; W:1 {} | ] " @@ -68,20 +42,6 @@ B " emb W, B pre not ex x (W(x) and not ex y C(x, y)) -RULE BlackRight: - [ | W:1 {} | ] " - - ? B - - ?W ? -" -> [ | W:1 {} | - ] " - - ? . - - B ? -" emb W, B - pre not ex x (W(x) and not ex y C(x, y)) LOC 0 { PLAYER 1 PAYOFF { @@ -92,7 +52,7 @@ :(ex x (B(x) and not ex y C(y, x))) + -1. * :(ex x (W(x) and not ex y C(x, y))) } - MOVES [WhiteLeft -> 1]; [WhiteStraight -> 1]; [WhiteRight -> 1] + MOVES [WhiteDiag -> 1]; [WhiteStraight -> 1] } LOC 1 { PLAYER 2 @@ -104,7 +64,7 @@ :(ex x (B(x) and not ex y C(y, x))) + -1. * :(ex x (W(x) and not ex y C(x, y))) } - MOVES [BlackLeft -> 0]; [BlackStraight -> 0]; [BlackRight -> 0] + MOVES [BlackDiag -> 0]; [BlackStraight -> 0] } MODEL [ | | ] " Modified: trunk/Toss/examples/Chess.toss =================================================================== --- trunk/Toss/examples/Chess.toss 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/examples/Chess.toss 2010-12-19 22:43:09 UTC (rev 1263) @@ -1,5 +1,5 @@ PLAYERS 1, 2 -DATA depth: 1 +DATA depth: 0, adv_ratio: 1 REL IsFirst(x) = not ex z C(z, x) REL IsSecond(x) = ex y (C(y, x) and IsFirst(y)) REL IsEight(x) = not ex z C(x, z) Modified: trunk/Toss/examples/Gomoku.toss =================================================================== --- trunk/Toss/examples/Gomoku.toss 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/examples/Gomoku.toss 2010-12-19 22:43:09 UTC (rev 1263) @@ -1,5 +1,5 @@ PLAYERS 1, 2 -DATA r1: circle, r2: line, adv_ratio: 4 +DATA r1: circle, r2: line, adv_ratio: 4, depth: 1 RULE Cross: [a1 | P:1 {}; Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] -> [a1 | P (a1); Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] Modified: trunk/Toss/examples/Tic-Tac-Toe.toss =================================================================== --- trunk/Toss/examples/Tic-Tac-Toe.toss 2010-12-19 20:42:04 UTC (rev 1262) +++ trunk/Toss/examples/Tic-Tac-Toe.toss 2010-12-19 22:43:09 UTC (rev 1263) @@ -1,4 +1,5 @@ PLAYERS 1, 2 +DATA r1: circle, r2: line, adv_ratio: 4, depth: 3 REL WinQ() = ex x, y, z (Q(x) and Q(y) and Q(z) and ( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-20 00:15:06
|
Revision: 1264 http://toss.svn.sourceforge.net/toss/?rev=1264&view=rev Author: lukstafi Date: 2010-12-20 00:14:59 +0000 (Mon, 20 Dec 2010) Log Message: ----------- Order of argfind_max bug fix. Deterministic suggest setting (currently only ON for the GDL test). GDL suggestions only for played turn. Modified Paths: -------------- trunk/Toss/Formula/Aux.ml trunk/Toss/Formula/AuxTest.ml trunk/Toss/Play/GDL.ml trunk/Toss/Play/GDL.mli trunk/Toss/Play/Game.ml trunk/Toss/Play/Game.mli trunk/Toss/Play/GameTest.ml trunk/Toss/Play/Server.ml trunk/Toss/Play/ServerGDLTest.in trunk/Toss/Play/ServerGDLTest.out Modified: trunk/Toss/Formula/Aux.ml =================================================================== --- trunk/Toss/Formula/Aux.ml 2010-12-19 22:43:09 UTC (rev 1263) +++ trunk/Toss/Formula/Aux.ml 2010-12-20 00:14:59 UTC (rev 1264) @@ -236,9 +236,9 @@ let n = Array.length a in if n=0 then [] else - let best = ref (Array.unsafe_get a 0) - and besti = ref [0] in - for i = 1 to n-1 do + let best = ref (Array.unsafe_get a (n-1)) + and besti = ref [n-1] in + for i = n-2 downto 0 do let e = Array.unsafe_get a i in let res = cmp e !best in if res > 0 then (best := e; besti := [i]) Modified: trunk/Toss/Formula/AuxTest.ml =================================================================== --- trunk/Toss/Formula/AuxTest.ml 2010-12-19 22:43:09 UTC (rev 1263) +++ trunk/Toss/Formula/AuxTest.ml 2010-12-20 00:14:59 UTC (rev 1264) @@ -268,7 +268,7 @@ ); - "array_argfind, array_find_all, array_argfind_all" >:: + "array_argfind, array_find_all, array_argfind_all, array_argfind_all_max" >:: (fun () -> assert_equal ~printer:string_of_int 2 @@ -317,6 +317,13 @@ [] (Aux.array_argfind_all (fun e->e.[0]='e') [|"a";"c"; "b"|]); + + assert_equal + ~printer:(fun l->String.concat "; " (List.map string_of_int l)) + ~msg:"argfind_all_max" + [3;6] + (Aux.array_argfind_all_max (-) + [|2;3;2;5;3;4;5;1|]); ); "array_for_all, array_for_all2" >:: Modified: trunk/Toss/Play/GDL.ml =================================================================== --- trunk/Toss/Play/GDL.ml 2010-12-19 22:43:09 UTC (rev 1263) +++ trunk/Toss/Play/GDL.ml 2010-12-20 00:14:59 UTC (rev 1264) @@ -42,9 +42,9 @@ let compile_game_descr entries = entries -let client_player = ref (Const "uninitialized") +let playing_as = ref (Const "uninitialized") let game_description = ref [] -let game_state = ref (ref Arena.empty_state) +let player_name_terms = ref [| |] let state_of_file s = Printf.printf "GDL: Loading file %s...\n%!" s; @@ -56,31 +56,38 @@ res let initialize_game state player game_descr startcl = - game_state := state; - state := state_of_file "./examples/Tic-Tac-Toe.toss"; - - client_player := player; + playing_as := player; game_description := game_descr; + player_name_terms := [|Const "X"; Const "O"|]; let effort, horizon, heur_adv_ratio = 2, 100, 4.0 in effort, horizon, heur_adv_ratio let translate_last_action actions = - if actions = [] then - (* start of game -- Server will handle this answer as NOOP *) - "", [] - else - (* FIXME: really translate *) - "Cross", ["a1","a1"] + match actions with + | [] -> + (* start of game -- Server will handle this answer as NOOP *) + "", [] + | [Func ("MARK", [Const col; Const row]); Const "NOOP"] -> + "Cross", ["a1", + Structure.board_coords_name + (int_of_string col, int_of_string row)] + | [ Const "NOOP"; Func ("MARK", [Const col; Const row])] -> + "Circle", ["a1", + Structure.board_coords_name + (int_of_string col, int_of_string row)] + | _ -> assert false +let our_turn state = + let loc = state.Arena.cur_loc in + let loc_player = + state.Arena.game.Arena.graph.(loc).Arena.player in + !player_name_terms.(loc_player) = !playing_as + let translate_move rule emb new_state = let struc = new_state.Arena.struc in let elem = snd (List.hd emb) in let c, r = Structure.board_elem_coords (Structure.elem_str struc elem) in - let mark = Printf.sprintf "(MARK %d %d)" c r in - match rule with - | "Cross" -> "(" ^ mark ^ " NOOP)" - | "Circle" -> "(NOOP " ^ mark ^ ")" - | _ -> assert false + Printf.sprintf "(MARK %d %d)" c r Modified: trunk/Toss/Play/GDL.mli =================================================================== --- trunk/Toss/Play/GDL.mli 2010-12-19 22:43:09 UTC (rev 1263) +++ trunk/Toss/Play/GDL.mli 2010-12-20 00:14:59 UTC (rev 1264) @@ -31,11 +31,11 @@ type request = | Start of string * term * game_description * int * int - (* prepare game: match id, role, game, startclock, playclock *) + (** prepare game: match id, role, game, startclock, playclock *) | Play of string * term list - (* request a move: match id, actions on previous step *) + (** request a move: match id, actions on previous step *) | Stop of string * term list - (* game ends here: match id, actions on previous step *) + (** game ends here: match id, actions on previous step *) val compile_game_descr : game_descr_entry list -> game_description @@ -46,6 +46,9 @@ val translate_last_action : term list -> string * (string * string) list -(* Rule name, embedding, game state. *) +(** Whether the current player is the one being played as. *) +val our_turn : Arena.game_state -> bool + +(** Rule name, embedding, game state. *) val translate_move : string -> (int * int) list -> Arena.game_state -> string Modified: trunk/Toss/Play/Game.ml =================================================================== --- trunk/Toss/Play/Game.ml 2010-12-19 22:43:09 UTC (rev 1263) +++ trunk/Toss/Play/Game.ml 2010-12-20 00:14:59 UTC (rev 1264) @@ -10,6 +10,8 @@ let debug_level = ref 0 let set_debug_level i = (debug_level := i) +let deterministic_suggest = ref false + (* A global "hurry up!" switch triggered by the timer alarm. *) let timeout = ref false let get_timeout () = !timeout @@ -497,7 +499,7 @@ if rel < 0 then find best acc tl else if rel = 0 then find best (hd::acc) tl else find hd [hd] tl - | [] -> acc in + | [] -> List.rev acc in match l with | [] -> invalid_arg "find_all_max: empty list" | hd::tl -> find hd [hd] tl @@ -509,7 +511,8 @@ measure [subt_sizes]. Return a best position (randomized if multiple are optimal) and a best scores table (averaged if multiple are optimal). *) -let find_best_score cooperative player scores subt_sizes = +let find_best_score ?(use_det_setting=false) cooperative player + scores subt_sizes = (* find a new best score *) let my_scores = Array.map (fun s->s.(player)) scores in let bestsc = Aux.array_argfind_all_max compare my_scores in @@ -532,6 +535,9 @@ match bestsc with | [] -> failwith "impossible" | [bestsc,_] -> scores.(bestsc), bestsc + | (bsc,_)::(bsc2,_)::_ + when use_det_setting && !deterministic_suggest -> + scores.(bsc), bsc | _ -> (* pick ones from biggest subtrees *) let bestsc = @@ -823,7 +829,7 @@ let scores = Array.map (maximax_tree player betas (depth-1)) models in let _, best = - find_best_score cooperative player scores + find_best_score ~use_det_setting:true cooperative player scores (Array.map (fun _ -> 1) scores) in let state = models.(best) in (* {{{ log entry *) @@ -895,7 +901,8 @@ (uctree_score ~num_players subtree)) node.node_subtrees in let _, best = - find_best_score params.cooperative loc.Arena.player + find_best_score ~use_det_setting:true + params.cooperative loc.Arena.player scores (Array.map uctree_size node.node_subtrees) in let state = uctree_state node.node_subtrees.(best) in (* {{{ log entry *) Modified: trunk/Toss/Play/Game.mli =================================================================== --- trunk/Toss/Play/Game.mli 2010-12-19 22:43:09 UTC (rev 1263) +++ trunk/Toss/Play/Game.mli 2010-12-20 00:14:59 UTC (rev 1264) @@ -221,3 +221,7 @@ If > 1, print the updated gametree at each move using treesearch. *) val set_debug_level : int -> unit + +(** If true, do not randomize the final choice of move. Useful mostly + for debugging. *) +val deterministic_suggest : bool ref Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2010-12-19 22:43:09 UTC (rev 1263) +++ trunk/Toss/Play/GameTest.ml 2010-12-20 00:14:59 UTC (rev 1264) @@ -564,17 +564,20 @@ "server: ServerGDLTest.in GDL Tic-Tac-Toe" >:: (fun () -> + let old_det_suggest = !Game.deterministic_suggest in + Game.deterministic_suggest := true; let in_ch = open_in "./Play/ServerGDLTest.in" in let out_ch = open_out "./Play/ServerGDLTest.temp" in (try while true do Server.req_handle in_ch out_ch done with End_of_file -> ()); close_in in_ch; close_out out_ch; + Game.deterministic_suggest := old_det_suggest; let result = Aux.input_file (open_in "./Play/ServerGDLTest.temp") in let target = Aux.input_file (open_in "./Play/ServerGDLTest.out") in - Sys.remove "./Play/ServerTest.temp"; + Sys.remove "./Play/ServerGDLTest.temp"; assert_equal ~printer:(fun x->x) target result ); Modified: trunk/Toss/Play/Server.ml =================================================================== --- trunk/Toss/Play/Server.ml 2010-12-19 22:43:09 UTC (rev 1263) +++ trunk/Toss/Play/Server.ml 2010-12-20 00:14:59 UTC (rev 1264) @@ -152,6 +152,7 @@ let req = req_of_str line in let resp = match req with + | Aux.Left (Arena.SuggestLocMoves (loc, timer, effort, how, horizon, heuristic, heur_adv_ratio)) -> ( @@ -241,8 +242,9 @@ time = !state.Arena.time; loc = !state.Arena.cur_loc} pos memory | _ -> failwith "req_handle: impossible" in - state := new_state; (* Rewriting doesn't handle location update. *) + state := + {new_state with Arena.cur_loc = moves.(pos).Game.next_loc}; let new_game_state = { Game.struc = new_state.Arena.struc; loc = moves.(pos).Game.next_loc; @@ -282,157 +284,175 @@ GDL.translate_last_action actions in if r_name <> "" then ( - let {Arena.rules=rules; graph=graph} = !state.Arena.game in - let struc = !state.Arena.struc in - let fn s n = Structure.find_elem s n in - let r = List.assoc r_name rules in - let lhs = - r.ContinuousRule.discrete.DiscreteRule.lhs_struc in - let m = - List.map (fun (l, s) -> (fn lhs l, fn struc s)) mtch in - let moves = - Game.gen_moves Game.cGRID_SIZE rules - !state.Arena.struc graph.(!state.Arena.cur_loc) in - let pos = - (try - for i = 0 to Array.length moves - 1 do + let {Arena.rules=rules; graph=graph} = !state.Arena.game in + let struc = !state.Arena.struc in + let fn s n = Structure.find_elem s n in + let r = List.assoc r_name rules in + let lhs = + r.ContinuousRule.discrete.DiscreteRule.lhs_struc in + let m = + List.map (fun (l, s) -> (fn lhs l, fn struc s)) mtch in + let moves = + Game.gen_moves Game.cGRID_SIZE rules + !state.Arena.struc graph.(!state.Arena.cur_loc) in + let pos = + (try + for i = 0 to Array.length moves - 1 do (* FIXME: handle time and params! *) - let mov = moves.(i) in + let mov = moves.(i) in (* {{{ log entry *) - if !debug_level > 1 then ( - Printf.printf "GDL: considering move %s\n%!" - (Game.move_gs_str !state mov) - ); + if !debug_level > 3 then ( + Printf.printf "GDL: for %s considering move %s\n%!" + r_name (Game.move_gs_str !state mov) + ); (* }}} *) - if - r_name = mov.Game.rule && + if + r_name = mov.Game.rule && (* t = mov.Game.time && *) (* something wrong with this: List.for_all (fun (pn, pv) -> pv = List.assoc pn mov.Game.parameters) p && *) - List.for_all (fun (e, f) -> - f = List.assoc e mov.Game.embedding) m + List.for_all (fun (e, f) -> + f = List.assoc e mov.Game.embedding) m (* TODO: handle location matching *) - then ( - expected_location := mov.Game.next_loc; - let _ = if !debug_level > 2 then - Printf.printf "expected_location = %d\n%!" - !expected_location in - raise (Found i)) - done; + then ( + expected_location := mov.Game.next_loc; + let _ = if !debug_level > 2 then + Printf.printf "expected_location = %d\n%!" + !expected_location in + raise (Found i)) + done; (* TODO: if not due to only time or params mismatch, block or warn about invalid rule application *) - - failwith - "Server GDL Play request: action mismatched with play state" - with Found pos -> pos) in - let old_struc = !state.Arena.struc in - let req = Arena.ApplyRule (r_name, mtch, 0.1, []) in - let (new_state, resp) = Arena.handle_request !state req in - let memory = match !play, !play_state with - | Some play, Some {Game.memory=memory; game_state=pstate} -> - Game.update_memory - ~num_players:play.Game.game.Arena.num_players - {Game.struc=old_struc; - time = !state.Arena.time; - loc = !state.Arena.cur_loc} pos memory - | _ -> failwith "req_handle: impossible" in - state := new_state; + + failwith + "Server GDL Play request: action mismatched with play state" + with Found pos -> pos) in + let old_struc = !state.Arena.struc in + let req = Arena.ApplyRule (r_name, mtch, 0.1, []) in + let (new_state, resp) = Arena.handle_request !state req in + let memory = match !play, !play_state with + | Some play, Some {Game.memory=memory; game_state=pstate} -> + Game.update_memory + ~num_players:play.Game.game.Arena.num_players + {Game.struc=old_struc; + time = !state.Arena.time; + loc = !state.Arena.cur_loc} pos memory + | _ -> failwith "req_handle: impossible" in (* Rewriting doesn't handle location update. *) - let new_game_state = { - Game.struc = new_state.Arena.struc; - loc = moves.(pos).Game.next_loc; - time = new_state.Arena.time; - } in - play_state := Some { - Game.game_state = new_game_state; - memory = memory; - }); - - let time_used = - time_started - (int_of_float (ceil (Sys.time ()))) in - let p, ps = - match !play, !play_state with - | Some play, Some play_state -> - play, play_state - | _ -> assert false in - ignore (Unix.alarm (!playclock - time_used)); - let res = Game.suggest p ps in - Game.cancel_timeout (); - let mov_msg = - match res with - | Some (move, new_state) -> - play_state := Some new_state; - GDL.translate_move move.Game.rule move.Game.embedding - !state - | None -> "NOOP" in - let msg_len = String.length mov_msg in - "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: " - ^ string_of_int msg_len ^ "\r\n\r\n" ^ mov_msg + state := + {new_state with Arena.cur_loc = moves.(pos).Game.next_loc}; + let new_game_state = { + Game.struc = new_state.Arena.struc; + loc = moves.(pos).Game.next_loc; + time = new_state.Arena.time; + } in + play_state := Some { + Game.game_state = new_game_state; + memory = memory; + }); + if GDL.our_turn !state + then + let time_used = + time_started - (int_of_float (ceil (Sys.time ()))) in + let p, ps = + match !play, !play_state with + | Some play, Some play_state -> + play, play_state + | _ -> assert false in + ignore (Unix.alarm (!playclock - time_used)); + let res = Game.suggest p ps in + Game.cancel_timeout (); + let mov_msg = + match res with + | Some (move, new_state) -> + (* Do not change state yet! *) + GDL.translate_move move.Game.rule move.Game.embedding + !state + | None -> "NOOP" in + let msg_len = String.length mov_msg in + "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: " + ^ string_of_int msg_len ^ "\r\n\r\n" ^ mov_msg + else + "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: " + ^ "4\r\n\r\nNOOP" + + | Aux.Right (GDL.Stop (_, actions)) -> + let time_started = int_of_float (Sys.time ()) in let r_name, mtch = GDL.translate_last_action actions in - let {Arena.rules=rules; graph=graph} = !state.Arena.game in - let struc = !state.Arena.struc in - let fn s n = Structure.find_elem s n in - let r = List.assoc r_name rules in - let lhs = - r.ContinuousRule.discrete.DiscreteRule.lhs_struc in - let m = - List.map (fun (l, s) -> (fn lhs l, fn struc s)) mtch in - let moves = - Game.gen_moves Game.cGRID_SIZE rules - !state.Arena.struc graph.(!state.Arena.cur_loc) in - let pos = - (try - for i = 0 to Array.length moves - 1 do + if r_name <> "" then ( + let {Arena.rules=rules; graph=graph} = !state.Arena.game in + let struc = !state.Arena.struc in + let fn s n = Structure.find_elem s n in + let r = List.assoc r_name rules in + let lhs = + r.ContinuousRule.discrete.DiscreteRule.lhs_struc in + let m = + List.map (fun (l, s) -> (fn lhs l, fn struc s)) mtch in + let moves = + Game.gen_moves Game.cGRID_SIZE rules + !state.Arena.struc graph.(!state.Arena.cur_loc) in + let pos = + (try + for i = 0 to Array.length moves - 1 do (* FIXME: handle time and params! *) - let mov = moves.(i) in - if - r_name = mov.Game.rule && + let mov = moves.(i) in + (* {{{ log entry *) + if !debug_level > 3 then ( + Printf.printf "GDL: for %s considering move %s\n%!" + r_name (Game.move_gs_str !state mov) + ); + (* }}} *) + if + r_name = mov.Game.rule && (* t = mov.Game.time && *) (* something wrong with this: List.for_all (fun (pn, pv) -> pv = List.assoc pn mov.Game.parameters) p && *) - List.for_all (fun (e, f) -> - f = List.assoc e mov.Game.embedding) m + List.for_all (fun (e, f) -> + f = List.assoc e mov.Game.embedding) m (* TODO: handle location matching *) - then ( - expected_location := mov.Game.next_loc; - let _ = if !debug_level > 2 then - Printf.printf "expected_location = %d\n%!" - !expected_location in - raise (Found i)) - done; + then ( + expected_location := mov.Game.next_loc; + let _ = if !debug_level > 2 then + Printf.printf "expected_location = %d\n%!" + !expected_location in + raise (Found i)) + done; (* TODO: if not due to only time or params mismatch, block or warn about invalid rule application *) - failwith - "Server GDL Play request: action mismatched with play state" - with Found pos -> pos) in - let old_struc = !state.Arena.struc in - let req = Arena.ApplyRule (r_name, mtch, 0.1, []) in - let (new_state, resp) = Arena.handle_request !state req in - let memory = match !play, !play_state with - | Some play, Some {Game.memory=memory; game_state=pstate} -> - Game.update_memory - ~num_players:play.Game.game.Arena.num_players - {Game.struc=old_struc; - time = !state.Arena.time; - loc = !state.Arena.cur_loc} pos memory - | _ -> failwith "req_handle: impossible" in - state := new_state; + + failwith + "Server GDL Stop request: action mismatched with play state" + with Found pos -> pos) in + let old_struc = !state.Arena.struc in + let req = Arena.ApplyRule (r_name, mtch, 0.1, []) in + let (new_state, resp) = Arena.handle_request !state req in + let memory = match !play, !play_state with + | Some play, Some {Game.memory=memory; game_state=pstate} -> + Game.update_memory + ~num_players:play.Game.game.Arena.num_players + {Game.struc=old_struc; + time = !state.Arena.time; + loc = !state.Arena.cur_loc} pos memory + | _ -> failwith "req_handle: impossible" in (* Rewriting doesn't handle location update. *) - let new_game_state = { - Game.struc = new_state.Arena.struc; - loc = moves.(pos).Game.next_loc; - time = new_state.Arena.time; - } in - play_state := Some { - Game.game_state = new_game_state; - memory = memory; - }; + state := + {new_state with Arena.cur_loc = moves.(pos).Game.next_loc}; + let new_game_state = { + Game.struc = new_state.Arena.struc; + loc = moves.(pos).Game.next_loc; + time = new_state.Arena.time; + } in + play_state := Some { + Game.game_state = new_game_state; + memory = memory; + }); + "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: 4" ^ "\r\n\r\nDONE" Modified: trunk/Toss/Play/ServerGDLTest.in =================================================================== --- trunk/Toss/Play/ServerGDLTest.in 2010-12-19 22:43:09 UTC (rev 1263) +++ trunk/Toss/Play/ServerGDLTest.in 2010-12-20 00:14:59 UTC (rev 1264) @@ -32,7 +32,7 @@ Content-type: text/acl Content-length: 41 -(PLAY MATCH.3316980891 (NOOP (MARK 1 1))) +(PLAY MATCH.3316980891 (NOOP (MARK 3 1))) POST / HTTP/1.0 Accept: text/delim @@ -41,7 +41,7 @@ Content-type: text/acl Content-length: 41 -(PLAY MATCH.3316980891 ((MARK 2 2) NOOP)) +(PLAY MATCH.3316980891 ((MARK 2 1) NOOP)) POST / HTTP/1.0 Accept: text/delim @@ -50,7 +50,7 @@ Content-type: text/acl Content-length: 41 -(PLAY MATCH.3316980891 (NOOP (MARK 1 2))) +(PLAY MATCH.3316980891 (NOOP (MARK 2 3))) POST / HTTP/1.0 Accept: text/delim @@ -59,4 +59,13 @@ Content-type: text/acl Content-length: 41 -(STOP MATCH.3316980891 ((MARK 1 1) NOOP)) +(PLAY MATCH.3316980891 ((MARK 3 3) NOOP)) + +POST / HTTP/1.0 +Accept: text/delim +Sender: GAMEMASTER +Receiver: GAMEPLAYER +Content-type: text/acl +Content-length: 41 + +(STOP MATCH.3316980891 (NOOP (MARK 1 1))) Modified: trunk/Toss/Play/ServerGDLTest.out =================================================================== --- trunk/Toss/Play/ServerGDLTest.out 2010-12-19 22:43:09 UTC (rev 1263) +++ trunk/Toss/Play/ServerGDLTest.out 2010-12-20 00:14:59 UTC (rev 1264) @@ -1,36 +1,41 @@ -HTTP/1.0 200 OK -Content-type: text/acl -Content-length: 5 - +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 5 + READY -HTTP/1.0 200 OK -Content-type: text/acl -Content-length: 10 - +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 10 + (MARK 2 2) -HTTP/1.0 200 OK -Content-type: text/acl -Content-length: 4 - +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 4 + NOOP -HTTP/1.0 200 OK -Content-type: text/acl -Content-length: 10 - -(MARK 2 2) -HTTP/1.0 200 OK -Content-type: text/acl -Content-length: 4 - +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 10 + +(MARK 2 1) +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 4 + NOOP -HTTP/1.0 200 OK -Content-type: text/acl -Content-length: 10 - -(MARK 1 1) -HTTP/1.0 200 OK -Content-type: text/acl -Content-length: 4 - +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 10 + +(MARK 3 3) +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 4 + +NOOP +HTTP/1.0 200 OK +Content-type: text/acl +Content-length: 4 + DONE ERR processing completed -- EOF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-20 02:05:30
|
Revision: 1265 http://toss.svn.sourceforge.net/toss/?rev=1265&view=rev Author: lukaszkaiser Date: 2010-12-20 02:05:24 +0000 (Mon, 20 Dec 2010) Log Message: ----------- Corrections to play Tic-Tac-Toe on GGP server. (Test broken just this one time.) Modified Paths: -------------- trunk/Toss/Formula/Aux.ml trunk/Toss/Formula/Aux.mli trunk/Toss/Play/GDL.ml Modified: trunk/Toss/Formula/Aux.ml =================================================================== --- trunk/Toss/Formula/Aux.ml 2010-12-20 00:14:59 UTC (rev 1264) +++ trunk/Toss/Formula/Aux.ml 2010-12-20 02:05:24 UTC (rev 1265) @@ -398,16 +398,26 @@ with End_of_file -> ()); Buffer.contents buf +let is_space c = + c = '\n' || c = '\r' || c = ' ' || c = '\t' + +let strip_spaces s = + let (b, e) = (ref 0, ref ((String.length s) - 1)) in + while !b < !e && is_space (s.[!b]) do b := !b + 1 done; + while !b <= !e && is_space (s.[!e]) do e := !e - 1 done; + if !e < !b then "" else String.sub s !b (!e - !b + 1) + let rec input_http_message file = let buf = Buffer.create 256 in let line = ref "POST / HTTP" in let msg_len = ref 0 in - while !line <> "" && !line <> "\r" do - line := input_line file; + while !line <> "" do + line := strip_spaces (input_line file); let line_len = String.length !line in - if line_len > 16 && String.sub !line 0 15 = "Content-length:" then + if line_len > 16 && String.sub !line 0 15 = "Content-length:" then ( msg_len := int_of_string (String.sub !line 16 (line_len - 16)); + ) done; Buffer.add_channel buf file !msg_len; Buffer.contents buf Modified: trunk/Toss/Formula/Aux.mli =================================================================== --- trunk/Toss/Formula/Aux.mli 2010-12-20 00:14:59 UTC (rev 1264) +++ trunk/Toss/Formula/Aux.mli 2010-12-20 02:05:24 UTC (rev 1265) @@ -168,7 +168,11 @@ val is_digit : char -> bool val is_letter : char -> bool val is_alphanum : char -> bool +val is_space : char -> bool +(** Strip spaces from left and right of a string. *) +val strip_spaces : string -> string + (** Printf helper functions. *) val list_fprint : (out_channel -> 'a -> unit) -> out_channel -> 'a list -> unit Modified: trunk/Toss/Play/GDL.ml =================================================================== --- trunk/Toss/Play/GDL.ml 2010-12-20 00:14:59 UTC (rev 1264) +++ trunk/Toss/Play/GDL.ml 2010-12-20 02:05:24 UTC (rev 1265) @@ -59,7 +59,7 @@ state := state_of_file "./examples/Tic-Tac-Toe.toss"; playing_as := player; game_description := game_descr; - player_name_terms := [|Const "X"; Const "O"|]; + player_name_terms := [|Const "XPLAYER"; Const "OPLAYER"|]; let effort, horizon, heur_adv_ratio = 2, 100, 4.0 in effort, horizon, heur_adv_ratio This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-21 00:19:02
|
Revision: 1266 http://toss.svn.sourceforge.net/toss/?rev=1266&view=rev Author: lukaszkaiser Date: 2010-12-21 00:18:56 +0000 (Tue, 21 Dec 2010) Log Message: ----------- Corrections for Gomoku play and WebClient style. Modified Paths: -------------- trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Play/GDL.ml trunk/Toss/Play/Server.ml trunk/Toss/WebClient/Style.css Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2010-12-20 02:05:24 UTC (rev 1265) +++ trunk/Toss/Formula/FormulaOps.ml 2010-12-21 00:18:56 UTC (rev 1266) @@ -813,7 +813,9 @@ and append_quant vs ~universal flist = let (have_v, no_v) = List.partition (has_free vs) flist in - let res lst = if universal then Or lst else And lst in + let res = function + | [x] -> x + | lst -> if universal then Or lst else And lst in match have_v with [] -> res no_v | [phi] -> @@ -893,7 +895,31 @@ | Ex (vs, phi) -> Ex (vs, order_by_fv_phi acc_fv phi) | All (vs, phi) -> All (vs, order_by_fv_phi acc_fv phi) | f -> f - + +let rec push_in_quant phi = + match phi with + | In _ | Rel _ | Eq _ | RealExpr _ -> phi + | Not (Or fl) -> push_in_quant (And (List.map (fun f -> Not f) fl)) + | Not (And fl) -> push_in_quant (Or (List.map (fun f -> Not f) fl)) + | Not f -> Not (push_in_quant f) + | And fl -> And (List.map push_in_quant fl) + | Or fl -> Or (List.map push_in_quant fl) + | Ex ([], phi) | All ([], phi) -> push_in_quant phi + | Ex (vs, Or fl) -> push_in_quant (Or (List.map (fun f -> Ex (vs, f)) fl)) + | All (vs, And fl) -> push_in_quant (And(List.map (fun f -> All(vs,f)) fl)) + | Ex ([v], And fl) -> + append_quant [v] ~universal:false (List.map push_in_quant fl) + | Ex (vs, And fl) -> + push_in_quant (Ex ([List.hd vs], push_in_quant (Ex (List.tl vs, And fl)))) + | All ([v], Or fl) -> + append_quant [v] ~universal:true (List.map push_in_quant fl) + | All (vs, Or fl) -> + push_in_quant (All ([List.hd vs], push_in_quant (All (List.tl vs,Or fl)))) + | Ex (vs, f) -> Ex (vs, push_in_quant f) + | All (vs, f) -> All (vs, push_in_quant f) + +let rec push_quant f = push_in_quant (flatten_sort (f)) + let tnf_fv phi = let fv = free_vars phi in let psi = rename_quant_avoiding [] (Ex (fv, phi)) in Modified: trunk/Toss/Play/GDL.ml =================================================================== --- trunk/Toss/Play/GDL.ml 2010-12-20 02:05:24 UTC (rev 1265) +++ trunk/Toss/Play/GDL.ml 2010-12-21 00:18:56 UTC (rev 1266) @@ -56,27 +56,25 @@ res let initialize_game state player game_descr startcl = - state := state_of_file "./examples/Tic-Tac-Toe.toss"; + state := state_of_file "./examples/Gomoku.toss"; playing_as := player; game_description := game_descr; - player_name_terms := [|Const "XPLAYER"; Const "OPLAYER"|]; + player_name_terms := [|Const "X"; Const "O"|]; let effort, horizon, heur_adv_ratio = 2, 100, 4.0 in effort, horizon, heur_adv_ratio let translate_last_action actions = + let number_of_letter c = + string_of_int ((Char.code (Char.lowercase c)) - 96) in match actions with | [] -> (* start of game -- Server will handle this answer as NOOP *) "", [] | [Func ("MARK", [Const col; Const row]); Const "NOOP"] -> - "Cross", ["a1", - Structure.board_coords_name - (int_of_string col, int_of_string row)] + "Cross", ["a1", ((String.lowercase col) ^ (number_of_letter row.[0]))] | [ Const "NOOP"; Func ("MARK", [Const col; Const row])] -> - "Circle", ["a1", - Structure.board_coords_name - (int_of_string col, int_of_string row)] + "Circle", ["a1", ((String.lowercase col) ^ (number_of_letter row.[0]))] | _ -> assert false let our_turn state = @@ -90,4 +88,5 @@ let elem = snd (List.hd emb) in let c, r = Structure.board_elem_coords (Structure.elem_str struc elem) in - Printf.sprintf "(MARK %d %d)" c r + let cs, rs = Char.chr (c + 64), Char.chr (r + 64) in + Printf.sprintf "(MARK %c %c)" cs rs Modified: trunk/Toss/Play/Server.ml =================================================================== --- trunk/Toss/Play/Server.ml 2010-12-20 02:05:24 UTC (rev 1265) +++ trunk/Toss/Play/Server.ml 2010-12-21 00:18:56 UTC (rev 1266) @@ -361,7 +361,7 @@ | Some play, Some play_state -> play, play_state | _ -> assert false in - ignore (Unix.alarm (!playclock - time_used)); + ignore (Unix.alarm (!playclock - time_used - 1)); let res = Game.suggest p ps in Game.cancel_timeout (); let mov_msg = Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2010-12-20 02:05:24 UTC (rev 1265) +++ trunk/Toss/WebClient/Style.css 2010-12-21 00:18:56 UTC (rev 1266) @@ -34,7 +34,7 @@ } #plays .bt { - width: 7em; + width: 7.5em; font-size: 0.75em; position: absolute; right: 2px; @@ -457,7 +457,7 @@ margin-right: auto; margin-top: 3em; min-width: 10em; - max-width: 60em; + max-width: 90em; width: 80%; display: none; } @@ -482,7 +482,7 @@ #board { min-width: 10em; - max-width: 60em; + max-width: 90em; width: 70%; margin-left: auto; margin-right: auto; @@ -569,11 +569,11 @@ /* SVG styling */ #svg { min-width: 10em; - max-width: 60em; - width: 70%; + max-width: 90em; + width: 80%; min-height: 10em; - max-height: 60em; - height: 70%; + max-height: 90em; + height: 80%; /* border: 1px solid #260314; */ } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-21 23:42:22
|
Revision: 1269 http://toss.svn.sourceforge.net/toss/?rev=1269&view=rev Author: lukaszkaiser Date: 2010-12-21 23:42:15 +0000 (Tue, 21 Dec 2010) Log Message: ----------- WebClient improvements, Gc compact on NOOP, more readable definitions of Tic-Tac-Toe and Gomoku. Modified Paths: -------------- trunk/Toss/Play/Server.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/DefaultStyle.js trunk/Toss/WebClient/Handler.py trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/README trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/Wrapper.py trunk/Toss/WebClient/index.html trunk/Toss/examples/Gomoku.toss trunk/Toss/examples/Tic-Tac-Toe.toss Modified: trunk/Toss/Play/Server.ml =================================================================== --- trunk/Toss/Play/Server.ml 2010-12-21 23:14:48 UTC (rev 1268) +++ trunk/Toss/Play/Server.ml 2010-12-21 23:42:15 UTC (rev 1269) @@ -354,8 +354,7 @@ memory = memory; }); - if GDL.our_turn !state - then + if GDL.our_turn !state then ( let time_used = int_of_float time_started - int_of_float (ceil (Sys.time ())) in let p, ps = @@ -376,9 +375,11 @@ let msg_len = String.length mov_msg in "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: " ^ string_of_int msg_len ^ "\r\n\r\n" ^ mov_msg - else + ) else ( + Gc.compact (); "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: " ^ "4\r\n\r\nNOOP" + ) | Aux.Right (GDL.Stop (_, actions)) -> @@ -460,7 +461,7 @@ in if !debug_level > 0 then ( Printf.printf "Resp-time: %F\n%!" (Sys.time () -. time_started); - print_endline ("Repl: " ^ resp ^ "\n"); + print_endline ("\nRepl: " ^ resp ^ "\n"); ); output_string out_ch (resp ^ "\n"); flush out_ch; Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2010-12-21 23:14:48 UTC (rev 1268) +++ trunk/Toss/WebClient/Connect.js 2010-12-21 23:42:15 UTC (rev 1269) @@ -21,12 +21,11 @@ var SUGGESTED_ELEM_SIZEX = 25; // suggested size of elements var SUGGESTED_ELEM_SIZEY = 25; // suggested size of elements -var CACHED_MOVES = "" - var DIM_STR = "" var ELEM_STR = "" var RELS_STR = "" var MOVES_STR = "" +var PAYOFF_STR = "" // Helper function: sign of a number. @@ -36,11 +35,6 @@ else { return (0); } } -// Clears cached moves. -function clear_move_cache () { - CACHED_MOVES = ""; -} - function set_info (info) { var res_arr = []; res_arr = info.split("$"); @@ -48,7 +42,13 @@ DIM_STR = res_arr[0]; ELEM_STR = res_arr[1]; RELS_STR = res_arr[2]; - MOVES_STR = res_arr[3]; + if (res_arr[3].substring(0, 1) == "(") { + MOVES_STR = res_arr[3]; + PAYOFF_STR = ""; + } else { + MOVES_STR = ""; + PAYOFF_STR = res_arr[3]; + }; var dim = strip('(', ')', DIM_STR).split(','); MODEL_MAXX = parseFloat(strip(' ', ' ', dim[0])); MODEL_MINX = parseFloat(strip(' ', ' ', dim[1])); @@ -56,7 +56,6 @@ 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); } @@ -130,15 +129,16 @@ // Get moves applicable to [elem] in a game. -function get_moves (elem) { - if (CACHED_MOVES == "") { - CACHED_MOVES = MOVES_STR - } - var all_moves = convert_python_list (';', CACHED_MOVES); +function get_moves (elem, other) { + var all_moves = convert_python_list (';', MOVES_STR); var elem_moves = [] for (i = 0; i < all_moves.length; i++) { if (all_moves[i].indexOf(elem) >= 0) { - elem_moves.push(all_moves[i]) + if (other == "") { + elem_moves.push(all_moves[i]) + } else if (all_moves[i].indexOf(other) >= 0) { + elem_moves.push(all_moves[i]) + } } } return (elem_moves) Modified: trunk/Toss/WebClient/DefaultStyle.js =================================================================== --- trunk/Toss/WebClient/DefaultStyle.js 2010-12-21 23:14:48 UTC (rev 1268) +++ trunk/Toss/WebClient/DefaultStyle.js 2010-12-21 23:42:15 UTC (rev 1269) @@ -37,7 +37,7 @@ 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-Bx" /> \ + 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" /> \ @@ -65,7 +65,7 @@ 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-Bx" /> \ + 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" /> \ @@ -77,7 +77,7 @@ 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-Bx" /> \ + class="chess-path-B" /> \ <path \ d="M 11,14 L 34,14" \ class="chess-path-D" /> \ @@ -122,12 +122,12 @@ </g>'; var DEFking = '<g transform="translate(-22.5,-22.5)"> \ - <path d="M 22.5,11.625 L 22.5,6" class="chess-path-D" /> \ + <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-D" /> \ - <path d="M 20,8 L 25,8" class="chess-path-D" /> \ + 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" /> \ @@ -136,6 +136,20 @@ </g>'; +function is_int (s) { + return (parseInt(s).toString() == s) +} + +// 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 (elem) { var pos = ELEM_POS[elem]; @@ -145,7 +159,7 @@ ["width", 2 * SUGGESTED_ELEM_SIZEX], ["height", 2 * SUGGESTED_ELEM_SIZEX], ["id", "elem_" + elem], - ["class", "model-elem"], + ["class", elem_class(elem)], ["onclick", ("handle_elem_click('" + elem + "')")]] ); } @@ -159,7 +173,7 @@ // Unhighlight the element [elem]. function unhighlight_elem (elem) { var e = document.getElementById ("elem_" + elem); - e.setAttribute ("class", "model-elem"); + e.setAttribute ("class", elem_class(elem)); } // Draw relation [rel_name] between elements [args]. Modified: trunk/Toss/WebClient/Handler.py =================================================================== --- trunk/Toss/WebClient/Handler.py 2010-12-21 23:14:48 UTC (rev 1268) +++ trunk/Toss/WebClient/Handler.py 2010-12-21 23:42:15 UTC (rev 1269) @@ -92,7 +92,9 @@ dim_s = str(client.model.get_dim()) model_s = str(client.model.get_elems_with_pos()) rels_s = str(client.model.get_rels_simple()) - moves_s = str(client.cur_moves()) + moves = client.cur_moves() + moves_s = str(moves) + if (len(moves) == 0): moves_s = client.get_payoffs() return (dim_s + "$" + model_s + "$" + rels_s + "$" + moves_s) def get_free_id (db): Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2010-12-21 23:14:48 UTC (rev 1268) +++ trunk/Toss/WebClient/Main.js 2010-12-21 23:42:15 UTC (rev 1269) @@ -14,6 +14,8 @@ var FULL_OPNT_LEN = 0; var CUR_OPNT_START = 0; +var LAST_CLICKED_ELEM = ""; + // Get model information from server. function get_model_info () { get_elems_with_pos (); @@ -44,7 +46,7 @@ // Clear whole svg box. function clear_svg () { - clear_move_cache (); + LAST_CLICKED_ELEM = ""; ELEM_COUNTERS = {}; CUR_MOVE = ""; CUR_ELEMS = []; @@ -60,6 +62,13 @@ get_model_info (); create_svg_box (SVG_MARGINX, SVG_MARGINY, "board"); draw_model (); + if (PAYOFF_STR == "") { + document.getElementById('movebt').innerHTML = "Make move:"; + document.getElementById('cur-move').innerHTML = "none"; + } else { + document.getElementById('movebt').innerHTML = "Payoffs:"; + document.getElementById('cur-move').innerHTML = PAYOFF_STR; + } document.getElementById("working").style.display = "none"; } @@ -79,6 +88,7 @@ // 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 = m.substring (m.indexOf("},")+4, m.lastIndexOf(',')-1); for (var i = 0; i < CUR_ELEMS.length; i++) { unhighlight_elem (CUR_ELEMS[i]); @@ -91,7 +101,7 @@ document.getElementById('cur-move').innerHTML = "none"; } else { document.getElementById('cur-move').innerHTML = - m_rule + ': ' + m_str; + m_str.replace (/,/g, " — ") + " (" + m_rule + ")" } CUR_ELEMS = m_act; CUR_MOVE = m.toString(); @@ -99,14 +109,28 @@ // Handler for clicks on elements. function handle_elem_click (elem) { - var moves = get_moves (elem); + var moves = get_moves (elem, LAST_CLICKED_ELEM); + if (moves.length == 0) { + LAST_CLICKED_ELEM = ""; + moves = get_moves (elem, LAST_CLICKED_ELEM); + }; if (moves.length > ELEM_COUNTERS[elem]) { show_move (moves[ELEM_COUNTERS[elem]]); ELEM_COUNTERS[elem] += 1; } else if (moves.length > 0) { show_move (moves[0]); ELEM_COUNTERS[elem] = 1; - } + }; + if (moves.length > 1 && LAST_CLICKED_ELEM == "") { + for (var i = 0; i < CUR_ELEMS.length; i++) { + unhighlight_elem (CUR_ELEMS[i]); + } + document.getElementById('cur-move').innerHTML = elem + " — ?" + highlight_elem (elem); + CUR_ELEMS = [elem]; + CUR_MOVE = ""; + }; + LAST_CLICKED_ELEM = elem; } function play_py_id (i) { @@ -160,16 +184,18 @@ function game_click (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") { // bigger margins needed - create_svg_box (130, 130, "board"); - } else { - create_svg_box (40, 40, "board"); - } - document.getElementById("game-disp").style.display = "block"; + 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") { // bigger margins needed + create_svg_box (130, 130, "board"); + } 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) { @@ -198,13 +224,11 @@ document.getElementById("working").style.display = "block"; var info = srv("MOVE_PLAY", 'c, '+ CUR_MOVE +', '+ play_py_id (CUR_PLAY_I)); set_info (info); - clear_move_cache (); CUR_MOVE = ""; CUR_ELEMS = []; ELEM_COUNTERS = {}; document.getElementById("cur-player").innerHTML = disp_name(PLAYS[CUR_PLAY_I][(m + 1) % 2]); - document.getElementById('cur-move').innerHTML = "none"; document.getElementById("working").style.display = "none"; full_redraw (); PLAYS[CUR_PLAY_I][3] = parseInt(PLAYS[CUR_PLAY_I][3]) + 1; @@ -214,8 +238,8 @@ var li = new_play_item (GAME_NAME, CUR_PLAY_I); old_li.parentNode.replaceChild (li, old_li); if (PLAYS[CUR_PLAY_I][(m + 1) % 2] == "computer") { - suggest_move (); - make_move (); + var m = suggest_move (); + if (m != "") { make_move (); } } } @@ -345,12 +369,14 @@ function suggest_move () { var m = srv("SUGGEST", 'c, '+ play_py_id (CUR_PLAY_I)); - show_move (m); + if (m != "") { show_move (m); } + return (m); } function suggest_move_better () { var m = srv("SUGGESTX", 'c, '+ play_py_id (CUR_PLAY_I)); - show_move (m); + if (m != "") { show_move (m); } + return (m); } function toggle_suggestions () { Modified: trunk/Toss/WebClient/README =================================================================== --- trunk/Toss/WebClient/README 2010-12-21 23:14:48 UTC (rev 1268) +++ trunk/Toss/WebClient/README 2010-12-21 23:42:15 UTC (rev 1269) @@ -19,8 +19,6 @@ TODO: - - move interface: first click all, second click toggle, if one - confirm msg - - display results, prevent suggestion bug when game has already ended - sort plays by who's turn it is - option to give up game and offer a draw - enable google (or other) analytics Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2010-12-21 23:14:48 UTC (rev 1268) +++ trunk/Toss/WebClient/Style.css 2010-12-21 23:42:15 UTC (rev 1269) @@ -2,14 +2,16 @@ html { position: absolute; - height: 100%; + min-height: 100%; + height: auto; + min-width: 45em; width: 100%; } body { position: absolute; - height: 100%; width: 100%; + min-height: 100%; padding: 0px; margin: 0px; text-align: center; @@ -23,7 +25,7 @@ -moz-border-radius: 4px; border-width: 1px; color: #260314; - background-color: #ffe4aa; + background-color: #fff1d4; font-size: 0.9em; font-family: Verdana, 'TeXGyreHerosRegular', sans; } @@ -34,10 +36,11 @@ } #plays .bt { - width: 7.5em; + width: 8em; font-size: 0.75em; - position: absolute; - right: 2px; + /* position: absolute; + right: 2px; */ + float: right; } .obt { @@ -47,7 +50,7 @@ -moz-border-radius: 4px; border-width: 0px; color: #260314; - background-color: #ffe4aa; + background-color: #fff1d4; font-size: 0.9em; font-family: Verdana, 'TeXGyreHerosRegular', sans; } @@ -58,11 +61,11 @@ } .dbt { - border-color: #ffe4aa; + border-color: #fff1d4; border-radius: 4px; -moz-border-radius: 4px; border-width: 0px; - color: #ffe4aa; + color: #fff1d4; background-color: #400827; font-size: 0.9em; font-family: Verdana, 'TeXGyreHerosRegular', sans; @@ -95,7 +98,7 @@ } .loginput { - border-color: #ffe4aa; + border-color: #fff1d4; border-radius: 4px; -moz-border-radius: 4px; border-width: 1px; @@ -104,7 +107,7 @@ } .forminput { - border-color: #ffe4aa; + border-color: #fff1d4; border-radius: 4px; -moz-border-radius: 4px; border-width: 2px; @@ -134,7 +137,7 @@ font-family: Verdana, 'TeXGyreHerosRegular', sans; color: #400827; background-color: #ffffff; - border-color: #ffe4aa; + border-color: #fff1d4; border-radius: 4px; -moz-border-radius: 4px; border-width: 1px; @@ -150,9 +153,9 @@ font-family: Verdana, 'TeXGyreHerosRegular', sans; font-size: 1em; font-weight: bold; - color: #ffe4aa; + color: #fff1d4; background-color: #400827; - border-color: #ffe4aa; + border-color: #fff1d4; border-radius: 4px; -moz-border-radius: 4px; border-width: 0px; @@ -189,7 +192,7 @@ } #top a, #logo a:link, #logo a:active, #logo a:visited { - color: #ffe4aa; + color: #fff1d4; background-color: transparent; text-decoration: none; } @@ -210,7 +213,7 @@ left: 0px; width: 100%; height: 2.5em; - color: #ffe4aa; + color: #fff1d4; background-color: #400827; border-color: #260314; border-style: solid; @@ -252,7 +255,7 @@ text-align: center; font-size: 0.9em; font-weight: bold; - color: #ffe4aa; + color: #fff1d4; background-color: #400827; border-color: #260314; border-style: solid; @@ -260,7 +263,7 @@ } #bottom a, #bottom a:link, #bottom a:active, #bottom a:visited { - color: #ffe4aa; + color: #fff1d4; text-decoration: none; } @@ -286,7 +289,7 @@ left: 0.5em; border: 0px; background-color: #400827; - color: #ffe4aa; + color: #fff1d4; font-family: Verdana, 'TeXGyreHerosRegular', sans; font-size: 1em; font-weight: bold; @@ -315,7 +318,7 @@ #topbar a { font-weight: bold; text-decoration: none; - color: #ffe4aa; + color: #fff1d4; width: 100%; } @@ -338,29 +341,28 @@ text-align: left; position: absolute; top: 0px; - bottom: 0px; left: 0px; right: 0px; margin-left: auto; margin-right: auto; width: 90%; - height: 100%; + min-height: 100%; padding-top: 0px; padding-bottom: 0px; padding-left: 2px; padding-right: 2px; color: #260314; - background-color: #ffe4aa; + background-color: #fff1d4; border-left: 1px solid #260314; border-right: 1px solid #260314; } -#main a, #main a:link, #main a:active, #main a:visited { +#welcome a, #welcome a:link, #welcome a:active, #welcome a:visited { color: #260314; text-decoration: none; } -#main a:hover { +#welcome a:hover { color: #400827; text-decoration: underline; } @@ -386,7 +388,7 @@ width: 20em; margin-left: auto; margin-right: auto; - color: #ffe4aa; + color: #fff1d4; background-color: #400827; font-weight: bold; padding: 1em; @@ -420,7 +422,7 @@ -moz-border-radius: 4px; border-width: 1px; color: #260314; - background-color: #ffe4aa; + background-color: #fff1d4; font-weight: normal; text-align: center; font-size: 0.9em; @@ -456,9 +458,10 @@ margin-left: auto; margin-right: auto; margin-top: 3em; + margin-bottom: 1.5em; min-width: 10em; - max-width: 90em; - width: 80%; + max-width: 120em; + width: 100%; display: none; } @@ -482,8 +485,8 @@ #board { min-width: 10em; - max-width: 90em; - width: 70%; + max-width: 120em; + width: 100%; margin-left: auto; margin-right: auto; margin-top: 0em; @@ -500,7 +503,7 @@ margin-right: auto; text-align: center; font-weight: bold; - color: #ffe4aa; + color: #fff1d4; background-color: #400827; display: none; padding: 1em; @@ -513,7 +516,7 @@ width: 16em; text-align: center; font-weight: bold; - color: #ffe4aa; + color: #fff1d4; background-color: #400827; display: none; padding: 1em; @@ -531,10 +534,12 @@ } #plays { - position: absolute; + /* position: absolute; left: 0px; right: 0px; - top: 2.5em; + top: 2.5em; */ + margin-top: 3.5em; + margin-bottom: 2em; margin-left: auto; margin-right: auto; width: 100%; @@ -542,6 +547,16 @@ display: none; } +#plays a, #plays a:link, #plays a:active, #plays a:visited { + color: #260314; + text-decoration: none; +} + +#plays a:hover { + color: #400827; + text-decoration: underline; +} + .plays-list { margin-left: 1em; padding-left: 0px; @@ -569,22 +584,34 @@ /* SVG styling */ #svg { min-width: 10em; - max-width: 90em; - width: 80%; + max-width: 120em; + width: 65%; min-height: 10em; - max-height: 90em; - height: 80%; + max-height: 120em; + height: 75%; /* border: 1px solid #260314; */ } -.model-elem { - fill: #b5bf8f; +.model-elem, .model-elem-0, .model-elem-1 { + fill: #ffe4aa; /* #ffce9e; */ stroke: #260314; stroke-width: 3px; } +.Game-Chess .model-elem-0 { + fill: #d18b47; + stroke: #260314; + stroke-width: 3px; +} + +.Game-Chess .model-elem-1 { + fill: #ffe4aa; /* #ffce9e; */ + stroke: #260314; + stroke-width: 3px; +} + .model-elem-highlight { - fill: #ffe4aa; + fill: #b5bf8f; stroke: #400827; stroke-width: 3px; } @@ -596,12 +623,12 @@ } .model-pred-Q { - fill: #b5bf8f; + fill: #ffe4aa; /* #ffce9e; */ stroke: #260314; } .model-pred-C { - fill: #ffe4aa; + fill: #fff1d4; stroke: #260314; stroke-width: 3px; } @@ -613,7 +640,7 @@ } .model-pred-W { - fill: #ffe4aa; + fill: #fff1d4; stroke: #260314; stroke-width: 3px; } @@ -632,7 +659,7 @@ .chessW .chess-path-A { opacity: 1; - fill: #ffe4aa; + fill: #fff1d4; fill-opacity: 1; fill-rule: nonzero; stroke: #260314; @@ -662,7 +689,7 @@ .chessW .chess-path-B { opacity: 1; - fill: #ffe4aa; + fill: #fff1d4; fill-opacity: 1; fill-rule: evenodd; stroke: #260314; @@ -690,7 +717,7 @@ .chessW .chess-path-Bx { opacity: 1; - fill: #ffe4aa; + fill: #fff1d4; fill-opacity: 1; fill-rule: evenodd; stroke: #260314; @@ -704,7 +731,7 @@ .chessB .chess-path-Bx { opacity: 1; - fill: #ffe4aa; + fill: #fff1d4; fill-opacity: 1; fill-rule: evenodd; stroke: #400827; @@ -731,9 +758,9 @@ .chessB .chess-path-C { opacity:1; - fill: #ffe4aa; + fill: #fff1d4; fill-opacity: 1; - stroke: #ffe4aa; + stroke: #fff1d4; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; @@ -743,7 +770,7 @@ } .chessW .chess-path-D { - fill: #ffe4aa; + fill: #fff1d4; fill-opacity: 0.75; fill-rule: evenodd; stroke: #260314; @@ -759,7 +786,7 @@ fill: #400827; fill-opacity: 0.75; fill-rule: evenodd; - stroke: #ffe4aa; + stroke: #fff1d4; stroke-width: 1; stroke-linecap: round; stroke-linejoin: miter; Modified: trunk/Toss/WebClient/Wrapper.py =================================================================== --- trunk/Toss/WebClient/Wrapper.py 2010-12-21 23:14:48 UTC (rev 1268) +++ trunk/Toss/WebClient/Wrapper.py 2010-12-21 23:42:15 UTC (rev 1269) @@ -221,6 +221,7 @@ " alpha_beta_ord") self.set_time (ts, t) msg = [s.strip() for s in m.split(';')] + if len(msg) < 2: return ("") emb = dict() for s in msg[1].split(','): es = [x.strip() for x in s.split(':')] Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2010-12-21 23:14:48 UTC (rev 1268) +++ trunk/Toss/WebClient/index.html 2010-12-21 23:42:15 UTC (rev 1269) @@ -15,6 +15,9 @@ </head> <body onload="startup()"> + +<div id="main"> + <div id="top"> <div id="logo"><a href="index.html">tPlay</a></div> <div id="topbar"> @@ -49,9 +52,7 @@ <a href="register.html">Register</a> </span> </div> -</div> -<div id="main"> <div id="opponents"> Pick Opponent: @@ -150,7 +151,6 @@ <div id="board"><div id="working">Working...</div></div> </div> -</div> <div id="bottom"> <button id="suggestions-toggle" onclick="toggle_suggestions()"> @@ -160,5 +160,7 @@ <a href="contact.html" id="contact">Contact and Info</a> </div> +</div> + </body> </html> Modified: trunk/Toss/examples/Gomoku.toss =================================================================== --- trunk/Toss/examples/Gomoku.toss 2010-12-21 23:14:48 UTC (rev 1268) +++ trunk/Toss/examples/Gomoku.toss 2010-12-21 23:42:15 UTC (rev 1269) @@ -1,157 +1,45 @@ PLAYERS 1, 2 DATA r1: circle, r2: line, adv_ratio: 4, depth: 1 +REL DiagA (x, y) = ex u (R(x, u) and C(u, y)) +REL DiagB (x, y) = ex u (R(x, u) and C(y, u)) +REL Row5 (x, y, z, v, w) = R(x, y) and R(y, z) and R(z, v) and R(v, w) +REL Col5 (x, y, z, v, w) = C(x, y) and C(y, z) and C(z, v) and C(v, w) +REL DiagA5 (x, y, z, v, w) = + DiagA(x, y) and DiagA(y, z) and DiagA(z, v) and DiagA(v, w) +REL DiagB5 (x, y, z, v, w) = + DiagB(x, y) and DiagB(y, z) and DiagB(z, v) and DiagB(v, w) +REL Conn5 (x, y, z, v, w) = + Row5(x,y,z,v,w) or Col5(x,y,z,v,w) or DiagA5(x,y,z,v,w) or DiagB5(x,y,z,v,w) +REL WinQ() = + ex x,y,z,v,w (Q(x) and Q(y) and Q(z) and Q(v) and Q(w) and Conn5(x,y,z,v,w)) +REL WinP() = + ex x,y,z,v,w (P(x) and P(y) and P(z) and P(v) and P(w) and Conn5(x,y,z,v,w)) RULE Cross: - [a1 | P:1 {}; Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] -> + [a1 | P:1 {}; Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] + -> [a1 | P (a1); Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] - emb Q, P - pre - not - ex v, w, x, y, z - (Q(v) and Q(w) and Q(x) and Q(y) and Q(z) and - (R(v, w) and R(w, x) and R(x, y) and R(y, z) or - C(v, w) and C(w, x) and C(x, y) and C(y, z) or - ex r, s, t, u - (R(v, r) and C(r, w) and R(w, s) and C(s, x) and R(x, t) and C(t, y) and - R(y, u) and - C(u, z)) or - ex r, s, t, u - (R(v, r) and C(w, r) and R(w, s) and C(x, s) and R(x, t) and C(y, t) and - R(y, u) and - C(z, u)))) + emb Q, P pre not WinQ() RULE Circle: - [a1 | P:1 {}; Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] -> + [a1 | P:1 {}; Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] + -> [a1 | P:1 {}; Q (a1) | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] - emb Q, P - pre - not - ex v, w, x, y, z - (P(v) and P(w) and P(x) and P(y) and P(z) and - (R(v, w) and R(w, x) and R(x, y) and R(y, z) or - C(v, w) and C(w, x) and C(x, y) and C(y, z) or - ex r, s, t, u - (R(v, r) and C(r, w) and R(w, s) and C(s, x) and R(x, t) and C(t, y) and - R(y, u) and - C(u, z)) or - ex r, s, t, u - (R(v, r) and C(w, r) and R(w, s) and C(x, s) and R(x, t) and C(y, t) and - R(y, u) and - C(z, u)))) + emb Q, P pre not WinP() LOC 0 { - PLAYER 1 + PLAYER 1 PAYOFF { - 1: - :( - ex v, w, x, y, z - (P(v) and P(w) and P(x) and P(y) and P(z) and - (C(v, w) and C(w, x) and C(x, y) and C(y, z) or - R(v, w) and R(w, x) and R(x, y) and R(y, z) or - ex r, s, t, u - (C(r, w) and C(s, x) and C(t, y) and C(u, z) and R(v, r) and R(w, - s) and R(x, t) and R(y, u)) or - ex r, s, t, u - (R(v, r) and C(w, r) and R(w, s) and C(x, s) and R(x, t) and C(y, - t) and R(y, u) and C(z, u)))) - ) + - -1. * - :( - ex v, w, x, y, z - (Q(v) and Q(w) and Q(x) and Q(y) and Q(z) and - (C(v, w) and C(w, x) and C(x, y) and C(y, z) or - R(v, w) and R(w, x) and R(x, y) and R(y, z) or - ex r, s, t, u - (C(r, w) and C(s, x) and C(t, y) and C(u, z) and R(v, r) and R(w, - s) and R(x, t) and R(y, u)) or - ex r, s, t, u - (R(v, r) and C(w, r) and R(w, s) and C(x, s) and R(x, t) and C(y, - t) and R(y, u) and C(z, u)))) - ); - 2: - :( - ex v, w, x, y, z - (Q(v) and Q(w) and Q(x) and Q(y) and Q(z) and - (C(v, w) and C(w, x) and C(x, y) and C(y, z) or - R(v, w) and R(w, x) and R(x, y) and R(y, z) or - ex r, s, t, u - (C(r, w) and C(s, x) and C(t, y) and C(u, z) and R(v, r) and R(w, - s) and R(x, t) and R(y, u)) or - ex r, s, t, u - (R(v, r) and C(w, r) and R(w, s) and C(x, s) and R(x, t) and C(y, - t) and R(y, u) and C(z, u)))) - ) + - -1. * - :( - ex v, w, x, y, z - (P(v) and P(w) and P(x) and P(y) and P(z) and - (C(v, w) and C(w, x) and C(x, y) and C(y, z) or - R(v, w) and R(w, x) and R(x, y) and R(y, z) or - ex r, s, t, u - (C(r, w) and C(s, x) and C(t, y) and C(u, z) and R(v, r) and R(w, - s) and R(x, t) and R(y, u)) or - ex r, s, t, u - (R(v, r) and C(w, r) and R(w, s) and C(x, s) and R(x, t) and C(y, - t) and R(y, u) and C(z, u)))) - ) - } + 1: :(WinP()) - :(WinQ()); + 2: :(WinQ()) - :(WinP()) + } MOVES [Cross -> 1] - } +} LOC 1 { - PLAYER 2 + PLAYER 2 PAYOFF { - 1: - :( - ex v, w, x, y, z - (P(v) and P(w) and P(x) and P(y) and P(z) and - (C(v, w) and C(w, x) and C(x, y) and C(y, z) or - R(v, w) and R(w, x) and R(x, y) and R(y, z) or - ex r, s, t, u - (C(r, w) and C(s, x) and C(t, y) and C(u, z) and R(v, r) and R(w, - s) and R(x, t) and R(y, u)) or - ex r, s, t, u - (R(v, r) and C(w, r) and R(w, s) and C(x, s) and R(x, t) and C(y, - t) and R(y, u) and C(z, u)))) - ) + - -1. * - :( - ex v, w, x, y, z - (Q(v) and Q(w) and Q(x) and Q(y) and Q(z) and - (C(v, w) and C(w, x) and C(x, y) and C(y, z) or - R(v, w) and R(w, x) and R(x, y) and R(y, z) or - ex r, s, t, u - (C(r, w) and C(s, x) and C(t, y) and C(u, z) and R(v, r) and R(w, - s) and R(x, t) and R(y, u)) or - ex r, s, t, u - (R(v, r) and C(w, r) and R(w, s) and C(x, s) and R(x, t) and C(y, - t) and R(y, u) and C(z, u)))) - ); - 2: - :( - ex v, w, x, y, z - (Q(v) and Q(w) and Q(x) and Q(y) and Q(z) and - (C(v, w) and C(w, x) and C(x, y) and C(y, z) or - R(v, w) and R(w, x) and R(x, y) and R(y, z) or - ex r, s, t, u - (C(r, w) and C(s, x) and C(t, y) and C(u, z) and R(v, r) and R(w, - s) and R(x, t) and R(y, u)) or - ex r, s, t, u - (R(v, r) and C(w, r) and R(w, s) and C(x, s) and R(x, t) and C(y, - t) and R(y, u) and C(z, u)))) - ) + - -1. * - :( - ex v, w, x, y, z - (P(v) and P(w) and P(x) and P(y) and P(z) and - (C(v, w) and C(w, x) and C(x, y) and C(y, z) or - R(v, w) and R(w, x) and R(x, y) and R(y, z) or - ex r, s, t, u - (C(r, w) and C(s, x) and C(t, y) and C(u, z) and R(v, r) and R(w, - s) and R(x, t) and R(y, u)) or - ex r, s, t, u - (R(v, r) and C(w, r) and R(w, s) and C(x, s) and R(x, t) and C(y, - t) and R(y, u) and C(z, u)))) - ) - } + 1: :(WinP()) - :(WinQ()); + 2: :(WinQ()) - :(WinP()) + } MOVES [Circle -> 0] - } +} MODEL [ | P:1 {}; Q:1 {} | ] " ... ... ... ... Modified: trunk/Toss/examples/Tic-Tac-Toe.toss =================================================================== --- trunk/Toss/examples/Tic-Tac-Toe.toss 2010-12-21 23:14:48 UTC (rev 1268) +++ trunk/Toss/examples/Tic-Tac-Toe.toss 2010-12-21 23:42:15 UTC (rev 1269) @@ -1,43 +1,41 @@ PLAYERS 1, 2 DATA r1: circle, r2: line, adv_ratio: 4, depth: 3 -REL WinQ() = - ex x, y, z - (Q(x) and Q(y) and Q(z) and ( - (R(x, y) and R(y, z)) or - (C(x, y) and C(y, z)) or - (ex u, v (R(x, v) and C(v, y) and R(y, u) and C(u, z))) or - (ex u, v (R(x, v) and C(y, v) and R(y, u) and C(z, u))) )) -REL WinP() = - ex x, y, z - (P(x) and P(y) and P(z) and ( - (R(x, y) and R(y, z)) or - (C(x, y) and C(y, z)) or - (ex u, v (R(x, v) and C(v, y) and R(y, u) and C(u, z))) or - (ex u, v (R(x, v) and C(y, v) and R(y, u) and C(z, u))) )) +REL DiagA (x, y) = ex u (R(x, u) and C(u, y)) +REL DiagB (x, y) = ex u (R(x, u) and C(y, u)) +REL Row3 (x, y, z) = R(x, y) and R(y, z) +REL Col3 (x, y, z) = C(x, y) and C(y, z) +REL DiagA3 (x, y, z) = DiagA(x, y) and DiagA(y, z) +REL DiagB3 (x, y, z) = DiagB(x, y) and DiagB(y, z) +REL Conn3 (x, y, z) = + Row3(x, y, z) or Col3(x, y, z) or DiagA3(x, y, z) or DiagB3(x, y, z) +REL WinQ() = ex x, y, z (Q(x) and Q(y) and Q(z) and Conn3(x, y, z)) +REL WinP() = ex x, y, z (P(x) and P(y) and P(z) and Conn3(x, y, z)) RULE Cross: - [a1 | P:1 {}; Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] -> + [a1 | P:1 {}; Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] + -> [a1 | P (a1); Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] - emb Q, P pre not WinQ() + emb Q, P pre not WinQ() RULE Circle: - [a1 | P:1 {}; Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] -> + [a1 | P:1 {}; Q:1 {} | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] + -> [a1 | P:1 {}; Q (a1) | vx {a1->0.}; vy {a1->0.}; x {a1->0.}; y {a1->0.}] - emb Q, P pre not WinP() + emb Q, P pre not WinP() LOC 0 { - PLAYER 1 + PLAYER 1 PAYOFF { 1: :(WinP()) - :(WinQ()); 2: :(WinQ()) - :(WinP()) - } + } MOVES [Cross -> 1] - } +} LOC 1 { - PLAYER 2 + PLAYER 2 PAYOFF { 1: :(WinP()) - :(WinQ()); 2: :(WinQ()) - :(WinP()) - } + } MOVES [Circle -> 0] - } +} MODEL [ | P:1 {}; Q:1 {} | ] " This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2010-12-30 22:58:07
|
Revision: 1273 http://toss.svn.sourceforge.net/toss/?rev=1273&view=rev Author: lukaszkaiser Date: 2010-12-30 22:58:00 +0000 (Thu, 30 Dec 2010) Log Message: ----------- Non-standard checkers (will be corrected). Modified Paths: -------------- trunk/Toss/WebClient/DefaultStyle.js trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/MakeDB.py trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html Added Paths: ----------- trunk/Toss/examples/Checkers.toss trunk/Toss/examples/Checkers.tossstyle Modified: trunk/Toss/WebClient/DefaultStyle.js =================================================================== --- trunk/Toss/WebClient/DefaultStyle.js 2010-12-22 09:50:51 UTC (rev 1272) +++ trunk/Toss/WebClient/DefaultStyle.js 2010-12-30 22:58:00 UTC (rev 1273) @@ -227,14 +227,16 @@ 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") { // Chess Figure: white queen - var f = svg_from_string (pos[0], pos[1], 20, 20, - '<g class="chessW" ' + is + hs + '>' + DEFqueen + '</g>'); + } 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 == "bQ") { // Chess Figure: 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>'); Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2010-12-22 09:50:51 UTC (rev 1272) +++ trunk/Toss/WebClient/Login.js 2010-12-30 22:58:00 UTC (rev 1273) @@ -23,10 +23,11 @@ document.getElementById("welcome").style.display = "none"; document.getElementById("plays").style.display = "block"; list_plays_string ("Breakthrough", udata[2]); - list_plays_string ("Chess", udata[3]); - list_plays_string ("Entanglement", udata[4]); - list_plays_string ("Gomoku", udata[5]); - list_plays_string ("Tic-Tac-Toe", udata[6]); + list_plays_string ("Checkers", udata[3]); + list_plays_string ("Chess", udata[4]); + list_plays_string ("Entanglement", udata[5]); + list_plays_string ("Gomoku", udata[6]); + list_plays_string ("Tic-Tac-Toe", udata[7]); get_opponents (); } Modified: trunk/Toss/WebClient/MakeDB.py =================================================================== --- trunk/Toss/WebClient/MakeDB.py 2010-12-22 09:50:51 UTC (rev 1272) +++ trunk/Toss/WebClient/MakeDB.py 2010-12-30 22:58:00 UTC (rev 1273) @@ -8,7 +8,8 @@ SERVER_FILE = "/var/www/WebClient/TossServer" GAMES_PATH = "../examples" -GAMES = ["Breakthrough", "Chess", "Entanglement", "Gomoku", "Tic-Tac-Toe"] +GAMES = ["Breakthrough", "Checkers", "Chess", "Entanglement", + "Gomoku", "Tic-Tac-Toe"] TUID = "toss_id_05174_" Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2010-12-22 09:50:51 UTC (rev 1272) +++ trunk/Toss/WebClient/Style.css 2010-12-30 22:58:00 UTC (rev 1273) @@ -598,13 +598,13 @@ stroke-width: 3px; } -.Game-Chess .model-elem-0 { +.Game-Chess .model-elem-0, .Game-Checkers .model-elem-0 { fill: #d18b47; stroke: #260314; stroke-width: 3px; } -.Game-Chess .model-elem-1 { +.Game-Chess .model-elem-1, .Game-Checkers .model-elem-1 { fill: #ffe4aa; /* #ffce9e; */ stroke: #260314; stroke-width: 3px; Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2010-12-22 09:50:51 UTC (rev 1272) +++ trunk/Toss/WebClient/index.html 2010-12-30 22:58:00 UTC (rev 1273) @@ -102,6 +102,12 @@ </p> <ul class="plays-list" id="plays-list-Breakthrough"></ul> <p class="game-par"> + <button class="bt" onclick="new_play ('Checkers')">New Game</button> + <a class="game_list" + href="http://en.wikipedia.org/wiki/Checkers">Checkers</a> + </p> + <ul class="plays-list" id="plays-list-Checkers"></ul> + <p class="game-par"> <button class="bt" onclick="new_play ('Chess')">New Game</button> <a class="game_list" href="http://en.wikipedia.org/wiki/Chess">Chess</a> </p> Added: trunk/Toss/examples/Checkers.toss =================================================================== --- trunk/Toss/examples/Checkers.toss (rev 0) +++ trunk/Toss/examples/Checkers.toss 2010-12-30 22:58:00 UTC (rev 1273) @@ -0,0 +1,211 @@ +PLAYERS 1, 2 +DATA depth: 2, adv_ratio: 2 +REL IsFirst(x) = not ex z C(z, x) +REL IsEight(x) = not ex z C(x, z) +REL w(x) = W(x) or Wq(x) +REL b(x) = B(x) or Bq(x) +REL DiagWa (x, y) = ex z (C(x, z) and R(y, z)) +REL DiagBa (x, y) = ex z (C(z, x) and R(z, y)) +REL DiagWb (x, y) = ex z (C(x, z) and R(z, y)) +REL DiagBb (x, y) = ex z (C(z, x) and R(y, z)) +REL DiagW2 (x, y, z) = + (DiagWa (x, y) and DiagWa (y, z)) or (DiagWb (x, y) and DiagWb (y, z)) +REL DiagB2 (x, y, z) = + (DiagBa (x, y) and DiagBa (y, z)) or (DiagBb (x, y) and DiagBb (y, z)) +REL Diag2 (x, y, z) = DiagW2 (x, y, z) or DiagB2 (x, y, z) +REL BeatsW (x, y) = ex z (b(z) and not b(y) and not w(y) and Diag2 (x, z, y)) +REL BeatsB (x, y) = ex z (w(z) and not b(y) and not w(y) and Diag2 (x, z, y)) +REL Da (x, y) = DiagWa (x, y) or DiagBa (x, y) +REL Db (x, y) = DiagWb (x, y) or DiagBb (x, y) +REL FreeDa (x, y) = tc 7 x, y (Da (x, y) and not w(y) and not b(y)) +REL FreeDb (x, y) = tc 7 x, y (Db (x, y) and not w(y) and not b(y)) +REL FreeDWa (x, y) = tc 6 x, y (DiagWa (x, y) and not w(y) and not b(y)) +REL FreeDWb (x, y) = tc 6 x, y (DiagWb (x, y) and not w(y) and not b(y)) +REL FreeDBa (x, y) = tc 6 x, y (DiagBa (x, y) and not w(y) and not b(y)) +REL FreeDBb (x, y) = tc 6 x, y (DiagBb (x, y) and not w(y) and not b(y)) +REL TrDWa (x, y) = ex z (FreeDWa (x, z) and (z = y or DiagWa (z, y))) +REL TrDWb (x, y) = ex z (FreeDWb (x, z) and (z = y or DiagWb (z, y))) +REL TrDBa (x, y) = ex z (FreeDBa (x, z) and (z = y or DiagBa (z, y))) +REL TrDBb (x, y) = ex z (FreeDBb (x, z) and (z = y or DiagBb (z, y))) +REL TDiagW2 (x, y, z) = + (TrDWa (x, y) and DiagWa (y, z)) or (TrDWb (x, y) and DiagWb (y, z)) +REL TDiagB2 (x, y, z) = + (TrDBa (x, y) and DiagBa (y, z)) or (TrDBb (x, y) and DiagBb (y, z)) +REL TDiag2 (x, y, z) = TDiagW2 (x, y, z) or TDiagB2 (x, y, z) +RULE WhiteMove: + [ a, b | W { a } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + -> + [ a, b | W { b } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + emb w, b pre (not IsEight(b)) and (DiagWa(a, b) or DiagWb(a, b)) + and not ex x, y (W(x) and BeatsW (x, y)) +RULE BlackMove: + [ a, b | B { a } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + -> + [ a, b | B { b } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + emb w, b pre (not IsFirst(b)) and (DiagBa(a, b) or DiagBb(a, b)) + and not ex x, y (B(x) and BeatsB (x, y)) +RULE WhitePromote: + [ a, b | W { a } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + -> + [ a, b | Wq { b } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + emb w, b pre (IsEight(b)) and (DiagWa(a, b) or DiagWb(a, b)) + and not ex x, y (W(x) and BeatsW (x, y)) +RULE BlackPromote: + [ a, b | B { a } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + -> + [ a, b | Bq { b } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + emb w, b pre (IsFirst(b)) and (DiagBa(a, b) or DiagBb(a, b)) + and not ex x, y (B(x) and BeatsB(x, y)) +RULE WhiteQMove: + [ a, b | Wq { a } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + -> + [ a, b | Wq { b } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + emb w, b pre FreeDa(a, b) or FreeDb(a, b) +RULE BlackQMove: + [ a, b | Bq { a } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + -> + [ a, b | Bq { b } | + vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + emb w, b pre FreeDa(a, b) or FreeDb(a, b) +RULE WhiteBeat: + [ a, b, c | W { a }; b { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> + [ a, b, c | W { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre Diag2 (a, b, c) and not IsEight(c) + post not ex x, y (_new_W(x) and BeatsW (x, y)) +RULE BlackBeat: + [ a, b, c | B { a }; w { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> + [ a, b, c | B { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre Diag2 (a, b, c) and not IsFirst(c) + post not ex x, y (_new_B(x) and BeatsB (x, y)) +RULE WhiteBeatPromote: + [ a, b, c | W { a }; b { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> + [ a, b, c | Wq { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre Diag2 (a, b, c) and IsEight(c) + post not ex x, y (_new_W(x) and BeatsW (x, y)) +RULE BlackBeatPromote: + [ a, b, c | B { a }; w { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> + [ a, b, c | Bq { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre Diag2 (a, b, c) and IsFirst(c) + post not ex x, y (_new_B(x) and BeatsB (x, y)) +RULE WhiteBeatCont: + [ a, b, c | W { a }; b { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> + [ a, b, c | W { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre Diag2 (a, b, c) post ex x, y (_new_W(x) and BeatsW (x, y)) +RULE BlackBeatCont: + [ a, b, c | B { a }; w { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> + [ a, b, c | B { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre Diag2 (a, b, c) post ex x, y (_new_B(x) and BeatsB (x, y)) +RULE WhiteQBeat: + [ a, b, c | Wq { a }; b { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> + [ a, b, c | Wq { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre TDiag2 (a, b, c) +RULE BlackQBeat: + [ a, b, c | Bq { a }; w { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> + [ a, b, c | Bq { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre TDiag2 (a, b, c) +LOC 0 { + PLAYER 1 + PAYOFF { + 1: :(ex x w(x)) - :(ex x b(x)); + 2: :(ex x b(x)) - :(ex x w(x)) + } + MOVES [WhiteMove -> 1]; [WhitePromote -> 1]; [WhiteQMove -> 1]; + [WhiteBeat -> 1]; [WhiteBeatPromote -> 1]; [WhiteQBeat -> 1]; + [WhiteBeatCont -> 2] +} +LOC 1 { + PLAYER 2 + PAYOFF { + 1: :(ex x w(x)) - :(ex x b(x)); + 2: :(ex x b(x)) - :(ex x w(x)) + } + MOVES [BlackMove -> 0]; [BlackPromote -> 0]; [BlackQMove -> 0]; + [BlackBeat -> 0]; [BlackBeatPromote -> 0]; [BlackQBeat -> 0]; + [BlackBeatCont -> 3] +} +LOC 2 { + PLAYER 1 + PAYOFF { + 1: :(ex x w(x)) - :(ex x b(x)); + 2: :(ex x b(x)) - :(ex x w(x)) + } + MOVES [WhiteBeat -> 1]; [WhiteBeatPromote -> 1]; [WhiteBeatCont -> 2] +} +LOC 3 { + PLAYER 2 + PAYOFF { + 1: :(ex x w(x)) - :(ex x b(x)); + 2: :(ex x b(x)) - :(ex x w(x)) + } + MOVES [BlackBeat -> 0]; [BlackBeatPromote -> 0]; [BlackBeatCont -> 3] +} +MODEL [ | Wq:1 { }; Bq:1 { } | + ] " + ... ... ... ... + B.. B.. B.. B.. + ... ... ... ... + B.. B.. B.. B.. + ... ... ... ... + B.. B.. B.. B.. + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + W.. W.. W.. W.. + ... ... ... ... + W.. W.. W.. W.. + ... ... ... ... + W.. W.. W.. W.. +" Added: trunk/Toss/examples/Checkers.tossstyle =================================================================== --- trunk/Toss/examples/Checkers.tossstyle (rev 0) +++ trunk/Toss/examples/Checkers.tossstyle 2010-12-30 22:58:00 UTC (rev 1273) @@ -0,0 +1,6 @@ +nocolor ; +elOPACITY: 20 ; +relOPACITY: 150 ; +arrLENscale: 0.0 ; +W: ~/greencircle.svg; +B: ~/bluecircle.svg; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-01-05 00:52:46
|
Revision: 1274 http://toss.svn.sourceforge.net/toss/?rev=1274&view=rev Author: lukaszkaiser Date: 2011-01-05 00:52:39 +0000 (Wed, 05 Jan 2011) Log Message: ----------- Correcting checkers, adding pure chess pawn progress game. Modified Paths: -------------- trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/index.html trunk/Toss/examples/Checkers.toss Added Paths: ----------- trunk/Toss/examples/Pawns.toss trunk/Toss/examples/Pawns.tossstyle Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2010-12-30 22:58:00 UTC (rev 1273) +++ trunk/Toss/WebClient/Main.js 2011-01-05 00:52:39 UTC (rev 1274) @@ -238,7 +238,7 @@ var li = new_play_item (GAME_NAME, CUR_PLAY_I); old_li.parentNode.replaceChild (li, old_li); if (PLAYS[CUR_PLAY_I][(m + 1) % 2] == "computer") { - var m = suggest_move (); + var m = suggest_move_better (); if (m != "") { make_move (); } } } @@ -390,4 +390,4 @@ "Hide Move Suggestions"; document.getElementById("player-info-par").style.display = "block"; } -} \ No newline at end of file +} Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2010-12-30 22:58:00 UTC (rev 1273) +++ trunk/Toss/WebClient/index.html 2011-01-05 00:52:39 UTC (rev 1274) @@ -104,7 +104,7 @@ <p class="game-par"> <button class="bt" onclick="new_play ('Checkers')">New Game</button> <a class="game_list" - href="http://en.wikipedia.org/wiki/Checkers">Checkers</a> + href="http://en.wikipedia.org/wiki/English_draughts">Checkers</a> </p> <ul class="plays-list" id="plays-list-Checkers"></ul> <p class="game-par"> Modified: trunk/Toss/examples/Checkers.toss =================================================================== --- trunk/Toss/examples/Checkers.toss 2010-12-30 22:58:00 UTC (rev 1273) +++ trunk/Toss/examples/Checkers.toss 2011-01-05 00:52:39 UTC (rev 1274) @@ -8,30 +8,17 @@ REL DiagBa (x, y) = ex z (C(z, x) and R(z, y)) REL DiagWb (x, y) = ex z (C(x, z) and R(z, y)) REL DiagBb (x, y) = ex z (C(z, x) and R(y, z)) +REL AnyDiag (x, y) = + DiagWa (x, y) or DiagWb (x, y) or DiagBa (x, y) or DiagBb (x, y) REL DiagW2 (x, y, z) = (DiagWa (x, y) and DiagWa (y, z)) or (DiagWb (x, y) and DiagWb (y, z)) REL DiagB2 (x, y, z) = (DiagBa (x, y) and DiagBa (y, z)) or (DiagBb (x, y) and DiagBb (y, z)) REL Diag2 (x, y, z) = DiagW2 (x, y, z) or DiagB2 (x, y, z) -REL BeatsW (x, y) = ex z (b(z) and not b(y) and not w(y) and Diag2 (x, z, y)) -REL BeatsB (x, y) = ex z (w(z) and not b(y) and not w(y) and Diag2 (x, z, y)) -REL Da (x, y) = DiagWa (x, y) or DiagBa (x, y) -REL Db (x, y) = DiagWb (x, y) or DiagBb (x, y) -REL FreeDa (x, y) = tc 7 x, y (Da (x, y) and not w(y) and not b(y)) -REL FreeDb (x, y) = tc 7 x, y (Db (x, y) and not w(y) and not b(y)) -REL FreeDWa (x, y) = tc 6 x, y (DiagWa (x, y) and not w(y) and not b(y)) -REL FreeDWb (x, y) = tc 6 x, y (DiagWb (x, y) and not w(y) and not b(y)) -REL FreeDBa (x, y) = tc 6 x, y (DiagBa (x, y) and not w(y) and not b(y)) -REL FreeDBb (x, y) = tc 6 x, y (DiagBb (x, y) and not w(y) and not b(y)) -REL TrDWa (x, y) = ex z (FreeDWa (x, z) and (z = y or DiagWa (z, y))) -REL TrDWb (x, y) = ex z (FreeDWb (x, z) and (z = y or DiagWb (z, y))) -REL TrDBa (x, y) = ex z (FreeDBa (x, z) and (z = y or DiagBa (z, y))) -REL TrDBb (x, y) = ex z (FreeDBb (x, z) and (z = y or DiagBb (z, y))) -REL TDiagW2 (x, y, z) = - (TrDWa (x, y) and DiagWa (y, z)) or (TrDWb (x, y) and DiagWb (y, z)) -REL TDiagB2 (x, y, z) = - (TrDBa (x, y) and DiagBa (y, z)) or (TrDBb (x, y) and DiagBb (y, z)) -REL TDiag2 (x, y, z) = TDiagW2 (x, y, z) or TDiagB2 (x, y, z) +REL BeatsW (x, y) = ex z (b(z) and not b(y) and not w(y) and DiagW2 (x, z, y)) +REL BeatsWX (x, y) = ex z (b(z) and not b(y) and not w(y) and Diag2 (x, z, y)) +REL BeatsB (x, y) = ex z (w(z) and not b(y) and not w(y) and DiagB2 (x, z, y)) +REL BeatsBX (x, y) = ex z (w(z) and not b(y) and not w(y) and DiagB2 (x, z, y)) RULE WhiteMove: [ a, b | W { a } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] @@ -70,14 +57,14 @@ -> [ a, b | Wq { b } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] - emb w, b pre FreeDa(a, b) or FreeDb(a, b) + emb w, b pre AnyDiag (a, b) RULE BlackQMove: [ a, b | Bq { a } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] -> [ a, b | Bq { b } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] - emb w, b pre FreeDa(a, b) or FreeDb(a, b) + emb w, b pre AnyDiag (a, b) RULE WhiteBeat: [ a, b, c | W { a }; b { b } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; @@ -86,7 +73,7 @@ [ a, b, c | W { c } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] - emb w, b pre Diag2 (a, b, c) and not IsEight(c) + emb w, b pre DiagW2 (a, b, c) and not IsEight(c) post not ex x, y (_new_W(x) and BeatsW (x, y)) RULE BlackBeat: [ a, b, c | B { a }; w { b } | @@ -96,7 +83,7 @@ [ a, b, c | B { c } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] - emb w, b pre Diag2 (a, b, c) and not IsFirst(c) + emb w, b pre DiagB2 (a, b, c) and not IsFirst(c) post not ex x, y (_new_B(x) and BeatsB (x, y)) RULE WhiteBeatPromote: [ a, b, c | W { a }; b { b } | @@ -106,7 +93,7 @@ [ a, b, c | Wq { c } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] - emb w, b pre Diag2 (a, b, c) and IsEight(c) + emb w, b pre DiagW2 (a, b, c) and IsEight(c) post not ex x, y (_new_W(x) and BeatsW (x, y)) RULE BlackBeatPromote: [ a, b, c | B { a }; w { b } | @@ -116,7 +103,7 @@ [ a, b, c | Bq { c } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] - emb w, b pre Diag2 (a, b, c) and IsFirst(c) + emb w, b pre DiagB2 (a, b, c) and IsFirst(c) post not ex x, y (_new_B(x) and BeatsB (x, y)) RULE WhiteBeatCont: [ a, b, c | W { a }; b { b } | @@ -144,7 +131,7 @@ [ a, b, c | Wq { c } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] - emb w, b pre TDiag2 (a, b, c) + emb w, b pre Diag2 (a, b, c) RULE BlackQBeat: [ a, b, c | Bq { a }; w { b } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; @@ -153,7 +140,7 @@ [ a, b, c | Bq { c } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] - emb w, b pre TDiag2 (a, b, c) + emb w, b pre Diag2 (a, b, c) LOC 0 { PLAYER 1 PAYOFF { Added: trunk/Toss/examples/Pawns.toss =================================================================== --- trunk/Toss/examples/Pawns.toss (rev 0) +++ trunk/Toss/examples/Pawns.toss 2011-01-05 00:52:39 UTC (rev 1274) @@ -0,0 +1,183 @@ +PLAYERS 1, 2 +DATA depth: 2, adv_ratio: 2 +REL DiagW (x, y) = ex z (C(x, z) and (R(y, z) or R(z, y))) +REL DiagB (x, y) = ex z (C(z, x) and (R(y, z) or R(z, y))) +REL IsFirst(x) = not ex z C(z, x) +REL IsSecond(x) = ex y (C(y, x) and IsFirst(y)) +REL IsEight(x) = not ex z C(x, z) +REL IsSeventh(x) = ex y (C(x, y) and IsEight(y)) +RULE WhiteDiag: + [ a, b | W { a }; B { b } | + vx {a->0.,b->10.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + -> + [ a, b | W { b } | + vx {a->0.,b->10.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + emb W, B pre DiagW(a, b) and not ex x (B(x) and not ex y C(y, x)) +RULE WhiteStraight: + [ | B:1 {}; R:2 {} | ] " + + . + + W +" -> [ | B:1 {}; R:2 {} | + ] " + + W + + . +" emb W, B pre not ex x (B(x) and not ex y C(y, x)) +RULE WhiteStraightTwo: + [ | B:1 {}; R:2 {} | ] " + + . + + . + + W +" -> [ | B:1 {}; R:2 {} | + ] " + + W + + . + + . +" emb W, B pre IsSecond(a1) and not ex x (B(x) and not ex y C(y, x)) +RULE WhitePawnRightDbl: + [ | | ] " + ... + ?..-B + ... + ? ... + ... + W..B +" -> [ | | ] " + ... + ?... + ... + ? W.. + ... + .... +" emb W, B +RULE WhitePawnLeftDbl: + [ | | ] " + ... + -B.? + ... + . ?.. + ... + B..W +" -> [ | | ] " + ... + ...? + ... + W ?.. + ... + .... +" emb W, B +RULE BlackDiag: + [ a, b | B { a }; W { b } | + vx {a->0.,b->10.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + -> + [ a, b | B { b } | + vx {a->0.,b->10.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] + emb W, B pre DiagB(a, b) and not ex x (W(x) and not ex y C(x, y)) +RULE BlackStraight: + [ | R:2 {}; W:1 {} | ] " + + B + + . +" -> [ | R:2 {}; W:1 {} | + ] " + + . + + B +" emb W, B pre not ex x (W(x) and not ex y C(x, y)) +RULE BlackStraightTwo: + [ | R:2 {}; W:1 {} | ] " + + B + + . + + . +" -> [ | R:2 {}; W:1 {} | + ] " + + . + + . + + B +" emb W, B pre IsSeventh(a3) and not ex x (W(x) and not ex y C(x, y)) +RULE BlackPawnRightDbl: + [ | | ] " + ... + B..W + ... + ? ... + ... + ?..-W +" -> [ | | ] " + ... + .... + ... + ? B.. + ... + ?... +" emb W, B +RULE BlackPawnLeftDbl: + [ | | ] " + ... + W..B + ... + . ?.. + ... + -W.? +" -> [ | | ] " + ... + .... + ... + B ?.. + ... + ...? +" emb W, B +LOC 0 { + PLAYER 1 + PAYOFF { + 1: :(ex x (W(x) and not ex y C(x, y))) - :(ex x (B(x) and not ex y C(y, x))); + 2: :(ex x (B(x) and not ex y C(y, x))) - :(ex x (W(x) and not ex y C(x, y))) + } + MOVES [WhiteDiag -> 1]; [WhiteStraight -> 1]; + [WhitePawnRightDbl -> 1]; [WhitePawnLeftDbl -> 1]; [WhiteStraightTwo -> 1] +} +LOC 1 { + PLAYER 2 + PAYOFF { + 1: :(ex x (W(x) and not ex y C(x, y))) - :(ex x (B(x) and not ex y C(y, x))); + 2: :(ex x (B(x) and not ex y C(y, x))) - :(ex x (W(x) and not ex y C(x, y))) + } + MOVES [BlackDiag -> 0]; [BlackStraight -> 0]; + [BlackPawnRightDbl -> 0]; [BlackPawnLeftDbl -> 0]; [BlackStraightTwo -> 0] +} +MODEL [ | | + ] " + ... ... ... ... + ... ... ... ... + ... ... ... ... + B..B B..B B..B B..B + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + W W..W W..W W..W W.. + ... ... ... ... + ... ... ... ... +" Added: trunk/Toss/examples/Pawns.tossstyle =================================================================== --- trunk/Toss/examples/Pawns.tossstyle (rev 0) +++ trunk/Toss/examples/Pawns.tossstyle 2011-01-05 00:52:39 UTC (rev 1274) @@ -0,0 +1,6 @@ +nocolor ; +elOPACITY: 20 ; +relOPACITY: 150 ; +arrLENscale: 0.0 ; +W: ~/pawn_white.svg; +B: ~/pawn_black.svg; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-01-07 11:41:34
|
Revision: 1276 http://toss.svn.sourceforge.net/toss/?rev=1276&view=rev Author: lukaszkaiser Date: 2011-01-07 11:41:28 +0000 (Fri, 07 Jan 2011) Log Message: ----------- Corrections Modified Paths: -------------- trunk/Toss/README trunk/Toss/Toss.py trunk/Toss/WebClient/README trunk/Toss/examples/Tic-Tac-Toe.toss Modified: trunk/Toss/README =================================================================== --- trunk/Toss/README 2011-01-05 14:24:57 UTC (rev 1275) +++ trunk/Toss/README 2011-01-07 11:41:28 UTC (rev 1276) @@ -11,7 +11,7 @@ -- Installing dependencies under Ubuntu Run the following in terminal: - sudo apt-get install python-qt4 python-dev pyqt4-dev-tools ocaml-findlib menhir libounit-ocaml-dev + sudo apt-get install g++ python-qt4 python-dev pyqt4-dev-tools ocaml-findlib menhir libounit-ocaml-dev Finally to compile Toss just type make Modified: trunk/Toss/Toss.py =================================================================== --- trunk/Toss/Toss.py 2011-01-05 14:24:57 UTC (rev 1275) +++ trunk/Toss/Toss.py 2011-01-07 11:41:28 UTC (rev 1276) @@ -4,7 +4,6 @@ import os import subprocess import socket -import socket from PyQt4.QtGui import QApplication # QtGui Ref: www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qtgui.html Modified: trunk/Toss/WebClient/README =================================================================== --- trunk/Toss/WebClient/README 2011-01-05 14:24:57 UTC (rev 1275) +++ trunk/Toss/WebClient/README 2011-01-07 11:41:28 UTC (rev 1276) @@ -3,8 +3,8 @@ Connection with Server goes through a python wrapper and it uses sqlite, so do: sudo apt-get install libapache2-mod-python sqlite3 python-pysqlite2 to run the wrapper. Make sure apache works (you may need to edit the file -/etc/apache2/apache2.conf and set ServerRoot to e.g. /var/www/) and then -in the file /etc/apache2/sites-enabled/[your-site] add e.g. +/etc/apache2/apache2.conf and uncoment ServerRoot to e.g. /etc/apache2) and +then in the file /etc/apache2/sites-enabled/[your-site] add e.g. <Directory /var/www/WebClient> AddHandler mod_python .py PythonHandler Handler Modified: trunk/Toss/examples/Tic-Tac-Toe.toss =================================================================== --- trunk/Toss/examples/Tic-Tac-Toe.toss 2011-01-05 14:24:57 UTC (rev 1275) +++ trunk/Toss/examples/Tic-Tac-Toe.toss 2011-01-07 11:41:28 UTC (rev 1276) @@ -1,5 +1,5 @@ PLAYERS 1, 2 -DATA r1: circle, r2: line, adv_ratio: 4, depth: 3 +DATA r1: circle, r2: line, adv_ratio: 4, depth: 4 REL DiagA (x, y) = ex u (R(x, u) and C(u, y)) REL DiagB (x, y) = ex u (R(x, u) and C(y, u)) REL Row3 (x, y, z) = R(x, y) and R(y, z) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-01-09 20:58:16
|
Revision: 1277 http://toss.svn.sourceforge.net/toss/?rev=1277&view=rev Author: lukstafi Date: 2011-01-09 20:58:08 +0000 (Sun, 09 Jan 2011) Log Message: ----------- GDL translation initial commit, work in progress. Aux.unique_sorted bug fix. Modified Paths: -------------- trunk/Toss/Formula/Aux.ml trunk/Toss/Formula/Aux.mli trunk/Toss/Formula/AuxTest.ml trunk/Toss/Play/GDL.ml trunk/Toss/Play/GDL.mli trunk/Toss/Play/GDLParser.mly trunk/Toss/Play/KIFLexer.mll trunk/Toss/Solver/Structure.ml trunk/Toss/Solver/Structure.mli Added Paths: ----------- trunk/Toss/Play/GDLTest.ml trunk/Toss/examples/breakthrough.gdl trunk/Toss/examples/checkers.gdl trunk/Toss/examples/chess.gdl trunk/Toss/examples/connect5.gdl Modified: trunk/Toss/Formula/Aux.ml =================================================================== --- trunk/Toss/Formula/Aux.ml 2011-01-07 11:41:28 UTC (rev 1276) +++ trunk/Toss/Formula/Aux.ml 2011-01-09 20:58:08 UTC (rev 1277) @@ -24,6 +24,10 @@ in List.rev (cmap_f [] l) +let rec map_prepend tl f = function + [] -> tl + | a::l -> let r = f a in r :: map_prepend tl f l + let map_some f l = let rec maps_f accu = function | [] -> accu @@ -87,8 +91,15 @@ let tl = map_try f tl in try f hd :: tl with Not_found -> tl - +let rec fold_left_try f accu l = + match l with + [] -> accu + | a::l -> + try + fold_left_try f (f accu a) l + with Not_found -> fold_left_try f accu l + let product l = List.fold_right (fun set prod -> concat_map (fun el -> List.map (fun tup -> el::tup) prod) set) @@ -126,13 +137,27 @@ | [] -> acc in List.rev (aux [] l) -(* TODO: that's quadratic, perhaps (sort |> drop_repeating) - would be faster in practice *) +(* Not tail-recursive. *) +let unique_sorted l = + let rec idemp = function + | e1::(e2::_ as tl) when e1 = e2 -> idemp tl + | e::tl -> e::idemp tl + | [] -> [] in + idemp (List.sort Pervasives.compare l) + +(* TODO: that's quadratic, optimize? *) let rec unique eq = function | [] -> [] | x :: xs -> x :: unique eq (List.filter (fun y -> not (eq y x)) xs) +let not_unique xs = + let rec aux left = function + | [] -> false + | x :: xs when List.mem x left || List.mem x xs -> true + | x :: xs -> aux (x::left) xs in + aux [] xs + let take_n n l = let rec aux n acc = function | hd::tl when n > 0 -> Modified: trunk/Toss/Formula/Aux.mli =================================================================== --- trunk/Toss/Formula/Aux.mli 2011-01-07 11:41:28 UTC (rev 1276) +++ trunk/Toss/Formula/Aux.mli 2011-01-09 20:58:08 UTC (rev 1277) @@ -15,6 +15,10 @@ (** Concatenate results of a function. *) val concat_map : ('a -> 'b list) -> 'a list -> 'b list +(** Map a second list and prepend the result to the first list, by + single traversal. Not tail-recursive. *) +val map_prepend : 'a list -> ('b -> 'a) -> 'b list -> 'a list + (** Map a list filtering out some elements. *) val map_some : ('a -> 'b option) -> 'a list -> 'b list @@ -54,6 +58,12 @@ raise [Not_found]. Therefore [map_try] call cannot raise [Not_found]. *) val map_try : ('a -> 'b) -> 'a list -> 'b list + +(** Fold [f] over the list collecting results whose computation does + not raise [Not_found]. Therefore [fold_left_try] call cannot raise + [Not_found]. *) +val fold_left_try : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a + (** Cartesian product of lists. Not tail recursive. *) val product : 'a list list -> 'a list list @@ -78,12 +88,18 @@ equal elements only the last one is preserved.) *) val maximal : ('a -> 'a -> bool) -> 'a list -> 'a list +(** Return the list of structurally unique elements, in order sorted + by {!Pervasives.compare}. Not tail-recursive. *) +val unique_sorted : 'a list -> 'a list + (** Return the list of unique elements, under the given comparison (the input does not need to be sorted). (Currently uses a - straightforward [n^2] algorithm, a sorting-based would reduce it to - [n log n]. Currently not tail-recursive.) *) + straightforward [n^2] algorithm. Currently not tail-recursive.) *) val unique : ('a -> 'a -> bool) -> 'a list -> 'a list +(** Check whether the list contains duplicates, using structural equality. *) +val not_unique : 'a list -> bool + (** Take [n] elements of the given list, or less it the list does not contain enough values. *) val take_n : int -> 'a list -> 'a list Modified: trunk/Toss/Formula/AuxTest.ml =================================================================== --- trunk/Toss/Formula/AuxTest.ml 2011-01-07 11:41:28 UTC (rev 1276) +++ trunk/Toss/Formula/AuxTest.ml 2011-01-09 20:58:08 UTC (rev 1277) @@ -198,13 +198,25 @@ ["a1";"c2"; "b1"; "a3"; "c7"]); ); - "unique, take_n" >:: + "unique, unique_soted, not_unique, take_n" >:: (fun () -> assert_equal ~printer:(String.concat "; ") - ["a";"c";"b";"d"] - (Aux.unique (=) ["a";"c";"b"; "d"; "c"]); + ~msg:"should remove duplicates" + ["a";"c";"e";"b";"d"] + (Aux.unique (=) ["a";"c";"e"; "b"; "d"; "e"; "c"; "e"]); assert_equal ~printer:(String.concat "; ") + ~msg:"should remove duplicates" + ["a";"b";"c";"d";"e"] + (Aux.unique_sorted ["a";"c";"e"; "b"; "d"; "e"; "c"; "e"]); + + assert_bool "not unique" + (Aux.not_unique ["a";"c";"b"; "d"; "c"]); + + assert_bool "unique" + (not (Aux.not_unique ["a";"c";"b";"d"])); + + assert_equal ~printer:(String.concat "; ") ["a";"c";"b"] (Aux.take_n 3 ["a";"c";"b"; "d"; "c"]); Modified: trunk/Toss/Play/GDL.ml =================================================================== --- trunk/Toss/Play/GDL.ml 2011-01-07 11:41:28 UTC (rev 1276) +++ trunk/Toss/Play/GDL.ml 2011-01-09 20:58:08 UTC (rev 1277) @@ -1,10 +1,338 @@ (** {2 Game Description Language.} - Type definitions, helper functions, game specification translation. *) + Type definitions, helper functions, game specification + translation. + The translation is not complete (yet), and not yet guaranteed to + be sound (but aiming at it) -- report any cases where the + algorithm does not fail explicitly but does not preserve + semantics. + + (1) Aggregate playout: generate successive states as if all moves + legal in the previous state were performed. Do not check the + termination predicate. + + (1a) Reason for unsoundness: "legal" or "next" preconditions can + depend negatively on state, preventing further moves in the + aggregate state that would be possible in some of valid game + states; the aggregate state does not have enough terms as a + result. Workaround: remove negative literals from "legal"/"next" + conditions for generating aggregate playout. + + (1b) Saturation works on definitions stratified + w.r.t. negation. Positive literals are instantiated one by one, + then negative literals are checked over the facts derived from + previous strata. To avoid redundancy, new facts and new + instantiations are kept separate for the next iteration within a + stratum. + + (1c) Heuristic reason for unsoundness: while we check for fixpoint + in the playout, we rule out state terms "F(X)" where X is a player + (assuming that "F" means "control"). Workaround: turn off fixpoint + checking [aggregate_fixpoint]. + + (2) Arena graph: currently, only a simple cycle is allowed. The + succession of players is determined from the aggregate playout. + + (2a) We need to recognize which player actually makes a move in a + state. For this we need to locate the "noop" arguments to "legal" + and "does" relations. A noop action in a location is the only + action in the corresponding state of an aggregate playout for the + player that is additionally constant. + + (2b) We determine the player of a location by requiring that at + most one player has a non-noop action in an aggregate + state. When all players are noops we select the control player so + that the smallest "game cycle" is preserved. Otherwise (more than + one no-noop move) we fail (simultaneous moves not supported). We + remember the noop actions for each location and player. + + (3) Currently, a constant number of elements is assumed. The rules + processed in (3a)-(3b) are already expanded by (6). + + (3a) Element terms are collected from the aggregate playout: the + sum of state terms (the "control" function could be dropped but we + are not taking the effort to identify it). + + (3b) Element masks are generated by generalization from all "next" + rules where the "does" relations are expanded by all unifying + "legal" rules (see also (7a)). + + (3c) Generalization in a single expanded "next" rule is by finding + for the "next" term the closest "true" term in the lexicographic + ordering of (# of matched variables, # of other matched leaves), + but in case the closest term is found in the negative part, it is + further processed. + + (3c1) Unmatched subterms are replaced by meta-variables. + + (3c2) When the generalization comes from the negative part, we + replace all constant leaves with meta-variables. Warning: this + heuristic is a reason for unsoundness -- search for a workaround + once a real counterexample is encountered. + + (3d) The masks are all the minimal w.r.t. matching (substitution) + of the generalized terms, with only meta-variable positions of the + mask matching meta-variable positions of a generalized + term. + + (3e) The elements are the equivalence classes of element terms, + where terms are equivalent when they both match a single mask and + their matching substitutions differ only at + meta-variables. (I.e. for t1 and t2 there exists a mask m and + substitutions s1 and s2 such that s1(m)=t1 and s2(m)=t2 and + s1(x)=/=s2(x) implies that x is/contains a meta-variable.) + + (Note that there is "nothing wrong" with a given equiv class not + having any member in the initial state or some other state. The + element is still there in the structure, still participating in + the "static" relations, but not in the "dynamic" predicates in + that particular state. We use a special _BLANK_ term/predicate to + faciliate operations on such "absent" elements.) + + (4) Static relations (their tuples do not change during the game) + are derived from static facts with subterms common with element + terms but not below meta-variables. + + Define mask-paths as the set of a mask together with a path in it + to a position that is not below (or at) a meta-variable. + + Implementation: currently we approximate paths by only taking the + positions of variables in the mask. + + (4a) (Fact relations.) For a static fact (a relation that does not + depend on "true" or "init") (unless it is expanded -- see (6)), + introduce a relation for each mask-paths tuple with arity of the + relation (i.e., introduced relations are a dependent product of + static fact relations and a cartesian n-th power of the mask-paths + set where n is the arity of the relation). An introduced relation + holds over a tuple of elements, iff the corresponding element + terms match the respective masks, and the original relation holds + over the tuple of subterms selected from the element terms by the + corresponding paths. + + (Relations that do not hold for any tuple of element terms in the + whole aggregate playout can be removed.) + + (4b) (Equality relations.) For each mask-path, introduce a binary + relation that holds over elements which have the same subterm at + the mask-path position. (Because of mask-paths definition, same + for all element terms in element's equivalence class.) + + (4c) (Anchor predicates.) Collect all terms under "true" and + "next" predicates in the game definition. For each mask-path + pointing to a constant in some of the terms and that constant, + introduce a new predicate with semantics: "matches the mask and + has the constant at the path position". + + (5) (Mostly) dynamic relations ("fluents": their tuples change + during the game), relations derived from all below-meta-variable + subterms of element terms, initialized by those that appear in the + initial state. (Some relations introduced in this step might not + be fluents.) + + Collect all terms under "true" and "next" predicates in the game + definition. For each term, find the element mask it matches, and + introduce relations for each meta-variable of the element mask, + associated with the subterm that matches the meta-variable. The + semantic is that the relation selects the element terms that match + the mask with the associated subterm subsituted for the + corresponding meta-variable, with existential + interpretation. A relation holds initially over an element, if in + the initial set of element terms at least one from the element's + equivalence class is selected by the relation. An occurrence of + "true" or "next" relation is replaced by a conjunction of + relations whose substituted-masks match the relation's term. + + When generating predicates that hold over an element term, no + predicate is generated for any its meta-variable position that + contains _BLANK_. + + (6) Currently how to introduce defined relations in translation is + not yet solved in the presented framework. Currently, we simply + expand relations that are not static, or (optionally) are static + but do not contain ground facts, by duplicating the branch in + which body an atom of the relation occurs, for each branch of the + relation definition, unifying and applying the unifier. (If the + duplication turns out prohibitive, this will be a *huge* TODO for + this translation framework.) + + (6a) The definition: + + [(r, params1) <= body1 ... (r, params_n) <= body_n] + + provides a DNF defining formula (using negation-as-failure): + + [(r, args) <=> exist vars1 (args = params1 /\ body1) \/ ... + \/ exist vars_n (args = params_n /\ body_n)] + + which expands in a natural way for positive occurrences. We + duplicate the branch where [(r, args)] is substitued for each + disjunct and apply the unifier of [args = params_i] in the whole + [i]th cloned branch. We freshen each [vars_i] to avoid capture. If + unification fails, we drop the corresponding branch clone. + + (6b) For negative occurrences we transform the defining formula + to: + + [not (r, args) <=> not exist vars1 (args = params1 /\ body1) /\ ... + /\ not exist vars_n (args = params_n /\ body_n)] + + Currently we do not allow defined dynamic relations with negative + occurrences to have negative literals (or atoms of defined + relations with negative part) in any of [body_i]. (The limitation + can be lifted but it would further complicate the implementation.) + We therefore allow conjunctions of atoms to be negated (not only + literals) in a branch. We expand [not (r, args)] (in general, [not + (and (...(r args)...))]) into the conjunction of negations, with + no branch duplication (in general, duplicating the negated + subformula inside a branch). We only apply the unifier of [args = + params_i] to [body_i] (in general, the whole negated + subformula). Still, we freshen each [vars_i] to avoid capture. If + unification fails, we drop the corresponding negated + subformula. If unification succeeds but the corresponding [body_i] + is empty (and, in general, no other disjuncts in the negated + subformula are left), we drop the branch. + + (6b1) The general case is not implemented yet since it slightly + complicates the code, and expressivity gain is very small. + + (7) Generation of rewrite rules when the dynamic relations are not + recursive and are expanded in the GDL definition. + + (7a) We translate each branch of the "legal" relation definition + as one or more rewrite rules. Currently, we base availability of + rules in a location solely on the player in the location and in + the "legal" definition (currently, we do not allow simultaneous + moves). Consequently, we define rules on a per-player basis rather + than a per-location basis. If the branch of "legal" definition has + a variable for a player, it is instantiated for each player in the + game, and the variable substituted in the body of the "legal" + branch. + + (7b) We collect all the branches of the "next" relation definition + for which the selected branch of "legal" unifies with all (usually + one, but we allow zero or more) occurrences of "does" with a + single unifier per "next" branch. Split the unifiers into + equivalence classes (w.r.t. substitution), each class will be a + different rewrite rule (or set of rules). Associate negation of + equalities specific to the unifiers strictly less general than the + equivalence class with it, so that the resulting conditions form a + partition of the space of substitutions for the "legal" branch + processed. + + (7c) Find a single MGU that unifies the "legal" atom argument and + all the "does" atoms arguments into a single instance, and apply + it to all "next" branches of the rule. We remember all variables + in the "legal"/"does" instantiation as "fixed variables". We + replace all occurrences of "does" with the body of the selected + "legal" branch. + + (7d) We seggregate "next" atoms into these that contain some fixed + variables or no variables at all, and other containing only + unfixed variables. Eliminate unfixed variables from "next" + atoms with fixed variables by enumerating their domains and + duplicating whole "next" branches with each instantiation. (They + will not have unfixed variables.) + + (This perhaps could be done in a better way by better integrating + (7d) and (7e)...) + + (7e) Branches with (only) unfixed variables in "next" atoms are + the "frame" branches. Check that each "frame" branch is an + identity: the "next" atom is equal to one of the positive "true" + atoms. If not, expand all variables (as they are unfixed) + duplicating that branch for each instantiation (the duplicated + branches become regular branches -- with constant "next" + atoms). + + (7e1) Transform the remaining proper "frame" branches into + "erasure" branches: negate the body, push negation inside (using + de Morgan laws etc.), reduce to DNF and split into separate + "erasure" branch for each disjunct, place the original "next" atom + but with meta-variable positions replaced by _BLANK_ as the head + of the "erasure" branch, apply (and remove) unification atoms + resulting from negating the "distinct" relation. + + (7f) Introduce a new element variable for each class of "next" and + "true" terms equal modulo mask (i.e. there is a mask matching them + and they differ only at-or-below metavariables). (Remember the + atoms "corresponding variable".) + + (7g) Add an appropriate equality relation of (4b) for each case + of variable shared by terms corresponding to different element + variables (regardless if the element terms are in positive or + negative literals). + + (7h) For all subterms of "next" and "true" atoms, identify the + sets of <mask-path, element variable> they "inhabit". Replace a + static fact relation by relations built over a cartesian product + of <mask-path, element variable> sets derived for each static + fact's argument by applying corresponding (4a) relations. (For a + negative literal the result will be equivalent to a disjunction of + negations of generated atoms.) + + (7i) Identify variables in "next" & "true" terms that are + at-or-below meta-variables in the corresponding mask. (Most of + such variables should be already removed as belonging to "frame" + branches.) Expand them by duplicating given branch for all + instantiations (all (5) predicates derived from the considered + position). (Note that since branches do not have unfixed variables + anymore, we do not rename variables during duplication.) + + (7j) Now we build rewrite rules for a refinement of an equivalence + class of (7b): from the branches with unifiers in the equiv class, + from branches with unifiers more general than the equiv class, and + from the disjointness conditions (and the terminal condition, see + below). Build a pre-lattice of branch bodies w.r.t. subsumption, + in a manner similar to (7b). The subsumption test has to say "no" + when there exists a game state where the antecedent holds but the + consequent does not, but does not need to always say "yes" + otherwise. Build a rewrite rule for each equivalence class + w.r.t. subsumption, including also branches that are below the + equiv class, and including negation of conditions that make the + branches strictly above more specific -- so that the classes form + a partition of the nonterminal game states (it is semantically + necessary so that all applicable changes are applied in the + translated game when making a move). + + (7k) Replace the "next" and "true" atoms by the conjunction of + (4c) and (5) predicates over their corresponding variable. (For + negative "true" literals this will be equivalent to a disjunction + of negations of the predicates.) + + (7l) Include translated negation of the terminal condition. + + The rewrite rule is generated by joining the derived conjunctions + from "next" atoms as RHS, and from bodies as the + precondition. Exactly the RHS variables are listed in the LHS + (other variables are existentially closed in the precondition). + + (8) We use a single payoff matrix for all locations. Goal patterns + are expanded to regular goals by instantiating the value variable + by all values in its domain (for example, as gathered from the + aggregate playout), and expanding all atoms that contained value + variables (both static and dynamic) using (6); fail if a goal + value cannot be determined. The payoff formula is the sum of + "goal" value times the characterisic function of the "goal" + body. We do not translate the body if the value is zero (we drop + the zero goal branches from the definition). Translate the body + using (7f)-(7k), but treating "goal" branches separately -- when + (7i) duplicates a branch, new branches add new sum elements. + +*) + +let debug_level = ref 0 +let aggregate_drop_negative = ref false +let aggregate_fixpoint = ref true +(** Expand static relations that do not have ground facts and have + arity above the threshold. *) +let expand_arity_above = ref 0 + type term = | Const of string | Var of string + | MVar of string (* meta-variable, not used in GDL *) | Func of string * term list type atom = @@ -16,18 +344,19 @@ type literal = | Pos of atom | Neg of atom + | Disj of literal list type game_descr_entry = | Datalog of string * term list * literal list | Next of term * literal list | Legal of term * term * literal list | Goal of term * int * literal list + | GoalPattern of term * string * literal list | Terminal of literal list | Role of term | Initial of term * literal list | Atomic of string * term list - type request = | Start of string * term * game_descr_entry list * int * int (* prepare game: match id, role, game, startclock, playclock *) @@ -36,11 +365,369 @@ | Stop of string * term list (* game ends here: match id, actions on previous step *) -let compile_game_descr entries = entries +let rec term_str = function + | Const c -> c + | Var v -> "?"^v + | MVar v -> "@"^v + | Func (f, args) -> + "(" ^ f ^ " " ^ String.concat " " (List.map term_str args) ^ ")" +let rec term_to_name ?(nested=false) = function + | Const c -> c + | Var v -> v + | MVar v -> v + | Func (f, args) -> + f ^ "_" ^ (if nested then "_S_" else "") ^ + String.concat "_" (List.map (term_to_name ~nested:true) args) ^ + (if nested then "_Z_" else "") + +let fact_of_atom = function + | Distinct args -> assert false + | Rel (rel, args) -> rel, args + | Currently arg -> "true", [arg] + | Does (arg1, arg2) -> "does", [arg1; arg2] + +let rec body_of_literal = function + | Pos (Distinct args) -> + [Aux.Right ("distinct", args)] (* not negated actually! *) + | Neg (Distinct _) -> assert false + | Pos atom -> [Aux.Left (fact_of_atom atom)] + | Neg atom -> [Aux.Right (fact_of_atom atom)] + | Disj disjs -> + Aux.concat_map body_of_literal disjs + +let func_graph f terms = + Aux.map_some + (function Func (g, args) when f=g -> Some args | _ -> None) terms + +(* Type shortcuts (mostly for documentation). *) +type gdl_atom = string * term list +type gdl_rule = gdl_atom * gdl_atom list * gdl_atom list +(* Definition with expanded definitions: expansion of a negated + relation brings negated conjunctions. *) +type exp_def_branch = + term list * gdl_atom list * gdl_atom list list +type exp_def = + string * exp_def_branch list + +let rules_of_entry = function + | Datalog (rel, args, body) -> + let head = rel, args in + let bodies = Aux.product (List.map body_of_literal body) in + List.map (fun body -> + let pos_body, neg_body = Aux.partition_choice body in + head, pos_body, neg_body) bodies + | Next (head, body) -> + let head = "next", [head] in + let bodies = Aux.product (List.map body_of_literal body) in + List.map (fun body -> + let pos_body, neg_body = Aux.partition_choice body in + head, pos_body, neg_body) bodies + | Legal (arg1, arg2, body) -> + let head = "legal", [arg1; arg2] in + let bodies = Aux.product (List.map body_of_literal body) in + List.map (fun body -> + let pos_body, neg_body = Aux.partition_choice body in + head, pos_body, neg_body) bodies + | Goal (arg, payoff, body) -> + let head = "goal", [arg; Const (string_of_int payoff)] in + let bodies = Aux.product (List.map body_of_literal body) in + List.map (fun body -> + let pos_body, neg_body = Aux.partition_choice body in + head, pos_body, neg_body) bodies + | GoalPattern (arg, var, body) -> + let head = "goal", [arg; Var var] in + let bodies = Aux.product (List.map body_of_literal body) in + List.map (fun body -> + let pos_body, neg_body = Aux.partition_choice body in + head, pos_body, neg_body) bodies + | Terminal body -> + let head = "terminal", [] in + let bodies = Aux.product (List.map body_of_literal body) in + List.map (fun body -> + let pos_body, neg_body = Aux.partition_choice body in + head, pos_body, neg_body) bodies + | Role arg -> [("role", [arg]), [], []] + | Initial (arg, body) -> + let head = "init", [arg] in + let bodies = Aux.product (List.map body_of_literal body) in + List.map (fun body -> + let pos_body, neg_body = Aux.partition_choice body in + head, pos_body, neg_body) bodies + | Atomic (rel, args) -> [(rel, args), [], []] + +let defs_of_rules rules : (string * exp_def_branch list) list = + Aux.map_reduce + (fun ((drel, params), body, neg_body) -> + drel,(params, body, List.map (fun a->[a]) neg_body)) + (fun x y->y::x) [] rules + +(* Only use [rules_of_defs] when sure that no multi-premise negative + literal has been expanded. *) +let rules_of_defs (defs : exp_def list) = + Aux.concat_map (fun (rel, branches) -> + List.map (fun (args, body, neg_body) -> + let neg_body = + List.map (function [a]->a | _ -> assert false) neg_body in + (rel, args), body, neg_body) branches) defs + +(* Stratify either w.r.t. the dependency graph ([~def:true]) or its + subgraph the negation graph ([~def:false]). *) +let rec stratify ?(def=false) strata (defs : exp_def list) = + match + List.partition (fun (_, branches) -> + List.for_all (fun (_, body, neg_body) -> + List.for_all (fun (rel1,_) -> + rel1 = "distinct" || rel1 = "true" || rel1 = "does" || + not (List.mem_assoc rel1 defs)) + (if def then body @ List.concat neg_body + else List.concat neg_body)) branches) defs + with + | [], [] -> List.rev strata + | stratum, [] -> List.rev (stratum::strata) + | [], _ -> + if def then raise + (Lexer.Parsing_error + "GDL.stratify: recursive non-static definitions not handled yet") + else raise + (Lexer.Parsing_error + "GDL.stratify: cyclic negation dependency") + | stratum, rules -> stratify (stratum::strata) rules + + +let rec vars ?(meta=false) = function + | Const _ -> [] + | Var x -> [x] + | MVar x -> if meta then [x] else [] + | Func (_, args) -> Aux.concat_map vars args + +let rec subst_one (x, term as sb) = function + | Var y when x=y -> term + | MVar y when x=y -> term + | (Const _ | Var _ | MVar _ as t) -> t + | Func (f, args) -> + Func (f, List.map (subst_one sb) args) + +let rec unify sb terms1 terms2 = + match terms1, terms2 with + | [], [] -> sb + | Const a::terms1, Const b::terms2 when a=b -> + unify sb terms1 terms2 + | Func (f,args1)::terms1, Func (g,args2)::terms2 when f=g -> + unify sb (args1 @ terms1) (args2 @ terms2) + | Var x::terms1, Var y::terms2 when x=y -> + unify sb terms1 terms2 + | (Var x::terms1, (Var _ | Const _ as term)::terms2 + | (Const _ as term)::terms1, Var x::terms2) -> + let sb1 = x, term in + unify (sb1::List.map (fun (x,t)->x, subst_one sb1 t) sb) + (List.map (subst_one sb1) terms1) + (List.map (subst_one sb1) terms2) + | (Var x::_, term::_ | term::_, Var x::_) + when List.mem x (vars term) -> + raise Not_found + | Var x::terms1, term::terms2 | term::terms1, Var x::terms2 -> + let sb1 = x, term in + unify (sb1::List.map (fun (x,t)->x, subst_one sb1 t) sb) + (List.map (subst_one sb1) terms1) + (List.map (subst_one sb1) terms2) + | _ -> raise Not_found + +(* 3d *) +(* Match the first argument as term against the second argument as + pattern. Allow nonlinear (object) variables. *) +let rec match_meta sb m_sb terms1 terms2 = + match terms1, terms2 with + | [], [] -> sb, m_sb + | (Const a | Var a)::terms1, (Const b | Var b)::terms2 when a=b -> + match_meta sb m_sb terms1 terms2 + | Func (f,args1)::terms1, Func (g,args2)::terms2 when f=g -> + match_meta sb m_sb (args1 @ terms1) (args2 @ terms2) + | term::terms1, MVar x::terms2 -> + (* we don't substitute because metavariables are linear *) + match_meta sb ((x, term)::m_sb) terms1 terms2 + | MVar _::_, _ -> raise Not_found + | term::terms1, Var x::terms2 -> + let sb1 = x, term in + let sb = + if List.mem_assoc x sb then + if List.assoc x sb = term then sb + else raise Not_found + else sb1::sb in + match_meta sb m_sb terms1 terms2 + | _ -> raise Not_found + + +(* 3c1 *) +let generalize term1 term2 = + let fresh_count = ref 0 in + let rec loop pf terms1 terms2 = + match terms1, terms2 with + | [], [] -> (0, 0), [] + | (Const a as cst)::terms1, Const b::terms2 when a=b -> + let (good_vars, good_csts), gens = loop pf terms1 terms2 in + (good_vars, good_csts+1), cst::gens + | Func (f,args1)::terms1, Func (g,args2)::terms2 when f=g -> + let (good_vars1, good_csts1), gen_args = loop f args1 args2 in + let (good_vars2, good_csts2), gens = loop pf terms1 terms2 in + (good_vars1+good_vars2, good_csts1+good_csts2), + (Func (f,gen_args))::gens + | (Var x as var)::terms1, Var y::terms2 when x=y -> + let (good_vars, good_csts), gens = loop pf terms1 terms2 in + (good_vars+1, good_csts), var::gens + | _::terms1, _::terms2 -> + let measure, gens = loop pf terms1 terms2 in + incr fresh_count; + measure, MVar ("MV"^string_of_int !fresh_count)::gens + | _::_, [] | [], _::_ -> raise + (Lexer.Parsing_error + ("GDL.generalize: arity mismatch at function "^pf)) in + let measure, gens = loop "impossible" [term1] [term2] in + measure, !fresh_count, List.hd gens + +(* 3c2 *) +let abstract_consts fresh_count term = + let fresh_count = ref fresh_count in + let rec loop = function + | Const _ -> incr fresh_count; MVar ("MV"^string_of_int !fresh_count) + | Func (f,args) -> Func (f, List.map loop args) + | term -> term in + loop term + +let rec subst sb = function + | Var y as t -> + (try List.assoc y sb with Not_found -> t) + | MVar y as t -> + (try List.assoc y sb with Not_found -> t) + | Const _ as t -> t + | Func (f, args) -> + Func (f, List.map (subst sb) args) + +let unify_rels (rel1, args1) (rel2, args2) = + if rel1 = rel2 then unify [] args1 args2 + else raise Not_found + +let subst_rel sb (rel, args) = rel, List.map (subst sb) args +let subst_rels sb body = List.map (subst_rel sb) body +let compose_sb sb1 sb = Aux.map_prepend sb1 (fun (x,t)->x, subst sb1 t) sb + +let fact_str (rel, args) = + "("^rel^" "^String.concat " " (List.map term_str args) ^")" + +let tuples_str tups = + let tup_str tup = + "("^String.concat " " (List.map term_str tup) ^")" in + String.concat " " (List.map tup_str tups) + +let facts_str facts = + String.concat " " (List.map fact_str facts) + +let def_str (rel, branches) = + let neg_facts_str negs = + String.concat " " + (List.map (fun d -> "(not (and "^facts_str d^"))") negs) in + String.concat "\n" (List.map (fun (args, body, neg_body) -> + "("^ fact_str (rel, args) ^ " <= " ^ facts_str body ^ + " " ^ neg_facts_str neg_body ^ ")" + ) branches) + +let sb_str sb = + String.concat ", " (List.map (fun (v,t)->v^":="^term_str t) sb) + +(* 1b *) + +(* TODO: optimize by using rel-indexing (also in [aggregate_playout]). + TODO: optimize by using constant-time append data structure. *) +let saturate base rules = + + let instantiate_one tot_base cur_base irules = + Aux.concat_map (function + | head, [], neg_body -> + if List.mem head tot_base then [] + else if List.exists (fun (rel,args as neg_atom) -> + rel = "distinct" && Aux.not_unique args || + List.mem neg_atom tot_base) neg_body then [] + else [Aux.Left head] + | head, cond1::body, neg_body -> + Aux.map_try (fun fact -> + (* {{{ log entry *) + if !debug_level > 4 then ( + Printf.printf "instantiate_one: trying to unify %s and %s\n%!" + (fact_str fact) (fact_str cond1) + ); + (* }}} *) + let sb = unify_rels fact cond1 in + (* {{{ log entry *) + if !debug_level > 4 then ( + Printf.printf "instantiate_one: succeeded with %s\n%!" + (sb_str sb) + ); + (* }}} *) + let irule = + subst_rel sb head, + subst_rels sb body, subst_rels sb neg_body in + Aux.Right irule + ) cur_base) irules in + + let rec inst_stratum old_base old_irules cur_base cur_irules = + (* {{{ log entry *) + if !debug_level > 3 then ( + Printf.printf "inst_stratum: old_base = %s; cur_base = %s\n%!" + (facts_str old_base) (facts_str cur_base); + Printf.printf + "inst_stratum: #old_irules = %d, #cur_irules = %d\n%!" + (List.length old_irules) (List.length cur_irules) + ); + (* }}} *) + let base = Aux.unique_sorted (cur_base @ old_base) + and irules = Aux.unique_sorted (cur_irules @ old_irules) in + let new_base1, new_irules1 = + Aux.partition_choice (instantiate_one base cur_base cur_irules) in + (* {{{ log entry *) + if !debug_level > 3 then ( + Printf.printf "inst_stratum: cur-cur = %s\n%!" + (facts_str new_base1) + ); + (* }}} *) + let new_base2, new_irules2 = + Aux.partition_choice (instantiate_one base cur_base old_irules) in + (* {{{ log entry *) + if !debug_level > 3 then ( + Printf.printf "inst_stratum: cur-old = %s\n%!" + (facts_str new_base2) + ); + (* }}} *) + let new_base3, new_irules3 = + Aux.partition_choice (instantiate_one base old_base cur_irules) in + (* {{{ log entry *) + if !debug_level > 3 then ( + Printf.printf "inst_stratum: old-cur = %s\n%!" + (facts_str new_base3) + ); + (* }}} *) + let new_base = Aux.unique_sorted (new_base1 @ new_base2 @ new_base3) + and new_irules = Aux.unique_sorted + (new_irules1 @ new_irules2 @ new_irules3) in + let new_base = + List.filter (fun f->not (List.mem f base)) new_base in + let new_irules = + List.filter (fun f->not (List.mem f irules)) new_irules in + if new_base = [] && new_irules = [] + then base + else inst_stratum base irules new_base new_irules in + + let rec instantiate base = function + | [] -> base + | stratum::strata -> + instantiate (inst_stratum [] [] base stratum) strata in + + instantiate base + (List.map rules_of_defs (stratify [] (defs_of_rules rules))) + + let playing_as = ref (Const "uninitialized") let game_description = ref [] -let player_name_terms = ref [| |] +let player_terms = ref [| |] let state_of_file s = Printf.printf "GDL: Loading file %s...\n%!" s; @@ -51,99 +738,603 @@ Printf.printf "GDL: File %s loaded.\n%!" s; res -let initialize_game_gomoku state player game_descr startcl = - state := state_of_file "./examples/Gomoku.toss"; - playing_as := player; - game_description := game_descr; - player_name_terms := [|Const "X"; Const "O"|]; - let effort, horizon, heur_adv_ratio = - 2, 100, 4.0 in - effort, horizon, heur_adv_ratio +(* 6 *) -let initialize_game_breakthrough state player game_descr startcl = - state := state_of_file "./examples/Breakthrough.toss"; +(* TODO: do proper elegant renaming... *) +let freshen_def_branches = + let fresh_count = ref 0 in + let map_branch (args, body, neg_body) = + incr fresh_count; + let rec map_vnames = function + | Var x -> Var (x^string_of_int !fresh_count) + | MVar x -> MVar (x^string_of_int !fresh_count) + | Const _ as t -> t + | Func (f, args) -> + Func (f, List.map map_vnames args) in + let map_rel (rel, args) = + rel, List.map map_vnames args in + List.map map_vnames args, + List.map map_rel body, + List.map (List.map map_rel) neg_body in + List.map map_branch + +(* assumption: [defs] bodies are already clean of defined relations *) +let subst_def_branch (defs : exp_def list) + (head, body, neg_body : exp_def_branch) : exp_def_branch list = + (* 6a *) + let sols = + List.fold_left (fun sols (rel, args as atom) -> + (let try def = + freshen_def_branches (List.assoc rel defs) in + Aux.concat_map (fun (pos_sol, neg_sol, sb) -> + let args = List.map (subst sb) args in + Aux.map_some (fun (dparams, dbody, dneg_body) -> + try + let sb1 = unify [] dparams args in + Some ( + subst_rels sb1 (dbody @ pos_sol), + List.map (subst_rels sb1) (dneg_body @ neg_sol), + compose_sb sb1 sb) + with Not_found -> None + ) def + ) sols + with Not_found -> + List.map (fun (pos_sol, neg_sol, sb) -> + subst_rel sb atom::pos_sol, neg_sol, sb) sols)) + ([[],[],[]]) body in + (* 6b *) + let sols = + List.fold_left (fun sols -> function [rel, args as atom] -> + (let try def = + freshen_def_branches (List.assoc rel defs) in + List.map (fun (pos_sol, neg_sol, sb) -> + let args = List.map (subst sb) args in + let more_neg = + Aux.map_some (fun (dparams, dbody, dneg_body) -> + if dneg_body <> [] then + failwith + ("GDL.subst_def_branch: negation in negatively used" ^ + " defined rels not supported yet, relation "^rel); + try + let sb1 = unify [] dparams args in + Some (subst_rels sb1 dbody) + with Not_found -> None + ) def in + pos_sol, more_neg @ neg_sol, sb + ) sols + with Not_found -> + List.map (fun (pos_sol, neg_sol, sb) -> + pos_sol, [subst_rel sb atom]::neg_sol, sb) sols) + | _ -> failwith + "GDL.subst_def_branch: unimplemented, see (6b1) of spec") + sols neg_body in + Aux.map_some (fun (pos_sol, neg_sol, sb) -> + if List.mem [] neg_sol then None + else Some (List.map (subst sb) head, pos_sol, neg_sol)) sols + +(* Stratify and expand all relations in the given set. *) +let expand_def_rules ?(more_defs=[]) rules = + let rec loop base = function + | [] -> base + | stratum::strata -> + let step = List.map (fun (rel, branches) -> + rel, Aux.concat_map + (subst_def_branch (more_defs@base)) branches) stratum in + loop (base @ step) strata in + match stratify ~def:true [] (defs_of_rules rules) with + | [] -> [] + | [no_defined_rels] -> + if more_defs = [] then no_defined_rels + else List.map (fun (rel, branches) -> + rel, Aux.concat_map (subst_def_branch more_defs) branches) + no_defined_rels + | def_base::def_strata -> loop def_base def_strata + + +(* As [subst_def_branch], but specifically for "legal" definition and + result structured by "legal" definition branches. *) + (* +let subst_legal_rule (legal_defs : exp_def_branch list) + (head, body, neg_body : exp_def_branch) : exp_def_branch list = + (* 6a *) + let sols = + List.fold_left (fun sols (rel, args as atom) -> + (let try def = + freshen_def_branches (List.assoc rel defs) in + Aux.concat_map (fun (pos_sol, neg_sol, sb) -> + let args = List.map (subst sb) args in + Aux.map_some (fun (dparams, dbody, dneg_body) -> + try + let sb1 = unify [] dparams args in + Some ( + subst_rels sb1 (dbody @ pos_sol), + List.map (subst_rels sb1) (dneg_body @ neg_sol), + compose_sb sb1 sb) + with Not_found -> None + ) def + ) sols + with Not_found -> + List.map (fun (pos_sol, neg_sol, sb) -> + subst_rel sb atom::pos_sol, neg_sol, sb) sols)) + ([[],[],[]]) body in + (* 6b *) + let sols = + List.fold_left (fun sols -> function [rel, args as atom] -> + (let try def = + freshen_def_branches (List.assoc rel defs) in + List.map (fun (pos_sol, neg_sol, sb) -> + let args = List.map (subst sb) args in + let more_neg = + Aux.map_some (fun (dparams, dbody, dneg_body) -> + if dneg_body <> [] then + failwith + ("GDL.subst_def_branch: negation in negatively used" ^ + " defined rels not supported yet, relation "^rel); + try + let sb1 = unify [] dparams args in + Some (subst_rels sb1 dbody) + with Not_found -> None + ) def in + pos_sol, more_neg @ neg_sol, sb + ) sols + with Not_found -> + List.map (fun (pos_sol, neg_sol, sb) -> + pos_sol, [subst_rel sb atom]::neg_sol, sb) sols) + | _ -> failwith + "GDL.subst_def_branch: unimplemented, see (6b1) of spec") + sols neg_body in + Aux.map_some (fun (pos_sol, neg_sol, sb) -> + if List.mem [] neg_sol then None + else Some (List.map (subst sb) head, pos_sol, neg_sol)) sols + *) +(* 1 *) + +(* Collect the aggregate playout, but also the actions available in + the state. *) +let aggregate_ply players static current rules = + let base = + Aux.map_prepend static (fun term -> "true", [term]) current in + let base = saturate (base @ static) rules in + let does = Aux.map_some (fun (rel, args) -> + if rel = "legal" then Some ("does", args) else None) base in + if (* no move *) + Aux.array_existsi (fun _ player -> + List.for_all (function _, (actor::_) -> player <> actor | _ -> true) + does) players + then raise Not_found + else + let step = saturate (does @ base) rules in + let step = Aux.map_some (function ("next", [arg]) -> Some arg + | _ -> None) step in + if !aggregate_fixpoint && (* fixpoint reached *) + List.for_all (function + | Func (_,[arg]) when + Aux.array_existsi (fun _ player -> arg=player) players -> true + | term -> List.mem term current + ) step + then raise Not_found + else + List.map snd does, step + +(* Besides the aggregate playout, also return the separation of rules + into static and dynamic. Note that the list of playout states is + one longer than that of playout actions. *) +let aggregate_playout players horizon rules = + (* separate and precompute the static part *) + let rec separate static_rels state_rels = + let static, more_state = + List.partition (fun rel -> + List.for_all (fun ((rule,_), body, neg_body) -> + rule <> rel || List.for_all (fun srel -> + not (List.mem_assoc srel (neg_body @ body))) state_rels) + rules) static_rels in + if more_state = [] then static_rels, state_rels + else separate static (more_state @ state_rels) in + let static_rels, state_rels = + separate (List.map (fun ((r,_),_,_)->r) rules) + ["init"; "does"; "true"; "next"; "terminal"; "goal"] in + let static_rules, dynamic_rules = List.partition + (fun ((rel,_),_,_) -> List.mem rel static_rels) rules in + let static_base = saturate [] static_rules in + let state_rules = + (* 1a *) + if !aggregate_drop_negative then + List.map (function + | ("legal", _ as head), body, _ -> head, body, [] + | ("does", _ as head), body, _ -> head, body, [] + | rule -> rule) dynamic_rules + else dynamic_rules in + let rec loop actions_accu state_accu step state = + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "aggregate_playout: step %d...\n%!" step + ); + (* }}} *) + (let try actions, next = + aggregate_ply players static_base state state_rules in + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "aggregate_playout: state %s\n%!" + (String.concat " " (List.map term_str next)) + ); + (* }}} *) + if step < horizon then + loop (actions::actions_accu) (state::state_accu) (step+1) next + else + List.rev (actions::actions_accu), + List.rev (next::state::state_accu) + with Not_found -> + List.rev actions_accu, List.rev (state::state_accu)) in + (* FIXME: this is identity, right? remove *) + let init_base = saturate static_base state_rules in + let init_state = + Aux.map_some (function ("init", [arg]) -> Some arg + | _ -> None) init_base in + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "aggregate_playout: init %s\n%!" + (String.concat " " (List.map term_str init_state)) + ); + (* }}} *) + static_rules, dynamic_rules, static_base, loop [] [] 0 init_state + + +let find_cycle cands = + let rec loop cycle trav pref rem path = + if cycle = [] then + let ini = [List.hd path] in + loop ini ini ini [] (List.tl path) + else match path, rem with + | _, [] -> loop cycle trav [] cycle path + | [], _ -> cycle (* consumed the whole path *) + | x::tail, y::rem when x=y || x = None-> + (* either elements agree or indifferent path element *) + loop cycle (x::trav) (y::pref) rem tail + | x::tail, None::rem -> + (* instantiating undecided cycle element *) + loop (List.rev pref @ [x] @ rem) (x::trav) (x::pref) rem tail + | x::tail, _::_ -> + (* mismatch: grow the cycle to current point *) + let trav = x::trav in + let cycle = List.rev trav in + loop cycle trav [] cycle tail in + loop [] [] [] [] cands + + +let translate_game game_descr = + let player_terms = + Array.of_list + (Aux.map_some (function Role p -> Some p | _ -> None) game_descr) in + let rules = Aux.concat_map rules_of_entry game_descr in + let static_rules, dynamic_rules, static_base, (agg_actions, agg_states) = + aggregate_playout player_terms 30 rules in + (* (8) -- drop zero goal branches, "first round" *) + let dynamic_rules = List.filter + (function ("goal", [_; Const "0"]), _, _ -> false | _ -> true) + dynamic_rules in + let element_terms : term list = + List.fold_left (fun acc st -> Aux.unique_sorted (st @ acc)) [] + agg_states in + let noop_cands = List.map (fun actions -> + let actions = Aux.map_reduce + (function [player; action] -> player, action + | _ -> assert false) (fun y x->x::y) [] actions in + (* 2a *) + List.map (function + | player, [Const _ as noop] -> player, Some noop + | player, _ -> player, None) actions) agg_actions in + let control_cands = List.map (fun noop_cands -> + List.fold_left (fun accu -> function + | player, None -> + if accu = None then Some player + else raise + (Lexer.Parsing_error + ("GDL.initialize_game: branching arena graphs"^ + " or simultaneous moves not supported yet")) + | _, Some _ -> accu) None noop_cands) noop_cands in + (* 2b *) + let cycle = find_cycle control_cands in + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "translate_game: location players %s\n%!" + (String.concat " " + (List.map (function Some t->term_str t | None->"None") cycle)) + ); + (* }}} *) + (* 6 *) + let static_rules, exp_static_rules = + List.partition (fun ((rel,args), _, _) -> + List.length args <= !expand_arity_above || + List.exists (function ((r,_),[],[]) when rel=r-> true + | _ -> false) static_rules + ) static_rules in + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "translate_game: expanded static rules: %s\n%!" + (String.concat ", " (List.map (fun ((r,_),_,_)->r) exp_static_rules)); + ); + (* }}} *) + let static_exp_defs = expand_def_rules exp_static_rules in + let static_rules = + if static_exp_defs = [] then static_rules + else rules_of_defs + (List.map (fun (rel,branches) -> + rel, Aux.concat_map (subst_def_branch static_exp_defs) branches) + (defs_of_rules static_rules)) in + let exp_defs = + expand_def_rules ~more_defs:static_exp_defs dynamic_rules in + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "translate_game: All expanded dynamic rules:\n%s\n%!" + (String.concat "\n" (List.map def_str exp_defs)) + ); + (* }}} *) + (* 3 *) + let legal_rules = List.assoc "legal" exp_defs in + let next_rules = List.assoc "next" exp_defs in + (* 3b *) + let exp_next = + Aux.concat_map (subst_def_branch ["does", legal_rules]) next_rules in + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "translate_game: \"next\" rules with \"does\"<-\"legal\":\n%s\n%!" + (def_str ("next", exp_next)) + ); + (* }}} *) + (* 3c *) + let masks = List.map (function + | [next_arg], body, neg_body -> + let collect = Aux.map_some + (function "true", [arg] -> Some arg + | "true", _ -> raise + (Lexer.Parsing_error + ("GDL.initialize_game: invalid arity of \"true\" atom")) + | _ -> None) in + let pos_cands = collect body in + let neg_cands = Aux.concat_map collect neg_body in + let pos_gens = List.map (generalize next_arg) pos_cands in + let neg_gens = List.map (generalize next_arg) neg_cands in + (* using the fact that Pervasives.compare is lexicographic *) + let pos_gen = List.fold_left max ((-1,0),0,Const "") pos_gens in + let neg_gen = List.fold_left max ((-1,0),0,Const "") neg_gens in + let (_, fresh_count, mask as gen) = max pos_gen neg_gen in + if gen == pos_gen then mask + else abstract_consts fresh_count mask + | _ -> raise + (Lexer.Parsing_error + ("GDL.initialize_game: invalid arity of \"next\" atom"))) + exp_next in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf "translate_game: Generalized element terms (mask candidates):\n%s\n%!" + (String.concat " " (List.map term_str masks)) + ); + (* }}} *) + let cmp_masks t1 t2 = + Printf.printf "cmp_masks: %s <= %s .. " (term_str t1) (term_str t2); + try ignore (match_meta [] [] [t1] [t2]); Printf.printf "true\n%!"; true + with Not_found -> Printf.printf "false\n%!"; false in + let masks = Aux.maximal cmp_masks masks in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf "translate_game: Masks:\n%s\n%!" + (String.concat " " (List.map term_str masks)) + ); + (* }}} *) + (* 3e *) + let elements = List.fold_left (fun elements term -> + let mask, sb, m_sb = + match + Aux.map_try (fun mask -> + mask, match_meta [] [] [term] [mask]) masks + with [mask, (sb, m_sb)] -> mask, sb, m_sb + | _ -> assert false in (* masks are minimal *) + let sbs, elements = + try Aux.pop_assoc mask elements + with Not_found -> [], elements in + (mask, if List.mem sb sbs then sbs else sb::sbs)::elements + ) [] element_terms in + let struc = Structure.empty_structure () in + let struc, elements = + List.fold_left (fun (struc, elements) (mask, sbs) -> + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf "mask-elements:"; + ); + (* }}} *) + let struc, m_elements = + List.fold_left (fun (struc, m_elements) sb -> + let e_term = subst sb mask in + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf ", %s%!" (term_to_name e_term) + ); + (* }}} *) + let struc, elem = + Structure.add_new_elem struc ~name:(term_to_name e_term) () in + struc, (sb, elem)::m_elements + ) (struc, []) sbs in + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf "\n%!"; + ); + (* }}} *) + struc, (mask, m_elements)::elements + ) (struc, []) elements in + (* 4 *) + (* currently, position paths are approximated by variables + (non-variable positions are ignored) *) + let mask_paths = Aux.concat_map (function _, [] -> assert false + | mask, (sb,_)::_ -> List.map (fun (v,_)->mask, v) sb) elements in + (* 4a *) + (* TODO: move generation of static rels graphs to the end and + filter to only generate used relations *) + let static_rels = + Aux.unique_sorted + (List.map (fun ((rname,args),_,_) -> + rname, List.map (fun _ -> ()) args) static_rules) in + let static_rels = + List.map (fun (rel,args) -> + rel, + Aux.all_tuples_for args mask_paths) static_rels in + let static_base = + Aux.map_reduce (fun x->x) (fun x y->y::x) [] static_base in + (* TODO: optimize by indexing elements by path position + terms (currently, substitution values) *) + let struc = List.fold_left (fun struc (brel, path_tups) -> + let brel_tups = List.assoc brel static_base in + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "Translating static relation %s with %d tuples:\n%s\n%!" + brel (List.length brel_tups) (tuples_str brel_tups); + ); + (* }}} *) + List.fold_left (fun struc ptup -> + let rname = brel ^ "__" ^ String.concat "__" + (List.map (fun (mask,v)-> + term_to_name mask ^ "_" ^ v) ptup) in + let struc = + Structure.add_rel_name rname (List.length ptup) struc in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf "static-rel: %s, of... %!" rname; + ); + (* }}} *) + let elem_sets = + List.map (fun (mask,v)-> + List.map (fun (sb,elem)-> + try List.assoc v sb, elem + with Not_found -> assert false) + (List.assoc mask elements)) ptup in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf "%s ... %!" (String.concat "x" ( + List.map (fun x-> string_of_int (List.length x)) elem_sets)); + ); + (* }}} *) + let elem_tups = + Aux.concat_map (fun ttup -> + let elem_sets = List.map2 (fun term elems -> + Aux.map_some (fun (tcand, e) -> + if tcand=term then Some e else None) elems + ) ttup elem_sets in + List.map Array.of_list (Aux.product elem_sets) + ) brel_tups in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf "%d tuples, adding to struc...%!" (List.length elem_tups); + ); + (* }}} *) + let res = Structure.unsafe_add_rels struc rname elem_tups in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf " done\n%!"; + ); + (* }}} *) + res + ) struc path_tups) struc static_rels in + (* 4b *) + let struc = List.fold_left (fun struc (mask,v) -> + let rname = "EQ___" ^ term_to_name mask ^ "_" ^ v in + let struc = + Structure.add_rel_name rname 2 struc in + let elems = List.assoc mask elements in + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "Adding static EQ relation %s over %d elements.\n%!" + rname (List.length elems); + ); + (* }}} *) + let elem_tups = + List.fold_left (fun tups (sb1, e1) -> + List.fold_left (fun tups (sb2, e2) -> + try + if List.assoc v sb1 = List.assoc v sb2 + then [|e1; e2|]::[|e2; e1|]::tups + else tups + with Not_found -> assert false + ) tups elems + ) [] elems in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf "%d tuples, adding to struc...%!" (List.length elem_tups); + ); + (* }}} *) + let res = Structure.unsafe_add_rels struc rname elem_tups in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf " done\n%!"; + ); + (* }}} *) + res + ) struc mask_paths in + (* 4c: TODO -- see laziness TODO 4 *) + + (* 5: TODO *) + + (* 7a *) + let legal_rules = + Aux.concat_map (function [Const _; _], _, _ as lrule -> [lrule] + | [Var v; lterm], body, neg_body -> + Array.to_list + (Array.map (fun player -> [player; lterm], body, neg_body) + player_terms) + | [Func _; lterm], _, _ -> + (* TODO: easy to fix *) + failwith "GDL.translate_game: bigger player terms not handled yet" + | _ -> assert false) legal_rules in + (* indexed by players, then "legal" branches, then by MGUs for + unifier equivalence classes *) + (* + let player_next = + Aux.map_reduce (fun ()) in + *) + struc + +(* + let paths = collect_paths element_terms in + let static_facts = + Array.of_list + (Aux.map_some (function Atomic p -> Some p | _ -> None) game_descr) in + let element_names = List.map term_to_name element_terms in + + let struc = List.fold_left (fun acc name -> + fst (Structure.add_new_elem acc ~name ())) + Structure.empty_structure element_names in + *) + +let initialize_game state player game_descr startcl = playing_as := player; - game_description := game_descr; - player_name_terms := [|Const "WHITE"; Const "BLACK"|]; - let effort, horizon, heur_adv_ratio = - 3, 100, 2.0 in - effort, horizon, heur_adv_ratio + let struc = translate_game game_descr in + ignore struc; + (* state := Arena.process_definition ~extend_state:(!state) defs; *) + 2, 100, 2.0 -let initialize_game = - initialize_game_breakthrough - -let translate_last_action_gomoku actions = - let number_of_letter c = - string_of_int ((Char.code (Char.lowercase c)) - 96) in + +let translate_last_action actions = match actions with | [] -> (* start of game -- Server will handle this answer as NOOP *) "", [] | [Func ("MARK", [Const col; Const row]); Const "NOOP"] -> - "Cross", ["a1", ((String.lowercase col) ^ (number_of_letter row.[0]))] + "Cross", ["... [truncated message content] |
From: <luk...@us...> - 2011-01-09 23:36:47
|
Revision: 1278 http://toss.svn.sourceforge.net/toss/?rev=1278&view=rev Author: lukaszkaiser Date: 2011-01-09 23:36:40 +0000 (Sun, 09 Jan 2011) Log Message: ----------- Correcting examples and webclient. Modified Paths: -------------- trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/MakeDB.py trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/contact.html trunk/Toss/WebClient/favicon.ico trunk/Toss/WebClient/index.html trunk/Toss/WebClient/profile.html trunk/Toss/WebClient/register.html trunk/Toss/examples/Checkers.toss trunk/Toss/examples/Tic-Tac-Toe.toss trunk/Toss/www/links.php Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-01-09 20:58:08 UTC (rev 1277) +++ trunk/Toss/WebClient/Connect.js 2011-01-09 23:36:40 UTC (rev 1278) @@ -133,10 +133,12 @@ var all_moves = convert_python_list (';', MOVES_STR); var elem_moves = [] for (i = 0; i < all_moves.length; i++) { - if (all_moves[i].indexOf(elem) >= 0) { + 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) >= 0) { + } else if (all_moves[i].indexOf(other, br) > br) { elem_moves.push(all_moves[i]) } } Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-01-09 20:58:08 UTC (rev 1277) +++ trunk/Toss/WebClient/Main.js 2011-01-09 23:36:40 UTC (rev 1278) @@ -368,13 +368,21 @@ } function suggest_move () { + document.getElementById("working").innerHTML = "Calculating move..."; + document.getElementById("working").style.display = "block"; var m = srv("SUGGEST", 'c, '+ play_py_id (CUR_PLAY_I)); + document.getElementById("working").style.display = "none"; + document.getElementById("working").innerHTML = "Working..."; if (m != "") { show_move (m); } return (m); } function suggest_move_better () { + document.getElementById("working").innerHTML = "Calculating move..."; + document.getElementById("working").style.display = "block"; var m = srv("SUGGESTX", 'c, '+ play_py_id (CUR_PLAY_I)); + document.getElementById("working").style.display = "none"; + document.getElementById("working").innerHTML = "Working..."; if (m != "") { show_move (m); } return (m); } Modified: trunk/Toss/WebClient/MakeDB.py =================================================================== --- trunk/Toss/WebClient/MakeDB.py 2011-01-09 20:58:08 UTC (rev 1277) +++ trunk/Toss/WebClient/MakeDB.py 2011-01-09 23:36:40 UTC (rev 1278) @@ -45,7 +45,24 @@ os.chmod (db_file, 0777) +def reload_games (db_file, games_path, games): + conn = sqlite3.connect(db_file) + conn.execute ("delete from games"); + print "Deleted old games"; + for g in games: + f = open(games_path + "/" + g + ".toss") + toss = f.read() + f.close() + conn.execute ("insert into games(game, toss) values (?, ?)", (g, toss)) + print ("Reloading games: added " + g) + conn.commit () + if __name__ == "__main__": - print "Creating empty Toss DB" - create_db (DB_FILE, GAMES_PATH, GAMES) - print "Created tossdb.sqlite" + if os.path.exists (DB_FILE): + print ("Reloading games into Toss DB (" + DB_FILE + ")") + reload_games (DB_FILE, GAMES_PATH, GAMES) + print "Games reloaded" + else: + print ("Creating empty Toss DB (" + DB_FILE + ")") + create_db (DB_FILE, GAMES_PATH, GAMES) + print "Created tossdb.sqlite" Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-01-09 20:58:08 UTC (rev 1277) +++ trunk/Toss/WebClient/Style.css 2011-01-09 23:36:40 UTC (rev 1278) @@ -15,7 +15,7 @@ padding: 0px; margin: 0px; text-align: center; - background-color: #b5bf8f; + background-color: #f7ffd8; font-family: Verdana, 'TeXGyreHerosRegular', sans; } @@ -43,7 +43,7 @@ float: right; } -.obt { +.obt, .boldobt { text-align: left; border-color: #260314; border-radius: 4px; @@ -60,6 +60,16 @@ text-decoration: underline; } +.boldobt { + font-weight: bold; + font-size: 1em; +} + +.boldobt:hover { + cursor: pointer; + text-decoration: underline; +} + .dbt { border-color: #fff1d4; border-radius: 4px; @@ -163,7 +173,7 @@ #logoutbt:hover { cursor: pointer; - color: #b5bf8f; + color: #f7ffd8; } #login1 { @@ -191,6 +201,11 @@ padding-left: 0.25em; } +#logo img { + height: 1.5em; + width: 2.5em; +} + #top a, #logo a:link, #logo a:active, #logo a:visited { color: #fff1d4; background-color: transparent; @@ -198,7 +213,7 @@ } #top a:hover { - color: #b5bf8f; + color: #f7ffd8; } .logo-in { @@ -323,12 +338,22 @@ } #topbar a:hover { - color: #b5bf8f; + color: #f7ffd8; } /* Content */ +.mail { + color: #260314; + text-decoration: underline; +} + +.mail:hover { + cursor: pointer; + text-decoration: none; +} + .game_list { font-weight: bold; } @@ -505,7 +530,6 @@ font-weight: bold; color: #fff1d4; background-color: #400827; - display: none; padding: 1em; } @@ -585,9 +609,9 @@ #svg { min-width: 10em; max-width: 120em; - width: 65%; + width: 75%; min-height: 10em; - max-height: 120em; + max-height: 35em; height: 75%; /* border: 1px solid #260314; */ } @@ -611,7 +635,7 @@ } .model-elem-highlight { - fill: #b5bf8f; + fill: #f7ffd8; stroke: #400827; stroke-width: 3px; } @@ -651,6 +675,18 @@ stroke-width: 3px; } +.Game-Checkers .model-pred-B { + fill: #fff1d4; + stroke: #260314; + stroke-width: 3px; +} + +.Game-Checkers .model-pred-W { + fill: #400827; + stroke: #260314; + stroke-width: 3px; +} + .model-edge-E { fill: #260314; stroke: #260314; Modified: trunk/Toss/WebClient/contact.html =================================================================== --- trunk/Toss/WebClient/contact.html 2011-01-09 20:58:08 UTC (rev 1277) +++ trunk/Toss/WebClient/contact.html 2011-01-09 23:36:40 UTC (rev 1278) @@ -4,32 +4,51 @@ <meta http-equiv="Content-Type" content="text/xhtml+xml; charset=UTF-8" /> <title>tPlay — Contact</title> <meta http-equiv="X-UA-Compatible" content="chrome=1"> - <link rel="icon" type="image/vnd.microsoft.icon" href="/favicon.ico" /> + <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" /> <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> + <script type="text/javascript"> + function begin_mailto (name, domain, title) { + var address = name + '@' + domain; + if(title) { + document.write("<a class='mail' href='mailto:" + address + "'>" + "<span>"); + } else { + document.write("<a class='mail' href='mailto:" + address + "'>" + + address + "<span style='display: none;'>"); + } + } + function end_mailto() { + document.write("</span></a>"); + } + </script> </head> <body> + +<div id="main"> + <div id="top"> -<div id="logo"><a href="index.html">tPlay</a></div> +<div id="logo"><a href="index.html"><img src="toss.svg" alt="tPlay" /></a></div> </div> -<div id="main"> - <div id="register-content"> <h2>Contact tPlay</h2> -Just write us an email! +Just write an email to +<script type="text/javascript">begin_mailto("tossplay", "gmail.com");</script> +tossplay [AT] gmail [DOT] com +<script type="text/javascript">end_mailto();</script> </div> -</div> - <div id="bottom"> <a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a> <a href="contact.html" id="contact">Contact and Info</a> </div> +</div> + + </body> </html> Modified: trunk/Toss/WebClient/favicon.ico =================================================================== (Binary files differ) Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-01-09 20:58:08 UTC (rev 1277) +++ trunk/Toss/WebClient/index.html 2011-01-09 23:36:40 UTC (rev 1278) @@ -4,7 +4,7 @@ <meta http-equiv="Content-Type" content="text/xhtml+xml; charset=UTF-8" /> <title>tPlay</title> <meta http-equiv="X-UA-Compatible" content="chrome=1"> - <link rel="icon" type="image/vnd.microsoft.icon" href="/favicon.ico" /> + <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" /> <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> <script type="text/javascript" src="crypto-sha256.js"> </script> @@ -19,7 +19,7 @@ <div id="main"> <div id="top"> -<div id="logo"><a href="index.html">tPlay</a></div> +<div id="logo"><a href="index.html"><img src="toss.svg" alt="tPlay" /></a></div> <div id="topbar"> <span id="topuser"></span> <form id="loginform" style="display: inline;"> @@ -96,38 +96,40 @@ <div id="plays"> <p class="game-par"> - <button class="bt" onclick="new_play ('Breakthrough')">New Game</button> - <a href="http://en.wikipedia.org/wiki/Breakthrough_(board_game)" - class="game_list">Breakthrough</a> + <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"></ul> <p class="game-par"> - <button class="bt" onclick="new_play ('Checkers')">New Game</button> - <a class="game_list" - href="http://en.wikipedia.org/wiki/English_draughts">Checkers</a> + <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"></ul> <p class="game-par"> - <button class="bt" onclick="new_play ('Chess')">New Game</button> - <a class="game_list" href="http://en.wikipedia.org/wiki/Chess">Chess</a> + <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"></ul> <p class="game-par"> - <button class="bt" onclick="new_play ('Entanglement')">New Game</button> - <a href="http://en.wikipedia.org/wiki/Entanglement_(graph_measure)" - class="game_list">Entanglement</a> + <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"></ul> <p class="game-par"> - <button class="bt" onclick="new_play ('Gomoku')">New Game</button> - <a href="http://en.wikipedia.org/wiki/Gomoku" - class="game_list">Gomoku</a> + <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"></ul> <p class="game-par"> - <button class="bt" onclick="new_play ('Tic-Tac-Toe')">New Game</button> - <a href="http://en.wikipedia.org/wiki/Tic-tac-toe" - class="game_list">Tic-Tac-Toe</a> + <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"></ul> </div> Modified: trunk/Toss/WebClient/profile.html =================================================================== --- trunk/Toss/WebClient/profile.html 2011-01-09 20:58:08 UTC (rev 1277) +++ trunk/Toss/WebClient/profile.html 2011-01-09 23:36:40 UTC (rev 1278) @@ -4,7 +4,7 @@ <meta http-equiv="Content-Type" content="text/xhtml+xml; charset=UTF-8" /> <title>tPlay — Profile</title> <meta http-equiv="X-UA-Compatible" content="chrome=1"> - <link rel="icon" type="image/vnd.microsoft.icon" href="/favicon.ico" /> + <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" /> <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> <script type="text/javascript" src="crypto-sha256.js"> </script> @@ -16,7 +16,7 @@ <body onload="startup_profile()"> <div id="top"> -<div id="logo"><a href="index.html">tPlay</a></div> +<div id="logo"><a href="index.html"><img src="toss.svg" alt="tPlay" /></a></div> <div id="topbar"> <span id="topuser"></span> <form id="loginform" style="display: inline;"> Modified: trunk/Toss/WebClient/register.html =================================================================== --- trunk/Toss/WebClient/register.html 2011-01-09 20:58:08 UTC (rev 1277) +++ trunk/Toss/WebClient/register.html 2011-01-09 23:36:40 UTC (rev 1278) @@ -4,7 +4,7 @@ <meta http-equiv="Content-Type" content="text/xhtml+xml; charset=UTF-8" /> <title>tPlay — Registration</title> <meta http-equiv="X-UA-Compatible" content="chrome=1"> - <link rel="icon" type="image/vnd.microsoft.icon" href="/favicon.ico" /> + <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" /> <link href="fontstyle.css" media="screen" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="Style.css" media="screen" title="Default"/> <script type="text/javascript" src="crypto-sha256.js"> </script> @@ -14,7 +14,7 @@ <body> <div id="top"> -<div id="logo"><a href="index.html">tPlay</a></div> +<div id="logo"><a href="index.html"><img src="toss.svg" alt="tPlay" /></a></div> </div> <div id="main"> Modified: trunk/Toss/examples/Checkers.toss =================================================================== --- trunk/Toss/examples/Checkers.toss 2011-01-09 20:58:08 UTC (rev 1277) +++ trunk/Toss/examples/Checkers.toss 2011-01-09 23:36:40 UTC (rev 1278) @@ -18,54 +18,56 @@ REL BeatsW (x, y) = ex z (b(z) and not b(y) and not w(y) and DiagW2 (x, z, y)) REL BeatsWX (x, y) = ex z (b(z) and not b(y) and not w(y) and Diag2 (x, z, y)) REL BeatsB (x, y) = ex z (w(z) and not b(y) and not w(y) and DiagB2 (x, z, y)) -REL BeatsBX (x, y) = ex z (w(z) and not b(y) and not w(y) and DiagB2 (x, z, y)) -RULE WhiteMove: +REL BeatsBX (x, y) = ex z (w(z) and not b(y) and not w(y) and Diag2 (x, z, y)) +REL BJumps() = ex x, y ((B(x) and BeatsB (x, y)) or (Bq(x) and BeatsBX (x, y))) +REL WJumps() = ex x, y ((W(x) and BeatsW (x, y)) or (Wq(x) and BeatsWX (x, y))) +RULE RedMove: [ a, b | W { a } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] -> [ a, b | W { b } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] emb w, b pre (not IsEight(b)) and (DiagWa(a, b) or DiagWb(a, b)) - and not ex x, y (W(x) and BeatsW (x, y)) -RULE BlackMove: + and not WJumps() +RULE WhiteMove: [ a, b | B { a } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] -> [ a, b | B { b } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] emb w, b pre (not IsFirst(b)) and (DiagBa(a, b) or DiagBb(a, b)) - and not ex x, y (B(x) and BeatsB (x, y)) -RULE WhitePromote: + and not BJumps() +RULE RedPromote: [ a, b | W { a } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] -> [ a, b | Wq { b } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] emb w, b pre (IsEight(b)) and (DiagWa(a, b) or DiagWb(a, b)) - and not ex x, y (W(x) and BeatsW (x, y)) -RULE BlackPromote: + and not WJumps() +RULE WhitePromote: [ a, b | B { a } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] -> [ a, b | Bq { b } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] emb w, b pre (IsFirst(b)) and (DiagBa(a, b) or DiagBb(a, b)) - and not ex x, y (B(x) and BeatsB(x, y)) -RULE WhiteQMove: + and not BJumps() +RULE RedQMove: [ a, b | Wq { a } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] -> [ a, b | Wq { b } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] - emb w, b pre AnyDiag (a, b) -RULE BlackQMove: + emb w, b pre AnyDiag (a, b) and not WJumps() +RULE WhiteQMove: [ a, b | Bq { a } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] -> [ a, b | Bq { b } | vx {a->0.,b->0.}; vy {a->0.,b->0.}; x {a->0.,b->10.}; y {a->0.,b->10.} ] - emb w, b pre AnyDiag (a, b) -RULE WhiteBeat: + emb w, b pre AnyDiag (a, b) and not BJumps() +RULE RedBeat: [ a, b, c | W { a }; b { b } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] @@ -74,8 +76,8 @@ vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] emb w, b pre DiagW2 (a, b, c) and not IsEight(c) - post not ex x, y (_new_W(x) and BeatsW (x, y)) -RULE BlackBeat: + post not ex x, y (_new_W(x) and BeatsWX (x, y)) +RULE WhiteBeat: [ a, b, c | B { a }; w { b } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] @@ -84,18 +86,37 @@ vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] emb w, b pre DiagB2 (a, b, c) and not IsFirst(c) - post not ex x, y (_new_B(x) and BeatsB (x, y)) -RULE WhiteBeatPromote: + post not ex x, y (_new_B(x) and BeatsBX (x, y)) +RULE RedBeatBoth: [ a, b, c | W { a }; b { b } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] -> + [ a, b, c | W { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre _new_W(a) and Diag2 (a, b, c) and not IsEight(c) + post not ex x, y (_new_W(x) and BeatsWX (x, y)) +RULE WhiteBeatBoth: + [ a, b, c | B { a }; w { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> + [ a, b, c | B { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre _new_B(a) and Diag2 (a, b, c) and not IsFirst(c) + post not ex x, y (_new_B(x) and BeatsBX (x, y)) +RULE RedBeatPromote: + [ a, b, c | W { a }; b { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> [ a, b, c | Wq { c } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] emb w, b pre DiagW2 (a, b, c) and IsEight(c) - post not ex x, y (_new_W(x) and BeatsW (x, y)) -RULE BlackBeatPromote: +RULE WhiteBeatPromote: [ a, b, c | B { a }; w { b } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] @@ -104,8 +125,27 @@ vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] emb w, b pre DiagB2 (a, b, c) and IsFirst(c) - post not ex x, y (_new_B(x) and BeatsB (x, y)) +RULE RedBeatCont: + [ a, b, c | W { a }; b { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> + [ a, b, c | W { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre DiagW2 (a, b, c) and not IsEight(c) + post ex x, y (_new_W(x) and BeatsWX (x, y)) RULE WhiteBeatCont: + [ a, b, c | B { a }; w { b } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + -> + [ a, b, c | B { c } | + vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; + x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] + emb w, b pre DiagB2 (a, b, c) and not IsFirst(c) + post ex x, y (_new_B(x) and BeatsBX (x, y)) +RULE RedBeatBothCont: [ a, b, c | W { a }; b { b } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] @@ -113,8 +153,9 @@ [ a, b, c | W { c } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] - emb w, b pre Diag2 (a, b, c) post ex x, y (_new_W(x) and BeatsW (x, y)) -RULE BlackBeatCont: + emb w, b pre _new_W(a) and Diag2 (a, b, c) and not IsEight(c) + post ex x, y (_new_W(x) and BeatsWX (x, y)) +RULE WhiteBeatBothCont: [ a, b, c | B { a }; w { b } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] @@ -122,8 +163,9 @@ [ a, b, c | B { c } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] - emb w, b pre Diag2 (a, b, c) post ex x, y (_new_B(x) and BeatsB (x, y)) -RULE WhiteQBeat: + emb w, b pre _new_B(a) and Diag2 (a, b, c) and not IsFirst(c) + post ex x, y (_new_B(x) and BeatsBX (x, y)) +RULE RedQBeat: [ a, b, c | Wq { a }; b { b } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] @@ -132,7 +174,7 @@ vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] emb w, b pre Diag2 (a, b, c) -RULE BlackQBeat: +RULE WhiteQBeat: [ a, b, c | Bq { a }; w { b } | vx {a->0.,b->0.,c->0.}; vy {a->0.,b->0.,c->0.}; x {a->0.,b->10.,c->20.}; y {a->0.,b->10.,c->20.} ] @@ -147,9 +189,9 @@ 1: :(ex x w(x)) - :(ex x b(x)); 2: :(ex x b(x)) - :(ex x w(x)) } - MOVES [WhiteMove -> 1]; [WhitePromote -> 1]; [WhiteQMove -> 1]; - [WhiteBeat -> 1]; [WhiteBeatPromote -> 1]; [WhiteQBeat -> 1]; - [WhiteBeatCont -> 2] + MOVES [RedMove -> 1]; [RedPromote -> 1]; [RedQMove -> 1]; + [RedBeat -> 1]; [RedBeatPromote -> 1]; [RedQBeat -> 1]; + [RedBeatCont -> 2] } LOC 1 { PLAYER 2 @@ -157,9 +199,9 @@ 1: :(ex x w(x)) - :(ex x b(x)); 2: :(ex x b(x)) - :(ex x w(x)) } - MOVES [BlackMove -> 0]; [BlackPromote -> 0]; [BlackQMove -> 0]; - [BlackBeat -> 0]; [BlackBeatPromote -> 0]; [BlackQBeat -> 0]; - [BlackBeatCont -> 3] + MOVES [WhiteMove -> 0]; [WhitePromote -> 0]; [WhiteQMove -> 0]; + [WhiteBeat -> 0]; [WhiteBeatPromote -> 0]; [WhiteQBeat -> 0]; + [WhiteBeatCont -> 3] } LOC 2 { PLAYER 1 @@ -167,7 +209,7 @@ 1: :(ex x w(x)) - :(ex x b(x)); 2: :(ex x b(x)) - :(ex x w(x)) } - MOVES [WhiteBeat -> 1]; [WhiteBeatPromote -> 1]; [WhiteBeatCont -> 2] + MOVES [RedBeatBoth -> 1]; [RedBeatPromote -> 1]; [RedBeatBothCont -> 2] } LOC 3 { PLAYER 2 @@ -175,7 +217,7 @@ 1: :(ex x w(x)) - :(ex x b(x)); 2: :(ex x b(x)) - :(ex x w(x)) } - MOVES [BlackBeat -> 0]; [BlackBeatPromote -> 0]; [BlackBeatCont -> 3] + MOVES [WhiteBeatBoth -> 0]; [WhiteBeatPromote -> 0]; [WhiteBeatBothCont -> 3] } MODEL [ | Wq:1 { }; Bq:1 { } | ] " Modified: trunk/Toss/examples/Tic-Tac-Toe.toss =================================================================== --- trunk/Toss/examples/Tic-Tac-Toe.toss 2011-01-09 20:58:08 UTC (rev 1277) +++ trunk/Toss/examples/Tic-Tac-Toe.toss 2011-01-09 23:36:40 UTC (rev 1278) @@ -1,5 +1,5 @@ PLAYERS 1, 2 -DATA r1: circle, r2: line, adv_ratio: 4, depth: 4 +DATA r1: circle, r2: line, adv_ratio: 4, depth: 3 REL DiagA (x, y) = ex u (R(x, u) and C(u, y)) REL DiagB (x, y) = ex u (R(x, u) and C(y, u)) REL Row3 (x, y, z) = R(x, y) and R(y, z) Modified: trunk/Toss/www/links.php =================================================================== --- trunk/Toss/www/links.php 2011-01-09 20:58:08 UTC (rev 1277) +++ trunk/Toss/www/links.php 2011-01-09 23:36:40 UTC (rev 1278) @@ -4,6 +4,7 @@ $prefix = ""; $url = "links.php"; +$style = ""; $title = "Toss Links Page"; $body = ' <div class="main"> @@ -20,6 +21,18 @@ Zillions of Games is a language for defining games together with a simulator and a large library of games. It is very nice but unluckily not open source.</p> +<p><a href="http://www.kurnik.pl/">Kurnik</a><br/> +Kurnik is a polish site on which you can play various games.</p> + +<p><a href="http://abstractstrategy.com/main.html">Abstract Strategy Games</a><br/> +Abstract Strategy Games site allows you to learn and play such games.</p> + +<p><a href="http://www.yourturnmyturn.com/">Your Turn My Turn</a><br/> +On Your-Turn-My-Turn you can play various board games online.</p> + + + + <h2>Modelling Tools</h2> <p><a href="http://edu.kde.org/step/">Step</a><br/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |