added another layer of security to is_dead + added 1st prototype of seek_player
This commit is contained in:
parent
f555842ffc
commit
003a25f4cd
147
again.ml
147
again.ml
|
@ -49,7 +49,7 @@ type boost = {
|
||||||
let default_point = {
|
let default_point = {
|
||||||
x = 0 ;
|
x = 0 ;
|
||||||
y = 0 ;
|
y = 0 ;
|
||||||
}
|
} (* works for dead players - inside a wall *)
|
||||||
|
|
||||||
let default_bomb = {
|
let default_bomb = {
|
||||||
xy = default_point ;
|
xy = default_point ;
|
||||||
|
@ -689,7 +689,7 @@ 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 expl_time ->
|
(fun acc expl_time ->
|
||||||
acc || (t >= expl_time && t <= expl_time +. dt)
|
acc || (t >= expl_time && t <= expl_time +. dt) || (t >= expl_time -. dt && t <= expl_time)
|
||||||
)
|
)
|
||||||
false
|
false
|
||||||
dgs.explosionTimes.(x).(y)
|
dgs.explosionTimes.(x).(y)
|
||||||
|
@ -704,7 +704,7 @@ 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 expl_time ->
|
(fun acc expl_time ->
|
||||||
acc || (t >= expl_time && t <= expl_time +. dt)
|
acc || (t >= expl_time && t <= expl_time +. dt) || (t >= expl_time -. dt && t <= expl_time)
|
||||||
)
|
)
|
||||||
false
|
false
|
||||||
dgs.explosionTimes.(x).(y)
|
dgs.explosionTimes.(x).(y)
|
||||||
|
@ -962,6 +962,98 @@ 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 lines = Array.length gd.laby
|
||||||
|
and cols = Array.length gd.laby.(0) in
|
||||||
|
|
||||||
|
let visited = Hashtbl.create 100 in
|
||||||
|
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 +. interval, 4, 1) q ;
|
||||||
|
|
||||||
|
Queue.add (x0+1, y0, stime +. interval, 2, 1) q ;
|
||||||
|
Queue.add (x0-1, y0, stime +. interval, 0, 1) q ;
|
||||||
|
Queue.add (x0, y0+1, stime +. interval, 1, 1) q ;
|
||||||
|
Queue.add (x0, y0-1, stime +. interval, 3, 1) q ;
|
||||||
|
|
||||||
|
try
|
||||||
|
while not (Queue.is_empty q) do
|
||||||
|
let (x, y, ct, direction, polar) = Queue.pop q in
|
||||||
|
(*Printf.fprintf stderr "at (%d %d)\n" x y;*)
|
||||||
|
if is_valid x y lines cols && gd.laby.(x).(y) <> 1 && gd.laby.(x).(y) <> 2 then begin (* within the map *)
|
||||||
|
if Hashtbl.find_opt visited (x, y, polar) = None then begin (* has not been visited yet *)
|
||||||
|
Hashtbl.add visited (x, y, polar) 1 ;
|
||||||
|
if
|
||||||
|
ct <= stime +. interval *. (float_of_int max_dist) &&
|
||||||
|
not (is_dead_all dgs x y ct interval false) &&
|
||||||
|
not (Array.fold_left (fun acc (b : bomb) -> acc || (b.xy.x = x && b.xy.y = y)) false gd.bombs) &&
|
||||||
|
polar <= 4
|
||||||
|
then begin
|
||||||
|
if
|
||||||
|
(x = end_x && y = end_y) (* dest tile *)
|
||||||
|
then begin
|
||||||
|
raise (ReturnInt direction)
|
||||||
|
end;
|
||||||
|
for dir = 0 to 3 do
|
||||||
|
Queue.add (x + (fst order.(dir)), y + (snd order.(dir)), ct +. interval, direction, polar) q ;
|
||||||
|
done;
|
||||||
|
Queue.add (x, y, ct +. interval, direction, polar+1) q
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
done;
|
||||||
|
retval := false ;
|
||||||
|
4 ;
|
||||||
|
with
|
||||||
|
| ReturnInt k ->
|
||||||
|
retval := true ;
|
||||||
|
k ;;
|
||||||
|
|
||||||
|
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 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
|
||||||
|
try
|
||||||
|
if gd.players.(pid).ntraps = 0 then begin
|
||||||
|
if logg then Printf.fprintf stderr "no trap\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 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 within_range in
|
||||||
|
if !within_range then begin
|
||||||
|
if logg then Printf.fprintf stderr "\n\nlesgo\n\n\n";
|
||||||
|
if gd.players.(pl).xy.x = cxi && gd.players.(pl).xy.y = cyi then begin
|
||||||
|
act := 3
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
if !remaining_dash = 0. then begin
|
||||||
|
remaining_dash := 3. ;
|
||||||
|
act := 2 ;
|
||||||
|
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
|
||||||
|
with
|
||||||
|
| ReturnBool b -> b ;;
|
||||||
|
|
||||||
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 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
|
let lines = Array.length gd.laby
|
||||||
and cols = Array.length gd.laby.(0) in
|
and cols = Array.length gd.laby.(0) in
|
||||||
|
@ -1042,7 +1134,7 @@ let bfs_for_land ?return_x:(retx=fodder) ?return_y:(rety=fodder) ?return_ok:(ret
|
||||||
retfl := true ;
|
retfl := true ;
|
||||||
k ;;
|
k ;;
|
||||||
|
|
||||||
let move_land (gd : game_data) (dgs : danger_map) (gn : int array array) =
|
let rec move_land (gd : game_data) (dgs : danger_map) (gn : int array array) =
|
||||||
let max_cols = Array.mapi
|
let max_cols = Array.mapi
|
||||||
(fun i lne ->
|
(fun i lne ->
|
||||||
Array.fold_left
|
Array.fold_left
|
||||||
|
@ -1079,7 +1171,7 @@ let move_land (gd : game_data) (dgs : danger_map) (gn : int array array) =
|
||||||
let is_good = ref false in
|
let is_good = ref false in
|
||||||
|
|
||||||
let result_bomb = bfs_for_land ~return_ok:is_good true gd dgs cxi cyi xmax ymax gd.dt 1 80 in
|
let result_bomb = bfs_for_land ~return_ok:is_good true gd dgs cxi cyi xmax ymax gd.dt 1 80 in
|
||||||
if is_safe && gd.players.(pid).bomb_to_place > 0 && !is_good then begin
|
if is_safe && gd.players.(pid).bomb_to_place > 0 && !is_good && !action <> 2 then begin
|
||||||
if logg then Printf.fprintf stderr "kaboom\n" ;
|
if logg then Printf.fprintf stderr "kaboom\n" ;
|
||||||
action := 1 ;
|
action := 1 ;
|
||||||
result_bomb
|
result_bomb
|
||||||
|
@ -1093,9 +1185,25 @@ let move_land (gd : game_data) (dgs : danger_map) (gn : int array array) =
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
if logg then Printf.fprintf stderr "E\n" ;
|
if logg then Printf.fprintf stderr "no explosion ?\n" ;
|
||||||
let res = bfs_for_land ~leniency:20 false gd dgs cxi cyi xmax ymax gd.dt 1 80 in
|
let res = bfs_for_land ~leniency:20 ~return_ok:is_good false gd dgs cxi cyi xmax ymax gd.dt 1 80 in
|
||||||
res
|
if !is_good then begin
|
||||||
|
if logg then Printf.fprintf stderr "found\n";
|
||||||
|
res
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
if logg then Printf.fprintf stderr "Needs dash lmao (_2)\n";
|
||||||
|
if !remaining_dash <> 0. && gd.players.(pid).ndash > 0 then begin
|
||||||
|
if logg then Printf.fprintf stderr "-------------- Lets rewind time for a bit (_2) --------------\n";
|
||||||
|
remaining_dash := 3. ;
|
||||||
|
action := 2 ;
|
||||||
|
move_land gd dgs gn
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
if logg then Printf.fprintf stderr "Now you're screwed (_2)\n" ;
|
||||||
|
4
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end ;;
|
end ;;
|
||||||
|
|
||||||
|
@ -1144,6 +1252,7 @@ if game_map.player_id = 4 then begin
|
||||||
done
|
done
|
||||||
end ;;
|
end ;;
|
||||||
|
|
||||||
|
|
||||||
(*Printf.fprintf stderr "\n" ;;
|
(*Printf.fprintf stderr "\n" ;;
|
||||||
print_dangers danger_data ;;*)
|
print_dangers danger_data ;;*)
|
||||||
|
|
||||||
|
@ -1152,17 +1261,19 @@ print_dangers danger_data ;;*)
|
||||||
print_dangers danger_data ;;*)
|
print_dangers danger_data ;;*)
|
||||||
let direction = ref 4 ;;
|
let direction = ref 4 ;;
|
||||||
|
|
||||||
if exists_crate game_map danger_data then begin
|
if true || not (seek_player game_map danger_data) then begin
|
||||||
if logg then Printf.fprintf stderr "Crates\n" ;
|
if exists_crate game_map danger_data then begin
|
||||||
direction := move_crate game_map danger_data
|
if logg then Printf.fprintf stderr "Crates\n" ;
|
||||||
end
|
direction := move_crate game_map danger_data
|
||||||
else begin
|
end
|
||||||
if logg then Printf.fprintf stderr "No crates\n" ;
|
else begin
|
||||||
direction := move_land game_map danger_data gain_map
|
if logg then Printf.fprintf stderr "No crates\n" ;
|
||||||
end ;;
|
direction := move_land game_map danger_data gain_map
|
||||||
|
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 - 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;;
|
||||||
set_rem_dash ("again"^(string_of_int game_map.player_id)^".sav") ;;
|
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() ;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 1 3 1 6 1 4 1 3 1 6 1 3 1 6 1 3 1 4 1
|
1 6 1 6 1 3 1 3 1 0 1 3 1 0 1 5 1 5 1 4 1
|
||||||
1 6 6 3 3 3 3 4 4 4 3 6 3 4 3 3 3 3 3 4 1
|
1 6 3 3 3 3 3 3 3 3 0 5 5 5 5 5 5 5 5 5 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
|
||||||
7 15 3 184.53200000000103
|
6 13 5 169.34300000000087
|
||||||
9 10 1 185.70000000000073
|
3 10 4 169.5
|
||||||
6 11 4 186.45991999999896
|
7 12 5 170.8010000000009
|
||||||
9 16 3 186.71900000000107
|
2 11 4 171.5
|
||||||
4 9 8 186.80500000000103
|
6 15 5 173.40000000000057
|
||||||
4
|
1 10 4 173.5
|
||||||
6 13 0 5 1 4 4 5
|
9 12 5 174.44600000000096
|
||||||
11 17 1 3 0 3 2 1
|
3
|
||||||
9 11 2 1 7 1 4 2
|
8 15 0 1 1 5 4 2
|
||||||
6 9 3 3 1 8 2 1
|
1 9 1 0 0 4 3 1
|
||||||
1
|
9 11 2 3 0 5 3 4
|
||||||
6 1 0
|
2
|
||||||
|
10 9 0
|
||||||
|
4 11 1
|
||||||
|
|
|
@ -392,6 +392,7 @@ def execute_evenement(evenements, evenement, plateau, plateauCouleur, bombes, jo
|
||||||
indicePiege = trouve_objet(i,j, pieges)
|
indicePiege = trouve_objet(i,j, pieges)
|
||||||
penalite = 0
|
penalite = 0
|
||||||
if indicePiege != None:
|
if indicePiege != None:
|
||||||
|
piege = pieges[indicePiege]
|
||||||
if piege[P_JOUEUR] != indiceJoueur:
|
if piege[P_JOUEUR] != indiceJoueur:
|
||||||
penalite = 3
|
penalite = 3
|
||||||
piege.pop(indicePiege)
|
piege.pop(indicePiege)
|
||||||
|
@ -572,7 +573,7 @@ def simulation(strategies):
|
||||||
joueurs = []
|
joueurs = []
|
||||||
|
|
||||||
for i in range(len(strategies)):
|
for i in range(len(strategies)):
|
||||||
joueur = [positionsInitiales[i][0], positionsInitiales[i][1], strategies[i], 0, 1, 1, 1, 0, 0, 0, 0]
|
joueur = [positionsInitiales[i][0], positionsInitiales[i][1], strategies[i], 0, 1, 1, 1, 1, 0, 0, 0]
|
||||||
joueurs.append(joueur)
|
joueurs.append(joueur)
|
||||||
ajoute_evenement(evenements, [0., EVENEMENT_TOUR_JOUEUR, i])
|
ajoute_evenement(evenements, [0., EVENEMENT_TOUR_JOUEUR, i])
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
1
|
0
|
Loading…
Reference in New Issue