added dash usage when necessary

This commit is contained in:
Alexandre 2024-12-28 19:15:55 +01:00
parent a78367dc79
commit 4d1fda4738
13 changed files with 78 additions and 46 deletions

BIN
again

Binary file not shown.

BIN
again.cmi

Binary file not shown.

BIN
again.cmx

Binary file not shown.

View File

@ -11,7 +11,9 @@ TODO :
Random.self_init () ;; Random.self_init () ;;
let debug_all = false ;; let debug_all = false ;;
let logg = false ;; let logg = true ;;
let remaining_dash = ref 0. ;;
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
@ -330,6 +332,16 @@ let parse_input (str : string) =
close_in ptr ; close_in ptr ;
failwith "cannot happen unless something is wrong" ;; failwith "cannot happen unless something is wrong" ;;
let get_rem_dash (filename : string) =
let ptr = open_in filename in
remaining_dash := float_of_int (int_of_string (input_line ptr)) ;
close_in ptr ;;
let set_rem_dash (filename : string) =
let ptr = open_out filename in
Printf.fprintf ptr "%d\n" (int_of_float (max 0. (!remaining_dash -. 1.))) ;
close_out ptr ;;
let build_danger_map (gd : game_data) = let build_danger_map (gd : game_data) =
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
@ -842,10 +854,11 @@ let bfs_for_crate ?return_x:(retx=fodder) ?return_y:(rety=fodder) ?return_ok:(re
retfl := true ; retfl := true ;
k ;; k ;;
let move_crate (gd : game_data) (dgs : danger_map) = let rec move_crate (gd : game_data) (dgs : danger_map) =
let pid = gd.player_id in let pid = gd.player_id in
let cxi = gd.players.(pid).xy.x let cxi = gd.players.(pid).xy.x
and cyi = gd.players.(pid).xy.y in and cyi = gd.players.(pid).xy.y in
let interval = Float.pow 0.9 (float_of_int gd.players.(pid).nspeed) in
try try
(* send away a player standing right on top *) (* send away a player standing right on top *)
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
@ -853,15 +866,15 @@ let move_crate (gd : game_data) (dgs : danger_map) =
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 gd 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 -. !remaining_dash *. interval) false true false 0 false 5 in
if bonusres_2p <> 4 then begin if bonusres_2p <> 4 then begin
if logg then Printf.fprintf stderr "mine\n" ; if logg then Printf.fprintf stderr "mine (%d) \n" bonusres_2p ;
raise (ReturnInt bonusres_2p) ; raise (ReturnInt bonusres_2p) ;
end; end;
let resultp = bfs_for_crate gd dgs cxi cyi gd.dt false false true 1 false 80 in let resultp = bfs_for_crate gd dgs cxi cyi (gd.dt -. !remaining_dash *. interval) false false true 1 false 80 in
if resultp <> 4 then begin if resultp <> 4 && !action <> 2 then begin
if logg then Printf.fprintf stderr "go away\n" ; if logg then Printf.fprintf stderr "go away (%d) \n" resultp ;
action := 1 ; action := 1 ;
raise (ReturnInt resultp) ; raise (ReturnInt resultp) ;
end; end;
@ -874,15 +887,16 @@ let move_crate (gd : game_data) (dgs : danger_map) =
let saved = simulate_bomb_deconstruct gd 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 -. !remaining_dash *. interval) false true false 0 false 5 in
if bonusres_2 <> 4 && (tile_distance gd cxi cyi !bonus2_x !bonus2_y <= min_dist_from_player gd cxi cyi) then begin if bonusres_2 <> 4 && (tile_distance gd cxi cyi !bonus2_x !bonus2_y <= min_dist_from_player gd cxi cyi) && !action <> 2 then begin
if logg then Printf.fprintf stderr "Bonus Spotted\n" ; if logg then Printf.fprintf stderr "Bonus Spotted\n" ;
action := 1 ; action := 1 ;
raise (ReturnInt bonusres_2) ; raise (ReturnInt bonusres_2) ;
end; end;
let result = bfs_for_crate gd dgs cxi cyi gd.dt false false true 1 false 80 in let result = bfs_for_crate gd dgs cxi cyi (gd.dt -. !remaining_dash *. interval) false false true 1 false 80 in
if result <> 4 then begin if result <> 4 && !action <> 2 then begin
if logg then Printf.fprintf stderr "found (%d) \n" result ;
action := 1 ; action := 1 ;
raise (ReturnInt result) ; raise (ReturnInt result) ;
end; end;
@ -892,26 +906,35 @@ let move_crate (gd : game_data) (dgs : danger_map) =
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
and bonus_y = ref 0 in and bonus_y = ref 0 in
let bonusres = bfs_for_crate ~return_x:bonus_x ~return_y:bonus_y gd dgs cxi cyi gd.dt false true false 0 false 5 in let bonusres = bfs_for_crate ~return_x:bonus_x ~return_y:bonus_y gd dgs cxi cyi (gd.dt -. !remaining_dash *. interval) false true false 0 false 5 in
if bonusres <> 4 && (tile_distance gd cxi cyi !bonus_x !bonus_y <= min_dist_from_player gd cxi cyi) then begin if bonusres <> 4 && (tile_distance gd cxi cyi !bonus_x !bonus_y <= min_dist_from_player gd cxi cyi) then begin
if logg then Printf.fprintf stderr "bonus spotted\n" ; if logg then Printf.fprintf stderr "bonus spotted (%d) \n" bonusres ;
raise (ReturnInt bonusres) ; raise (ReturnInt bonusres) ;
end; end;
if logg then Printf.fprintf stderr "searching...\n" ; if logg then Printf.fprintf stderr "searching...\n" ;
let rescr = bfs_for_crate gd dgs cxi cyi gd.dt true false false 0 false 80 in let rescr = bfs_for_crate gd dgs cxi cyi (gd.dt -. !remaining_dash *. interval) true false false 0 false 80 in
if logg then Printf.fprintf stderr "searching Done...\n" ; if logg then Printf.fprintf stderr "searching Done (%d) ...\n" rescr ;
if rescr <> 4 then if rescr <> 4 then
rescr rescr
else begin else begin
if logg then Printf.fprintf stderr "searching 2...\n" ; if logg then Printf.fprintf stderr "searching 2...\n" ;
let success = ref false in let success = ref false in
let rescr2 = bfs_for_crate ~return_ok:success gd dgs cxi cyi gd.dt false false false 0 false 80 in let rescr2 = bfs_for_crate ~return_ok:success gd dgs cxi cyi (gd.dt -. !remaining_dash *. interval) false false false 0 false 80 in
if logg then Printf.fprintf stderr "searching 2 Done...\n" ; if logg then Printf.fprintf stderr "searching 2 Done (%d) ...\n" rescr2 ;
if !success then if !success then
rescr2 rescr2
else begin else begin
if logg then Printf.fprintf stderr "Needs dash lmao\n"; if logg then Printf.fprintf stderr "Needs dash lmao\n";
4 if !remaining_dash <> 0. && gd.players.(pid).ndash > 0 then begin
if logg then Printf.fprintf stderr "---------------- Lets rewind time for a bit ----------------\n";
remaining_dash := 3. ;
action := 2 ;
move_crate gd dgs
end
else begin
if logg then Printf.fprintf stderr "Now you're screwed\n" ;
4
end
end end
end end
with with
@ -1090,6 +1113,8 @@ 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 ;;
get_rem_dash ("again"^(string_of_int game_map.player_id)^".sav") ;;
(*Printf.fprintf stderr "\n" ;; (*Printf.fprintf stderr "\n" ;;
print_dangers danger_data ;;*) print_dangers danger_data ;;*)
@ -1108,9 +1133,9 @@ else begin
end ;; end ;;
Printf.printf "%d %d" !direction !action ; Printf.printf "%d %d" !direction !action ;
if logg then Printf.fprintf stderr "[player %d] %d %d (at time %f)\n" game_map.player_id !direction !action game_map.dt;; 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);;
set_rem_dash ("again"^(string_of_int game_map.player_id)^".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" (__end -. __start) ;; if logg then Printf.fprintf stderr "Time : %f\n\n" (__end -. __start) ;;

BIN
again.o

Binary file not shown.

1
again.sav Normal file
View File

@ -0,0 +1 @@
0

1
again0.sav Normal file
View File

@ -0,0 +1 @@
0

1
again1.sav Normal file
View File

@ -0,0 +1 @@
0

1
again2.sav Normal file
View File

@ -0,0 +1 @@
0

1
again3.sav Normal file
View File

@ -0,0 +1 @@
0

View File

@ -1,27 +1,29 @@
230.35480000000163 102.4000000000002
0 1
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 6 6 6 6 6 6 3 4 4 4 3 4 4 4 3 3 3 1 1 3 3 3 6 6 6 6 6 0 2 2 2 2 2 0 5 5 5 5 1
1 3 1 3 1 3 1 6 1 3 1 4 1 3 1 4 1 6 1 5 1 1 3 1 3 1 6 1 3 1 2 1 2 1 2 1 0 1 5 1 5 1
1 3 3 3 3 3 3 3 3 3 3 6 6 3 6 6 6 6 6 6 1 1 3 3 3 6 6 6 3 6 0 2 2 2 0 5 5 5 5 5 5 1
1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 6 1 4 1 3 1 1 3 1 6 1 6 1 6 1 2 1 2 1 2 1 5 1 5 1 5 1
1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 6 3 1 1 6 6 6 6 6 6 6 0 2 2 2 2 2 0 5 5 5 0 0 1
1 3 1 3 1 3 1 3 1 3 1 6 1 3 1 6 1 3 1 3 1 1 0 1 6 1 6 1 0 1 2 1 2 1 2 1 0 1 4 1 0 1
1 3 3 3 3 3 3 3 3 3 3 6 6 3 6 6 6 6 6 6 1 1 6 6 6 6 6 0 2 2 2 2 2 2 2 2 0 4 4 4 4 1
1 6 1 3 1 3 1 3 1 3 1 6 1 3 1 6 1 3 1 3 1 1 6 1 6 1 0 1 2 1 2 1 2 1 2 1 0 1 4 1 4 1
1 3 3 3 3 3 3 3 3 3 3 3 6 3 6 6 6 6 3 3 1 1 6 6 6 6 6 6 0 2 2 2 2 2 0 4 4 4 4 4 4 1
1 6 1 3 1 3 1 3 1 3 1 6 1 3 1 6 1 3 1 3 1 1 6 1 6 1 2 1 2 1 2 1 2 1 2 1 4 1 4 1 4 1
1 3 3 3 3 3 6 3 6 3 6 6 6 3 6 6 4 3 3 3 1 1 6 6 6 6 6 6 0 2 2 2 2 2 0 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
5 4
7 17 1 230.4744000000016 11 13 1 102.50000000000017
4 15 5 230.6500000000007 3 9 4 105.11000000000014
5 16 5 231.91820000000158 7 15 2 106.5
6 19 5 234.5426000000016 3 7 4 106.73000000000015
7 14 1 235.06710000000166
3 3
8 19 0 4 2 5 3 4 9 15 1 1 4 1 2 5
7 12 1 4 0 1 0 3 9 15 2 0 1 2 3 0
5 11 3 2 1 5 3 2 5 7 3 2 3 4 0 2
0 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 :", indiceJoueur, "\n\n") print("\n\nDEATH (at time =", evenement[0], "):", indiceJoueur, "\n\n")
#assert(false) #assert(false)
indiceJoueur = trouve_objet(i,j,joueurs) indiceJoueur = trouve_objet(i,j,joueurs)

View File

@ -1 +1 @@
2 0 3 0