open Board open Types let print_map_elem = function Plain -> '.' | Water -> '~' | Wall -> '#' | Home 0 -> '@' | Home 1 -> 'O' | Home 2 -> 'O' | Home 3 -> 'Q' | Home 4 -> 'Q' | Home 5 -> 'Q' | Home _ -> 'H' let rec print_int_list = function [] -> "" | [n] -> string_of_int n | n::l -> (string_of_int n)^", "^(print_int_list l) let print_map map = let height = Array.length map in if height = 0 then print_string "[empty]\n" else let width = Array.length map.(0) in for y = 0 to height - 1 do for x = 0 to width - 1 do print_char (print_map_elem map.(height - 1 - y).(x)) done; print_char '\n' done let print_loc( x, y ) = "("^(string_of_int x)^","^(string_of_int y)^")" let print_packs packs = let print_pack_info pack = (string_of_int pack.weight)^"kg, dest:"^(print_loc pack.dest) in let print_pack_loc = function No -> "absent" | Yes loc -> "at "^(print_loc loc) | Maybe loc -> "probably at "^(print_loc loc) in let print n = function Some pack_info, pack_loc -> print_string ("[pack " ^(string_of_int n)^", " ^(print_pack_info pack_info)^", "^(print_pack_loc pack_loc)^"]\n") | None, pack_loc -> print_string ("[pack " ^(string_of_int n)^", not revealed, " ^(print_pack_loc pack_loc)^"\n") in IntMap.iter print packs let print_robots robots = let print n robot_info = print_string ("[robot "^(string_of_int n)^", at " ^(print_loc robot_info.robot_loc)^", belongings: " ^(print_int_list (intset_to_list robot_info.own))^"]\n") in IntMap.iter print robots let print_myself() = let p = my_pack() in print_string ("[myself: id="^(string_of_int (!my_id)) ^", max weight="^(string_of_int (!max_weight)) ^", money="^(string_of_int (!money)) ^", belongings="^(print_int_list (intset_to_list p))^"]\n") let print_homes() = print_string "home:"; LocSet.iter (function loc -> print_string (" "^(print_loc loc))) (!homes); print_newline () let print_map_and_others map robots packs my_id = let height = Array.length map in if height = 0 then print_string "[empty]\n" else let width = Array.length map.(0) in let others = Array.create height [] in let add_pack n ( _, pack_loc ) = match pack_loc with No -> () | Yes( x, y ) -> others.(y) <- ( x, 'P' )::others.(y) | Maybe( x, y ) -> others.(y) <- ( x, 'P' )::others.(y) in IntMap.iter add_pack packs; let add_robot n r = let x, y = r.robot_loc in let c = if n = my_id then 'I' else (string_of_int (n mod 10)).[0] in others.(y) <- ( x, c )::others.(y) in IntMap.iter add_robot robots; for y = 0 to height - 1 do for x = 0 to width - 1 do let y = height - 1 - y in let c = if List.mem_assoc x others.(y) then List.assoc x others.(y) else print_map_elem map.(y).(x) in print_char c done; print_char '\n' done