is it working ?
This commit is contained in:
parent
a116a16d57
commit
e1c482979b
193
again.ml
193
again.ml
|
@ -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
|
let lines = Array.length gd.laby
|
||||||
and cols = Array.length gd.laby.(0) in
|
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 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
|
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 ;
|
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 ;
|
retval := true ;
|
||||||
k ;;
|
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) =
|
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
|
||||||
let cxi = gd.players.(pid).xy.x
|
let cxi = ref gd.players.(pid).xy.x
|
||||||
and cyi = gd.players.(pid).xy.y in
|
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 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 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
|
try
|
||||||
if gd.players.(pid).ntraps = 0 || (gd.players.(pid).bomb_to_place = 0 && is_empty_lst dgs.explosionTimes.(cxi).(cyi)) 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/no available bomb\n";
|
if logg then Printf.fprintf stderr "No trap/available bomb\n" ;
|
||||||
raise (ReturnBool false);
|
raise (ReturnBool false)
|
||||||
end;
|
end ;
|
||||||
if logg then Printf.fprintf stderr "has trap(s)\n";
|
if logg then Printf.fprintf stderr "Can trap\n" ;
|
||||||
for pl = 0 to 3 do
|
while not !has_trapped do
|
||||||
if gd.players.(pl).id <> -1 && gd.player_id <> pl then begin (* not dead *)
|
for pl = 0 to Array.length gd.players -1 do
|
||||||
let within_range = ref false in
|
if not !break && gd.players.(pl).id <> -1 && pl <> pid then begin
|
||||||
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
|
let destx = gd.players.(pl).xy.x
|
||||||
if !within_range then begin
|
and desty = gd.players.(pl).xy.y in
|
||||||
if logg then Printf.fprintf stderr "\n\nlesgo (at %d, %d)\n\n\n" cxi cyi;
|
let foundpath = ref false in
|
||||||
if gd.players.(pl).xy.x = cxi && gd.players.(pl).xy.y = cyi then begin
|
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 logg then Printf.fprintf stderr "no u\n" ;
|
if !foundpath then begin
|
||||||
act := 3
|
found := true ;
|
||||||
end
|
if logg then Printf.fprintf stderr "Found target (%d)\n" pl ;
|
||||||
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 "(%d, %d) --[%d]--> (%d, %d)\n" !cxi !cyi directn destx desty ;
|
||||||
if logg then Printf.fprintf stderr "boom\n" ;
|
if destx = !cxi && desty = !cyi then begin
|
||||||
act := 1
|
if logg then Printf.fprintf stderr " Trapping\n" ;
|
||||||
end
|
print_ret "again.sav" directn 3 print_escape ;
|
||||||
else begin
|
cxi := !cxi + fst order.(directn) ;
|
||||||
if !remaining_dash = 0. && gd.players.(pid).ndash > 0 then begin
|
cyi := !cyi + snd order.(directn) ;
|
||||||
remaining_dash := 3. ;
|
has_trapped := true ;
|
||||||
act := 2 ;
|
break := true ;
|
||||||
end
|
end
|
||||||
end;
|
else if !remaining_dash = 0. then begin
|
||||||
Printf.printf "%d %d" direct !act ;
|
if logg then Printf.fprintf stderr " Dashing\n" ;
|
||||||
if logg then Printf.fprintf stderr "[player %d] trap [%d] %d, %d\n" gd.player_id pl direct !act;
|
print_ret "again.sav" directn 2 print_escape ;
|
||||||
raise (ReturnBool true)
|
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 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
|
||||||
end
|
end
|
||||||
end
|
done ;
|
||||||
done;
|
if not !found then begin
|
||||||
if logg then Printf.fprintf stderr "wont trap\n";
|
if logg then Printf.fprintf stderr "No nearby target\n";
|
||||||
false
|
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
|
with
|
||||||
| ReturnBool b -> b ;;
|
| 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 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
|
||||||
|
@ -1283,28 +1370,34 @@ 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 ;;*)
|
||||||
|
|
||||||
(*get_meta_info game_map.player_id ;;*)
|
(*get_meta_info game_map.player_id ;;*)
|
||||||
(*Printf.fprintf stderr "\n" ;;
|
(*Printf.fprintf stderr "\n" ;;
|
||||||
print_dangers danger_data ;;*)
|
print_dangers danger_data ;;*)
|
||||||
let direction = ref 4 ;;
|
|
||||||
|
|
||||||
if not (seek_player game_map danger_data) then begin
|
if read_queue "again.sav" then begin
|
||||||
if exists_crate game_map danger_data then begin
|
()
|
||||||
if logg then Printf.fprintf stderr "Crates\n" ;
|
end
|
||||||
direction := move_crate game_map danger_data
|
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
|
||||||
|
if logg then Printf.fprintf stderr "Crates\n" ;
|
||||||
|
direction := move_crate game_map danger_data
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
if logg then Printf.fprintf stderr "No crates\n" ;
|
||||||
|
direction := move_land game_map danger_data gain_map
|
||||||
|
end ;
|
||||||
|
|
||||||
|
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
|
||||||
else begin
|
|
||||||
if logg then Printf.fprintf stderr "No crates\n" ;
|
|
||||||
direction := move_land game_map danger_data gain_map
|
|
||||||
end ;
|
|
||||||
|
|
||||||
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_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() ;;
|
||||||
|
|
42
entrees.txt
42
entrees.txt
|
@ -1,27 +1,21 @@
|
||||||
59.0
|
69.28
|
||||||
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 0 0 0 0 3 0 3 0 0 0 5 5 5 0 5 5 0 0 0 1
|
1 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 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 0 1 0 1 0 1 0 1 2 1 0 1 0 1 0 1 0 1 0 1
|
||||||
1 0 3 3 3 0 0 5 3 3 3 5 5 0 5 5 5 5 5 0 1
|
1 0 0 0 0 0 0 0 2 0 2 0 0 0 0 2 0 2 0 0 1
|
||||||
1 0 1 0 1 0 1 5 1 3 1 5 1 0 1 0 1 4 1 0 1
|
1 0 1 0 1 0 1 3 1 0 1 2 1 2 1 4 1 0 1 0 1
|
||||||
1 0 0 0 0 5 5 5 5 5 0 0 0 0 0 0 0 4 4 0 1
|
1 3 0 0 0 3 3 3 3 3 3 4 2 0 4 4 0 0 0 0 1
|
||||||
1 0 1 6 1 3 1 5 1 3 1 0 1 0 1 4 1 4 1 0 1
|
1 3 1 3 1 0 1 3 1 3 1 0 1 0 1 4 1 0 1 4 1
|
||||||
1 2 0 6 6 0 0 0 2 0 0 0 0 0 4 4 0 0 0 0 1
|
1 3 3 3 3 3 3 3 0 0 4 4 4 0 0 4 4 4 4 4 1
|
||||||
1 0 1 6 1 0 1 6 1 2 1 4 1 4 1 0 1 0 1 0 1
|
1 3 1 0 1 3 1 0 1 0 1 4 1 0 1 4 1 4 1 0 1
|
||||||
1 0 0 0 0 0 0 6 6 0 0 4 4 4 4 4 4 4 4 0 1
|
1 0 0 0 3 3 3 0 0 0 4 4 4 0 0 0 0 0 0 0 1
|
||||||
1 0 1 6 1 0 1 6 1 6 1 4 1 4 1 0 1 4 1 0 1
|
1 0 1 3 1 0 1 0 1 0 1 0 1 4 1 0 1 0 1 0 1
|
||||||
1 0 6 6 6 6 6 6 6 6 0 0 6 6 6 4 4 4 0 0 1
|
1 0 3 3 0 3 3 0 0 0 0 0 0 4 4 4 4 4 4 0 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
|
0
|
||||||
5 9 2 59.5
|
2
|
||||||
9 9 2 63.5
|
6 9 0 2 4 2 1 0
|
||||||
7 7 1 63.5
|
1 7 1 2 2 1 1 0
|
||||||
4
|
0
|
||||||
7 6 0 0 1 1 0 0
|
|
||||||
11 9 1 0 1 2 1 0
|
|
||||||
7 11 2 0 0 2 1 0
|
|
||||||
3 11 3 1 1 1 1 0
|
|
||||||
1
|
|
||||||
5 10 2
|
|
||||||
|
|
|
@ -383,6 +383,7 @@ def execute_evenement(evenements, evenement, plateau, plateauCouleur, bombes, jo
|
||||||
elif joueurs[indiceJoueur][J_PIEGESRESTANTS]>0 and action == A_PIEGE:
|
elif joueurs[indiceJoueur][J_PIEGESRESTANTS]>0 and action == A_PIEGE:
|
||||||
joueur[J_PIEGESRESTANTS]-=1
|
joueur[J_PIEGESRESTANTS]-=1
|
||||||
pieges.append([i,j,indiceJoueur])
|
pieges.append([i,j,indiceJoueur])
|
||||||
|
print("||||| trap at", i, j, "|||||")
|
||||||
ip,jp = prochain(i,j,direction)
|
ip,jp = prochain(i,j,direction)
|
||||||
if plateau[ip][jp]==PLATEAU_VIDE and trouve_objet(ip, jp, bombes)==None:
|
if plateau[ip][jp]==PLATEAU_VIDE and trouve_objet(ip, jp, bombes)==None:
|
||||||
joueur[J_LIGNE]=ip
|
joueur[J_LIGNE]=ip
|
||||||
|
@ -588,5 +589,5 @@ def simulation(strategies):
|
||||||
return
|
return
|
||||||
|
|
||||||
#simulation(["./again"])
|
#simulation(["./again"])
|
||||||
#simulation(["./again", "./again"])
|
simulation(["./again", "./again"])
|
||||||
simulation(["./again", "./again", "./again", "./again"])
|
#simulation(["./again", "./again", "./again", "./again"])
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0
|
1
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
3 0
|
1 0
|
Loading…
Reference in New Issue