failsafe
This commit is contained in:
parent
59292ef41b
commit
0767b46821
|
@ -0,0 +1,22 @@
|
||||||
|
11.0
|
||||||
|
3
|
||||||
|
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 2 2 2 2 2 0 2 2 0 2 2 2 2 2 2 5 5 1
|
||||||
|
1 3 1 2 1 2 1 2 1 0 1 2 1 2 1 0 1 2 1 5 1
|
||||||
|
1 0 2 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 0 2 1
|
||||||
|
1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1
|
||||||
|
1 2 0 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 1
|
||||||
|
1 2 1 2 1 2 1 0 1 2 1 2 1 2 1 2 1 2 1 2 1
|
||||||
|
1 2 2 2 0 0 2 2 2 0 2 2 2 2 2 2 2 2 2 2 1
|
||||||
|
1 2 1 2 1 2 1 0 1 2 1 2 1 2 1 2 1 2 1 2 1
|
||||||
|
1 2 2 2 2 2 2 2 2 2 2 0 2 0 2 2 0 2 0 2 1
|
||||||
|
1 0 1 2 1 0 1 2 1 0 1 2 1 2 1 2 1 2 1 0 1
|
||||||
|
1 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 1
|
||||||
|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||||
|
1
|
||||||
|
11 19 1 11.5
|
||||||
|
2
|
||||||
|
11 19 1 0 1 1 0 0
|
||||||
|
11 1 3 0 1 1 0 0
|
||||||
|
0
|
4
exec.sh
4
exec.sh
|
@ -1,2 +1,2 @@
|
||||||
ocamlc main.ml -o bin/main
|
chmod u+x main.ml
|
||||||
./bin/main
|
./main.ml
|
|
@ -379,4 +379,4 @@ def simulation(strategies):
|
||||||
return
|
return
|
||||||
|
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
simulation(["./patient.py", "./aleatoire.py","./patient.py", "./aleatoire.py"])
|
simulation(["./main.ml", "./main.ml","./main.ml", "./main.ml"])
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
3.7
|
3.7
|
||||||
0
|
0
|
||||||
7 11
|
7 11
|
||||||
2 0 0 0 0 0 0 0 0 0 0
|
0 0 2 2 2 2 2 2 2 0 0
|
||||||
0 0 0 0 0 0 0 0 0 0 0
|
0 1 2 1 2 1 2 1 2 1 0
|
||||||
0 0 0 0 0 0 0 0 0 0 2
|
2 2 2 2 2 2 2 0 2 2 2
|
||||||
0 0 0 0 0 0 0 0 0 0 0
|
2 1 0 1 2 1 2 1 2 1 0
|
||||||
3 3 3 0 0 0 0 0 4 4 0
|
2 2 2 2 2 2 2 2 2 2 2
|
||||||
0 0 0 0 0 0 0 0 0 0 0
|
0 1 2 1 2 1 2 1 0 1 0
|
||||||
0 0 0 0 0 0 0 3 3 0 0
|
0 0 2 2 2 2 2 2 2 0 0
|
||||||
3
|
3
|
||||||
3 2 4 4.1
|
3 2 4 4.1
|
||||||
4 4 2 4.3
|
0 1 2 3.9
|
||||||
8 6 3 5.5
|
8 6 3 5.5
|
||||||
5
|
5
|
||||||
2 6 0 0 2 4 5 3
|
1 0 0 0 2 4 5 3
|
||||||
2 0 1 4 3 2 2 2
|
2 0 1 4 3 2 2 2
|
||||||
10 5 2 0 2 3 2 3
|
10 5 2 0 2 3 2 3
|
||||||
5 5 3 5 1 10 2 3
|
5 5 3 5 1 10 2 3
|
||||||
|
|
BIN
bin/main → main
BIN
bin/main → main
Binary file not shown.
|
@ -1,7 +1,9 @@
|
||||||
|
#! /home/alexandre/.opam/myswitch/bin/ocaml
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
|
|
||||||
let debug_all = true ;;
|
let debug_all = false ;;
|
||||||
|
let debug_data = false ;;
|
||||||
let fatal_time = 1.0 ;;
|
let fatal_time = 1.0 ;;
|
||||||
let explosion_time = 1.0 ;;
|
let explosion_time = 1.0 ;;
|
||||||
|
|
||||||
|
@ -178,6 +180,28 @@ let print_gain_map (map : int array array) =
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
|
|
||||||
|
let get_meta_info () =
|
||||||
|
let ptr = open_in "main.sav" in
|
||||||
|
match (int_of_string (input_line ptr)) with
|
||||||
|
| 0 -> current_status := EscapeDeath
|
||||||
|
| 1 -> current_status := BlowUpCrates
|
||||||
|
| 2 -> current_status := ClaimLand
|
||||||
|
| 3 -> current_status := KillPlayers
|
||||||
|
| _ -> current_status := EscapeDeath ;
|
||||||
|
close_in ptr ;;
|
||||||
|
|
||||||
|
let set_meta_info () =
|
||||||
|
let ptr = open_out "main.sav" in
|
||||||
|
match !current_status with
|
||||||
|
| EscapeDeath -> Printf.fprintf ptr "0"
|
||||||
|
| BlowUpCrates -> Printf.fprintf ptr "1"
|
||||||
|
| ClaimLand -> Printf.fprintf ptr "2"
|
||||||
|
| KillPlayers -> Printf.fprintf ptr "3" ;
|
||||||
|
close_out ptr ;;
|
||||||
|
|
||||||
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
|
|
||||||
let int_of_string (str : string) =
|
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 ;;
|
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 ;;
|
||||||
|
|
||||||
|
@ -560,32 +584,40 @@ let move_explore (gd: game_data) (dgs : danger array array) =
|
||||||
result
|
result
|
||||||
in
|
in
|
||||||
|
|
||||||
(* check if there's a crate next to the player, and if upon placing a bomb it won't softlock the player *)
|
(* check if there's a crate next to the player, and if upon placing a bomb it won't softlock the player, and if you can place a bomb *)
|
||||||
if is_valid (cxi+1) (cyi) lines cols && gd.laby.(cxi+1).(cyi) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at South *)
|
if is_valid (cxi+1) (cyi) lines cols && gd.laby.(cxi+1).(cyi) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at South *)
|
||||||
|
if gd.players.(pid).nbomb_atonce > 0 then begin
|
||||||
current_status := EscapeDeath ;
|
current_status := EscapeDeath ;
|
||||||
action := 1;
|
action := 1;
|
||||||
if debug_all then Printf.printf "Fire in the hole!\n" ;
|
if debug_all then Printf.printf "Fire in the hole!\n" ;
|
||||||
|
end;
|
||||||
raise (ReturnInt 4) ;
|
raise (ReturnInt 4) ;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if is_valid (cxi-1) (cyi) lines cols && gd.laby.(cxi-1).(cyi) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at North *)
|
if is_valid (cxi-1) (cyi) lines cols && gd.laby.(cxi-1).(cyi) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at North *)
|
||||||
|
if gd.players.(pid).nbomb_atonce > 0 then begin
|
||||||
current_status := EscapeDeath ;
|
current_status := EscapeDeath ;
|
||||||
action := 1;
|
action := 1;
|
||||||
if debug_all then Printf.printf "Fire in the hole!\n" ;
|
if debug_all then Printf.printf "Fire in the hole!\n" ;
|
||||||
|
end;
|
||||||
raise (ReturnInt 4) ;
|
raise (ReturnInt 4) ;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if is_valid (cxi) (cyi+1) lines cols && gd.laby.(cxi).(cyi+1) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at East *)
|
if is_valid (cxi) (cyi+1) lines cols && gd.laby.(cxi).(cyi+1) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at East *)
|
||||||
|
if gd.players.(pid).nbomb_atonce > 0 then begin
|
||||||
current_status := EscapeDeath ;
|
current_status := EscapeDeath ;
|
||||||
action := 1;
|
action := 1;
|
||||||
if debug_all then Printf.printf "Fire in the hole!\n" ;
|
if debug_all then Printf.printf "Fire in the hole!\n" ;
|
||||||
|
end;
|
||||||
raise (ReturnInt 4) ;
|
raise (ReturnInt 4) ;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if is_valid (cxi) (cyi-1) lines cols && gd.laby.(cxi).(cyi-1) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at West *)
|
if is_valid (cxi) (cyi-1) lines cols && gd.laby.(cxi).(cyi-1) = 2 && (safe_path_with_bomb cxi cyi gd.players.(pid).bomb_radius <> 4) then begin (* Crate at West *)
|
||||||
|
if gd.players.(pid).nbomb_atonce > 0 then begin
|
||||||
current_status := EscapeDeath ;
|
current_status := EscapeDeath ;
|
||||||
action := 1;
|
action := 1;
|
||||||
if debug_all then Printf.printf "Fire in the hole!\n" ;
|
if debug_all then Printf.printf "Fire in the hole!\n" ;
|
||||||
|
end;
|
||||||
raise (ReturnInt 4) ;
|
raise (ReturnInt 4) ;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -599,14 +631,45 @@ 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 -> ()
|
||||||
|
| Fatal k -> (* should not happen *) current_status := EscapeDeath
|
||||||
|
| Blocked -> failwith "did you just suffocate the player ?" ;;
|
||||||
|
|
||||||
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
|
|
||||||
|
get_meta_info () ;;
|
||||||
|
|
||||||
let game_d = parse_input "input_test.txt" ;;
|
let game_d = parse_input "input_test.txt" ;;
|
||||||
let dangers = evaluate_dangers game_d ;;
|
let dangers = evaluate_dangers game_d ;;
|
||||||
let gains = cell_values game_d ;;
|
let gains = cell_values game_d ;;
|
||||||
|
|
||||||
print_game_data game_d ;;
|
if debug_data then begin
|
||||||
print_danger_levels dangers ;;
|
print_game_data game_d ;
|
||||||
print_gain_map gains ;;
|
print_danger_levels dangers ;
|
||||||
|
print_gain_map gains ;
|
||||||
|
end ;;
|
||||||
|
|
||||||
Printf.printf "move at\n";;
|
update_strat game_d dangers ;;
|
||||||
print_direction (move_explore game_d dangers) ;;
|
|
||||||
Printf.printf "\n" ;;
|
let main_actions () = match !current_status with
|
||||||
|
| EscapeDeath ->
|
||||||
|
Printf.printf "%d " (move_safe game_d dangers)
|
||||||
|
| 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)
|
||||||
|
else begin
|
||||||
|
current_status := EscapeDeath ;
|
||||||
|
Printf.printf "%d " (move_safe game_d dangers)
|
||||||
|
end
|
||||||
|
| ClaimLand ->
|
||||||
|
()
|
||||||
|
| KillPlayers ->
|
||||||
|
() ;;
|
||||||
|
|
||||||
|
main_actions () ;
|
||||||
|
Printf.printf "%d" !action ;
|
||||||
|
|
||||||
|
set_meta_info () ;;
|
|
@ -0,0 +1 @@
|
||||||
|
4 0
|
Loading…
Reference in New Issue