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1 4 1 4 1 5 1 4 1 4 1 +1 6 6 6 6 6 6 6 0 3 4 4 4 4 4 4 4 4 4 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -3 -4 17 3 59.5 -9 17 1 60.5 -5 4 2 62.400000000000006 -4 -6 3 0 2 2 2 0 1 -8 19 1 0 1 1 1 0 -4 19 2 0 2 3 0 0 -5 3 3 0 2 4 0 1 +2 +6 11 2 185.56136399999963 +9 13 4 186.85000000000056 +2 +8 13 1 2 3 4 1 3 +7 15 2 2 3 2 1 1 1 -6 19 2 +2 9 1 diff --git a/iachallenge2024_bomberman_tkinter.py b/iachallenge2024_bomberman_tkinter.py index a2f5c5d..155b976 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(["./main", "./main","./main", "./main"]) +simulation(["./main", "./main", "./main", "./main"]) diff --git a/main b/main index fdfbe45..ef1fc65 100755 Binary files a/main and b/main differ diff --git a/main.cmi b/main.cmi index 30b29f2..bd5ae92 100644 Binary files a/main.cmi and b/main.cmi differ diff --git a/main.cmo b/main.cmo index 8003efc..5b66a00 100644 Binary files a/main.cmo and b/main.cmo differ diff --git a/main.ml b/main.ml index dd079aa..c39c49b 100755 --- a/main.ml +++ b/main.ml @@ -476,6 +476,53 @@ let has_a_safe_path_origin (cx0 : int) (cy0 : int) (lines : int) (cols : int) (s with | ReturnInt b -> b ;; +let has_a_safe_path_origin_2 (cx0 : int) (cy0 : int) (lines : int) (cols : int) (simt : float) (interval : float) (gd : game_data) (dgs : danger array array) (white_dgs : danger array) (white_gd : int array) (black_dgs : danger array) (black_gd : int array) (maxdepth : int) = + (* + core function + performs a BFS starting at (cx0, cy0), avoiding anything in blacklists and halting upon stepping on a whitelisted element + *) + let visited = Hashtbl.create 100 in + let q = Queue.create () in + + Hashtbl.add visited (cx0, cy0) 1 ; + + + Queue.add (cx0+1, cy0, simt +. interval, 2) q ; + Queue.add (cx0-1, cy0, simt +. interval, 0) q ; + Queue.add (cx0, cy0+1, simt +. interval, 1) q ; + Queue.add (cx0, cy0-1, simt +. interval, 3) q ; + + if debug_all then Printf.fprintf stderr "[escape] Attempt 1/1...\n" ; + try + while not (Queue.is_empty q) do + let (cx, cy, cur_t, direct) = Queue.pop q in + + if (Hashtbl.find_opt visited (cx, cy) = None && is_valid cx cy lines cols && level_of_danger dgs.(cx).(cy) >= cur_t) then begin + Hashtbl.add visited (cx, cy) 1 ; + if cur_t > simt +. (float_of_int maxdepth) *. interval then (* too deep *) + raise (ReturnInt 4) + else if Array.mem dgs.(cx).(cy) white_dgs then + raise (ReturnInt direct) + else if Array.mem gd.laby.(cx).(cy) white_gd then + raise (ReturnInt direct) + else if Array.mem dgs.(cx).(cy) black_dgs then + () + else if Array.mem gd.laby.(cx).(cy) black_gd then + () + else begin + for dir = 0 to 3 do + let newx = cx + fst order.(dir) + and newy = cy + snd order.(dir) + and newt = cur_t +. interval in + Queue.add (newx, newy, newt, direct) q + done + end + end + done; + 4 + with + | ReturnInt b -> b ;; + (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) @@ -504,14 +551,15 @@ let move_safe (gd : game_data) (dgs : danger array array) = end; (*let result = has_a_safe_path (cx) (cy) gd.dt in*) - let result = has_a_safe_path_origin cx cy lines cols gd.dt interval gd dgs [|Bonus|] [||] [|Blocked|] [||] 20 in + let result = has_a_safe_path_origin_2 cx cy lines cols gd.dt interval gd dgs [|Bonus|] [||] [|Blocked|] [||] 20 in if result <> 4 then result else begin - let result2 = has_a_safe_path_origin cx cy lines cols gd.dt interval gd dgs [|Safe|] [||] [|Blocked|] [||] 80 in + let result2 = has_a_safe_path_origin_2 cx cy lines cols gd.dt interval gd dgs [|Safe|] [||] [|Blocked|] [||] 80 in if result2 <> 4 then result2 else begin (* you're probably dead if the code reaches here... *) if debug_all then Printf.fprintf stderr "[escape] Attempt F...\n"; + Printf.fprintf stderr "well shit\n" ; 4 end end @@ -521,6 +569,34 @@ let move_safe (gd : game_data) (dgs : danger array array) = (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) +let is_a_crate_nearby (gd : game_data) (dgs : danger array array) = + let pid = gd.player_id + and lines = Array.length gd.laby + and cols = Array.length gd.laby.(0) in + try + let halt = ref false in + let res = ref false in + for dir = 0 to 3 do + for o = 1 to gd.players.(pid).bomb_radius do + if not !halt then begin + let nx = gd.players.(pid).xy.x + o * (fst order.(dir)) + and ny = gd.players.(pid).xy.y + o * (snd order.(dir)) in + if is_valid nx ny lines cols then begin + if gd.laby.(nx).(ny) = 2 then + res := true + else if gd.laby.(nx).(ny) = 1 then + halt := true + else if dgs.(nx).(ny) = Bonus then + raise (ReturnBool false) + end + end + done; + halt := false ; + done; + !res + with + | ReturnBool b -> b ;; + let move_explore (gd: game_data) (dgs : danger array array) = (* destroy crates *) let pid = gd.player_id in @@ -534,13 +610,13 @@ let move_explore (gd: game_data) (dgs : danger array array) = let (cxi, cyi) = (gd.players.(pid).xy.x, gd.players.(pid).xy.y) in let move_with_caution (exit : bool) = - let res = has_a_safe_path_origin cxi cyi lines cols gd.dt interval gd dgs [|Bonus|] [||] [|Blocked|] [||] 5 in + let res = has_a_safe_path_origin_2 cxi cyi lines cols gd.dt interval gd dgs [|Bonus|] [||] [|Blocked|] [||] 5 in if res <> 4 then begin if debug_all then Printf.fprintf stderr "[crates] success 1/2!\n" ; res end else begin - let res2 = has_a_safe_path_origin cxi cyi lines cols gd.dt interval gd dgs [||] [|2|] [|Blocked|] [||] 80 in + let res2 = has_a_safe_path_origin_2 cxi cyi lines cols gd.dt interval gd dgs [||] [|2|] [|Blocked|] [||] 80 in if res2 <> 4 then begin if debug_all then Printf.fprintf stderr "[crates] success 2/2!\n" ; res2 @@ -560,7 +636,7 @@ let move_explore (gd: game_data) (dgs : danger array array) = let saved_dgs = Hashtbl.create (4 * (bsize +1)) in for dir = 0 to 3 do for w = 0 to bsize do - Hashtbl.add bomb_hash (bx + w*(fst order.(dir)), by + w*(snd order.(dir))) (Danger 5.5) ; + Hashtbl.add bomb_hash (bx + w*(fst order.(dir)), by + w*(snd order.(dir))) (Danger (gd.dt +. 5.5)) ; done done; Hashtbl.iter @@ -577,40 +653,13 @@ let move_explore (gd: game_data) (dgs : danger array array) = in (* 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 *) - if gd.players.(pid).nbomb_atonce > 0 then begin + if is_a_crate_nearby gd dgs && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at South *) + if dgs.(cxi).(cyi) = Safe && gd.players.(pid).nbomb_atonce > 0 then begin current_status := EscapeDeath ; action := 1; if debug_all then Printf.fprintf stderr "Fire in the hole!\n" ; + raise (ReturnInt 4) ; 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 *) - if gd.players.(pid).nbomb_atonce > 0 then begin - current_status := EscapeDeath ; - action := 1; - if debug_all then Printf.fprintf stderr "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 *) - if gd.players.(pid).nbomb_atonce > 0 then begin - current_status := EscapeDeath ; - action := 1; - if debug_all then Printf.fprintf stderr "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 *) - if gd.players.(pid).nbomb_atonce > 0 then begin - current_status := EscapeDeath ; - action := 1; - if debug_all then Printf.fprintf stderr "Fire in the hole!\n" ; - end; - raise (ReturnInt 4) ; end; if debug_all then Printf.fprintf stderr "[crates] Cannot bomb now, searching for a crate...\n"; @@ -625,7 +674,7 @@ 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 -> () + | Danger k -> current_status := EscapeDeath | Bonus -> () | Fatal k -> (* should not happen *) current_status := EscapeDeath | Blocked -> failwith "did you just suffocate the player ?" ;; diff --git a/main_0.sav b/main_0.sav index 56a6051..c227083 100644 --- a/main_0.sav +++ b/main_0.sav @@ -1 +1 @@ -1 \ No newline at end of file +0 \ No newline at end of file diff --git a/main_1.sav b/main_1.sav index 56a6051..c227083 100644 --- a/main_1.sav +++ b/main_1.sav @@ -1 +1 @@ -1 \ No newline at end of file +0 \ No newline at end of file diff --git a/main_3.sav b/main_3.sav index 56a6051..c227083 100644 --- a/main_3.sav +++ b/main_3.sav @@ -1 +1 @@ -1 \ No newline at end of file +0 \ No newline at end of file diff --git a/sortie.txt b/sortie.txt index 7cc0f37..e69de29 100644 --- a/sortie.txt +++ b/sortie.txt @@ -1 +0,0 @@ -4 0 \ No newline at end of file