diff --git a/compil.sh b/compil.sh index e4b88a4..a5fbb7d 100644 --- a/compil.sh +++ b/compil.sh @@ -1 +1 @@ -ocamlc main.ml -o bin/main \ No newline at end of file +ocamlc main.ml -o main \ No newline at end of file diff --git a/entrees.txt b/entrees.txt new file mode 100644 index 0000000..b2c3b5d --- /dev/null +++ b/entrees.txt @@ -0,0 +1,22 @@ +11.0 +3 +13 21 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 3 3 2 2 2 2 2 0 2 2 0 2 2 2 2 2 2 5 5 1 +1 3 1 2 1 2 1 2 1 0 1 2 1 2 1 0 1 2 1 5 1 +1 0 2 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 0 2 1 +1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 +1 2 0 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 1 +1 2 1 2 1 2 1 0 1 2 1 2 1 2 1 2 1 2 1 2 1 +1 2 2 2 0 0 2 2 2 0 2 2 2 2 2 2 2 2 2 2 1 +1 2 1 2 1 2 1 0 1 2 1 2 1 2 1 2 1 2 1 2 1 +1 2 2 2 2 2 2 2 2 2 2 0 2 0 2 2 0 2 0 2 1 +1 0 1 2 1 0 1 2 1 0 1 2 1 2 1 2 1 2 1 0 1 +1 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 +11 19 1 11.5 +2 +11 19 1 0 1 1 0 0 +11 1 3 0 1 1 0 0 +0 diff --git a/exec.sh b/exec.sh index c04a152..eba9c6e 100644 --- a/exec.sh +++ b/exec.sh @@ -1,2 +1,2 @@ -ocamlc main.ml -o bin/main -./bin/main \ No newline at end of file +chmod u+x main.ml +./main.ml \ No newline at end of file diff --git a/iachallenge2024_bomberman_tkinter.py b/iachallenge2024_bomberman_tkinter.py index 40d031e..5341da7 100644 --- a/iachallenge2024_bomberman_tkinter.py +++ b/iachallenge2024_bomberman_tkinter.py @@ -379,4 +379,4 @@ def simulation(strategies): return from importlib import import_module -simulation(["./patient.py", "./aleatoire.py","./patient.py", "./aleatoire.py"]) +simulation(["./main.ml", "./main.ml","./main.ml", "./main.ml"]) diff --git a/input_test.txt b/input_test.txt index 1dd06c7..069c595 100644 --- a/input_test.txt +++ b/input_test.txt @@ -1,19 +1,19 @@ 3.7 0 7 11 -2 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 2 -0 0 0 0 0 0 0 0 0 0 0 -3 3 3 0 0 0 0 0 4 4 0 -0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 3 3 0 0 +0 0 2 2 2 2 2 2 2 0 0 +0 1 2 1 2 1 2 1 2 1 0 +2 2 2 2 2 2 2 0 2 2 2 +2 1 0 1 2 1 2 1 2 1 0 +2 2 2 2 2 2 2 2 2 2 2 +0 1 2 1 2 1 2 1 0 1 0 +0 0 2 2 2 2 2 2 2 0 0 3 3 2 4 4.1 -4 4 2 4.3 +0 1 2 3.9 8 6 3 5.5 5 -2 6 0 0 2 4 5 3 +1 0 0 0 2 4 5 3 2 0 1 4 3 2 2 2 10 5 2 0 2 3 2 3 5 5 3 5 1 10 2 3 diff --git a/bin/main b/main similarity index 91% rename from bin/main rename to main index 4387b05..2392f9e 100755 Binary files a/bin/main and b/main differ diff --git a/main.cmi b/main.cmi index bab3cd8..1d5d113 100644 Binary files a/main.cmi and b/main.cmi differ diff --git a/main.cmo b/main.cmo deleted file mode 100644 index ae6037c..0000000 Binary files a/main.cmo and /dev/null differ diff --git a/main.ml b/main.ml old mode 100644 new mode 100755 index a3c775f..3155149 --- a/main.ml +++ b/main.ml @@ -1,7 +1,9 @@ +#! /home/alexandre/.opam/myswitch/bin/ocaml (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) -let debug_all = true ;; +let debug_all = false ;; +let debug_data = false ;; let fatal_time = 1.0 ;; let explosion_time = 1.0 ;; @@ -178,6 +180,28 @@ let print_gain_map (map : int array array) = (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) +let get_meta_info () = + let ptr = open_in "main.sav" in + match (int_of_string (input_line ptr)) with + | 0 -> current_status := EscapeDeath + | 1 -> current_status := BlowUpCrates + | 2 -> current_status := ClaimLand + | 3 -> current_status := KillPlayers + | _ -> current_status := EscapeDeath ; + close_in ptr ;; + +let set_meta_info () = + let ptr = open_out "main.sav" in + match !current_status with + | EscapeDeath -> Printf.fprintf ptr "0" + | BlowUpCrates -> Printf.fprintf ptr "1" + | ClaimLand -> Printf.fprintf ptr "2" + | KillPlayers -> Printf.fprintf ptr "3" ; + close_out ptr ;; + +(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) +(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) + let int_of_string (str : string) = String.fold_right (fun ch acc -> let cd = Char.code ch in if cd >= 48 || cd <= 57 then 10*acc + cd - 48 else failwith "not an integer\n") str 0 ;; @@ -560,32 +584,40 @@ let move_explore (gd: game_data) (dgs : danger array array) = result in - (* check if there's a crate next to the player, and if upon placing a bomb it won't softlock the player *) + (* check if there's a crate next to the player, and if upon placing a bomb it won't softlock the player, and if you can place a bomb *) if is_valid (cxi+1) (cyi) lines cols && gd.laby.(cxi+1).(cyi) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at South *) - current_status := EscapeDeath ; - action := 1; - if debug_all then Printf.printf "Fire in the hole!\n" ; + if gd.players.(pid).nbomb_atonce > 0 then begin + current_status := EscapeDeath ; + action := 1; + if debug_all then Printf.printf "Fire in the hole!\n" ; + end; raise (ReturnInt 4) ; end; if is_valid (cxi-1) (cyi) lines cols && gd.laby.(cxi-1).(cyi) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at North *) - current_status := EscapeDeath ; - action := 1; - if debug_all then Printf.printf "Fire in the hole!\n" ; + if gd.players.(pid).nbomb_atonce > 0 then begin + current_status := EscapeDeath ; + action := 1; + if debug_all then Printf.printf "Fire in the hole!\n" ; + end; raise (ReturnInt 4) ; end; if is_valid (cxi) (cyi+1) lines cols && gd.laby.(cxi).(cyi+1) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at East *) - current_status := EscapeDeath ; - action := 1; - if debug_all then Printf.printf "Fire in the hole!\n" ; + if gd.players.(pid).nbomb_atonce > 0 then begin + current_status := EscapeDeath ; + action := 1; + if debug_all then Printf.printf "Fire in the hole!\n" ; + end; raise (ReturnInt 4) ; end; if is_valid (cxi) (cyi-1) lines cols && gd.laby.(cxi).(cyi-1) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at West *) - current_status := EscapeDeath ; - action := 1; - if debug_all then Printf.printf "Fire in the hole!\n" ; + if gd.players.(pid).nbomb_atonce > 0 then begin + current_status := EscapeDeath ; + action := 1; + if debug_all then Printf.printf "Fire in the hole!\n" ; + end; raise (ReturnInt 4) ; end; @@ -599,14 +631,45 @@ let move_explore (gd: game_data) (dgs : danger array array) = (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) +let update_strat (gd : game_data) (dgs : danger array array) = match dgs.(gd.players.(gd.player_id).xy.x).(gd.players.(gd.player_id).xy.y) with + | Safe -> () + | Danger k -> () + | Fatal k -> (* should not happen *) current_status := EscapeDeath + | Blocked -> failwith "did you just suffocate the player ?" ;; + +(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) +(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) + +get_meta_info () ;; + let game_d = parse_input "input_test.txt" ;; let dangers = evaluate_dangers game_d ;; let gains = cell_values game_d ;; -print_game_data game_d ;; -print_danger_levels dangers ;; -print_gain_map gains ;; +if debug_data then begin + print_game_data game_d ; + print_danger_levels dangers ; + print_gain_map gains ; +end ;; -Printf.printf "move at\n";; -print_direction (move_explore game_d dangers) ;; -Printf.printf "\n" ;; \ No newline at end of file +update_strat game_d dangers ;; + +let main_actions () = match !current_status with + | EscapeDeath -> + Printf.printf "%d " (move_safe game_d dangers) + | BlowUpCrates -> + if dangers.(game_d.players.(game_d.player_id).xy.x).(game_d.players.(game_d.player_id).xy.y) = Safe then + Printf.printf "%d " (move_explore game_d dangers) + else begin + current_status := EscapeDeath ; + Printf.printf "%d " (move_safe game_d dangers) + end + | ClaimLand -> + () + | KillPlayers -> + () ;; + +main_actions () ; +Printf.printf "%d" !action ; + +set_meta_info () ;; \ No newline at end of file diff --git a/main.sav b/main.sav new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/main.sav @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/sortie.txt b/sortie.txt new file mode 100644 index 0000000..7cc0f37 --- /dev/null +++ b/sortie.txt @@ -0,0 +1 @@ +4 0 \ No newline at end of file