fix to crate detection + fix to dead end map creation

This commit is contained in:
Alexandre 2024-12-03 21:56:58 +01:00
parent 3e9adf8e2f
commit 4169e93b65
7 changed files with 65 additions and 39 deletions

BIN
again

Binary file not shown.

BIN
again.cmi

Binary file not shown.

BIN
again.cmx

Binary file not shown.

View File

@ -470,7 +470,7 @@ let simulate_bomb (dgs : danger_map) (b : bomb) =
done; done;
saved_data ;; saved_data ;;
let simulate_bomb_deconstruct (dgs : danger_map) (bx : int) (by : int) (bsize : int) (dtime0 : float) = let simulate_bomb_deconstruct (gd : game_data) (dgs : danger_map) (bx : int) (by : int) (bsize : int) (dtime0 : float) =
let saved_data = Hashtbl.create 30 in let saved_data = Hashtbl.create 30 in
let dtime = min dtime0 (List.fold_left min (32760.) dgs.explosionTimes.(bx).(by)) in let dtime = min dtime0 (List.fold_left min (32760.) dgs.explosionTimes.(bx).(by)) in
let lines = Array.length dgs.explosionTimes let lines = Array.length dgs.explosionTimes
@ -487,6 +487,25 @@ let simulate_bomb_deconstruct (dgs : danger_map) (bx : int) (by : int) (bsize :
end end
done; done;
done; done;
let pid = gd.player_id in
Array.iter (fun (pl : player) ->
if pl.id <> pid then begin
let dtimep = min (gd.dt +. 5.5) (List.fold_left min (32760.) dgs.explosionTimes.(pl.xy.x).(pl.xy.y)) in
for dir = 0 to 3 do
for w = 0 to bsize do
if (w > 0 || dir = 0) then begin
let nx = pl.xy.x + w * (fst order.(dir))
and ny = pl.xy.y + w * (snd order.(dir)) in
if is_valid nx ny lines cols then begin
Hashtbl.add saved_data (nx, ny) dtimep ;
dgs.explosionTimes.(nx).(ny) <- (dtimep)::(dgs.explosionTimes.(nx).(ny))
end
end
done;
done;
end
)
gd.players ;
saved_data ;; saved_data ;;
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
@ -586,14 +605,15 @@ let generate_dead_end_map (gd : game_data) =
((x = gd.players.(pid).xy.x && y = gd.players.(pid).xy.y) || not (Array.fold_left (fun acc (b : bomb) -> acc || (b.xy.x = x && b.xy.y = y)) false gd.bombs))(*&& ((x = gd.players.(pid).xy.x && y = gd.players.(pid).xy.y) || not (Array.fold_left (fun acc (b : bomb) -> acc || (b.xy.x = x && b.xy.y = y)) false gd.bombs))(*&&
(not (Array.fold_left (fun acc (p : player) -> acc || (p.xy.x = x && p.xy.y = y && p.id <> pid)) false gd.players))*) (not (Array.fold_left (fun acc (p : player) -> acc || (p.xy.x = x && p.xy.y = y && p.id <> pid)) false gd.players))*)
then begin then begin
Hashtbl.add visited (x, y) 1 ; if not (x = gd.players.(pid).xy.x && y = gd.players.(pid).xy.y) then
Hashtbl.add visited (x, y) 1 ;
if (amt_free_adj_spaces gd x y) >= 3 || (x = gd.players.(pid).xy.x && y = gd.players.(pid).xy.y) then begin if (amt_free_adj_spaces gd x y) >= 3 || (x = gd.players.(pid).xy.x && y = gd.players.(pid).xy.y) then begin
if prev <> [] then if prev <> [] then
Hashtbl.remove visited (x, y) ; Hashtbl.remove visited (x, y) ;
List.iter (fun (cx, cy) -> res.(cx).(cy) <- 0) ((x, y)::prev) ; List.iter (fun (cx, cy) -> res.(cx).(cy) <- 0) ((x, y)::prev) ;
for dir = 0 to 3 do for dir = 0 to 3 do
if fpass || (dir + 2) mod 4 <> last_dir then (* dont backtrack *) if fpass <> 0 || (dir + 2) mod 4 <> last_dir then (* dont backtrack *)
dfs (x + fst (order.(dir))) (y + snd (order.(dir))) [] dir false dfs (x + fst (order.(dir))) (y + snd (order.(dir))) [] dir (max 0 (fpass-1))
done done
end end
else begin else begin
@ -604,7 +624,7 @@ let generate_dead_end_map (gd : game_data) =
end end
end end
in in
dfs gd.players.(pid).xy.x gd.players.(pid).xy.y [] 4 true; dfs gd.players.(pid).xy.x gd.players.(pid).xy.y [] 4 1;
(* fills remaining spaces with BFS *) (* fills remaining spaces with BFS *)
let bfs (x0 : int) (y0 : int) = let bfs (x0 : int) (y0 : int) =
@ -655,13 +675,13 @@ let reverse_simulate_bomb (dgs : danger_map) (save : (int * int, float) Hashtbl.
save ;; save ;;
let is_dead (dgs : danger_map) (x : int) (y : int) (t : float) (dt : float) = let is_dead (dgs : danger_map) (x : int) (y : int) (t : float) (dt : float) =
(List.fold_left (List.fold_left (* bombs *)
(fun acc curtime -> (fun acc curtime ->
acc || (t >= curtime && t <= curtime +. dt) acc || (t >= curtime && t <= curtime +. dt)
) )
false false
dgs.explosionTimes.(x).(y) dgs.explosionTimes.(x).(y)
) || (List.fold_left ) || (List.fold_left (* player-related bombs (only if in range of another bomb) *)
(fun acc curtime -> (fun acc curtime ->
acc || (t >= curtime && t <= curtime +. dt) acc || (t >= curtime && t <= curtime +. dt)
) )
@ -755,8 +775,10 @@ let is_a_crate_nearby (gd : game_data) (dgs : danger_map) =
let nx = gd.players.(pid).xy.x + o * (fst order.(dir)) let nx = gd.players.(pid).xy.x + o * (fst order.(dir))
and ny = gd.players.(pid).xy.y + o * (snd order.(dir)) in and ny = gd.players.(pid).xy.y + o * (snd order.(dir)) in
if is_valid nx ny lines cols then begin if is_valid nx ny lines cols then begin
if gd.laby.(nx).(ny) = 2 then if gd.laby.(nx).(ny) = 2 && not dgs.explodedCrates.(nx).(ny) then begin
res := true res := true;
halt := true
end
else if gd.laby.(nx).(ny) = 1 then else if gd.laby.(nx).(ny) = 1 then
halt := true halt := true
else if dgs.bonusMap.(nx).(ny) then else if dgs.bonusMap.(nx).(ny) then
@ -783,8 +805,10 @@ let sees_a_crate (gd : game_data) (dgs : danger_map) (x : int) (y : int) =
let nx = x + o * (fst order.(dir)) let nx = x + o * (fst order.(dir))
and ny = y + o * (snd order.(dir)) in and ny = y + o * (snd order.(dir)) in
if is_valid nx ny lines cols then begin if is_valid nx ny lines cols then begin
if gd.laby.(nx).(ny) = 2 then if gd.laby.(nx).(ny) = 2 && not dgs.explodedCrates.(nx).(ny) then begin
res := true res := true;
halt := true
end
else if gd.laby.(nx).(ny) = 1 then else if gd.laby.(nx).(ny) = 1 then
halt := true halt := true
else if dgs.bonusMap.(nx).(ny) then else if dgs.bonusMap.(nx).(ny) then
@ -886,7 +910,7 @@ let move_crate (gd : game_data) (dgs : danger_map) =
if Array.exists (fun (p : player) -> p.id <> pid && p.xy.x = cxi && p.xy.y = cyi) gd.players && (is_empty_lst dgs.explosionTimes.(cxi).(cyi)) then begin if Array.exists (fun (p : player) -> p.id <> pid && p.xy.x = cxi && p.xy.y = cyi) gd.players && (is_empty_lst dgs.explosionTimes.(cxi).(cyi)) then begin
if gd.players.(pid).bomb_to_place > 0 then begin if gd.players.(pid).bomb_to_place > 0 then begin
if logg then Printf.fprintf stderr "oh no you dont\n" ; if logg then Printf.fprintf stderr "oh no you dont\n" ;
let saved_p = simulate_bomb_deconstruct dgs cxi cyi gd.players.(pid).bomb_radius (gd.dt +. 5.5) in let saved_p = simulate_bomb_deconstruct gd dgs cxi cyi gd.players.(pid).bomb_radius (gd.dt +. 5.5) in
let bonusres_2p = bfs_for_crate gd dgs cxi cyi gd.dt false true false 0 false 5 in let bonusres_2p = bfs_for_crate gd dgs cxi cyi gd.dt false true false 0 false 5 in
if bonusres_2p <> 4 then begin if bonusres_2p <> 4 then begin
@ -903,10 +927,10 @@ let move_crate (gd : game_data) (dgs : danger_map) =
reverse_simulate_bomb dgs saved_p ; reverse_simulate_bomb dgs saved_p ;
end end
end; end;
if (is_a_crate_nearby gd dgs) && (is_empty_lst dgs.explosionTimes.(cxi).(cyi)) then begin if (is_a_crate_nearby gd dgs)(* && (is_empty_lst dgs.explosionTimes.(cxi).(cyi)) *)then begin
if gd.players.(pid).bomb_to_place > 0 then begin if gd.players.(pid).bomb_to_place > 0 then begin
if logg then Printf.fprintf stderr "trying...\n" ; if logg then Printf.fprintf stderr "trying...\n" ;
let saved = simulate_bomb_deconstruct dgs cxi cyi gd.players.(pid).bomb_radius (gd.dt +. 5.5) in let saved = simulate_bomb_deconstruct gd dgs cxi cyi gd.players.(pid).bomb_radius (gd.dt +. 5.5) in
let bonus2_x = ref 0 let bonus2_x = ref 0
and bonus2_y = ref 0 in and bonus2_y = ref 0 in
let bonusres_2 = bfs_for_crate ~return_x:bonus2_x ~return_y:bonus2_y gd dgs cxi cyi gd.dt false true false 0 false 5 in let bonusres_2 = bfs_for_crate ~return_x:bonus2_x ~return_y:bonus2_y gd dgs cxi cyi gd.dt false true false 0 false 5 in
@ -923,9 +947,6 @@ let move_crate (gd : game_data) (dgs : danger_map) =
end; end;
reverse_simulate_bomb dgs saved ; reverse_simulate_bomb dgs saved ;
end end
else begin
raise (ReturnInt 4)
end;
end; end;
if logg then Printf.fprintf stderr "bonusing...\n" ; if logg then Printf.fprintf stderr "bonusing...\n" ;
let bonus_x = ref 0 let bonus_x = ref 0
@ -989,7 +1010,7 @@ let move_land_2 (gd : game_data) (dgs : danger_map) (gns : int array array) =
(is_empty_lst dgs.explosionTimes.(cxi).(cyi)) (is_empty_lst dgs.explosionTimes.(cxi).(cyi))
then begin then begin
if logg then Printf.fprintf stderr "trying...\n" ; if logg then Printf.fprintf stderr "trying...\n" ;
let _ = simulate_bomb_deconstruct dgs cxi cyi gd.players.(pid).bomb_radius (gd.dt +. 5.5) in let _ = simulate_bomb_deconstruct gd dgs cxi cyi gd.players.(pid).bomb_radius (gd.dt +. 5.5) in
let result = goto_tile gd dgs cxi cyi x y gd.dt in let result = goto_tile gd dgs cxi cyi x y gd.dt in
if result <> 4 then begin if result <> 4 then begin
action := 1 ; action := 1 ;

BIN
again.o

Binary file not shown.

View File

@ -1,24 +1,29 @@
330.0 93.0
3 2
13 21 13 21
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 3 3 3 6 6 0 2 0 0 5 5 5 5 5 5 5 5 5 5 1 1 3 3 3 0 2 2 2 2 2 2 0 2 2 2 2 0 5 5 5 1
1 3 1 6 1 0 1 2 1 0 1 5 1 5 1 4 1 5 1 5 1 1 3 1 0 1 2 1 2 1 2 1 0 1 2 1 2 1 0 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