is it working ?

This commit is contained in:
Alexandre 2025-01-03 08:53:10 +01:00
parent a116a16d57
commit e1c482979b
10 changed files with 166 additions and 79 deletions

BIN
again

Binary file not shown.

BIN
again.cmi

Binary file not shown.

BIN
again.cmx

Binary file not shown.

159
again.ml
View File

@ -966,7 +966,7 @@ let rec move_crate (gd : game_data) (dgs : danger_map) =
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
let path_seek (gd : game_data) (dgs : danger_map) (stime : float) (end_x : int) (end_y : int) (max_dist : int) (retval : bool ref) =
let path_seek (gd : game_data) (dgs : danger_map) (stime : float) (x0 : int) (y0 : int) (end_x : int) (end_y : int) (max_dist : int) (retval : bool ref) =
let lines = Array.length gd.laby
and cols = Array.length gd.laby.(0) in
@ -974,8 +974,6 @@ let path_seek (gd : game_data) (dgs : danger_map) (stime : float) (end_x : int)
let q = Queue.create () in
let interval = Float.pow (0.9) (float_of_int gd.players.(gd.player_id).nspeed) in
let pid = gd.player_id in
let x0 = gd.players.(pid).xy.x
and y0 = gd.players.(pid).xy.y in
Queue.add (x0, y0, stime, 4, 0) q ;
@ -1022,52 +1020,141 @@ let path_seek (gd : game_data) (dgs : danger_map) (stime : float) (end_x : int)
retval := true ;
k ;;
let open_append (filename : string) =
let memo = Array.make 45 "e" in
let id = ref 0 in
let ptrmem = open_in filename in
try
while true do
memo.(!id) <- input_line ptrmem ;
incr id;
done ;
failwith "oh no...\n"
with
| End_of_file ->
close_in ptrmem ;
let ptr = open_out filename in
for k = 0 to !id -1 do
Printf.fprintf ptr "%s\n" memo.(k)
done;
ptr ;;
let print_ret (filename : string) (dir : int) (act : int) (do_esc : bool ref) =
let ptr = open_append filename in
if !do_esc then
Printf.fprintf ptr "%d %d\n" dir act
else begin
Printf.printf "%d %d" dir act ;
do_esc := true
end ;
close_out ptr ;;
let seek_player (gd : game_data) (dgs : danger_map) =
(* returns whether or not it found a target, and prints if found *)
let pid = gd.player_id in
let cxi = gd.players.(pid).xy.x
and cyi = gd.players.(pid).xy.y in
let cxi = ref gd.players.(pid).xy.x
and cyi = ref gd.players.(pid).xy.y in
let interval = Float.pow (0.9) (float_of_int gd.players.(gd.player_id).nspeed) in
let act = ref 0 in
let player_range = 3 * gd.players.(pid).ndash in
let print_escape = ref false in
let has_trapped = ref false in
let break = ref false in
let found = ref false in
try
if gd.players.(pid).ntraps = 0 || (gd.players.(pid).bomb_to_place = 0 && is_empty_lst dgs.explosionTimes.(cxi).(cyi)) then begin
if logg then Printf.fprintf stderr "no trap/no available bomb\n";
raise (ReturnBool false);
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" ;
raise (ReturnBool false)
end ;
if logg then Printf.fprintf stderr "has trap(s)\n";
for pl = 0 to 3 do
if gd.players.(pl).id <> -1 && gd.player_id <> pl then begin (* not dead *)
let within_range = ref false in
let direct = path_seek gd dgs (gd.dt -. interval *. !remaining_dash) gd.players.(pl).xy.x gd.players.(pl).xy.y (player_range + int_of_float !remaining_dash) within_range in
if !within_range then begin
if logg then Printf.fprintf stderr "\n\nlesgo (at %d, %d)\n\n\n" cxi cyi;
if gd.players.(pl).xy.x = cxi && gd.players.(pl).xy.y = cyi then begin
if logg then Printf.fprintf stderr "no u\n" ;
act := 3
if logg then Printf.fprintf stderr "Can trap\n" ;
while not !has_trapped do
for pl = 0 to Array.length gd.players -1 do
if not !break && gd.players.(pl).id <> -1 && pl <> pid then begin
let destx = gd.players.(pl).xy.x
and desty = gd.players.(pl).xy.y in
let foundpath = ref false in
let directn = path_seek gd dgs (gd.dt -. interval *. !remaining_dash) !cxi !cyi destx desty (player_range + int_of_float !remaining_dash) foundpath in
if !foundpath then begin
found := true ;
if logg then Printf.fprintf stderr "Found target (%d)\n" pl ;
if logg then Printf.fprintf stderr "(%d, %d) --[%d]--> (%d, %d)\n" !cxi !cyi directn destx desty ;
if destx = !cxi && desty = !cyi then begin
if logg then Printf.fprintf stderr " Trapping\n" ;
print_ret "again.sav" directn 3 print_escape ;
cxi := !cxi + fst order.(directn) ;
cyi := !cyi + snd order.(directn) ;
has_trapped := true ;
break := true ;
end
else if abs (gd.players.(pl).xy.x - cxi) + abs (gd.players.(pl).xy.y - cyi) <= gd.players.(pid).bomb_radius then begin
if logg then Printf.fprintf stderr "boom\n" ;
act := 1
else if !remaining_dash = 0. then begin
if logg then Printf.fprintf stderr " Dashing\n" ;
print_ret "again.sav" directn 2 print_escape ;
remaining_dash := 3. ;
cxi := !cxi + fst order.(directn) ;
cyi := !cyi + snd order.(directn) ;
break := true ;
end
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" ;
print_ret "again.sav" directn 1 print_escape ;
cxi := !cxi + fst order.(directn) ;
cyi := !cyi + snd order.(directn) ;
break := true ;
end
else begin
if !remaining_dash = 0. && gd.players.(pid).ndash > 0 then begin
remaining_dash := 3. ;
act := 2 ;
if logg then Printf.fprintf stderr " Moving\n" ;
print_ret "again.sav" directn 0 print_escape ;
cxi := !cxi + fst order.(directn) ;
cyi := !cyi + snd order.(directn) ;
break := true ;
end
end;
Printf.printf "%d %d" direct !act ;
if logg then Printf.fprintf stderr "[player %d] trap [%d] %d, %d\n" gd.player_id pl direct !act;
raise (ReturnBool true)
end
end
done ;
if logg then Printf.fprintf stderr "wont trap\n";
false
if not !found then begin
if logg then Printf.fprintf stderr "No nearby target\n";
raise (ReturnBool false) ;
end ;
break := false ;
found := false ;
remaining_dash := max 0. (!remaining_dash -. 1.)
done ;
if logg then Printf.fprintf stderr "Success!\n" ;
true
with
| ReturnBool b -> b ;;
let read_queue (filename : string) =
let strings = Array.make 45 "e" in
let id = ref 0 in
let ptr = open_in filename in
try
while true do
strings.(!id) <- input_line ptr ;
incr id
done;
false
with
| End_of_file ->
close_in ptr ;
if strings.(0) <> "e" then begin
if logg then Printf.fprintf stderr "Reading queue\n";
let ptr2 = open_out filename in
for k = 1 to !id -1 do
Printf.fprintf ptr2 "%s\n" strings.(k)
done;
close_out ptr2 ;
let choices = int_n_of_string strings.(0) 2 useless in
Printf.printf "%d %d" choices.(0) choices.(1) ;
if logg then Printf.fprintf stderr "%d %d" choices.(0) choices.(1) ;
true
end else begin
if logg then Printf.fprintf stderr "No queue\n";
false
end
let bfs_for_land ?return_x:(retx=fodder) ?return_y:(rety=fodder) ?return_ok:(retfl=bodder) (skip_near : bool) (gd : game_data) (dgs : danger_map) (x0 : int) (y0 : int) (target_x : int) (target_y : int) ?leniency:(lenc=1) (stime : float) (minDist : int) (maxDist : int) =
let lines = Array.length gd.laby
and cols = Array.length gd.laby.(0) in
@ -1283,14 +1370,18 @@ if game_map.player_id = 4 then begin
done
end ;;
(*Printf.fprintf stderr "\n" ;;
print_dangers danger_data ;;*)
(*get_meta_info game_map.player_id ;;*)
(*Printf.fprintf stderr "\n" ;;
print_dangers danger_data ;;*)
let direction = ref 4 ;;
if read_queue "again.sav" then begin
()
end
else begin
let direction = ref 4 in
if not (seek_player game_map danger_data) then begin
if exists_crate game_map danger_data then begin
@ -1304,7 +1395,9 @@ if not (seek_player game_map danger_data) then begin
Printf.printf "%d %d" !direction !action ;
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;;
(*Printf.printf "\n4 0" ;;*)
set_rem_dash ("again"^(string_of_int game_map.player_id)^".sav") ;;
(*set_meta_info game_map.player_id ;;*)
let __end = Unix.gettimeofday() ;;

BIN
again.o

Binary file not shown.

View File

@ -1 +0,0 @@
0

View File

@ -1,27 +1,21 @@
59.0
0
69.28
1
13 21
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 3 0 3 0 0 0 5 5 5 0 5 5 0 0 0 1
1 0 1 3 1 3 1 3 1 0 1 5 1 5 1 5 1 5 1 0 1
1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

View File

@ -383,6 +383,7 @@ def execute_evenement(evenements, evenement, plateau, plateauCouleur, bombes, jo
elif joueurs[indiceJoueur][J_PIEGESRESTANTS]>0 and action == A_PIEGE:
joueur[J_PIEGESRESTANTS]-=1
pieges.append([i,j,indiceJoueur])
print("||||| trap at", i, j, "|||||")
ip,jp = prochain(i,j,direction)
if plateau[ip][jp]==PLATEAU_VIDE and trouve_objet(ip, jp, bombes)==None:
joueur[J_LIGNE]=ip
@ -588,5 +589,5 @@ def simulation(strategies):
return
#simulation(["./again"])
#simulation(["./again", "./again"])
simulation(["./again", "./again", "./again", "./again"])
simulation(["./again", "./again"])
#simulation(["./again", "./again", "./again", "./again"])

View File

@ -1 +1 @@
0
1

View File

@ -1 +1 @@
3 0
1 0