calibrated everything

This commit is contained in:
Alexandre 2024-11-09 17:16:56 +01:00
parent 5994546629
commit 8d46228c2e
14 changed files with 207 additions and 208 deletions

View File

@ -1,2 +1 @@
ocamlc main.ml -o main
./main

View File

@ -1,32 +1,25 @@
88.00000000000014
158.0
0
13 21
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 0 0 2 2 2 2 2 2 0 0 5 5 5 5 5 1
1 3 1 3 1 0 1 0 1 2 1 0 1 0 1 0 1 5 1 5 1
1 3 3 3 3 0 2 2 2 2 0 0 0 2 2 2 0 5 5 5 1
1 3 1 3 1 2 1 2 1 2 1 2 1 2 1 2 1 0 1 5 1
1 0 0 3 0 2 2 2 2 2 0 2 2 2 2 0 2 2 0 5 1
1 6 1 0 1 2 1 2 1 2 1 2 1 0 1 2 1 2 1 0 1
1 6 0 0 2 0 2 2 2 2 2 2 2 0 0 2 2 2 2 0 1
1 6 1 0 1 2 1 2 1 2 1 2 1 2 1 2 1 0 1 4 1
1 6 6 6 0 2 2 2 2 2 2 2 0 2 2 2 0 4 4 4 1
1 6 1 6 1 2 1 0 1 2 1 2 1 2 1 0 1 4 1 4 1
1 6 6 6 0 2 2 2 2 2 2 2 2 2 0 4 4 4 4 4 1
1 3 3 3 0 2 0 2 2 2 2 2 2 0 5 5 5 5 5 5 1
1 3 1 3 1 2 1 0 1 2 1 2 1 5 1 5 1 5 1 5 1
1 3 3 3 0 0 3 3 0 2 2 0 5 5 5 5 5 5 5 5 1
1 3 1 3 1 2 1 3 1 0 1 0 1 5 1 5 1 0 1 5 1
1 6 6 6 6 0 0 3 4 4 4 4 5 5 5 4 4 0 0 5 1
1 3 1 0 1 0 1 3 1 4 1 4 1 5 1 4 1 0 1 0 1
1 6 6 6 6 6 6 3 6 4 2 0 0 5 5 5 5 4 0 0 1
1 6 1 6 1 3 1 6 1 0 1 0 1 5 1 4 1 4 1 4 1
1 6 6 6 6 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 1
1 6 1 6 1 6 1 6 1 5 1 0 1 5 1 4 1 4 1 4 1
1 6 6 6 6 6 6 6 6 5 0 0 5 5 5 5 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
3
11 4 1 89.5
3 5 3 89.90000000000012
8 17 3 90.5
1
7 9 2 159.00000000000048
4
1 6 0 1 1 3 0 1
9 17 1 0 1 3 1 1
3 17 2 1 1 2 1 1
9 3 3 0 1 1 3 1
6
7 19 2
5 18 0
5 4 0
9 4 3
10 15 2
11 14 0
5 7 0 0 2 4 0 1
4 7 1 5 2 1 2 2
9 8 2 4 4 4 1 4
9 8 3 1 2 3 2 0
1
3 8 2

View File

@ -1,2 +1,2 @@
chmod u+x main.ml
./main.ml
ocamlc main.ml -o main
./main

View File

@ -7,7 +7,7 @@ Created on Wed Sep 12 13:52:48 2018
TEMPS_BASE = 1
TEMPS_PROPAGATION = 0.01
TEMPS_EXPLOSION = 5.5
TEMPS_PARTIE = 100
TEMPS_PARTIE = 1000
E_INSTANT = 0
E_NATURE = 1
@ -339,7 +339,7 @@ def simulation(strategies):
execute_evenement(evenements, evenement, plateau, plateauCouleur, bombes, joueurs, powerups, pieges)
affiche_plateau(canvas, plateau, plateauCouleur, bombes, joueurs, powerups)
affiche_infos(canvasInfosJoueurs, joueurs, plateauCouleur)
temps = int((evenements[0][0]-evenement[0])/3*500)
temps = int((evenements[0][0]-evenement[0])/3*100)
if temps != 0:
fenetre.after(temps, pas_de_jeu)
else:

BIN
main

Binary file not shown.

BIN
main.cmi

Binary file not shown.

BIN
main.cmo

Binary file not shown.

306
main.ml
View File

@ -76,18 +76,20 @@ type game_data = {
mutable boosts : boost array ;
}
type danger = Safe | Danger of float | Fatal of float | Blocked ;;
type danger = Safe | Danger of float | Fatal of float | Blocked | Bonus ;;
let int_of_danger = function
| Safe -> 0
| Danger _ -> 1
| Fatal _ -> 2
| Blocked -> 3 ;;
| Bonus -> 1
| Danger _ -> 2
| Fatal _ -> 3
| Blocked -> 4 ;;
let danger_of_int t = function
| 0 -> Safe
| 1 -> Danger t
| 2 -> Fatal t
| 1 -> Bonus
| 2 -> Danger t
| 3 -> Fatal t
| _ -> Blocked ;;
type moveType = EscapeDeath | BlowUpCrates | KillPlayers | ClaimLand ;;
@ -113,11 +115,11 @@ let is_valid i j len hei =
i >= 0 && j >= 0 && i < len && j < hei ;;
let print_direction = function
| 0 -> Printf.printf "NORTH "
| 1 -> Printf.printf "EAST "
| 2 -> Printf.printf "SOUTH "
| 3 -> Printf.printf "WEST "
| 4 -> Printf.printf "STILL "
| 0 -> Printf.fprintf stderr "NORTH "
| 1 -> Printf.fprintf stderr "EAST "
| 2 -> Printf.fprintf stderr "SOUTH "
| 3 -> Printf.fprintf stderr "WEST "
| 4 -> Printf.fprintf stderr "STILL "
| _-> failwith "ERROR : invalid direction" ;;
let level_of_danger = function
@ -135,57 +137,63 @@ let overwrite_file (filename : string) =
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
let print_game_data (gd : game_data) =
Printf.printf "--------------------------------| Board data |--------------------------------\n" ;
Printf.printf "Time : %f\n" gd.dt ;
Printf.printf "ID : %d\n" gd.player_id ;
Printf.printf "Laby [of size %d %d]:\n" (Array.length gd.laby) (Array.length gd.laby.(0));
Printf.fprintf stderr "--------------------------------| Board data |--------------------------------\n" ;
Printf.fprintf stderr "Time : %f\n" gd.dt ;
Printf.fprintf stderr "ID : %d\n" gd.player_id ;
Printf.fprintf stderr "Laby [of size %d %d]:\n" (Array.length gd.laby) (Array.length gd.laby.(0));
for l = 0 to Array.length gd.laby -1 do
Printf.printf " " ;
Printf.fprintf stderr " " ;
for c = 0 to Array.length gd.laby.(l) -1 do
Printf.printf "%d " gd.laby.(l).(c) ;
Printf.fprintf stderr "%d " gd.laby.(l).(c) ;
done;
Printf.printf "\n"
Printf.fprintf stderr "\n"
done ;
Printf.printf "Bombs (%d) : \n" gd.nbombs ;
Printf.fprintf stderr "Bombs (%d) : \n" gd.nbombs ;
for b = 0 to gd.nbombs -1 do
Printf.printf " [Bomb] (at %d %d) (of size %d) (blowing up at %f)\n" gd.bombs.(b).xy.x gd.bombs.(b).xy.y gd.bombs.(b).size gd.bombs.(b).det_time ;
Printf.fprintf stderr " [Bomb] (at %d %d) (of size %d) (blowing up at %f)\n" gd.bombs.(b).xy.x gd.bombs.(b).xy.y gd.bombs.(b).size gd.bombs.(b).det_time ;
done;
Printf.printf "Players (%d) : \n" gd.nplayers ;
Printf.fprintf stderr "Players (%d) : \n" gd.nplayers ;
for b = 0 to gd.nplayers -1 do
Printf.printf " [Player %d] (at %d %d) (holding %d %d %d %d %d)\n" gd.players.(b).id gd.players.(b).xy.x gd.players.(b).xy.y gd.players.(b).nspeed gd.players.(b).nbomb_atonce gd.players.(b).bomb_radius gd.players.(b).ndash gd.players.(b).ntraps ;
Printf.fprintf stderr " [Player %d] (at %d %d) (holding %d %d %d %d %d)\n" gd.players.(b).id gd.players.(b).xy.x gd.players.(b).xy.y gd.players.(b).nspeed gd.players.(b).nbomb_atonce gd.players.(b).bomb_radius gd.players.(b).ndash gd.players.(b).ntraps ;
done;
Printf.printf "Boosts (%d) : \n" gd.nboosts ;
Printf.fprintf stderr "Boosts (%d) : \n" gd.nboosts ;
for b = 0 to gd.nboosts -1 do
Printf.printf " [Boost] (at %d %d) (of type %d)\n" gd.boosts.(b).xy.x gd.boosts.(b).xy.y gd.boosts.(b).spec ;
Printf.fprintf stderr " [Boost] (at %d %d) (of type %d)\n" gd.boosts.(b).xy.x gd.boosts.(b).xy.y gd.boosts.(b).spec ;
done;;
let print_danger_levels (map : danger array array) =
Printf.printf "--------------------------------| Danger levels |--------------------------------\n" ;
Printf.fprintf stderr "--------------------------------| Danger levels |--------------------------------\n" ;
for l = 0 to (Array.length map -1) do
for c = 0 to (Array.length map.(l) -1) do
match map.(l).(c) with
| Blocked -> Printf.printf "@ "
| Safe -> Printf.printf ". "
| Danger x -> Printf.printf "! "
| Fatal x -> Printf.printf "X "
| Blocked -> Printf.fprintf stderr "@ "
| Safe -> Printf.fprintf stderr ". "
| Bonus -> Printf.fprintf stderr "+ "
| Danger x -> Printf.fprintf stderr "! "
| Fatal x -> Printf.fprintf stderr "X "
done;
Printf.printf "\n"
Printf.fprintf stderr "\n"
done ;;
let print_gain_map (map : int array array) =
Printf.printf "--------------------------------| Gain levels |--------------------------------\n" ;
Printf.fprintf stderr "--------------------------------| Gain levels |--------------------------------\n" ;
for l = 0 to (Array.length map -1) do
for c = 0 to (Array.length map.(l) -1) do
Printf.printf "%d " map.(l).(c) ;
Printf.fprintf stderr "%d " map.(l).(c) ;
done;
Printf.printf "\n"
Printf.fprintf stderr "\n"
done ;;
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
let get_meta_info () =
let ptr = open_in "main.sav" in
let rec ln_b b = function
| k when k < 0 -> failwith "are you sure about that ?"
| k when k < b -> 0
| k -> 1 + ln_b b (k/b) ;;
let get_meta_info (pid : int) =
let ptr = open_in ("main_"^(string_of_int pid)^".sav") in
match (int_of_string (input_line ptr)) with
| 0 -> current_status := EscapeDeath
| 1 -> current_status := BlowUpCrates
@ -194,8 +202,8 @@ let get_meta_info () =
| _ -> current_status := EscapeDeath ;
close_in ptr ;;
let set_meta_info () =
let ptr = open_out "main.sav" in
let set_meta_info (pid : int) =
let ptr = open_out ("main_"^(string_of_int pid)^".sav") in
match !current_status with
| EscapeDeath -> Printf.fprintf ptr "0"
| BlowUpCrates -> Printf.fprintf ptr "1"
@ -209,6 +217,9 @@ let set_meta_info () =
let int_of_string (str : string) =
String.fold_right (fun ch acc -> let cd = Char.code ch in if cd >= 48 || cd <= 57 then 10*acc + cd - 48 else failwith "not an integer\n") str 0 ;;
let string_of_int (k0 : int) =
String.make (1) (Char.chr (k0 + 48)) ;;
let int_n_of_string (str : string) (n : int) (nlast : int ref) =
let res = Array.make n 0 in
let rec aux idres idstr = match idstr with
@ -235,15 +246,15 @@ let parse_input (str : string) =
let (res : game_data) = {dt = 0. ; player_id = 0 ; laby = [||] ; nbombs = 0 ; bombs = [||] ; nplayers = 0 ; players = [||] ; nboosts = 0 ; boosts = [||] ;} in
try
(* time *)
if debug_all then Printf.printf "Time\n" ;
if debug_all then Printf.fprintf stderr "Time\n" ;
res.dt <- Float.of_string (input_line ptr) ;
(* player_id *)
if debug_all then Printf.printf "PID\n" ;
if debug_all then Printf.fprintf stderr "PID\n" ;
res.player_id <- int_of_string (input_line ptr) ;
(* maze *)
if debug_all then Printf.printf "Maze\n" ;
if debug_all then Printf.fprintf stderr "Maze\n" ;
let msize = int_n_of_string (input_line ptr) 2 useless in
res.laby <- Array.make msize.(0) [||] ;
@ -253,7 +264,7 @@ let parse_input (str : string) =
done;
(* bombs *)
if debug_all then Printf.printf "Boom\n" ;
if debug_all then Printf.fprintf stderr "Boom\n" ;
res.nbombs <- int_of_string (input_line ptr) ;
res.bombs <- Array.make res.nbombs default_bomb ;
@ -267,7 +278,7 @@ let parse_input (str : string) =
done;
(* players *)
if debug_all then Printf.printf "Players\n" ;
if debug_all then Printf.fprintf stderr "Players\n" ;
res.nplayers <- int_of_string (input_line ptr) ;
res.players <- Array.make res.nplayers default_player ;
@ -277,7 +288,7 @@ let parse_input (str : string) =
done;
(* boosts *)
if debug_all then Printf.printf "Boosts\n" ;
if debug_all then Printf.fprintf stderr "Boosts\n" ;
res.nboosts <- int_of_string (input_line ptr) ;
res.boosts <- Array.make res.nboosts default_boost ;
@ -286,7 +297,7 @@ let parse_input (str : string) =
res.boosts.(p) <- {xy = {x = dat.(0) ; y = dat.(1) ;} ; spec = dat.(2)}
done;
if debug_all then Printf.printf "Done!\n" ;
if debug_all then Printf.fprintf stderr "Done!\n" ;
close_in ptr ;
res
with
@ -318,6 +329,11 @@ let evaluate_dangers (gd : game_data) =
done
done ;
(* add bonuses *)
for b = 0 to gd.nboosts -1 do
res.(gd.boosts.(b).xy.x).(gd.boosts.(b).xy.y) <- danger_priority (res.(gd.boosts.(b).xy.x).(gd.boosts.(b).xy.y)) Bonus
done;
(* sort bombs based on detonation time *)
for b = 0 to gd.nbombs -1 do
let m = ref gd.bombs.(b).det_time
@ -401,64 +417,48 @@ let cell_values (gd : game_data) =
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
let is_safe = function
| Safe | Danger _ -> true
| Fatal _ | Blocked -> false ;;
let move_safe (gd : game_data) (dgs : danger array array) =
(* use this whenever you are standing on a non-safe tile *)
(* Strat : find the shortest, safest path *)
let pid = gd.player_id in
let interval = Float.pow 0.9 (float_of_int gd.players.(pid).nspeed) in
if debug_all then Printf.printf "I = %f\n" interval ;
let lines = Array.length gd.laby
and cols = Array.length gd.laby.(0) in
(* BFS to find the nearest safe spot (if it exists) *)
try
(* 0. if you're standing on a safe tile, stay there *)
let (cx, cy) = (gd.players.(pid).xy.x, gd.players.(pid).xy.y) in
if dgs.(cx).(cy) = Safe then begin
current_status := BlowUpCrates ;
raise (ReturnInt 4) ;
end;
let has_a_safe_path_origin (cx0 : int) (cy0 : int) (lines : int) (cols : int) (simt : float) (interval : float) (gd : game_data) (dgs : danger array array) (white_dgs : danger array) (white_gd : int array) (black_dgs : danger array) (black_gd : int array) (maxdepth : int) =
(*
core function
performs a BFS starting at (cx0, cy0), avoiding anything in blacklists and halting upon stepping on a whitelisted element
*)
let visited = Hashtbl.create 100 in
let has_a_safe_path (cx0 : int) (cy0 : int) (simt : float) =
let q = Queue.create () in
Hashtbl.add visited (cx0, cy0) 1 ;
if is_valid (cx0+1) (cy0) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0+1).(cy0)) && (simt +. interval) < (level_of_danger dgs.(cx0+1).(cy0)) +. explosion_time) then begin (* South *)
if debug_all then Printf.printf "[escape] +South\n" ;
if debug_all then Printf.fprintf stderr "[escape] +South\n" ;
Queue.add (cx0+1, cy0, simt +. interval, 2) q ;
end;
if is_valid (cx0-1) (cy0) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0-1).(cy0)) && (simt +. interval) < (level_of_danger dgs.(cx0-1).(cy0)) +. explosion_time) then begin (* North *)
if debug_all then Printf.printf "[escape] +North\n" ;
if debug_all then Printf.fprintf stderr "[escape] +North\n" ;
Queue.add (cx0-1, cy0, simt +. interval, 0) q ;
end;
if is_valid (cx0) (cy0+1) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0).(cy0+1)) && (simt +. interval) < (level_of_danger dgs.(cx0).(cy0+1)) +. explosion_time) then begin (* East *)
if debug_all then Printf.printf "[escape] +East\n" ;
if debug_all then Printf.fprintf stderr "[escape] +East\n" ;
Queue.add (cx0, cy0+1, simt +. interval, 1) q ;
end;
if is_valid (cx0) (cy0-1) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0).(cy0-1)) && (simt +. interval) < (level_of_danger dgs.(cx0).(cy0-1)) +. explosion_time) then begin (* West *)
if debug_all then Printf.printf "[escape] +West\n" ;
if debug_all then Printf.fprintf stderr "[escape] +West\n" ;
Queue.add (cx0, cy0-1, simt +. interval, 3) q ;
end;
if debug_all then Printf.printf "[escape] Attempt 1/1...\n" ;
if debug_all then Printf.fprintf stderr "[escape] Attempt 1/1...\n" ;
try
while not (Queue.is_empty q) do
let (cx, cy, cur_t, direct) = Queue.pop q in
if Hashtbl.find_opt visited (cx, cy) <> None then () else begin
Hashtbl.add visited (cx, cy) 1 ;
(*if debug_all then Printf.printf "dealing at (%d, %d) with dir %d\n" cx cy direct ;*)
if dgs.(cx).(cy) = Safe then
if cur_t > simt +. (float_of_int maxdepth) *. interval then (* too deep *)
raise (ReturnInt 4)
else if Array.mem dgs.(cx).(cy) white_dgs then
raise (ReturnInt direct)
else if dgs.(cx).(cy) = Blocked then
else if Array.mem gd.laby.(cx).(cy) white_gd then
raise (ReturnInt direct)
else if Array.mem dgs.(cx).(cy) black_dgs then
()
else if Array.mem gd.laby.(cx).(cy) black_gd then
()
else begin (* either danger or fatal *)
let dang_time = level_of_danger dgs.(cx).(cy) in
@ -474,16 +474,47 @@ let move_safe (gd : game_data) (dgs : danger array array) =
done;
4
with
| ReturnInt b -> b
in
| ReturnInt b -> b ;;
let result = has_a_safe_path (cx) (cy) gd.dt in
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
let is_safe = function
| Safe | Danger _ | Bonus -> true
| Fatal _ | Blocked -> false ;;
let move_safe (gd : game_data) (dgs : danger array array) =
(* use this whenever you are standing on a non-safe tile *)
(* Strat : find the shortest, safest path *)
let pid = gd.player_id in
let interval = Float.pow 0.9 (float_of_int gd.players.(pid).nspeed) in
if debug_all then Printf.fprintf stderr "I = %f\n" interval ;
let lines = Array.length gd.laby
and cols = Array.length gd.laby.(0) in
(* BFS to find the nearest safe spot (if it exists) *)
try
(* 0. if you're standing on a safe tile, stay there *)
let (cx, cy) = (gd.players.(pid).xy.x, gd.players.(pid).xy.y) in
if dgs.(cx).(cy) = Safe then begin
current_status := BlowUpCrates ;
raise (ReturnInt 4) ;
end;
(*let result = has_a_safe_path (cx) (cy) gd.dt in*)
let result = has_a_safe_path_origin cx cy lines cols gd.dt interval gd dgs [|Bonus|] [||] [|Blocked|] [||] 20 in
if result <> 4 then result else begin
let result2 = has_a_safe_path_origin cx cy lines cols gd.dt interval gd dgs [|Safe|] [||] [|Blocked|] [||] 80 in
if result2 <> 4 then result2
else begin
(* you're probably dead if the code reaches here... *)
if debug_all then Printf.printf "[escape] Attempt F...\n";
if debug_all then Printf.fprintf stderr "[escape] Attempt F...\n";
4
end
end
with
| ReturnInt k -> k ;;
@ -502,68 +533,25 @@ let move_explore (gd: game_data) (dgs : danger array array) =
try
let (cxi, cyi) = (gd.players.(pid).xy.x, gd.players.(pid).xy.y) in
let visited = Hashtbl.create 100 in
let has_a_safe_path (cx0 : int) (cy0 : int) (simt : float) =
let q = Queue.create () in
Hashtbl.add visited (cx0, cy0) 1 ;
if is_valid (cx0+1) (cy0) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0+1).(cy0)) && (simt +. interval) < (level_of_danger dgs.(cx0+1).(cy0)) +. explosion_time) then begin (* South *)
if debug_all then Printf.printf "[crates] +South\n" ;
Queue.add (cx0+1, cy0, simt +. interval, 2) q ;
end;
if is_valid (cx0-1) (cy0) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0-1).(cy0)) && (simt +. interval) < (level_of_danger dgs.(cx0-1).(cy0)) +. explosion_time) then begin (* North *)
if debug_all then Printf.printf "[crates] +North\n" ;
Queue.add (cx0-1, cy0, simt +. interval, 0) q ;
end;
if is_valid (cx0) (cy0+1) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0).(cy0+1)) && (simt +. interval) < (level_of_danger dgs.(cx0).(cy0+1)) +. explosion_time) then begin (* East *)
if debug_all then Printf.printf "[crates] +East\n" ;
Queue.add (cx0, cy0+1, simt +. interval, 1) q ;
end;
if is_valid (cx0) (cy0-1) lines cols && not ((simt +. interval) > (level_of_danger dgs.(cx0).(cy0-1)) && (simt +. interval) < (level_of_danger dgs.(cx0).(cy0-1)) +. explosion_time) then begin (* West *)
if debug_all then Printf.printf "[crates] +West\n" ;
Queue.add (cx0, cy0-1, simt +. interval, 3) q ;
end;
if debug_all then Printf.printf "[crates] Attempt 1/1...\n" ;
try
while not (Queue.is_empty q) do
let (cx, cy, cur_t, direct) = Queue.pop q in
if Hashtbl.find_opt visited (cx, cy) <> None then () else begin
Hashtbl.add visited (cx, cy) 1 ;
(*if debug_all then Printf.printf "[crates] exploring (%d, %d) at time %f for dir %d\n" cx cy cur_t direct ;*)
if gd.laby.(cx).(cy) = 2 then (* crate *)
raise (ReturnInt direct)
else if dgs.(cx).(cy) = Blocked then
()
else begin (* we need to go deeper *)
let dang_time = level_of_danger dgs.(cx).(cy) in
for dir = 0 to 3 do
let newx = cx + fst order.(dir)
and newy = cy + snd order.(dir)
and newt = cur_t +. interval in
if (is_valid newx newy lines cols) && not (newt > dang_time && newt < dang_time +. explosion_time) then
Queue.add (newx, newy, newt, direct) q
done
end
end
done;
(-1)
with
| ReturnInt k -> k
in
let move_with_caution (exit : bool) =
let res = has_a_safe_path cxi cyi gd.dt in
if res <> -1 then begin
if debug_all then Printf.printf "[crates] success!\n" ;
let res = has_a_safe_path_origin cxi cyi lines cols gd.dt interval gd dgs [|Bonus|] [||] [|Blocked|] [||] 5 in
if res <> 4 then begin
if debug_all then Printf.fprintf stderr "[crates] success 1/2!\n" ;
res
end
else begin
if false && exit then
let res2 = has_a_safe_path_origin cxi cyi lines cols gd.dt interval gd dgs [||] [|2|] [|Blocked|] [||] 80 in
if res2 <> 4 then begin
if debug_all then Printf.fprintf stderr "[crates] success 2/2!\n" ;
res2
end
else begin
if false && exit then (* TODO *)
current_status := ClaimLand ;
Printf.fprintf stderr "Exited.\n" ;
4
end
end
in
let safe_path_with_bomb (bx : int) (by : int) (bsize : int) =
@ -593,7 +581,7 @@ let move_explore (gd: game_data) (dgs : danger array array) =
if gd.players.(pid).nbomb_atonce > 0 then begin
current_status := EscapeDeath ;
action := 1;
if debug_all then Printf.printf "Fire in the hole!\n" ;
if debug_all then Printf.fprintf stderr "Fire in the hole!\n" ;
end;
raise (ReturnInt 4) ;
end;
@ -602,7 +590,7 @@ let move_explore (gd: game_data) (dgs : danger array array) =
if gd.players.(pid).nbomb_atonce > 0 then begin
current_status := EscapeDeath ;
action := 1;
if debug_all then Printf.printf "Fire in the hole!\n" ;
if debug_all then Printf.fprintf stderr "Fire in the hole!\n" ;
end;
raise (ReturnInt 4) ;
end;
@ -611,7 +599,7 @@ let move_explore (gd: game_data) (dgs : danger array array) =
if gd.players.(pid).nbomb_atonce > 0 then begin
current_status := EscapeDeath ;
action := 1;
if debug_all then Printf.printf "Fire in the hole!\n" ;
if debug_all then Printf.fprintf stderr "Fire in the hole!\n" ;
end;
raise (ReturnInt 4) ;
end;
@ -620,12 +608,12 @@ let move_explore (gd: game_data) (dgs : danger array array) =
if gd.players.(pid).nbomb_atonce > 0 then begin
current_status := EscapeDeath ;
action := 1;
if debug_all then Printf.printf "Fire in the hole!\n" ;
if debug_all then Printf.fprintf stderr "Fire in the hole!\n" ;
end;
raise (ReturnInt 4) ;
end;
if debug_all then Printf.printf "[crates] Cannot bomb now, searching for a crate...\n";
if debug_all then Printf.fprintf stderr "[crates] Cannot bomb now, searching for a crate...\n";
(* go to one without stepping into a dangerous tile *)
raise (ReturnInt (move_with_caution true)) ;
@ -638,24 +626,30 @@ let move_explore (gd: game_data) (dgs : danger array array) =
let update_strat (gd : game_data) (dgs : danger array array) = match dgs.(gd.players.(gd.player_id).xy.x).(gd.players.(gd.player_id).xy.y) with
| Safe -> ()
| Danger k -> ()
| Bonus -> ()
| Fatal k -> (* should not happen *) current_status := EscapeDeath
| Blocked -> failwith "did you just suffocate the player ?" ;;
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
let debug_game_data1 (gd : game_data) =
Printf.fprintf stderr "[player %d started turn]\n" gd.player_id ;;
let debug_game_data (gd : game_data) =
Printf.fprintf stderr "[player %d]\n" gd.player_id ;;
Printf.fprintf stderr "[player %d ended turn]\n" gd.player_id ;;
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
get_meta_info () ;;
let game_d = parse_input "entrees.txt" ;;
let dangers = evaluate_dangers game_d ;;
let gains = cell_values game_d ;;
get_meta_info game_d.player_id ;;
(*debug_game_data1 game_d ;;*)
if debug_data then begin
print_game_data game_d ;
print_danger_levels dangers ;
@ -664,15 +658,21 @@ end ;;
update_strat game_d dangers ;;
let chosen = ref 0 ;;
let main_actions () = match !current_status with
| EscapeDeath ->
Printf.printf "%d " (move_safe game_d dangers)
chosen := move_safe game_d dangers ;
Printf.printf "%d " !chosen
| BlowUpCrates ->
if dangers.(game_d.players.(game_d.player_id).xy.x).(game_d.players.(game_d.player_id).xy.y) = Safe then
Printf.printf "%d " (move_explore game_d dangers)
if dangers.(game_d.players.(game_d.player_id).xy.x).(game_d.players.(game_d.player_id).xy.y) = Safe then begin
chosen := move_explore game_d dangers ;
Printf.printf "%d " !chosen
end
else begin
current_status := EscapeDeath ;
Printf.printf "%d " (move_safe game_d dangers)
chosen := move_safe game_d dangers ;
Printf.printf "%d " !chosen
end
| ClaimLand ->
()
@ -682,6 +682,10 @@ let main_actions () = match !current_status with
main_actions () ;
Printf.printf "%d" !action ;
debug_game_data game_d ;;
(*debug_game_data game_d ;;*)
set_meta_info () ;;
Printf.fprintf stderr "[player %d went at direction " game_d.player_id ;;
print_direction !chosen ;;
Printf.fprintf stderr "with action %d] time at end : %f\n" !action game_d.dt ;;
set_meta_info game_d.player_id ;;

View File

@ -1 +1 @@
0
1

1
main_0.sav Normal file
View File

@ -0,0 +1 @@
1

1
main_1.sav Normal file
View File

@ -0,0 +1 @@
1

1
main_2.sav Normal file
View File

@ -0,0 +1 @@
0

1
main_3.sav Normal file
View File

@ -0,0 +1 @@
0

View File

@ -1 +0,0 @@
4 1