Commits

Anonymous committed f355d30

pure alphabeta, no more hybrid

Comments (0)

Files changed (1)

mills/ai_alphabeta.ml

 
 let score heuristic node = alphabeta heuristic node min_int max_int
 
-let estimate_basic state =
+let estimate state =
   let black = (get_count state Black)
   and white = (get_count state White) in
-  black - white
-
-let estimate_mc playouts state = Ai_montecarlo.estimate state 0 playouts 30
-
-let estimate_hybrid playouts state =
-  let e = estimate_basic state in
-  (max 100 playouts) * e + estimate_mc playouts state
+  if not (can_put state) then
+    if black > 2 && white <= 2 then max_int
+    else if black <= 2 && white > 2 then min_int
+    else black - white
+  else black - white
 
 let player =
-  let find_best state lastmove depth playouts =
+  let find_best state lastmove depth =
     reset_force ();
     let root = build state lastmove depth in
-(*    force_tree root;    *)
-(*    print_force_stat ();*)
     reset_force ();
-(*    let positions = count_positions root in*)
-(*    let nplayouts = playouts / positions in*)
     let children = match force root with Node (_, _, c) -> c in
-    let scores = List.map (score (estimate_basic)) children in
+    let scores = List.map (score estimate) children in
     let better = if (get_turn state) mod 2 = 0 then (<) else (>) in
     let init = if (get_turn state) mod 2 = 0 then max_int else min_int in
     let rec select nodes scores selected score =
     val mutable last_move = Init
     
     method put state =
-      let selected = find_best state Init 3 15000 in
+      let depth = (* reduced when too few stones are present *)
+        if get_count state Black > 3 && get_count state White > 3 then 7
+        else 4
+      in 
+      let selected = find_best state Init 5 in
       match selected with
       | Node(_, Put i, _) -> last_move <- Put i ; i
       | _ -> failwith "no put found"
     method move state =
       let before = Unix.gettimeofday() in
-      let selected = find_best state Init 6 30000 in      
+      let depth = (* reduced when one player can jump *)
+        if get_count state Black > 3 && get_count state White > 3 then 7
+        else 4
+      in 
+      let selected = find_best state Init depth in      
       let after = Unix.gettimeofday() in
       Printf.printf "time: %f\n%!" (after -. before);
       match selected with
       | Node(_, Move (f, g), _) -> last_move <- Move (f, g) ; f, g
       | _ -> failwith "no move found"
     method fly state =
-      let selected = find_best state Init 6 30000 in
+      let selected = find_best state Init 4 in
       match selected with
       | Node(_, Fly (f, g), _) -> last_move <- Fly (f, g) ; f, g
       | _ -> failwith "no fly found"
     method capture state =
       end_of_turn state; (* unrolled later *)
-      let selected = find_best state last_move 4 10000 in
+      let selected = find_best state last_move 4 in
       match selected with
       | Node(_, Capture i, _) -> last_move <- Capture i ; i
       | _ -> failwith "no capture found"