Thread: [Toss-devel-svn] SF.net SVN: toss:[1510] trunk/Toss/GGP/TranslateGame.ml
Status: Beta
Brought to you by:
lukaszkaiser
From: <luk...@us...> - 2011-07-13 09:54:31
|
Revision: 1510 http://toss.svn.sourceforge.net/toss/?rev=1510&view=rev Author: lukstafi Date: 2011-07-13 09:54:19 +0000 (Wed, 13 Jul 2011) Log Message: ----------- GDL translation work in progress. Does not compile yet. Modified Paths: -------------- trunk/Toss/GGP/TranslateGame.ml Modified: trunk/Toss/GGP/TranslateGame.ml =================================================================== --- trunk/Toss/GGP/TranslateGame.ml 2011-07-10 19:47:57 UTC (rev 1509) +++ trunk/Toss/GGP/TranslateGame.ml 2011-07-13 09:54:19 UTC (rev 1510) @@ -226,10 +226,11 @@ ) struc element_reps ) struc maks_reps in next_clauses, f_paths, m_paths, mask_reps, defined_rels, - stable_base, init_state, struc, elem_term_map + stable_base, init_state, struc, agg_actions, elem_term_map -(* Find the rule clauses $\ol{\calC},\ol{\calN}$. *) +(* Find the rule clauses $\ol{\calC},\ol{\calN}$. Do not remove the + "does" atoms from clauses. *) let move_tuples used_vars next_cls legal_tuples = (* computing the $d_i(\calN)$ for each $\calN$ *) let fresh_x_f () = @@ -346,9 +347,9 @@ legal_tup, next_cls @ erasure_cls -(* Assign rule clauses to rule cases, i.e. candidates for Toss - rules. Collect the conditions and RHS state terms together. *) -let rule_cases (legal_tup, next_cls) = +(* Assign rule clauses to rule cases, i.e. candidates for + Toss rules. Collect the conditions and RHS state terms together. *) +let rule_cases next_cls = let atoms = Aux.concat_map (fun (_, body) -> Aux.map_some (function | Pos (Rel _ as a) | Neg (Rel _ as a) -> Some a @@ -387,18 +388,37 @@ ) choice patterns ) next_cls in let case_rhs, case_conds = List.split case_cls in - case_rhs, separation_cond @ case_conds in - let legal_tup, legal_cond = List.split legal_tup in - let legal_cond = List.concat legal_cond in - List.map (fun choice -> - let case_rhs, case_conds = rule_case choice in - let case_conds = case_conds @ legal_cond in - legal_tup, case_rhs, case_conds) choices + case_cls, case_rhs, separation_cond @ case_conds in + List.map rule_case choices +let nonint_rule_cases (legal_tup, next_cls) = + let legal_tup, legal_cond = List.split legal_tup in + let legal_cond = List.combine legal_cond in + List.map (fun (case_rhs, case_cond) -> + legal_tup, case_rhs, case_cond @ legal_cond + ) (rule_cases next_cls) + +(* If "Concurrent Moves" case, divide rule clauses among players. *) +let concurrent_rule_cases players (legal_tup, next_cls) = + Array.mapi (fun i player -> + let legal_head, legal_cond = legal_tup.(i) in + let cls = List.filter + (fun (_,cl_body) -> List.exists ( + function Does (p, _) when p=player -> true | _ -> false) + cl_body) + next_cls in + List.map (fun (case_rhs, case_cond) -> + legal_head, case_rhs, case_cond @ legal_cond + ) (rule_cases cls) + ) players + +let general_int_rule_cases (legal_tup, next_cls) = + failwith "General Interaction Games not implemented yet" + (* The candidates need to be filtered before finishing the translation of Toss rules. *) -let create_rule_cands used_vars next_cls clauses = +let create_rule_cands is_turn_based used_vars next_cls clauses = let players = (* Array.of_list *) Aux.map_some (function | ("role", [player]), _ -> Some player @@ -406,6 +426,13 @@ ) clauses in let legal_cls = List.filter (fun ((rel,_),_) -> rel="legal") clauses in + let is_concurrent = not is_turn_based && + List.for_all + (fun (_, body) -> + List.length + (List.filter (function Does _ -> true | _ -> false) body) + <= 1) + next_cls in (* let next_cls = List.filter (fun ((rel,_),_) -> rel="next") clauses in *) (* constructing $(\calC_1,...,\calC_n)$ tuples *) @@ -415,14 +442,26 @@ | ("legal",[lp; l]), body when lp = p -> Some (l, body) | _ -> None) legal_cls ) players in - let legal_tuples = Aux.product legal_by_player in - let move_tups = move_tuples used_vars next_cls legal_tuples in - let move_tups = - List.map (fun (sb, legal_tup, n_cls) -> - List.map (subst sb) legal_tup, - List.map (subst_clause sb) n_cls) move_tups in - let move_tups = List.map add_erasure_clauses move_tups in - Aux.concat_map rule_cases move_tups + let process_rule_cands legal_tuples = + let move_tups = move_tuples used_vars next_cls legal_tuples in + let move_tups = + List.map (fun (sb, legal_tup, n_cls) -> + List.map (subst sb) legal_tup, + List.map (subst_clause sb) n_cls) move_tups in + List.map add_erasure_clauses move_tups in + let concurrent_rule_cands player legal_cls = + let legal_tuples = List.map (fun cl -> [cl]) legal_cls in + let move_tups = process_rule_cands legal_tuples in + player, Aux.concat_map nonint_rule_cases move_tups + if is_concurrent then + Right (List.map2 concurrent_rule_cands players legal_by_player) + else + let legal_tuples = Aux.product legal_by_player in + let move_tups = process_rule_cands legal_tuples in + if is_turn_based then + Left (Aux.concat_map nonint_rule_cases move_tups) + else + Left (Aux.concat_map general_int_rule_cases move_tups) let filter_rule_cands stable_base defined_rels rule_cands = @@ -434,18 +473,109 @@ List.mem rel defined_rels || not (List.exists (rels_unify a) stable_base) | _ -> true in - List.filter (fun (_, _, case_conds) -> - List.for_all check_atom case_conds - ) rule_cands + let check_cands cands = + List.filter (fun (_, _, _, case_conds) -> + List.for_all check_atom case_conds + ) cands in + match rule_cands with + | Left cands -> Left (check_cands cands) + | Right cands -> + Right (List.map (fun (p,cands) -> p, check_cands cands) cands) +exception Not_turn_based +(* Check if game is turn based and return the player cycle if it is, + otherwise rise [Not_turn_based]. Also return the [noop] actions + for players in the locations. *) +let check_turn_based players agg_actions = + 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 + 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 Not_turn_based + | _, Some _ -> accu) None noop_cands) noop_cands in + let noop_cands = List.map Aux.collect noop_cands in + (* throw in players with (multiple) constant actions *) + let control_noop_cands = List.map2 (fun ccand noops -> + let nccands, noops = Aux.partition_map + (function player, [] -> assert false + | player, [noop] -> Aux.Right (player, noop) + | player, more_actions -> Aux.Left player) noops in + match ccand, nccands with + | None, [player] -> Some player, noops + | Some _, [] -> ccand, noops + | _ -> raise Not_turn_based + ) control_cands noop_cands in + let control_cands, noop_cands = + List.split control_noop_cands in + (* 2b *) + let loc_players = find_cycle control_cands in + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "check_turn_based: location players %s\n%!" + (String.concat " " + (List.map (function Some t->term_str t | None->"None") + loc_players)) + ); + (* }}} *) + let loc_players = Array.of_list + (List.map (function Some p -> p | None -> players.(0)) + loc_players) in + let loc_n = Array.length loc_players in + let find_player_locs player = + Aux.array_argfind_all (fun p->p=player) loc_players in + (* noop actions of a player in a location *) + let loc_noops = + let i = ref 0 in + let noops = ref noop_cands in + let loc_noops = Array.make_matrix loc_n players_n None in + while !noops <> [] do + List.iter (function _, None -> () + | player, (Some _ as noop) -> + let p_i = find_player player in + if loc_noops.(!i).(p_i) = None + then loc_noops.(!i).(p_i) <- noop + else if loc_noops.(!i).(p_i) <> noop + (* moves are not simultaneous, but different [noop] actions + are used by the same player -- can be resolved by + introducing separate locations for each noop case *) + then raise Not_turn_based) + (List.hd !noops); + incr i; if !i = loc_n then i := 0; + noops := List.tl !noops + done; + loc_noops in + loc_players, loc_noops + + +let loc_graph_turn_based loc_players loc_noops rule_cands = + + +let loc_graph_general_int = + failwith "GDL: General Interaction Games not implemented yet" + +let loc_graph_concurrent = +() + let translate_game clauses = let clauses = expand_players clauses in let used_vars, clauses = rename_clauses clauses in let next_cls, f_paths, m_paths, mask_reps, defined_rels, - stable_base, init_state, struc, elem_term_map = + stable_base, init_state, struc, agg_actions, elem_term_map = create_init_struc clauses in - let rule_cands = create_rule_cands used_vars next_cls clauses in + let turn_data = + try Some (check_turn_based players agg_actions) + with Not_turn_based -> None in + let rule_cands = + create_rule_cands (turn_data <> None) used_vars next_cls clauses in let rule_cands = filter_rule_cands stable_base rule_cands in let all_state_terms = Aux.concat_map state_terms (List.map snd clauses) in @@ -460,18 +590,42 @@ defrel_arg_type = ref []; (* built in TranslateFormula *) term_arities = term_arities; } in - - let game = assert false + let defined_rels = build_defrels transl_data clauses in + let players = Array.of_list + (Aux.map_some (function + | ("role", [player]), _ -> Some player + | _ -> None + ) clauses) in + let player_names = Array.to_list + (Array.mapi (fun i p -> term_to_name p, i) players) in + let graph (*: player_loc array array*) = + match turn_data, rule_cands with + | Some (loc_players, loc_noops), Left cands -> + loc_graph_turn_based loc_players loc_noops cands + | None, Left cands -> + loc_graph_general_int + | None, Right cands + loc_graph_concurrent + | _ -> assert false in + let game = { + Arena.rules = rules; + patterns = []; + graph = graph; + num_players = Array.length players; + player_names = player_names; + data = []; + defined_rels = defined_rels; + } in let gdl_translation = { - (* map between structure elements and their term representations; - the reverse direction is by using element names *) + (* map between structure elements and their term representations; + the reverse direction is by using element names *) elem_term_map = elem_term_map; f_paths = f_paths; m_paths = m_paths; masks = mask_reps; tossrule_data = tossrule_data; - (* rule name to rule translation data *) + (* rule name to rule translation data *) } in gdl_translation, (game, {Arena.struc = struc; time = 0.; cur_loc = 0}) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-07-15 18:21:16
|
Revision: 1514 http://toss.svn.sourceforge.net/toss/?rev=1514&view=rev Author: lukstafi Date: 2011-07-15 18:21:05 +0000 (Fri, 15 Jul 2011) Log Message: ----------- GDL translation work in progress: preparing move translation data. Does not compile yet. Modified Paths: -------------- trunk/Toss/GGP/TranslateGame.ml Modified: trunk/Toss/GGP/TranslateGame.ml =================================================================== --- trunk/Toss/GGP/TranslateGame.ml 2011-07-14 22:56:38 UTC (rev 1513) +++ trunk/Toss/GGP/TranslateGame.ml 2011-07-15 18:21:05 UTC (rev 1514) @@ -25,7 +25,7 @@ let env_player = Const "ENVIRONMENT" type tossrule_data = { - lead_legal : term; + legal_tuple : term; (* the "legal"/"does" term of the player that performs the move, we call its parameters "fixed variables" as they are provided externally *) precond : Formula.formula; @@ -34,10 +34,9 @@ (* the elements of LHS/RHS structures, corresponding to the "next" terms *) struc_elems : string list; - fixvar_elemvars : - (string * (term * (string * string list) list) list) list; + fixvar_elemvars : (string * (term * path)) list; (* "state" terms indexed by variables that they contain, together - with the mask-path of the variable *) + with the path to the variable *) elemvars : term Aux.StrMap.t; (* "state" terms indexed by Toss variable names they generate *) } @@ -52,9 +51,11 @@ masks : term list; tossrule_data : tossrule_data Aux.StrMap.t; (* rule name to rule translation data *) - turnbased_noops : term array array option; + turnbased_noops : term option array array option; (* in case of a turn-based translation, for each location and each player, the player's noop move (if any) for the location *) + playing_as : int; + (* "active" player *) } (* [most_similar c ts] finds a term from [ts] most similar to [c], and @@ -204,18 +205,21 @@ ) struc path_tups ) (Structure.empty ()) struc_rels in (* adding anchor and fluent predicates *) - let add_pred struc paths elements = + let add_pred rels struc paths elements = List.fold_left (fun path -> Aux.fold_left_try (fun elem -> let pred = pred_on_path_subterm path (at_path elem path) in + rels := pred :: !rels; let tup = [|elem|] in Structure.add_rel_named_elems struc pred (Aux.array_map_of_list name_of_term tup) ) struc elements ) struc paths in - let struc = add_pred struc m_pathl element_reps in - let struc = add_pred struc f_pathl init_state in + let stable_rels = ref [] in + let fluents = ref [] in + let struc = add_pred stable_rels struc m_pathl element_reps in + let struc = add_pred fluents struc f_pathl init_state in (* adding mask predicates *) let all_paths = paths_union m_paths f_paths in let struc = @@ -223,13 +227,15 @@ let pred = term_to_name m in List.fold_left (fun struc elem -> if simult_subst all_paths blank elem = m - then + then ( + stable_rels := pred :: !stable_rels; Structure.add_rel_named_elems struc pred - [|name_of_term elem|] + [|name_of_term elem|]) else struc ) struc element_reps ) struc maks_reps in next_clauses, f_paths, m_paths, mask_reps, defined_rels, + !stable_rels, !fluents, stable_base, init_state, struc, agg_actions, elem_term_map @@ -585,41 +591,64 @@ let build_toss_rule transl_data rule_names struc fluents - synch_precond synch_postcond (legal_tup, case_rhs, case_cond) = + synch_precond synch_postcond (legal_tuple, case_rhs, case_cond) = let rname = Aux.not_conflicting_name rule_names - (String.concat "_" (List.map term_to_name legal_tup)) in + (String.concat "_" (List.map term_to_name legal_tuple)) in rule_names := Aux.Strings.add rname !rule_names; let label = {Arena.rule = rname; time_in = 0.1, 0.1; parameters_in = []} in let precond = synch_precond @ TranslateFormula.translate transl_data case_cond in - let rhs_pos = Aux.concat_map + let rhs_add = Aux.concat_map (function _, [sterm] -> let s_subterms = map_paths (fun path subt -> subt, path) transl_data.f_paths sterm in let s_subterms = List.filter (fun (subt, _) -> subt <> blank) s_subterms in - let vartup = [|var_of_term data sterm|] in + let vartup = [|TranslateFormula.var_of_term data sterm|] in List.map (fun (subt, path) -> pred_on_path_subterm path subt, vartup) s_subterms | _ -> assert false) case_rhs in - let rhs_pos = synch_postcond @ rhs_pos in + let rhs_add = synch_postcond @ rhs_add in let signat = Structure.rel_signature struc in let discrete = DiscreteRule.translate_from_precond ~precond - ~add:rhs_pos ~emb_rels:fluents ~signat ~struc_elems in + ~add:rhs_add ~emb_rels:fluents ~signat ~struc_elems in let rule = ContinuousRule.make_rule signature [] discrete [] [] ~pre:discrete.DiscreteRule.pre () in - label, (rname, rule) + let struc_elem_terms = List.map + (function _, [sterm] -> sterm | _ -> assert false) + case_rhs in + let struc_elems = List.map + (fun sterm -> Formula.var_str (TranslateFormula.var_of_term data sterm)) + struc_elem_terms in + let elemvars = Aux.strmap_of_assoc + (List.combine struc_elems struc_elem_terms) in + let fixvar_elemvars = List.map + (fun sterm -> map_paths + (fun path -> function Var v -> v, (sterm, path) + | _ -> assert false) + (term_paths (function Var _ -> true | _ -> false) sterm)) + struc_elem_terms in + let tossrule_data = { + legal_tuple = legal_tuple; + precond = precond; + rhs_add = rhs_add; + struc_elems = struc_elems; + fixvar_elemvars = fixvar_elemvars; + elemvars = elemvars; + } in + ((rname, tossrule_data), label), (rname, rule) let loc_graph_turn_based player_nums player_payoffs loc_players loc_noops build_rule rule_cands = let rules = ref [] in + let tossr_data = ref [] in let loc_n = Array.length loc_players in let player_rules = Aux.collect player_rules in let graph = Array.mapi @@ -637,8 +666,10 @@ then Some (build_rule rcand) else None ) rule_cands in - let labels, loc_rules = List.split loc_rules in + let loc_rdata, loc_rules = List.split loc_rules in + let loc_rdata, labels = List.split loc_rdata in rules := !rules @ loc_rules; + tossr_data := !tossr_data @ loc_rdata; let pl_moves = List.map (fun l -> l, (loc + 1) mod loc_n) labels in Array.mapi @@ -649,7 +680,7 @@ moves = if pl_num = player_num then pl_moves else []}) player_payoffs) loc_players in - graph, !rules + graph, !rules, !tossr_data let sControl = "CONTROL__" @@ -660,7 +691,7 @@ list. [rule_cands] is a player-indexed array. [players] are all player terms, excluding "environment". *) let loc_graph_concurrent players - player_payoffs struc build_rule rule_cands = + player_payoffs struc build_rule fluents rule_cands = (* finding or creating the control predicate *) let control_pred, control_e, struc = try @@ -685,10 +716,12 @@ Formula.fo_var_of_string (Structure.elem_name struc control_e) in let player_marker pl = [player_pred pl, [|control_v|]; control_pred, [|control_v|]] in + let fluents = List.map player_pred players @ fluents in let all_players_precond = (List.map (fun (rel,tup) -> Formula.Rel (rel,tup))) (Aux.concat_map player_marker players) in let rules = ref [] in + let tossr_data = ref [] in let player_moves = Array.mapi (fun pl_num (pl, p_rules) -> let p_rules = List.map @@ -700,8 +733,10 @@ p_rules in (* we need to build first before adding [player_cond] because of how formula translation works *) - let labels, p_rules = List.split p_rules in + let p_rdata, p_rules = List.split p_rules in + let p_rdata, labels = List.split p_rdata in rules := !rules @ p_rules; + tossr_data := !tossr_data @ p_rdata; List.map (fun l -> l, (loc + 1) mod loc_n)) rule_cands in let graph = @@ -714,7 +749,7 @@ moves = moves}) player_payoffs player_moves |] in - (graph, !rules), struc + (graph, !rules, !tossr_data), struc @@ -722,6 +757,7 @@ let clauses = expand_players clauses in let used_vars, clauses = rename_clauses clauses in let next_cls, f_paths, m_paths, mask_reps, defined_rels, + stable_rels, fluents, stable_base, init_state, struc, agg_actions, elem_term_map = create_init_struc clauses in let turn_data = @@ -752,7 +788,7 @@ let player_names = Array.to_list (Array.mapi (fun i p -> term_to_name p, i) players) in (* possibly update the structure with a control element and predicate *) - let (graph, rules), struc = + let (graph, rules, tossrule_data), struc = match turn_data, rule_cands with | Some (loc_players, loc_noops), Left cands -> let build_rule = @@ -765,7 +801,7 @@ let build_rule = build_toss_rule transl_data rule_names in loc_graph_concurrent players player_payoffs struc build_rule - rule_cands + fluents rule_cands | _ -> assert false in let game = { @@ -777,6 +813,7 @@ data = []; defined_rels = defined_rels; } in + let tossrule_data = Aux.strmap_of_assoc tossrule_data in let gdl_translation = { (* map between structure elements and their term representations; the reverse direction is by using element names *) @@ -785,7 +822,6 @@ m_paths = m_paths; masks = mask_reps; tossrule_data = tossrule_data; - (* rule name to rule translation data *) } in gdl_translation, (game, {Arena.struc = struc; time = 0.; cur_loc = 0}) @@ -795,23 +831,172 @@ (* ************************************************************ *) (** {3 Translating Moves.} *) +let translate_incoming_move_turnbased gdl state actions = + let loc = (snd state).Arena.cur_loc in + let actions = Array.of_list actions in + let location = (fst state).Arena.graph.(loc) in + let player_action = actions.(Aux.array_argfind (fun l -> l.Arena.moves <> []) + location) in + let struc = (snd state).Arena.struc in + let tossrules = + Aux.strmap_filter (fun _ rdata -> + try ignore (match_meta [] [] [player_action] [rdata.legal_tuple.(loc_player)]); true + with Not_found -> false + ) gdl.tossrule_data in + let candidates = Aux.map_some (fun (rname, rdata) -> + let fixed_inst, _ = + match_meta [] [] [player_action] [rdata.legal_tuple.(loc_player)] in + (* FIXME: rethink how elemvars are used and adjust how they're + created *) + let anchors = Aux.concat_map (fun (v,t) -> + let elemvars = List.assoc v rdata.fixvar_elemvars in + Aux.concat_map (fun (mask, pevs) -> + Aux.concat_map (fun (path, evs) -> + let pred = List.assoc t + (List.assoc path (List.assoc mask gdl.anchor_terms)) in + List.map (fun ev-> + Formula.Rel (pred, [|Formula.fo_var_of_string + (String.lowercase ev)|])) evs) + pevs) elemvars + ) fixed_inst in + let precond = Formula.And (anchors @ [rdata.precond]) in + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf + "GDL.translate_incoming_move: rule=%s; trying precond=\n%s\n...%!" + rname (Formula.sprint precond) + ); + (* }}} *) + let signat = Structure.rel_signature struc in + let rule = + DiscreteRule.translate_from_precond ~precond ~add:rdata.rhs_add + ~emb_rels:gdl.fluents ~signat ~struc_elems:rdata.struc_elems in + let lhs_struc = rule.DiscreteRule.lhs_struc in + let rule = DiscreteRule.compile_rule signat [] rule in + let asgns = + DiscreteRule.find_matchings struc rule in + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf "found %s\n%!" (AssignmentSet.str asgns) + ); + (* }}} *) + (* faster *) + (* let emb = + DiscreteRule.choose_match (snd state).Arena.struc rule asgns in *) + (* but we should check whether there's no ambiguity... *) + match + DiscreteRule.enumerate_matchings struc rule asgns + with + | [] -> None + | [emb] -> Some (rname, emb, lhs_struc) + | _ -> failwith + ("GDL.translate_incoming_move: match ambiguity for rule "^rname) + ) tossrules in + match candidates with + | [] -> + failwith + "GDL.translate_incoming_move: no matching rule found" + | [rname, emb, lhs_struc] -> + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "GDL.translate_incoming_move: rname=%s; emb=%s\n...%!" + rname + (String.concat ", " (List.map (fun (v,e) -> + Structure.elem_str lhs_struc v ^ ": " ^ + Structure.elem_str struc e) emb)) + ); + (* }}} *) + rname, emb + | _ -> + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "GDL.translate_incoming_move: ambiguity\n%!"; + List.iter (fun (rname, emb, lhs_struc) -> + Printf.printf "rname=%s; emb=%s\n%!" + rname + (String.concat ", " (List.map (fun (v,e) -> + Structure.elem_str lhs_struc v ^ ": " ^ + Structure.elem_str struc e) emb))) candidates + ); + (* }}} *) + failwith + ("GDL.translate_incoming_move: ambiguity among rules "^ + String.concat ", " (List.map Aux.fst3 candidates)) -let initialize_game player game_descr startcl = - let gdl_transl, state = translate_game player game_descr in - state, None, gdl_transl - - -let translate_last_action gdl_translation state actions = - if actions = [] then (* start of game -- Server will not perform a move *) - "", [] - else translate_incoming_move gdl_translation state actions +let translate_incoming_move_concurrent gdl state actions = + failwith "TODO" -let translate_move gdl_translation new_state rule emb = - let res = translate_outgoing_move gdl_translation new_state rule emb in +let translate_incoming_move_general_int gdl state actions = + failwith + "translate_incoming_move: general interaction games not supported yet" + +let translate_incoming_move gdl state actions = + failwith "TODO" + + +(* + (10a) associate the rule with its corresponding data: the "lead + legal" term, the fixed variables corresponding to rule elements, + ... + + (10b) earlier, return/store the mapping from an element to the + mask and subsitution that define the element; + + (10c) earlier, for each rule store a mapping from fixed variables + to rule variables and the mask variables that in the rule variable + are instantiated by the fixed variables; + + (10d) to determine how to instantiate the fixed variables in the + "lead legal" term, find the (10b) substitutions of assigned + elements and (10c) mask variables for fixed variables; compose the + maps to get fixed variable to GDL ground term mapping, each + "route" should give the same term. + *) +let translate_outgoing_move gdl state rname emb = + (* let loc = (snd state).Arena.cur_loc in *) + (* let location = (fst state).Arena.graph.(loc) in *) + let tossrule = Aux.StrMap.find rname gdl.tossrule_data in + let rule = List.assoc rname (fst state).Arena.rules in (* {{{ log entry *) if !debug_level > 0 then ( - Printf.printf "GDL.translate_move: %s\n%!" res + Printf.printf "GDL.translate_outgoing_move: rname=%s; emb={%s}\n%!" + rname (String.concat ", "(List.map (fun (v, e)-> + let vname = + DiscreteRule.elemvar_of_elem + rule.ContinuousRule.compiled.DiscreteRule.lhs_elem_inv_names v in + let ename = Structure.elem_str (snd state).Arena.struc e in + if ename = "control__blank_" then + Structure.print (snd state).Arena.struc; + vname ^ ": " ^ ename + ) emb)) ); (* }}} *) + (* 10d *) + let emb = List.map (fun (v, e) -> + let vterm = + DiscreteRule.elemvar_of_elem + rule.ContinuousRule.compiled.DiscreteRule.lhs_elem_inv_names v in + Aux.StrMap.find vterm tossrule.elemvars, + Aux.IntMap.find e gdl.t_elements) emb in + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf "outgoing-emb={%s}\n%!" + (String.concat ", "(List.map (fun (vt, et)-> + term_str vt ^ ": " ^ term_str et) emb)) + ); + (* }}} *) + let sb = + try + List.fold_left (fun sb (v_term, e_term) -> + fst (match_meta ~ignore_meta:true sb [] [e_term] [v_term])) [] emb + with Not_found -> failwith + ("GDL.translate_outgoing_move: inconsistent match for rule " + ^rname) in + let res = term_str (subst sb tossrule.legal_tuple.(gdl.playing_as)) in + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "GDL.translate_outgoing_move: result = %s\n%!" res + ); + (* }}} *) res This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-07-16 21:54:40
|
Revision: 1515 http://toss.svn.sourceforge.net/toss/?rev=1515&view=rev Author: lukstafi Date: 2011-07-16 21:54:34 +0000 (Sat, 16 Jul 2011) Log Message: ----------- GDL translation work in progress (minor edits). Does not compile yet. Modified Paths: -------------- trunk/Toss/GGP/TranslateGame.ml Modified: trunk/Toss/GGP/TranslateGame.ml =================================================================== --- trunk/Toss/GGP/TranslateGame.ml 2011-07-15 18:21:05 UTC (rev 1514) +++ trunk/Toss/GGP/TranslateGame.ml 2011-07-16 21:54:34 UTC (rev 1515) @@ -56,6 +56,7 @@ player, the player's noop move (if any) for the location *) playing_as : int; (* "active" player *) + is_concurrent : bool; } (* [most_similar c ts] finds a term from [ts] most similar to [c], and @@ -831,7 +832,11 @@ (* ************************************************************ *) (** {3 Translating Moves.} *) -let translate_incoming_move_turnbased gdl state actions = +(* The common part between turn-based and concurrent case -- + translate a non-noop action. *) +let translate_incoming_single_action gdl state action rname = + +let translate_incoming_move_turnbased gdl state actions noops = let loc = (snd state).Arena.cur_loc in let actions = Array.of_list actions in let location = (fst state).Arena.graph.(loc) in @@ -924,17 +929,31 @@ String.concat ", " (List.map Aux.fst3 candidates)) +(* We translate as a suite of moves, one for each player; after these + rules have been applied, the server should apply the environment rule. *) let translate_incoming_move_concurrent gdl state actions = - failwith "TODO" + + let translate_incoming_move_general_int gdl state actions = failwith "translate_incoming_move: general interaction games not supported yet" + let translate_incoming_move gdl state actions = - failwith "TODO" + if actions = [] (* start of game -- do nothing *) + then "", [] + else + match gdl.turnbased_noops with + | Some noops -> + translate_incoming_move_turnbased gdl state actions noops + | None -> + if gdl.is_concurrent then + translate_incoming_move_concurrent gdl state actions + else + translate_incoming_move_general_int gdl state actions - + (* (10a) associate the rule with its corresponding data: the "lead legal" term, the fixed variables corresponding to rule elements, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-07-29 10:13:24
|
Revision: 1520 http://toss.svn.sourceforge.net/toss/?rev=1520&view=rev Author: lukaszkaiser Date: 2011-07-29 10:13:18 +0000 (Fri, 29 Jul 2011) Log Message: ----------- Final small correction, TossServer runs. Modified Paths: -------------- trunk/Toss/GGP/TranslateGame.ml Modified: trunk/Toss/GGP/TranslateGame.ml =================================================================== --- trunk/Toss/GGP/TranslateGame.ml 2011-07-29 09:53:41 UTC (rev 1519) +++ trunk/Toss/GGP/TranslateGame.ml 2011-07-29 10:13:18 UTC (rev 1520) @@ -790,8 +790,8 @@ let sControl = "CONTROL__" -let loc_graph_general_int = - failwith "GDL: General Interaction Games not implemented yet" +let loc_graph_general_int = ([||], [], []), (Structure.empty_structure ()) + (* failwith "GDL: General Interaction Games not implemented yet" *) (* "environment" will the last player -- also in payoffs array. [players] are all player terms, excluding "environment"! *) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-08-28 23:15:02
|
Revision: 1548 http://toss.svn.sourceforge.net/toss/?rev=1548&view=rev Author: lukstafi Date: 2011-08-28 23:14:56 +0000 (Sun, 28 Aug 2011) Log Message: ----------- GDL translation: command-line translation minor fix. Modified Paths: -------------- trunk/Toss/GGP/TranslateGame.ml Modified: trunk/Toss/GGP/TranslateGame.ml =================================================================== --- trunk/Toss/GGP/TranslateGame.ml 2011-08-28 22:05:49 UTC (rev 1547) +++ trunk/Toss/GGP/TranslateGame.ml 2011-08-28 23:14:56 UTC (rev 1548) @@ -1734,7 +1734,9 @@ let tossrule_preconds = Aux.StrMap.map (fun rdata->rdata.precond) tossrule_data in let playing_as = - Aux.array_argfind (fun x -> x = playing_as) players in + try + Aux.array_argfind (fun x -> x = playing_as) players + with Not_found -> 0 in (match !generate_test_case with | None -> () | Some game_name -> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-10-11 10:33:34
|
Revision: 1589 http://toss.svn.sourceforge.net/toss/?rev=1589&view=rev Author: lukstafi Date: 2011-10-11 10:33:28 +0000 (Tue, 11 Oct 2011) Log Message: ----------- GDL translation: simple bug fix (inversion of turns for turn-based games). Modified Paths: -------------- trunk/Toss/GGP/TranslateGame.ml Modified: trunk/Toss/GGP/TranslateGame.ml =================================================================== --- trunk/Toss/GGP/TranslateGame.ml 2011-10-10 21:44:01 UTC (rev 1588) +++ trunk/Toss/GGP/TranslateGame.ml 2011-10-11 10:33:28 UTC (rev 1589) @@ -2882,6 +2882,7 @@ let game, state = result in let inl_game = Arena.map_to_formulas GameSimpl.remove_exist (inline_defined_rels game.Arena.defined_rels game) in + (* debug_level := 5; *) gdl_translation, game, (inl_game, state) @@ -3173,14 +3174,17 @@ match gdl.turnbased_noops with | None -> true | Some noops -> - noops.(state.Arena.cur_loc).(gdl.playing_as) <> None + noops.(state.Arena.cur_loc).(gdl.playing_as) = None let noop_move gdl state = match gdl.turnbased_noops with | None -> failwith "noop_move: not a turn-based game" | Some noops -> match noops.(state.Arena.cur_loc).(gdl.playing_as) with - | None -> failwith "noop_move: not a NOOP location" + | None -> + Printf.printf "noop_move: cur_loc=%d; playing_as=%d\n%!" + (state.Arena.cur_loc) (gdl.playing_as); + failwith "noop_move: not a NOOP location" | Some noop -> term_str noop let is_turnbased gdl = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |