Commits

Yaron Minsky committed b908650

Player now exports record fields

  • Participants
  • Parent commits cce7923

Comments (0)

Files changed (1)

 open Direction.Export
 open Action.Export
 
+
 module Player = struct
-  type t = { pos: Vec.t
-           }
+  module Export = struct
+    type _player = { pos: Vec.t } with sexp, bin_io
+  end
+  open Export
+
+  type t = _player
   with sexp, bin_io
 end
+open Player.Export
 
 type t =
   { players: Player.t Player_name.Map.t
   let players' =
     Map.change t.players pname (function
       | None ->
-        let player = { Player.
-                       pos = vec (Random.int t.max_x) (Random.int t.max_y) }
+        let player = { pos = vec (Random.int t.max_x) (Random.int t.max_y) }
         in
         Some player
       | Some _ as x -> x
 
 let find_winners t =
   Map.to_alist t.players
-  |> List.map ~f:(fun (pn,ps) -> (ps.Player.pos,pn))
+  |> List.map ~f:(fun (pn,ps) -> (ps.pos,pn))
   |> Vec.Map.of_alist_multi
   |> Map.to_alist
   |> List.filter ~f:(fun (_,players) -> List.length players > 1)
       Map.to_alist t.players
       |> List.filter ~f:(fun (pn',_) -> pn' <> pn)
       |> List.map ~f:(fun (pn',ps') ->
-        let dist =
-          Vec.manhattan_distance
-            ps.Player.pos
-            ps'.Player.pos
-        in
+        let dist = Vec.manhattan_distance ps.pos ps'.pos in
         (pn',dist))
       |> List.map ~f:(fun (pn,d) -> Player_name.to_string pn ^ ":" ^ Int.to_string d)
       |> String.concat ~sep:","
     match action with
     | Move d ->
       let delta = Direction.to_vec d in
-      let player' = { Player. pos = Vec.add player.Player.pos delta } in
+      let player' = { pos = Vec.add player.pos delta } in
       let players' = Map.add t.players ~key:pname ~data:player' in
       ({ t with players = players' }, Update.empty)
     | Status ->