seek_player now anticipates bombs

This commit is contained in:
Alexandre 2025-01-06 21:04:24 +01:00
parent 8ae37b145e
commit c9b2b9f392
10 changed files with 65 additions and 29 deletions

BIN
again

Binary file not shown.

BIN
again.cmi

Binary file not shown.

BIN
again.cmx

Binary file not shown.

View File

@ -14,6 +14,7 @@ let debug_all = false ;;
let logg = false ;; let logg = false ;;
let remaining_dash = ref 0. ;; let remaining_dash = ref 0. ;;
let cd = ref 0.0 ;;
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
@ -973,7 +974,6 @@ let path_seek (gd : game_data) (dgs : danger_map) (stime : float) (x0 : int) (y0
let visited = Hashtbl.create 100 in let visited = Hashtbl.create 100 in
let q = Queue.create () in let q = Queue.create () in
let interval = Float.pow (0.9) (float_of_int gd.players.(gd.player_id).nspeed) in let interval = Float.pow (0.9) (float_of_int gd.players.(gd.player_id).nspeed) in
let pid = gd.player_id in
Queue.add (x0, y0, stime, 4, 0) q ; Queue.add (x0, y0, stime, 4, 0) q ;
@ -1072,6 +1072,14 @@ let direction_after_trap (gd : game_data) (dgs : danger_map) (x0 : int) (y0 : in
else else
raise (ReturnBool false) ;; raise (ReturnBool false) ;;
let remove_bombs (dgs : danger_map) (lst : (int * int, float) Hashtbl.t list) =
let rec aux = function
| [] -> ()
| h::t ->
reverse_simulate_bomb dgs h ;
aux t in
aux lst ;;
let seek_player (gd : game_data) (dgs : danger_map) = let seek_player (gd : game_data) (dgs : danger_map) =
(* returns whether or not it found a target, and prints if found *) (* returns whether or not it found a target, and prints if found *)
let pid = gd.player_id in let pid = gd.player_id in
@ -1086,6 +1094,7 @@ let seek_player (gd : game_data) (dgs : danger_map) =
let has_trapped = ref false in let has_trapped = ref false in
let break = ref false in let break = ref false in
let found = ref false in let found = ref false in
let simulated_bombs = ref [] in
try try
if gd.players.(pid).ntraps = 0 || gd.players.(pid).bomb_to_place = 0 then begin if gd.players.(pid).ntraps = 0 || gd.players.(pid).bomb_to_place = 0 then begin
if logg then Printf.fprintf stderr "No trap/available bomb\n" ; if logg then Printf.fprintf stderr "No trap/available bomb\n" ;
@ -1122,6 +1131,7 @@ let seek_player (gd : game_data) (dgs : danger_map) =
else if abs (destx - !cxi) + abs (desty - !cyi) <= gd.players.(pid).bomb_radius && gd.players.(pid).bomb_to_place > 0 then begin else if abs (destx - !cxi) + abs (desty - !cyi) <= gd.players.(pid).bomb_radius && gd.players.(pid).bomb_to_place > 0 then begin
if logg then Printf.fprintf stderr " Bombing\n" ; if logg then Printf.fprintf stderr " Bombing\n" ;
print_ret "again_dash.sav" directn 1 print_escape ; print_ret "again_dash.sav" directn 1 print_escape ;
simulated_bombs := (simulate_bomb_deconstruct gd dgs gd.players.(pid).xy.x gd.players.(pid).xy.y gd.players.(pid).bomb_radius (gd.dt +. 5.5))::(!simulated_bombs) ;
cxi := !cxi + fst order.(directn) ; cxi := !cxi + fst order.(directn) ;
cyi := !cyi + snd order.(directn) ; cyi := !cyi + snd order.(directn) ;
break := true ; break := true ;
@ -1146,9 +1156,12 @@ let seek_player (gd : game_data) (dgs : danger_map) =
done ; done ;
if logg then Printf.fprintf stderr "[%d] Success!\n" pid ; if logg then Printf.fprintf stderr "[%d] Success!\n" pid ;
remaining_dash := !remaining_dash +. 1. ; remaining_dash := !remaining_dash +. 1. ;
remove_bombs dgs !simulated_bombs ;
true true
with with
| ReturnBool b -> b ;; | ReturnBool b ->
remove_bombs dgs !simulated_bombs ;
b ;;
let read_queue (filename : string) = let read_queue (filename : string) =
let strings = Array.make 45 "e" in let strings = Array.make 45 "e" in
@ -1376,13 +1389,31 @@ let exists_crate (gd : game_data) (dgs : danger_map) =
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
let get_cd (filename : string) =
let ptr = open_in filename in
cd := Float.of_string (input_line ptr) ;
close_in ptr ;;
let set_cd (nspeed : int) (filename : string) =
if !remaining_dash = 0. then begin
let ptr = open_out filename in
let interval = Float.pow 0.9 (float_of_int nspeed) in
Printf.fprintf ptr "%f\n" (max 0. (!cd -. interval)) ;
close_out ptr
end ;;
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
let __start = Unix.gettimeofday() ;; 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 danger_data ;; let gain_map = generate_gain_map game_map danger_data ;;
get_rem_dash ("again"^(string_of_int game_map.player_id)^".sav") ;; (* ("again"^(string_of_int game_map.player_id)^".sav") *)
get_rem_dash "again_rem.sav" ;;
get_cd "again_cooldown.sav" ;;
(*Printf.fprintf stderr "\n" ;;*) (*Printf.fprintf stderr "\n" ;;*)
if game_map.player_id = 4 then begin if game_map.player_id = 4 then begin
@ -1408,7 +1439,7 @@ end
else begin else begin
let direction = ref 4 in let direction = ref 4 in
if not (seek_player game_map danger_data) then begin if !cd >= 0.01 || not (seek_player game_map danger_data) then begin
if exists_crate game_map danger_data then begin if exists_crate game_map danger_data then begin
if logg then Printf.fprintf stderr "Crates\n" ; if logg then Printf.fprintf stderr "Crates\n" ;
direction := move_crate game_map danger_data direction := move_crate game_map danger_data
@ -1422,11 +1453,13 @@ else begin
if logg then Printf.fprintf stderr "[player %d] %d %d (at time %f - with %d dash potential)\n" game_map.player_id !direction !action game_map.dt (int_of_float !remaining_dash); if logg then Printf.fprintf stderr "[player %d] %d %d (at time %f - with %d dash potential)\n" game_map.player_id !direction !action game_map.dt (int_of_float !remaining_dash);
end end
else begin else begin
cd := (Float.pow 0.9 (float_of_int game_map.players.(game_map.player_id).nspeed)) *. 1.9 ;
ignore (read_queue "again_dash.sav") ignore (read_queue "again_dash.sav")
end end
end;; end;;
(*Printf.printf "\n4 0" ;;*) (*Printf.printf "\n4 0" ;;*)
set_rem_dash ("again"^(string_of_int game_map.player_id)^".sav") ;; set_rem_dash "again_rem.sav" ;;
set_cd game_map.players.(game_map.player_id).nspeed "again_cooldown.sav" ;;
(*set_meta_info game_map.player_id ;;*) (*set_meta_info game_map.player_id ;;*)
let __end = Unix.gettimeofday() ;; let __end = Unix.gettimeofday() ;;
if logg then Printf.fprintf stderr "Time : %f\n\n" (__end -. __start) ;; if logg then Printf.fprintf stderr "Time : %f\n\n" (__end -. __start) ;;

BIN
again.o

Binary file not shown.

1
again_cooldown.sav Normal file
View File

@ -0,0 +1 @@
0.000000

View File

@ -1,26 +1,28 @@
150.1250000000006 144.63000000000028
1 0
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 3 3 3 3 3 0 2 2 2 0 5 5 5 5 5 5 1 1 3 3 3 3 3 3 3 0 2 2 2 2 0 5 5 5 5 5 5 1
1 3 1 3 1 3 1 0 1 2 1 2 1 2 1 5 1 5 1 5 1 1 3 1 3 1 3 1 0 1 0 1 2 1 2 1 5 1 5 1 5 1
1 3 3 3 3 3 3 3 3 0 2 2 2 2 2 5 5 5 5 4 1 1 3 3 3 3 3 6 6 6 6 0 2 2 2 0 5 5 5 5 5 1
1 3 1 6 1 3 1 4 1 2 1 2 1 2 1 2 1 5 1 4 1 1 3 1 3 1 3 1 3 1 0 1 2 1 2 1 0 1 4 1 5 1
1 3 3 6 6 4 4 4 4 4 2 2 2 2 2 4 2 0 0 4 1 1 3 3 3 3 3 3 3 3 0 2 2 2 2 2 2 2 4 0 5 1
1 0 1 6 1 3 1 4 1 2 1 2 1 2 1 4 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