[Toss-devel-svn] SF.net SVN: toss:[1410] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
|
From: <luk...@us...> - 2011-04-14 23:57:30
|
Revision: 1410
http://toss.svn.sourceforge.net/toss/?rev=1410&view=rev
Author: lukaszkaiser
Date: 2011-04-14 23:57:24 +0000 (Thu, 14 Apr 2011)
Log Message:
-----------
Main game type change, prepare for concurrency, imperfect information, feature learning. Just breaks things for now, sorry.
Modified Paths:
--------------
trunk/Toss/Arena/Arena.ml
trunk/Toss/Arena/Arena.mli
trunk/Toss/Arena/ArenaParser.mly
trunk/Toss/Play/GameTree.ml
trunk/Toss/Play/GameTreeTest.ml
trunk/Toss/Play/Heuristic.ml
trunk/Toss/Play/Move.ml
trunk/Toss/Play/Move.mli
Modified: trunk/Toss/Arena/Arena.ml
===================================================================
--- trunk/Toss/Arena/Arena.ml 2011-04-14 01:58:27 UTC (rev 1409)
+++ trunk/Toss/Arena/Arena.ml 2011-04-14 23:57:24 UTC (rev 1410)
@@ -15,20 +15,25 @@
parameters_in : (string * (float * float)) list ;
}
-(* 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 ;
+
+(** A game has locations. In each one, each player has 0 or more
+ possible moves, each with a label, to one of the next locations.
+ We also store the view (see elsewhere) and weights for heuristics.
+ If no moves are possible, everyone gets a payoff.
+ Players are indexed continuously starting from 0. *)
+type player_loc = {
+ payoff : Formula.real_expr ;
moves : (label * int) list ;
+ view : Formula.formula * (string * Formula.formula) list ;
+ heur : float list ;
}
-(* The basic type of Arena. *)
+
+(** The basic type of Arena. *)
type game = {
rules : (string * ContinuousRule.rule) list;
- graph : location array;
+ patterns : Formula.real_expr list;
+ graph : player_loc array array;
num_players : int;
player_names : (string * int) list ;
data : (string * string) list ;
@@ -46,7 +51,10 @@
let emp_struc = Structure.empty_structure () in
let zero = Formula.Const 0.0 in
{rules = [];
- graph = Array.make 1 { id = 0; player = 0; payoffs = [|zero|]; moves = [] };
+ patterns = [];
+ graph = Array.make 1
+ (Array.make 1
+ { payoff = zero; moves = []; view = (Formula.And [],[]); heur = [] });
player_names = ["1", 0] ;
data = [] ;
defined_rels = [] ;
@@ -70,11 +78,8 @@
(* Rules with which a player with given number can move. *)
let rules_for_player player_no game =
- let rules_of_loc l =
- if l.player = player_no then
- Some (List.map (fun (lab, _) -> lab.rule) l.moves)
- else None in
- List.concat (Aux.map_some rules_of_loc (Array.to_list game.graph))
+ let rules_of_loc l = List.map (fun (lab,_) -> lab.rule) l.(player_no).moves in
+ List.concat (List.map rules_of_loc (Array.to_list game.graph))
(* Add a defined relation to a structure. *)
let add_def_rel_single struc (r_name, vars, def_phi) =
@@ -101,7 +106,7 @@
(string * (string list * Formula.formula)) list -> string ->
ContinuousRule.rule)
(* add a rule *)
- | DefLoc of ((string * int) list -> location)
+ | DefLoc of ((string * int) list -> player_loc array)
(* add location to graph *)
| DefPlayers of string list (* add players (fresh numbers) *)
| DefRel of string * string list * Formula.formula
@@ -146,11 +151,14 @@
let pname = match pname with None -> "1" | Some p -> p in
fun player_names ->
let player = List.assoc pname player_names in
- let zero = Formula.Const 0.0 in
- let payoffs =
- array_of_players zero player_names payoffs in
- { id = id; player = player; payoffs = payoffs; moves = moves }
+ let zero_loc = { payoff = Formula.Const 0. ; view = (Formula.And [], []);
+ heur = []; moves = [] } in
+ let locs = List.map (fun (pl, poff) ->
+ (pl, { payoff = poff ; view = (Formula.And [], []); heur = [];
+ moves = if pl = pname then moves else [] })) payoffs in
+ array_of_players zero_loc player_names locs
+
open Printf
(* Create a game state, possibly by extending an old state, from a
@@ -239,14 +247,15 @@
let updated_locs =
if old_locs = [] then old_locs
else
- let zero = Formula.Const 0.0 in
- let add_payoffs loc =
- let more = num_players - Array.length loc.payoffs in
- {loc with payoffs = Array.append loc.payoffs (Array.make more zero);} in
- List.map add_payoffs old_locs in
+ let more = num_players - Array.length (List.hd old_locs) in
+ let zero_loc = { payoff = Formula.Const 0. ; view = (Formula.And [], []);
+ heur = []; moves = [] } in
+ let add_more loc = Array.append loc (Array.make more zero_loc) in
+ List.map add_more old_locs in
let add_def_rel loc =
- let ps = Array.map (FormulaOps.subst_rels_expr def_rels_pure) loc.payoffs in
- { loc with payoffs = ps; } in
+ let sub_p l =
+ { l with payoff = FormulaOps.subst_rels_expr def_rels_pure l.payoff } in
+ Array.map sub_p loc in
(* {{{ log entry *)
if !debug_level > 2 then (
printf "process_definition: parsing locations (registering payoffs)...%!";
@@ -259,19 +268,11 @@
printf " parsed\n%!";
);
(* }}} *)
- let graph =
- try
- Aux.array_from_assoc
- (List.map (fun loc->loc.id, loc) locations)
- with Invalid_argument _ ->
- let loc_numbers =
- List.sort compare (List.map (fun loc->loc.id) locations) in
- raise (
- Arena_definition_error (
- "Locations not consecutive from 0: " ^
- String.concat ", " (List.map string_of_int loc_numbers))) in
+ let graph = Array.of_list (List.rev locations) in
+ (* TODO; FIXME; JUST THIS List.rev ABOVE WILL NOT ALWAYS BE GOOD, OR?!! *)
let game = {
rules = rules;
+ patterns = [];
graph = graph;
num_players = num_players;
player_names = player_names;
@@ -299,15 +300,15 @@
(* Print a move as string. *)
let move_str (lb, i) = "["^ (label_str lb) ^" -> "^ (string_of_int i) ^"]"
-let fprint_loc_body struc pnames f
- {player = player; payoffs = payoffs; moves = moves} =
+let fprint_loc_body_in struc pnames f player
+ {payoff = payoff; moves = moves} =
Format.fprintf f "@[<1>PLAYER@ %s@]@ "
(Aux.rev_assoc pnames player);
Format.fprintf f "@[<1>PAYOFF@ {@,@[<1>%a@]@,}@]@ "
(Aux.fprint_sep_list ";" (fun f (p, ex) ->
Format.fprintf f "@[<1>%s:@ %a@]" (Aux.rev_assoc pnames p)
(Formula.fprint_real(* _nobra 0 *)) ex))
- (Array.to_list (Array.mapi (fun i l->i, l) payoffs));
+ (Array.to_list (Array.mapi (fun i l->i, l) [|payoff|]));
Format.fprintf f "@[<1>MOVES@ %a@]"
(Aux.fprint_sep_list ";" (fun f ({
rule=r; time_in=(t_l, t_r); parameters_in=params}, target) ->
@@ -320,6 +321,10 @@
Format.fprintf f "@[<1>%s:@ %F@ --@ %F@]" pn p_l p_r)) params;
Format.fprintf f "@ ->@ %d@]@,]" target)) moves
+
+let fprint_loc_body struc pnames f loc =
+ Array.iteri (fun p l -> fprint_loc_body_in struc pnames f p l) loc
+
let equational_def_style = ref true
let fprint_state_full print_compiled_rules ppf
@@ -357,9 +362,9 @@
List.iter (fun (rname, r) ->
Format.fprintf ppf "@[<1>RULE %s:@ %a@]@ " rname
(ContinuousRule.fprint_full print_compiled_rules) r) rules;
- Array.iter (fun loc ->
+ Array.iteri (fun loc_id loc ->
Format.fprintf ppf "@[<1>LOC %d@ {@,@[<1>@,%a@]@,}@]@ "
- loc.id (fprint_loc_body struc player_names) loc) graph;
+ loc_id (fprint_loc_body struc player_names) loc) graph;
Format.fprintf ppf "@[<1>MODEL@ %a@]@ "
(Structure.fprint ~show_empty:true) struc;
if cur_loc <> 0 then
@@ -388,12 +393,12 @@
let add_new_player (state_game, state) pname =
let player = state_game.num_players in
- let zero = Formula.Const 0.0 in
- let add_payoff loc =
- {loc with payoffs = Array.append loc.payoffs [|zero|]; } in
+ let zero_loc = { payoff = Formula.Const 0. ; view = (Formula.And [], []);
+ heur = []; moves = [] } in
+ let add_more loc = Array.append loc [|zero_loc|] in
let game = {state_game with
num_players = state_game.num_players + 1;
- graph = Array.map add_payoff state_game.graph;
+ graph = Array.map add_more state_game.graph;
player_names = (pname, player)::state_game.player_names;
} in
(game, state), player
@@ -403,11 +408,9 @@
rules = List.map (fun (rn, r) ->
rn, ContinuousRule.map_to_formulas f r
) game.rules;
- graph = Array.map (fun loc ->
- {loc with
- payoffs =
- Array.map (FormulaOps.map_to_formulas_expr f) loc.payoffs;
- }) game.graph;
+ graph = Array.map (fun la -> Array.map (fun loc ->
+ {loc with payoff = FormulaOps.map_to_formulas_expr f loc.payoff;
+ }) la) game.graph;
defined_rels = List.map (fun (drel, (args, def)) ->
drel, (args, f def)) game.defined_rels;
}
@@ -418,9 +421,9 @@
ContinuousRule.fold_over_formulas f r
) game.rules acc in
let acc =
- Array.fold_right (fun loc ->
- Array.fold_right (FormulaOps.fold_over_formulas_expr f) loc.payoffs
- ) game.graph acc in
+ Array.fold_right (fun la -> Array.fold_right
+ (fun loc -> FormulaOps.fold_over_formulas_expr f loc.payoff) la)
+ game.graph acc in
let acc =
if include_defined_rels then
List.fold_right (fun (_, (_, def)) -> f def)
@@ -490,37 +493,32 @@
let pnames2 = List.sort cmp_pn g2.player_names in
if pnames1 <> pnames2 then
raise (Diff_result "Game players are given in different order.");
- Array.iteri (fun i loc1 ->
- let loc2 = g2.graph.(i) in
- let dmoves1 = Aux.list_diff loc1.moves loc2.moves in
- if dmoves1 <> [] then raise (Diff_result (
- let label, dest = List.hd dmoves1 in
- Printf.sprintf
- "At location %d, only the first game has label %s->%d"
- i label.rule dest));
- let dmoves2 = Aux.list_diff loc2.moves loc1.moves in
- if dmoves2 <> [] then raise (Diff_result (
- let label, dest = List.hd dmoves1 in
- Printf.sprintf
- "At location %d, only the second game has label %s->%d"
- i label.rule dest));
- if loc1.player <> loc2.player then raise (Diff_result (
- Printf.sprintf
- "At location %d, the first game has player %d, second %d"
- i loc1.player loc2.player));
- Array.iteri (fun p poff1 ->
+ Array.iteri (fun i locarr1 ->
+ Array.iteri (fun pl loc1 ->
+ let loc2 = g2.graph.(i).(pl) in
+ let dmoves1 = Aux.list_diff loc1.moves loc2.moves in
+ if dmoves1 <> [] then raise (Diff_result (
+ let label, dest = List.hd dmoves1 in
+ Printf.sprintf
+ "At location %d, only the first game has label %s->%d"
+ i label.rule dest));
+ let dmoves2 = Aux.list_diff loc2.moves loc1.moves in
+ if dmoves2 <> [] then raise (Diff_result (
+ let label, dest = List.hd dmoves1 in
+ Printf.sprintf
+ "At location %d, only the second game has label %s->%d"
+ i label.rule dest));
let poff1 =
FormulaOps.map_to_formulas_expr FormulaOps.flatten_formula
- poff1 in
+ loc1.payoff in
let poff2 =
FormulaOps.map_to_formulas_expr FormulaOps.flatten_formula
- loc2.payoffs.(p) in
+ loc2.payoff in
if poff1 <> poff2 then raise (Diff_result (
Printf.sprintf
"At location %d, payffs for player %d differ:\n%s\nvs.\n%s"
- i p (Formula.real_str poff1)
- (Formula.real_str poff2)));
- ) loc1.payoffs
+ i pl (Formula.real_str poff1) (Formula.real_str poff2)));
+ ) locarr1
) g1.graph;
if List.sort Pervasives.compare g1.defined_rels <>
List.sort Pervasives.compare g2.defined_rels
@@ -769,9 +767,10 @@
| SetLoc (i) ->
let l = Array.length state_game.graph in
if i < 0 || i > l then (* make new location and set there *)
- let a = Array.make 1
- { id = l; player=0; payoffs=[| |]; moves=[] } in
- (({state_game with graph=Array.append state_game.graph a},
+ let zero_loc = { payoff = Formula.Const 0. ; heur = []; moves = [] ;
+ view = (Formula.And [], []); } in
+ let a = Array.make (Array.length state_game.graph.(0)) zero_loc in
+ (({state_game with graph = Array.append state_game.graph [|a|]},
{state with cur_loc = l }),
"NEW LOC ADDED AND CUR LOC SET TO " ^ (string_of_int l))
else
@@ -779,22 +778,13 @@
| GetLoc ->
((state_game, state), (string_of_int state.cur_loc) ^ " / " ^
(string_of_int (Array.length state_game.graph)))
- | SetLocPlayer (i, player) ->
- let (state_game, state), player =
- try (state_game, state), List.assoc player state_game.player_names
- with Not_found -> add_new_player (state_game, state) player in
- if i < 0 || i > Array.length state_game.graph then
+ | SetLocPlayer (i, player) -> failwith "unsupported for now, concurrency"
+ (* ((state_game, state), "LOC PLAYER SET") *)
+ | GetLocPlayer (i) -> failwith "unsupported for now, concurrency"
+ (* if i < 0 || i > Array.length state_game.graph then
((state_game, state), "ERR location "^string_of_int i^" not found")
- else (
- state_game.graph.(i) <-
- { state_game.graph.(i) with player = player };
- ((state_game, state), "LOC PLAYER SET")
- )
- | GetLocPlayer (i) ->
- if i < 0 || i > Array.length state_game.graph then
- ((state_game, state), "ERR location "^string_of_int i^" not found")
else ((state_game, state), Aux.rev_assoc state_game.player_names
- state_game.graph.(i).player)
+ state_game.graph.(i).player) *)
| SetLocPayoff (i, player, payoff) ->
let (state_game, state), player =
try (state_game, state), List.assoc player state_game.player_names
@@ -803,7 +793,8 @@
((state_game, state), "ERR location "^string_of_int i^" not found")
else (
let simp_payoff = FormulaOps.tnf_re payoff in
- state_game.graph.(i).payoffs.(player) <- simp_payoff;
+ state_game.graph.(i).(player) <-
+ { state_game.graph.(i).(player) with payoff = simp_payoff };
((state_game, state), "LOC PAYOFF SET")
)
| GetLocPayoff (i, player) ->
@@ -811,31 +802,33 @@
((state_game, state), "ERR location "^string_of_int i^" not found")
else (
try
- ((state_game, state), Formula.real_str
- state_game.graph.(i).payoffs.(List.assoc player
- state_game.player_names))
+ let pno = List.assoc player state_game.player_names in
+ ((state_game, state),
+ Formula.real_str state_game.graph.(i).(pno).payoff)
with Not_found -> ((state_game, state), "0.0")
)
| GetCurPayoffs ->
let payoffs = Array.to_list
- (Array.mapi (fun i v->string_of_int i,v)
- state_game.graph.(state.cur_loc).payoffs) in
+ (Array.mapi (fun i v->string_of_int i, v.payoff)
+ state_game.graph.(state.cur_loc)) in
let ev (p,e) =
p^": "^(string_of_float (Solver.M.get_real_val e struc)) in
((state_game, state),
String.concat ", " (List.sort compare (List.map ev payoffs)))
- | SetLocMoves (i, moves) ->
- if i < 0 || i > Array.length state_game.graph then
+ | SetLocMoves (i, moves) -> failwith "unsupported for now, concurrency"
+ (* if i < 0 || i > Array.length state_game.graph then
((state_game, state), "ERR location "^string_of_int i^" not found")
else (
state_game.graph.(i) <- { state_game.graph.(i) with moves = moves };
((state_game, state), "LOC MOVES SET")
- )
- | GetLocMoves (i) ->
+ ) *)
+ | GetLocMoves (i) -> (* TODO! adapt for concurrency! *)
if i < 0 || i > Array.length state_game.graph then
((state_game, state), "ERR location "^string_of_int i^" not found")
- else ((state_game, state),
- (String.concat "; " (List.map move_str state_game.graph.(i).moves)))
+ else
+ let all_moves = List.concat (Array.to_list (Array.map (
+ fun loc -> loc.moves) state_game.graph.(i))) in
+ ((state_game,state), (String.concat "; " (List.map move_str all_moves)))
| SuggestLocMoves _ ->
failwith "handle_req: SuggestLocMoves handled in Server"
| EvalFormula (phi) -> ((state_game, state), "ERR eval not yet implemented")
Modified: trunk/Toss/Arena/Arena.mli
===================================================================
--- trunk/Toss/Arena/Arena.mli 2011-04-14 01:58:27 UTC (rev 1409)
+++ trunk/Toss/Arena/Arena.mli 2011-04-14 23:57:24 UTC (rev 1410)
@@ -10,21 +10,24 @@
parameters_in : (string * (float * float)) list ;
}
-(** 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 ;
+(** A game has locations. In each one, each player has 0 or more
+ possible moves, each with a label, to one of the next locations.
+ We also store the view (see elsewhere) and weights for heuristics.
+ If no moves are possible, everyone gets a payoff.
+ Players are indexed continuously starting from 0. *)
+type player_loc = {
+ payoff : Formula.real_expr ;
moves : (label * int) list ;
+ view : Formula.formula * (string * Formula.formula) list ;
+ heur : float list ;
}
(** The basic type of Arena. *)
type game = {
rules : (string * ContinuousRule.rule) list;
- graph : location array;
+ patterns : Formula.real_expr list;
+ graph : player_loc array array;
num_players : int;
player_names : (string * int) list ;
data : (string * string) list ;
@@ -85,7 +88,7 @@
(string * (string list * Formula.formula)) list -> string ->
ContinuousRule.rule)
(** add a rule *)
- | DefLoc of ((string * int) list -> location)
+ | DefLoc of ((string * int) list -> player_loc array)
(** add location to graph *)
| DefPlayers of string list (** add players (fresh numbers) *)
| DefRel of string * string list * Formula.formula
@@ -109,7 +112,7 @@
[< `Moves of (label * int) list
| `Payoffs of (string * Formula.real_expr) list
| `PlayerName of string ]
- list -> (string * int) list -> location
+ list -> (string * int) list -> player_loc array
(** Create a game state, possibly by extending an old state, from a
list of definitions (usually corresponding to a ".toss" file.) *)
Modified: trunk/Toss/Arena/ArenaParser.mly
===================================================================
--- trunk/Toss/Arena/ArenaParser.mly 2011-04-14 01:58:27 UTC (rev 1409)
+++ trunk/Toss/Arena/ArenaParser.mly 2011-04-14 23:57:24 UTC (rev 1410)
@@ -12,7 +12,7 @@
%start parse_game_defs parse_game_state parse_request
%type <Arena.request> parse_request request
%type <Arena.struct_loc> struct_location
-%type <(string * int) list -> Arena.location> location
+%type <(string * int) list -> Arena.player_loc array> location
%type <Arena.definition> parse_game_defs
%type <Arena.game * Arena.game_state> parse_game_state game_state
%type <Arena.game * Arena.game_state -> Arena.game * Arena.game_state> extend_game_state
Modified: trunk/Toss/Play/GameTree.ml
===================================================================
--- trunk/Toss/Play/GameTree.ml 2011-04-14 01:58:27 UTC (rev 1409)
+++ trunk/Toss/Play/GameTree.ml 2011-04-14 23:57:24 UTC (rev 1410)
@@ -3,6 +3,9 @@
let debug_level = ref 0
let set_debug_level i = debug_level := i
+(* TODO; FIXME; THIS IS A STUB, TRUE CONCURRENCY SUPPORT NEEDED. *)
+let moving_player = Aux.array_argfind (fun l -> l.Arena.moves <> [])
+
(* Abstract game tree, just stores state and move information. *)
type ('a, 'b) abstract_game_tree =
| Terminal of Arena.game_state * int * 'b (* terminal state with player *)
@@ -55,7 +58,7 @@
(* Abstract game tree initialization. *)
let init_abstract game state info_leaf =
- let player = game.Arena.graph.(state.Arena.cur_loc).Arena.player in
+ let player = moving_player game.Arena.graph.(state.Arena.cur_loc) in
let info = info_leaf game state player in
Leaf (state, player, info)
@@ -80,7 +83,7 @@
Solver.M.clear_timeout();
raise (Aux.Timeout "GameTree.unfold_abstract.lm");
);
- let l_pl = game.Arena.graph.(leaf_s.Arena.cur_loc).Arena.player in
+ let l_pl = moving_player game.Arena.graph.(leaf_s.Arena.cur_loc) in
let l_info = info_leaf (depth+1) game leaf_s l_pl player in
Leaf (leaf_s, l_pl, l_info) in
let children = Array.mapi (fun i (m,s) -> (m,leaf_of_move i s)) moves in
@@ -175,8 +178,9 @@
let info_terminal_f f depth game state player leaf_info =
let calc re = Solver.M.get_real_val re state.Arena.struc in
- let payoffs =
- Array.map calc game.Arena.graph.(state.Arena.cur_loc).Arena.payoffs in
+ let payoff_terms = Array.map (fun l -> l.Arena.payoff)
+ game.Arena.graph.(state.Arena.cur_loc) in
+ let payoffs = Array.map calc payoff_terms in
{ payoffs = payoffs; heurs_t = leaf_info.heurs ; info_t = f depth game state }
let info_node_f f depth game state player children =
Modified: trunk/Toss/Play/GameTreeTest.ml
===================================================================
--- trunk/Toss/Play/GameTreeTest.ml 2011-04-14 01:58:27 UTC (rev 1409)
+++ trunk/Toss/Play/GameTreeTest.ml 2011-04-14 23:57:24 UTC (rev 1410)
@@ -64,8 +64,9 @@
let ch = (fun _ _ _ _ _ _ _ -> 0) in
let u = GameTree.unfold g h i_l i_n ch t in
(* print_endline (GameTree.str string_of_int u); *)
+ let moving_player = Aux.array_argfind (fun l -> l.Arena.moves <> []) in
assert_equal ~printer:(fun x -> string_of_int x) (GameTree.player u)
- g.Arena.graph.((GameTree.state u).Arena.cur_loc).Arena.player;
+ (moving_player g.Arena.graph.((GameTree.state u).Arena.cur_loc));
);
]
Modified: trunk/Toss/Play/Heuristic.ml
===================================================================
--- trunk/Toss/Play/Heuristic.ml 2011-04-14 01:58:27 UTC (rev 1409)
+++ trunk/Toss/Play/Heuristic.ml 2011-04-14 23:57:24 UTC (rev 1410)
@@ -1072,7 +1072,7 @@
Array.fold_right (fun x y->Plus (x, y)) ar (Const 0.) in
let all_payoffs =
array_plus (Array.map (fun loc ->
- array_plus loc.Arena.payoffs) graph) in
+ array_plus (Array.map (fun l -> l.Arena.payoff) loc)) graph) in
let posi_poff_rels, nega_poff_rels =
FormulaOps.rels_signs_expr all_payoffs in
let all_poff_rels =
@@ -1136,7 +1136,7 @@
);
(* }}} *)
res)
- node.Arena.payoffs in
+ (Array.map (fun l -> l.Arena.payoff) node) in
if !force_competitive && Array.length res > 1
then
Array.mapi (fun p v ->
Modified: trunk/Toss/Play/Move.ml
===================================================================
--- trunk/Toss/Play/Move.ml 2011-04-14 01:58:27 UTC (rev 1409)
+++ trunk/Toss/Play/Move.ml 2011-04-14 23:57:24 UTC (rev 1410)
@@ -115,7 +115,11 @@
Array.of_list moves, Array.of_list models
let list_moves game s =
- let loc = game.Arena.graph.(s.Arena.cur_loc) in
+ let select_moving a =(*temporary function - accept just one player w/ moves*)
+ let locs = Aux.array_find_all (fun l -> l.Arena.moves <> []) a in
+ if List.length locs <> 1 then failwith "too many moves in loc for now" else
+ if locs = [] then a.(0) else List.hd locs in
+ let loc = select_moving (game.Arena.graph.(s.Arena.cur_loc)) in
let m = gen_moves cGRID_SIZE game.Arena.rules s.Arena.struc loc in
Array.of_list (gen_models_list game.Arena.rules s.Arena.struc s.Arena.time m)
Modified: trunk/Toss/Play/Move.mli
===================================================================
--- trunk/Toss/Play/Move.mli 2011-04-14 01:58:27 UTC (rev 1409)
+++ trunk/Toss/Play/Move.mli 2011-04-14 23:57:24 UTC (rev 1410)
@@ -28,7 +28,7 @@
(** Generate moves available from a state, as an array, in fixed order. *)
val gen_moves : int -> (string * ContinuousRule.rule) list ->
- Structure.structure -> Arena.location -> move array
+ Structure.structure -> Arena.player_loc -> move array
val gen_models : (string * ContinuousRule.rule) list -> Structure.structure ->
float -> move array -> move array * Arena.game_state array
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|