Commits

vfiack  committed 54eca40

small refactor

  • Participants
  • Parent commits cc009eb

Comments (0)

Files changed (4)

File mills/ai_alphabeta.ml

 open Mill
 
-let all_moves state =
-  let color = get_color (get_turn state) in
-  let moves a = List.map (fun b -> (a, b)) (free_neighbors state a) in
-  List.flatten (List.map moves (movables state color))
-
-let all_flies state =
-  let color = get_color (get_turn state) in
-  let flies a = List.map (fun b -> (a, b)) (free_dots state) in
-  List.flatten (List.map flies (movables state color))
-
 type move =
   | Init
   | Put of int (* index *)

File mills/ai_montecarlo.ml

     with _ -> () (* not  movable or capturable *)
   end
 
-let all_moves state =
-  let color = get_color (get_turn state) in
-  let moves a = List.map (fun b -> (a, b)) (free_neighbors state a) in
-  List.flatten (List.map moves (movables state color))
-
-let all_flies state =
-  let color = get_color (get_turn state) in
-  let flies a = List.map (fun b -> (a, b)) (free_dots state) in
-  List.flatten (List.map flies (movables state color))
-
 let playout state maxturn =
   while not (game_ended state) && (get_turn state) < maxturn do
     do_turn state Ai_random.player;

File mills/mill.ml

 
 let neighbors i = connections.(i)
 
+let get_color turn = if turn mod 2 = 0 then White else Black    
+
+let get_turn state = state.turn
+
 let free_neighbors state i =
   let free i = state.dots.(i) = None in
   List.filter (free) (neighbors i)
   let check i = (free_neighbors state i) <> [] in
   List.filter check (colored_dots state color)
 
+let all_moves state =
+  let color = get_color (get_turn state) in
+  let moves a = List.map (fun b -> (a, b)) (free_neighbors state a) in
+  List.flatten (List.map moves (movables state color))
 
-let get_color turn = if turn mod 2 = 0 then White else Black    
-
-let get_turn state = state.turn
+let all_flies state =
+  let color = get_color (get_turn state) in
+  let flies a = List.map (fun b -> (a, b)) (free_dots state) in
+  List.flatten (List.map flies (movables state color))
 
 let get_count state color = match color with
   | White -> state.nwhite

File mills/mill.mli

 val neighbors : int -> int list
 val free_neighbors : state -> int -> int list 
 val capturables : state -> color -> int list
-val movables:state -> color -> int list
+val movables : state -> color -> int list
+val all_moves : state -> (int*int) list  
+val all_flies : state -> (int*int) list
 
 val can_put : state -> bool
 val can_fly : state -> bool