minor-ish changes to BFS conditions

This commit is contained in:
Alexandre 2024-11-08 22:24:33 +01:00
parent 3486ed84c1
commit 59292ef41b
5 changed files with 11 additions and 11 deletions

BIN
bin/main

Binary file not shown.

View File

@ -13,7 +13,7 @@
4 4 2 4.3
8 6 3 5.5
5
3 0 0 0 2 4 5 3
2 6 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

BIN
main.cmi

Binary file not shown.

BIN
main.cmo

Binary file not shown.

20
main.ml
View File

@ -3,7 +3,7 @@
let debug_all = true ;;
let fatal_time = 1.0 ;;
let explosion_time = 0.5 ;;
let explosion_time = 1.0 ;;
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
@ -160,8 +160,8 @@ let print_danger_levels (map : danger array array) =
match map.(l).(c) with
| Blocked -> Printf.printf "@ "
| Safe -> Printf.printf ". "
| Danger _ -> Printf.printf "! "
| Fatal _ -> Printf.printf "X "
| Danger x -> Printf.printf "! "
| Fatal x -> Printf.printf "X "
done;
Printf.printf "\n"
done ;;
@ -348,7 +348,7 @@ let cell_values (gd : game_data) =
for ln = 0 to lines -1 do
for cl = 0 to cols -1 do
if gd.laby.(ln).(cl) >= 3 && gd.laby.(ln).(cl) <> 3 + gd.player_id then begin
if (gd.laby.(ln).(cl) >= 3 && gd.laby.(ln).(cl) <> 3 + gd.player_id) || gd.laby.(ln).(cl) = 0 then begin
(* use a similar method than danger for bombs *)
let halt = ref false in
@ -481,19 +481,19 @@ let move_explore (gd: game_data) (dgs : danger array array) =
Hashtbl.add visited (cx0, cy0) 1 ;
if is_valid (cx0+1) (cy0) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0+1).(cy0)) && (simt +. interval) < (level_of_danger dgs.(cx0+1).(cy0)) +. explosion_time) then begin (* South *)
if debug_all then Printf.printf "[escape] +South\n" ;
if debug_all then Printf.printf "[crates] +South\n" ;
Queue.add (cx0+1, cy0, simt +. interval, 2) q ;
end;
if is_valid (cx0-1) (cy0) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0-1).(cy0)) && (simt +. interval) < (level_of_danger dgs.(cx0-1).(cy0)) +. explosion_time) then begin (* North *)
if debug_all then Printf.printf "[escape] +North\n" ;
if debug_all then Printf.printf "[crates] +North\n" ;
Queue.add (cx0-1, cy0, simt +. interval, 0) q ;
end;
if is_valid (cx0) (cy0+1) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0).(cy0+1)) && (simt +. interval) < (level_of_danger dgs.(cx0).(cy0+1)) +. explosion_time) then begin (* East *)
if debug_all then Printf.printf "[escape] +East\n" ;
if debug_all then Printf.printf "[crates] +East\n" ;
Queue.add (cx0, cy0+1, simt +. interval, 1) q ;
end;
if is_valid (cx0) (cy0-1) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0).(cy0-1)) && (simt +. interval) < (level_of_danger dgs.(cx0).(cy0-1)) +. explosion_time) then begin (* West *)
if debug_all then Printf.printf "[escape] +West\n" ;
if debug_all then Printf.printf "[crates] +West\n" ;
Queue.add (cx0, cy0-1, simt +. interval, 3) q ;
end;
@ -508,7 +508,7 @@ let move_explore (gd: game_data) (dgs : danger array array) =
raise (ReturnInt direct)
else if dgs.(cx).(cy) = Blocked then
()
else begin (* either danger or fatal *)
else begin (* we need to go deeper *)
let dang_time = level_of_danger dgs.(cx).(cy) in
for dir = 0 to 3 do
let newx = cx + fst order.(dir)
@ -560,7 +560,7 @@ 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 block the player *)
(* check if there's a crate next to the player, and if upon placing a bomb it won't softlock the player *)
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;