Commits

Anonymous committed 4be7d6e

args

  • Participants
  • Parent commits ed10fd7

Comments (0)

Files changed (2)

mills/mills.ml

-let human = object
-	method put state =
-    Printf.printf "%sput: %!" (Mill.to_string state);    
-    read_int ()
-	method move state = 
-    Printf.printf "%smove from: %!" (Mill.to_string state);    
-    let from = read_int () in
-    Printf.printf "move to: %!";    
-    let goal = read_int () in     
-    from, goal
-	method fly state = 
-    Printf.printf "%sfly from: %!" (Mill.to_string state);
-    let from = read_int () in
-    Printf.printf "fly to: %!";    
-    let goal = read_int () in     
-    from, goal
-	method capture state =
-    Printf.printf "%scapture: %!" (Mill.to_string state);    
-    read_int ()
-end
-
-let do_turn state player = 
-  if Mill.can_put state then begin 
-    let goal = player#put state in
-    Mill.put state goal;
-    if Mill.in_mill state goal then Mill.capture state (player#capture state)
-  end
-  else if Mill.can_fly state then begin
-    let from, goal = player#fly state in
-    Mill.fly state from goal;
-    if Mill.in_mill state goal then Mill.capture state (player#capture state)
-  end
-  else begin
-    let from, goal = player#move state in
-    Mill.move state from goal;
-    if Mill.in_mill state goal then Mill.capture state (player#capture state)
-  end
-
-let engine p1 p2 =
-  let next p = if p = p1 then p2 else p1 in
-  let loop state =
-    let p = ref p1 in
-    let s = ref state in
-    while not (Mill.game_ended !s) do
-      let state' = Mill.copy !s in
-	    begin
-        try
-          do_turn state' !p;
-          Mill.end_of_turn state';
-          s := state';
-          p := next !p
-	      with ex -> 
-          if !p <> human then raise ex 
-      end;
-    done;
-    Printf.printf "end\n"
-  in
-  loop (Mill.make ())
-
-  
-let debug p1 p2 =
-  let next p = if p = p1 then p2 else p1 in
-  let loop state =
-    let p = ref p1 in
-    let s = ref state in
-    while Mill.get_turn !s < 6 do
-      let state' = Mill.copy !s in
-	    begin
-          do_turn state' !p;
-          Mill.end_of_turn state';
-          s := state';
-          p := next !p
-      end;
-    done;
-    Printf.printf "end\n"
-  in
-  loop (Mill.make ())      
-
-let () = 
-  engine human Ai_montecarlo.player
-  

mills/sdlmills.ml

   Sdlvideo.set_video_mode Image.background_size Image.background_size []
 
 let _ =
+  let white = ref Human.player in
+  let black = ref Ai_alphabeta.player in
+  let players = ["human";"montecarlo";"minimax";"alphabeta";"random"] in
+  let get_player = function
+    | "human" -> Human.player
+    | "montecarlo" -> Ai_montecarlo.player
+    | "minimax" -> Ai_minimax.player
+    | "alphabeta" -> Ai_alphabeta.player
+    | "random" -> Ai_random.player
+    | _ -> raise (Arg.Bad "unkown player")
+  in
+  let set_white s = white := get_player s in
+  let set_black s = black := get_player s in
+  let args =
+    let open Arg in
+    ("-white", Symbol (players, set_white), "player who will play white") ::
+    ("-black", Symbol (players, set_black), "player who will play white") ::
+    []
+  in
+  Arg.parse args ignore "usage";    
+  
   Random.self_init ();
   let screen = init_sdl () in
   Image.load screen;
   Sfx.load ();
   try
-    mainloop Ai_minimax.player Ai_alphabeta.player;
+    mainloop !white !black;
     Sdltimer.delay 1500;
   with Exit -> ()