fixed gain map being incorrect with walls + added ignorePlayers check for bfs

This commit is contained in:
Alexandre 2024-12-29 12:26:50 +01:00
parent 4d1fda4738
commit f555842ffc
9 changed files with 80 additions and 51 deletions

BIN
again

Binary file not shown.

BIN
again.cmi

Binary file not shown.

BIN
again.cmx

Binary file not shown.

View File

@ -241,6 +241,11 @@ let set_meta_info (pid : int) =
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
let print_integer_aligned (n : int) (dmax : int) =
let size = 1+ln_b 10 n in
Printf.fprintf stderr "%d" n ;
Printf.fprintf stderr "%s" (String.make (dmax-size+1) ' ') ;;
let int_of_string (str : string) = let int_of_string (str : string) =
String.fold_left (fun acc ch -> let cd = Char.code ch in if cd >= 48 || cd <= 57 then 10*acc + cd - 48 else failwith "not an integer\n") 0 str ;; String.fold_left (fun acc ch -> let cd = Char.code ch in if cd >= 48 || cd <= 57 then 10*acc + cd - 48 else failwith "not an integer\n") 0 str ;;
@ -432,7 +437,7 @@ let build_danger_map (gd : game_data) =
done; done;
res ;; res ;;
let generate_gain_map (gd : game_data) = let generate_gain_map (gd : game_data) (dgs : danger_map) =
let lines = Array.length gd.laby let lines = Array.length gd.laby
and cols = Array.length gd.laby.(0) in and cols = Array.length gd.laby.(0) in
let bsize = gd.players.(gd.player_id).bomb_radius in let bsize = gd.players.(gd.player_id).bomb_radius in
@ -441,6 +446,7 @@ let generate_gain_map (gd : game_data) =
(* aim towards center by adding a bonus *) (* aim towards center by adding a bonus *)
for i = 0 to lines -1 do for i = 0 to lines -1 do
for j = 0 to cols -1 do for j = 0 to cols -1 do
if (gd.laby.(i).(j) >= 3) || gd.laby.(i).(j) = 0 then
res.(i).(j) <- res.(i).(j) + (min (min (i) (lines -1-i)) (min (j) (cols -1-j))) ; res.(i).(j) <- res.(i).(j) + (min (min (i) (lines -1-i)) (min (j) (cols -1-j))) ;
done done
done ; done ;
@ -449,18 +455,24 @@ let generate_gain_map (gd : game_data) =
for l = 0 to lines -1 do for l = 0 to lines -1 do
for c = 0 to cols -1 do for c = 0 to cols -1 do
if (gd.laby.(l).(c) >= 3) || gd.laby.(l).(c) = 0 then begin if (gd.laby.(l).(c) >= 3) || gd.laby.(l).(c) = 0 then begin
let halt = ref false in
for dir = 0 to 3 do for dir = 0 to 3 do
for w = 0 to bsize do for w = 0 to bsize do
if (w > 0) || dir = 0 then begin if dir = 0 || w > 0 then begin
let nx = l + w * (fst order.(dir)) let nx = l + w * (fst order.(dir))
and ny = c + w * (snd order.(dir)) in and ny = c + w * (snd order.(dir)) in
if is_valid nx ny lines cols && gd.laby.(l).(c) <> 3+gd.player_id then begin if is_valid nx ny lines cols then begin
res.(nx).(ny) <- res.(nx).(ny) + 1; if gd.laby.(nx).(ny) = 1 || gd.laby.(nx).(ny) = 2 || Array.exists (fun (b : bomb) -> b.xy.x = nx && b.xy.y = ny) gd.bombs then
if (gd.laby.(l).(c) >= 3) then halt := true
res.(nx).(ny) <- res.(nx).(ny) + 1; else if gd.laby.(nx).(ny) <> 3+gd.player_id then begin
res.(l).(c) <- res.(l).(c) +1 ;
if gd.laby.(nx).(ny) <> 0 then
res.(l).(c) <- res.(l).(c) +1 ;
end end
end end
done end
done ;
halt := false ;
done done
end end
done done
@ -676,14 +688,14 @@ let reverse_simulate_bomb (dgs : danger_map) (save : (int * int, float) Hashtbl.
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 (* bombs *) (List.fold_left (* bombs *)
(fun acc curtime -> (fun acc expl_time ->
acc || (t >= curtime && t <= curtime +. dt) acc || (t >= expl_time && t <= expl_time +. dt)
) )
false false
dgs.explosionTimes.(x).(y) dgs.explosionTimes.(x).(y)
) || (List.fold_left (* player-related bombs (only if in range of another bomb) *) ) || (List.fold_left (* player-related bombs (only if in range of another bomb) *)
(fun acc curtime -> (fun acc expl_time ->
acc || (t >= curtime && t <= curtime +. dt) acc || (t >= expl_time && t <= expl_time +. dt)
) )
false false
dgs.playersTimes.(x).(y) dgs.playersTimes.(x).(y)
@ -691,8 +703,8 @@ let is_dead (dgs : danger_map) (x : int) (y : int) (t : float) (dt : float) =
let is_dead_2 (dgs : danger_map) (x : int) (y : int) (t : float) (dt : float) = let is_dead_2 (dgs : danger_map) (x : int) (y : int) (t : float) (dt : float) =
(List.fold_left (List.fold_left
(fun acc curtime -> (fun acc expl_time ->
acc || (t >= curtime && t <= curtime +. dt) acc || (t >= expl_time && t <= expl_time +. dt)
) )
false false
dgs.explosionTimes.(x).(y) dgs.explosionTimes.(x).(y)
@ -923,6 +935,12 @@ let rec move_crate (gd : game_data) (dgs : danger_map) =
if logg then Printf.fprintf stderr "searching 2 Done (%d) ...\n" rescr2 ; if logg then Printf.fprintf stderr "searching 2 Done (%d) ...\n" rescr2 ;
if !success then if !success then
rescr2 rescr2
else begin
if logg then Printf.fprintf stderr "ignoring players...\n" ;
let rescrip2 = bfs_for_crate ~return_ok:success gd dgs cxi cyi (gd.dt -. !remaining_dash *. interval) false false false 0 true 80 in
if logg then Printf.fprintf stderr "ignoring players Done (%d)...\n" rescrip2 ;
if !success then
rescrip2
else begin else begin
if logg then Printf.fprintf stderr "Needs dash lmao\n"; if logg then Printf.fprintf stderr "Needs dash lmao\n";
if !remaining_dash <> 0. && gd.players.(pid).ndash > 0 then begin if !remaining_dash <> 0. && gd.players.(pid).ndash > 0 then begin
@ -937,6 +955,7 @@ let rec move_crate (gd : game_data) (dgs : danger_map) =
end end
end end
end end
end
with with
| ReturnInt k -> k ;; | ReturnInt k -> k ;;
@ -1111,10 +1130,20 @@ let __start = Unix.gettimeofday() ;;
let game_map = parse_input "entrees.txt" ;; let game_map = parse_input "entrees.txt" ;;
if debug_all then print_game_data game_map ;; if debug_all then print_game_data game_map ;;
let danger_data = build_danger_map game_map ;; let danger_data = build_danger_map game_map ;;
let gain_map = generate_gain_map game_map ;; let gain_map = generate_gain_map game_map danger_data ;;
get_rem_dash ("again"^(string_of_int game_map.player_id)^".sav") ;; get_rem_dash ("again"^(string_of_int game_map.player_id)^".sav") ;;
Printf.fprintf stderr "\n" ;;
if game_map.player_id = 4 then begin
for l = 0 to Array.length gain_map -1 do
for c = 0 to Array.length gain_map.(l) -1 do
print_integer_aligned gain_map.(l).(c) 3
done;
Printf.fprintf stderr "\n"
done
end ;;
(*Printf.fprintf stderr "\n" ;; (*Printf.fprintf stderr "\n" ;;
print_dangers danger_data ;;*) print_dangers danger_data ;;*)

BIN
again.o

Binary file not shown.

View File

@ -1,29 +1,29 @@
102.4000000000002 182.76300000000106
1 3
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 6 6 6 0 2 2 2 2 2 0 5 5 5 5 1 1 3 3 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 1
1 3 1 3 1 6 1 3 1 2 1 2 1 2 1 0 1 5 1 5 1 1 3 1 3 1 3 1 6 1 3 1 6 1 6 1 6 1 5 1 5 1
1 3 3 3 6 6 6 3 6 0 2 2 2 0 5 5 5 5 5 5 1 1 3 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 1
1 3 1 6 1 6 1 6 1 2 1 2 1 2 1 5 1 5 1 5 1 1 3 1 3 1 6 1 3 1 3 1 6 1 6 1 6 1 3 1 5 1
1 6 6 6 6 6 6 6 0 2 2 2 2 2 0 5 5 5 0 0 1 1 3 6 6 6 4 4 4 4 4 4 4 4 4 4 4 6 6 6 4 1
1 0 1 6 1 6 1 0 1 2 1 2 1 2 1 0 1 4 1 0 1 1 0 1 3 1 5 1 4 1 3 1 6 1 6 1 6 1 3 1 4 1
1 6 6 6 6 6 0 2 2 2 2 2 2 2 2 0 4 4 4 4 1 1 6 6 3 3 5 3 3 3 3 3 3 3 3 3 6 3 3 3 3 1
1 6 1 6 1 0 1 2 1 2 1 2 1 2 1 0 1 4 1 4 1 1 6 1 3 1 5 1 4 1 3 1 6 1 6 1 6 1 3 1 4 1
1 6 6 6 6 6 6 0 2 2 2 2 2 0 4 4 4 4 4 4 1 1 6 6 5 5 5 5 5 5 5 3 6 3 6 3 6 3 3 3 3 1
1 6 1 6 1 2 1 2 1 2 1 2 1 2 1 4 1 4 1 4 1 1 6 1 3 1 6 1 4 1 3 1 6 1 3 1 6 1 3 1 4 1
1 6 6 6 6 6 6 0 2 2 2 2 2 0 4 4 4 4 4 4 1 1 6 6 3 3 3 3 4 4 4 3 6 3 4 3 3 3 3 3 4 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
5
7 15 3 184.53200000000103
9 10 1 185.70000000000073
6 11 4 186.45991999999896
9 16 3 186.71900000000107
4 9 8 186.80500000000103
4 4
11 13 1 102.50000000000017 6 13 0 5 1 4 4 5
3 9 4 105.11000000000014 11 17 1 3 0 3 2 1
7 15 2 106.5 9 11 2 1 7 1 4 2
3 7 4 106.73000000000015 6 9 3 3 1 8 2 1
3 1
9 15 1 1 4 1 2 5 6 1 0
9 15 2 0 1 2 3 0
5 7 3 2 3 4 0 2
3
11 7 0
9 7 1
3 13 4

View File

@ -450,7 +450,7 @@ def execute_evenement(evenements, evenement, plateau, plateauCouleur, bombes, jo
indiceJoueur = trouve_objet(i,j,joueurs) indiceJoueur = trouve_objet(i,j,joueurs)
while indiceJoueur != None: while indiceJoueur != None:
joueurs[indiceJoueur] = None joueurs[indiceJoueur] = None
print("\n\nDEATH (at time =", evenement[0], "):", indiceJoueur, "\n\n") print("\n--------------------------------------------------------------------------------------------------------\n\nDEATH (at time =", evenement[0], "):", indiceJoueur, "\n\n--------------------------------------------------------------------------------------------------------\n")
#assert(false) #assert(false)
indiceJoueur = trouve_objet(i,j,joueurs) indiceJoueur = trouve_objet(i,j,joueurs)

View File

@ -1 +1 @@
0 1

View File

@ -1 +1 @@
3 0 2 0