|
Zakath |
 |
Guru 
Déconnecté
Niveau : 5 N° de Membre :
7213
Ancienneté : 97%
Participation : 12%
Inscription: 15 Dec 2002
Localisation: Copenhague
Messages: 9866
Sujets Lancés : 426
|
Allez, un serveur qui marche et une fourmi qui devrait marcher mais qui ne marche pas encore :
code: type pos = int * int;;
type left_or_right = Left | Right;;
type sense_dir = Here | Ahead | RightAhead | LeftAhead;;
type color = Black | Red;;
type ant = {mutable id :int; col :color; mutable resting :int; mutable dir :int; mutable has_food :bool; mutable state :int};;
type case = Rock | Clear | AntHill of color;;
type etat_case = {mutable phys :case; mutable food :int; mutable fourmi :ant; mutable marker :bool array * bool array};;
(*carte_phys
carte_food
carte_marker_0
carte_marker_1
carte_marker_2
carte_marker_3
carte_marker_4
carte_marker_5
carte_ant_id
carte_ant_col
carte_ant_dir
carte_ant_resting
carte_ant_has_food
carte_ant_state*)
type sensedir =
Here
|Ahead
|LeftAhead
|RightAhead;;
type condition =
Friend
|Foe
|FriendWithFood
|FoeWithFood
|Nourriture
|Caillou
|Marker of int
|FoeMarker
|Home
|FoeHome;;
type instruction =
Sense of sensedir * int * int * condition
|Mark of int * int
|Unmark of int * int
|PickUp of int * int
|Drop of int
|Turn of left_or_right * int
|Move of int * int
|Flip of int * int * int;;
let void_ant = {id = -1; col = Red; resting = 0; dir = 0; has_food = false; state = 0};;
let init_ant ident couleur =
{id = ident; col = couleur; resting = 0; dir = 0; has_food = false; state = 0};;
let adjacent_cell p d =
let (x, y) = p in
match d with
|0 -> (x+1,y)
|1 -> if (y mod 2 = 0) then (x,y+1) else (x+1,y+1)
|2 -> if (y mod 2 = 0) then (x-1,y+1) else (x,y+1)
|3 -> (x-1,y)
|4 -> if (y mod 2 = 0) then (x-1,y-1) else (x,y-1)
|5 -> if (y mod 2 = 0) then (x,y-1) else (x+1,y-1)
|_ -> failwith "Mauvaise direction";;
let turn d = function
|Left -> (d + 5) mod 6
|Right -> (d + 1) mod 6;;
let sensed_cell p d = function
|Here -> p
|Ahead -> adjacent_cell p d
|LeftAhead -> adjacent_cell p (turn d Left)
|RightAhead -> adjacent_cell p (turn d Right);;
let other_color = function
|Red -> Black
|Black -> Red;;
(* Lecture d'une map *)
let read_map file =
let fcarte = open_in file in
let x_dim = int_of_string (input_line fcarte) in
let y_dim = int_of_string (input_line fcarte) in
(*let carte = Array.create_matrix x_dim y_dim {phys = Clear; food = 0; fourmi = void_ant; marker = ([|false;false;false;false;false;false|], [|false; false; false; false; false;false|])} in*)
let carte_phys = Array.create_matrix y_dim x_dim Clear and
carte_food = Array.create_matrix y_dim x_dim 0 and
carte_marker_0 = Array.create_matrix y_dim x_dim (false, false) and
carte_marker_1 = Array.create_matrix y_dim x_dim (false, false) and
carte_marker_2 = Array.create_matrix y_dim x_dim (false, false) and
carte_marker_3 = Array.create_matrix y_dim x_dim (false, false) and
carte_marker_4 = Array.create_matrix y_dim x_dim (false, false) and
carte_marker_5 = Array.create_matrix y_dim x_dim (false, false) and
carte_ant_id = Array.create_matrix y_dim x_dim (-1) and
carte_ant_col = Array.create_matrix y_dim x_dim Red and
carte_ant_resting = Array.create_matrix y_dim x_dim 0 and
carte_ant_has_food = Array.create_matrix y_dim x_dim false and
carte_ant_dir = Array.create_matrix y_dim x_dim 0 and
carte_ant_state = Array.create_matrix y_dim x_dim 0 and f = ref 0 in
for i = 0 to (y_dim - 1) do
let ligne = input_line fcarte in
let j = ref 0 and n = String.length ligne and k = ref 0 in
while !j < n do
match ligne.[!j] with
|' ' -> j:= !j+1
|'#' -> carte_phys.(i).(!k) <- Rock; j:= !j+1; k:= !k+1
|'.' -> j:= !j+1; k:= !k+1
|'+' -> carte_phys.(i).(!k) <- AntHill Red; carte_ant_id.(i).(!k) <- !f; j:= !j+1; k:= !k+1; f:= !f+1;
|'-' -> carte_phys.(i).(!k) <- AntHill Black; carte_ant_id.(i).(!k) <- !f; carte_ant_col.(i).(!k) <- Black; j:= !j+1; k:= !k+1;f:= !f+1
|w -> carte_food.(i).(!k) <- (int_of_char w - 48); j:= !j+1; k:= !k+1
done
done;
(carte_phys, carte_food, carte_marker_0, carte_marker_1, carte_marker_2, carte_marker_3, carte_marker_4, carte_marker_5, carte_ant_id, carte_ant_col, carte_ant_dir, carte_ant_resting, carte_ant_has_food, carte_ant_state, x_dim, y_dim);;
let (carte_phys, carte_food, carte_marker_0, carte_marker_1, carte_marker_2, carte_marker_3, carte_marker_4, carte_marker_5, carte_ant_id, carte_ant_col, carte_ant_dir, carte_ant_resting, carte_ant_has_food, carte_ant_state, x_dim, y_dim) = read_map "E:\\Informatique\\ICFP\\sample.world";;
let rocky (x,y) =
try carte_phys.(x).(y) = Rock with Invalid_argument("Array.get") -> true;;
let nb_ants() = (*Compte le nombre de fourmis*)
let n = ref 0 in
for i = 0 to (y_dim-1) do
for j = 0 to (x_dim-1) do
if carte_ant_id.(i).(j) >= 0 then
n := !n + 1;
done
done;
!n;;
let ant_pos = Array.create (nb_ants()) (-1,-1);;
let find_ant ident =
let f = ref void_ant and x= ref (-1) and y = ref (-1) in
for i = 0 to (y_dim-1) do
for j = 0 to (x_dim-1) do
if carte_ant_id.(i).(j) = ident then (x:= i; y:= j)
done
done;
(!x, !y);;
for i = 0 to (Array.length ant_pos - 1) do
ant_pos.(i) <- (find_ant i);
done;;
(*let chan = open_out "E:\\Informatique\\ICFP\\out2" in
for x = 0 to (y_dim - 1) do
for y = 0 to (x_dim - 1) do
Printf.fprintf chan "cell (%d, %d): " x y;
if rocky (x,y) then Printf.fprintf chan "rocky;" else
(if carte_food.(x).(y) > 0 then Printf.fprintf chan "%d food; " carte_food.(x).(y);
if carte_phys.(x).(y) = AntHill Red then Printf.fprintf chan "red hill; ";
if carte_phys.(x).(y) = AntHill Black then Printf.fprintf chan "black hill; ";
if carte_ant_id.(x).(y) >= 0 then (if carte_ant_col.(x).(y) = Red then Printf.fprintf chan "red " else Printf.fprintf chan "black "; Printf.fprintf chan "ant of id %d, dir %d, food %b, state %d, resting %d;" carte_ant_id.(x).(y) carte_ant_dir.(x).(y) carte_ant_has_food.(x).(y) carte_ant_state.(x).(y) carte_ant_resting.(x).(y)));
Printf.fprintf chan "\n"
done
done;
Printf.fprintf chan "\n\n\n";;*)
(* Lecture d'un cerveau de fourmi *)
let read_brain file =
let fbrain = open_in file in
let instruct = Array.create 9999 "" and k = ref 0 in
try
for i = 0 to 9998 do
instruct.(i) <- input_line fbrain;
k:= !k+1
done;
instruct;
with End_of_file -> let t = Array.create !k "" in
for i = 0 to (!k-1) do
t.(i) <- instruct.(i)
done; t;;
let instruct1 = read_brain "E:\\Informatique\\ICFP\\brain3_def";;
let instruct2 = read_brain "E:\\Informatique\\ICFP\\do_nothing.ant";;
let rec print_list = function
|[] -> ()
|t::q -> Printf.printf "%s\n" t; print_list q;;
let lexeur inst =
let i = ref 0 and i2 = ref 0 and l = ref [] in
while !i < (String.length inst) do
while (!i < (String.length inst) && inst.[!i] <> ' ') do
i:= !i+1
done;
l:= (String.sub inst !i2 (!i - !i2))::(!l);
i:= !i+1;
i2 := !i
done;
List.rev(!l);;
let cond_of_string = function
|"Friend" -> Friend
|"Foe" -> Foe
|"FriendWithFood" -> FriendWithFood
|"FoeWithFood" -> FoeWithFood
|"Rock" -> Caillou
|"Food" -> Nourriture
|"Marker 0" -> Marker 0
|"Marker 1" -> Marker 1
|"Marker 2" -> Marker 2
|"Marker 3" -> Marker 3
|"Marker 4" -> Marker 4
|"Marker 5" -> Marker 5
|"FoeMarker" -> FoeMarker
|"Home" -> Home
|"FoeHome" -> FoeHome
|t -> Printf.printf "%s\n" t; failwith "Erreur de condition";;
let lr_of_string = function
|"Left" -> Left
|"Right" -> Right
|_ -> failwith "Erreur de direction de virage";;
let sensedir_of_string = function
|"Here" -> Here
|"Ahead" -> Ahead
|"LeftAhead" -> LeftAhead
|"RightAhead" -> RightAhead
|_ -> failwith "Erreur de direction de détection";;
let parseur = function
|["Sense";sd;st1;st2;cond] -> Sense ((sensedir_of_string sd), (int_of_string st1), (int_of_string st2), (cond_of_string cond))
|["Sense";sd;st1;st2;cond;i] -> Sense ((sensedir_of_string sd), (int_of_string st1), (int_of_string st2), (cond_of_string (cond^" "^i)))
|["Mark";i;st] -> Mark ((int_of_string i), (int_of_string st))
|["Unmark";i;st] -> Unmark ((int_of_string i), (int_of_string st))
|["PickUp";st1;st2] -> PickUp ((int_of_string st1), (int_of_string st2))
|["Drop";st] -> Drop (int_of_string st)
|["Turn";lr;st] -> Turn ((lr_of_string lr), (int_of_string st))
|["Move";st1;st2] -> Move ((int_of_string st1), (int_of_string st2))
|["Flip";p;st1;st2] -> Flip ((int_of_string p), (int_of_string st1), (int_of_string st2))
|t -> print_list t; failwith "Instruction non valide";;
let make_inst t =
let n = Array.length t in
let inst = Array.create n (Drop 0) in
for i = 0 to (n-1) do
inst.(i) <- parseur (lexeur (t.(i)))
done;
inst;;
let inst1 = make_inst instruct1;;
let inst2 = make_inst instruct2;;
let some_ant_is_at (x,y) =
carte_ant_id.(x).(y) >= 0;;
let ant_is_alive ident col =
let (x,y) = (ant_pos.(ident)) in
carte_ant_id.(x).(y) >= 0;;
let test_anthill (x,y) col =
match carte_phys.(x).(y) with
|AntHill c -> c = col
|_ -> false;;
let test_marker (x,y) = function
|Red -> (fst(carte_marker_0.(x).(y))) || (fst(carte_marker_1.(x).(y))) || (fst(carte_marker_2.(x).(y))) || (fst(carte_marker_3.(x).(y))) || (fst(carte_marker_4.(x).(y))) || (fst(carte_marker_5.(x).(y)))
|Black -> (snd(carte_marker_0.(x).(y))) || (snd(carte_marker_1.(x).(y))) || (snd(carte_marker_2.(x).(y))) || (snd(carte_marker_3.(x).(y))) || (snd(carte_marker_4.(x).(y))) || (snd(carte_marker_5.(x).(y)));;
let cell_match (x,y) col = function
|Caillou -> rocky (x,y)
|Friend -> carte_ant_id.(x).(y) >=0 && carte_ant_col.(x).(y) = col
|Foe -> carte_ant_id.(x).(y) >=0 && carte_ant_col.(x).(y) <> col
|FriendWithFood -> carte_ant_id.(x).(y) >=0 && carte_ant_col.(x).(y) = col && carte_ant_has_food.(x).(y)
|FoeWithFood -> carte_ant_id.(x).(y) >=0 && carte_ant_col.(x).(y) <> col && carte_ant_has_food.(x).(y)
|Nourriture -> carte_food.(x).(y) > 0
|Marker 0 -> if col = Red then (fst(carte_marker_0.(x).(y))) else (snd(carte_marker_0.(x).(y)))
|Marker 1 -> if col = Red then (fst(carte_marker_1.(x).(y))) else (snd(carte_marker_1.(x).(y)))
|Marker 2 -> if col = Red then (fst(carte_marker_2.(x).(y))) else (snd(carte_marker_2.(x).(y)))
|Marker 3 -> if col = Red then (fst(carte_marker_3.(x).(y))) else (snd(carte_marker_3.(x).(y)))
|Marker 4 -> if col = Red then (fst(carte_marker_4.(x).(y))) else (snd(carte_marker_4.(x).(y)))
|Marker 5 -> if col = Red then (fst(carte_marker_5.(x).(y))) else (snd(carte_marker_5.(x).(y)))
|Marker i -> failwith "Marqueur invalide"
|FoeMarker -> test_marker (x,y) col
|Home -> test_anthill (x,y) col
|FoeHome -> test_anthill (x,y) (other_color col);;
let adjacent_ants (x,y) col =
let n = ref 0 in
for d = 0 to 5 do
let (i,j) = adjacent_cell (x,y) d in
if carte_ant_id.(i).(j) >= 0 && carte_ant_col.(i).(j) = col then n:= !n+1
done; !n;;
let check_surrounded_ant (x,y) =
if carte_ant_id.(x).(y) >= 0 then
if (adjacent_ants (x,y) (other_color carte_ant_col.(x).(y))) >= 5 then
begin
ant_pos.(carte_ant_id.(x).(y)) <- ((-1), (-1));
carte_ant_id.(x).(y) <- (-1);
carte_food.(x).(y) <- (carte_food.(x).(y) + 3);
if carte_ant_has_food.(x).(y) then carte_food.(x).(y) <- carte_food.(x).(y) + 1;
end;;
let check_surrounded_ants (x,y) =
check_surrounded_ant (x,y);
for d = 0 to 5 do
check_surrounded_ant (adjacent_cell (x,y) d)
done;;
let print_carte() =
let chan = open_out "E:\\Informatique\\ICFP\\out" in
for x = 0 to (x_dim - 1) do
for y = 0 to (y_dim - 1) do
Printf.fprintf chan "cell (%d, %d): " x y;
if rocky (x,y) then Printf.fprintf chan "rocky;" else
(if carte_food.(x).(y) > 0 then Printf.fprintf chan "%d food; " carte_food.(x).(y);
if carte_phys.(x).(y) = AntHill Red then Printf.fprintf chan "red hill; ";
if carte_phys.(x).(y) = AntHill Black then Printf.fprintf chan "black hill; ";
if carte_ant_id.(x).(y) >= 0 then (if carte_ant_col.(x).(y) = Red then Printf.fprintf chan "red " else Printf.fprintf chan "black "; Printf.fprintf chan "ant of id %d, dir %d, food %b, state %d, resting %d;" carte_ant_id.(x).(y) carte_ant_dir.(x).(y) carte_ant_has_food.(x).(y) carte_ant_state.(x).(y) carte_ant_resting.(x).(y)));
Printf.fprintf chan "\n"
done
done;
Printf.fprintf chan "\n\n";;
let step ident ch =
let inst = ref [||] in
let (x, y) = (ant_pos.(ident)) in
if x <> (-1) then
begin
if carte_ant_resting.(x).(y) > 0 then carte_ant_resting.(x).(y) <- carte_ant_resting.(x).(y) - 1
else
begin
if carte_ant_col.(x).(y) = Red then inst := inst1 else inst:= inst2;
match !inst.(carte_ant_state.(x).(y)) with
|Sense (sd, st1, st2, cond) ->
Printf.fprintf ch "Sense\n";
let p2 = sensed_cell (x,y) carte_ant_dir.(x).(y) sd in
let st = if cell_match (x,y) carte_ant_col.(x).(y) cond then st1 else st2 in
carte_ant_state.(x).(y) <- st;
|Mark (0, st) ->
Printf.fprintf ch "Mark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_0.(x).(y) <- (true, snd(carte_marker_0.(x).(y)))) else (carte_marker_0.(x).(y) <- (fst(carte_marker_0.(x).(y)), true));
carte_ant_state.(x).(y) <- st
|Mark (1, st) ->
Printf.fprintf ch "Mark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_1.(x).(y) <- (true, snd(carte_marker_1.(x).(y)))) else (carte_marker_1.(x).(y) <- (fst(carte_marker_1.(x).(y)), true));
carte_ant_state.(x).(y) <- st
|Mark (2, st) ->
Printf.fprintf ch "Mark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_2.(x).(y) <- (true, snd(carte_marker_2.(x).(y)))) else (carte_marker_2.(x).(y) <- (fst(carte_marker_2.(x).(y)), true));
carte_ant_state.(x).(y) <- st
|Mark (3, st) ->
Printf.fprintf ch "Mark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_3.(x).(y) <- (true, snd(carte_marker_3.(x).(y)))) else (carte_marker_3.(x).(y) <- (fst(carte_marker_3.(x).(y)), true));
carte_ant_state.(x).(y) <- st
|Mark (4, st) ->
Printf.fprintf ch "Mark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_4.(x).(y) <- (true, snd(carte_marker_4.(x).(y)))) else (carte_marker_4.(x).(y) <- (fst(carte_marker_4.(x).(y)), true));
carte_ant_state.(x).(y) <- st
|Mark (5, st) ->
Printf.fprintf ch "Mark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_5.(x).(y) <- (true, snd(carte_marker_5.(x).(y)))) else (carte_marker_5.(x).(y) <- (fst(carte_marker_5.(x).(y)), true));
carte_ant_state.(x).(y) <- st
|Mark(i, st) -> failwith "Marqueur invalide";
|Unmark (0, st) ->
Printf.fprintf ch "Unmark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_0.(x).(y) <- (false, snd(carte_marker_0.(x).(y)))) else (carte_marker_0.(x).(y) <- (fst(carte_marker_0.(x).(y)), false));
carte_ant_state.(x).(y) <- st
|Unmark (1, st) ->
Printf.fprintf ch "Unmark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_1.(x).(y) <- (false, snd(carte_marker_1.(x).(y)))) else (carte_marker_1.(x).(y) <- (fst(carte_marker_1.(x).(y)), false));
carte_ant_state.(x).(y) <- st
|Unmark (2, st) ->
Printf.fprintf ch "Unmark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_2.(x).(y) <- (false, snd(carte_marker_2.(x).(y)))) else (carte_marker_2.(x).(y) <- (fst(carte_marker_2.(x).(y)), false));
carte_ant_state.(x).(y) <- st
|Unmark (3, st) ->
Printf.fprintf ch "Unmark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_3.(x).(y) <- (false, snd(carte_marker_3.(x).(y)))) else (carte_marker_3.(x).(y) <- (fst(carte_marker_3.(x).(y)), false));
carte_ant_state.(x).(y) <- st
|Unmark (4, st) ->
Printf.fprintf ch "Unmark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_4.(x).(y) <- (false, snd(carte_marker_4.(x).(y)))) else (carte_marker_4.(x).(y) <- (fst(carte_marker_4.(x).(y)), false));
carte_ant_state.(x).(y) <- st
|Unmark (5, st) ->
Printf.fprintf ch "Unmark\n";
if carte_ant_col.(x).(y) = Red then (carte_marker_5.(x).(y) <- (false, snd(carte_marker_5.(x).(y)))) else (carte_marker_5.(x).(y) <- (fst(carte_marker_5.(x).(y)), false));
carte_ant_state.(x).(y) <- st
|Unmark (i, st) -> failwith "Marqueur invalide";
|PickUp (st1, st2) ->
Printf.fprintf ch "PickUp\n";
if (carte_food.(x).(y) = 0 || carte_ant_has_food.(x).(y)) then
carte_ant_state.(x).(y) <- st2
else
begin
carte_food.(x).(y) <- carte_food.(x).(y) - 1;
carte_ant_has_food.(x).(y) <- true;
carte_ant_state.(x).(y) <- st1;
end
|Drop st ->
Printf.fprintf ch "Drop\n";
if carte_ant_has_food.(x).(y) then
(carte_ant_has_food.(x).(y) <- false;
carte_food.(x).(y) <- carte_food.(x).(y) + 1);
carte_ant_state.(x).(y) <- st
|Turn (lr, st) ->
Printf.fprintf ch "Turn\n";
carte_ant_dir.(x).(y) <- turn carte_ant_dir.(x).(y) lr;
carte_ant_state.(x).(y) <- st
|Move (st1, st2) ->
Printf.fprintf ch "Move\n";
let (x2, y2) = adjacent_cell (x,y) carte_ant_dir.(x).(y) in
if (rocky (x2, y2) || carte_ant_id.(x2).(y2) >= 0) then
carte_ant_state.(x).(y) <- st2
else
begin
carte_ant_id.(x2).(y2) <- carte_ant_id.(x).(y);
ant_pos.(carte_ant_id.(x2).(y2)) <- (x2, y2);
carte_ant_col.(x2).(y2) <- carte_ant_col.(x).(y);
carte_ant_dir.(x2).(y2) <- carte_ant_dir.(x).(y);
carte_ant_has_food.(x2).(y2) <- carte_ant_has_food.(x).(y);
carte_ant_resting.(x2).(y2) <- 14;
carte_ant_state.(x2).(y2) <- st1;
carte_ant_id.(x).(y) <- (-1);
check_surrounded_ants (x2, y2);
end;
|Flip (p, st1, st2) ->
Printf.fprintf ch "Flip\n";
if Random.int p = 0 then carte_ant_state.(x).(y) <- st1 else carte_ant_state.(x).(y) <- st2
end;
end
(*else Printf.printf "Pas bouge\n"*);;
let compte col = (*Comptabilise la quantité de nourriture sur les fourmilières *)
let n = ref 0 in
for i = 0 to (y_dim-1) do
for j = 0 to (x_dim-1) do
if test_anthill (i,j) col then
n := !n + carte_food.(i).(j)
done
done;
!n;;
let play nb_turns =
let chan = open_out "E:\\Informatique\\ICFP\\out" in
let ch = open_out "E:\\Informatique\\ICFP\\log" in
let n = (Array.length ant_pos) in
for k = 1 to nb_turns do
if k mod 500 = 0 then
(Printf.fprintf ch "\n\nTour n° %d\n" k;
for x = 0 to (y_dim - 1) do
for y = 0 to (x_dim - 1) do
Printf.fprintf chan "cell (%d, %d): " x y;
if rocky (x,y) then Printf.fprintf chan "rock;" else
(if carte_food.(x).(y) > 0 then Printf.fprintf chan "%d food; " carte_food.(x).(y);
if carte_phys.(x).(y) = AntHill Red then Printf.fprintf chan "red hill; ";
if carte_phys.(x).(y) = AntHill Black then Printf.fprintf chan "black hill; ";
if carte_ant_id.(x).(y) >= 0 then (if carte_ant_col.(x).(y) = Red then Printf.fprintf chan "red " else Printf.fprintf chan "black "; Printf.fprintf chan "ant of id %d, dir %d, food %b, state %d, resting %d;" carte_ant_id.(x).(y) carte_ant_dir.(x).(y) carte_ant_has_food.(x).(y) carte_ant_state.(x).(y) carte_ant_resting.(x).(y)));
Printf.fprintf chan "\n"
done
done;
Printf.fprintf chan "\n\n\n";);
Printf.printf "%d\t" k;
if k mod 500 = 0 then
(for i = 0 to (n-1) do
Printf.fprintf ch "fourmi id %d :\n" i;
step i ch;
done;)
else
(let ch2 = open_out "E:\\Informatique\\ICFP\\dev_null" in
for i = 0 to (n-1) do
Printf.fprintf ch2 "fourmi id %d :\n" i;
step i ch2
done;
close_out ch2);
done;
let f_red = compte Red and f_black = compte Black in
if f_red > f_black then
(Printf.printf "Victoire des Rouges avec %d contre %d\n" f_red f_black;
Printf.fprintf ch "Victoire des Rouges avec %d contre %d\n" f_red f_black)
else
(if f_black > f_red then
(Printf.printf "Victoire des Noirs avec %d contre %d\n" f_black f_red;
Printf.fprintf ch "Victoire des Noirs avec %d contre %d\n" f_black f_red)
else (Printf.printf "Egalite avec %d\n" f_red;
Printf.fprintf ch "Egalite avec %d\n" f_red;));;
let print_marker fd (x,y) i =
match carte_marker_5.(x).(y) with
|(true, false) -> Printf.fprintf fd "y "
|(false, true) -> Printf.fprintf fd "h "
|(true, true) -> Printf.fprintf fd "b "
|(false, false) ->
match carte_marker_4.(x).(y) with
|(true, false) -> Printf.fprintf fd "t "
|(false, true) -> Printf.fprintf fd "g "
|(true, true) -> Printf.fprintf fd "b "
|(false, false) ->
match carte_marker_3.(x).(y) with
|(true, false) -> Printf.fprintf fd "r "
|(false, true) -> Printf.fprintf fd "f "
|(true, true) -> Printf.fprintf fd "v "
|(false, false) ->
match carte_marker_2.(x).(y) with
|(true, false) -> Printf.fprintf fd "e "
|(false, true) -> Printf.fprintf fd "d "
|(true, true) -> Printf.fprintf fd "c "
|(false, false) ->
match carte_marker_1.(x).(y) with
|(true, false) -> Printf.fprintf fd "z "
|(false, true) -> Printf.fprintf fd "s "
|(true, true) -> Printf.fprintf fd "x "
|(false, false) ->
match carte_marker_0.(x).(y) with
|(true, false) -> Printf.fprintf fd "a "
|(false, true) -> Printf.fprintf fd "q "
|(true, true) -> Printf.fprintf fd "w "
|(false, false) -> if i = 1 then Printf.fprintf fd ". " else (if i = 2 then Printf.fprintf fd "+ " else Printf.fprintf fd "- ");;
let print_marker2 fd (x,y) i =
match carte_marker_0.(x).(y) with
|(true, false) -> Printf.fprintf fd "a "
|(false, true) -> Printf.fprintf fd "q "
|(true, true) -> Printf.fprintf fd "w "
|(false, false) ->
match carte_marker_1.(x).(y) with
|(true, false) -> Printf.fprintf fd "z "
|(false, true) -> Printf.fprintf fd "s "
|(true, true) -> Printf.fprintf fd "x "
|(false, false) ->
if i = 1 then Printf.fprintf fd ". " else (if i = 2 then Printf.fprintf fd "+ " else Printf.fprintf fd "- ");;
let print_map() =
let de = open_out "E:\\Informatique\\ICFP\\dessin" in
for x = 0 to (x_dim - 1) do
if x mod 2 = 1 then
Printf.fprintf de " ";
for y = 0 to (y_dim - 1) do
match carte_phys.(x).(y) with
|Rock -> Printf.fprintf de "# "
|AntHill Red -> if carte_food.(x).(y) > 0 then
Printf.fprintf de "%d " carte_food.(x).(y)
else
begin
if carte_ant_id.(x).(y) >= 0 then
begin
if carte_ant_col.(x).(y) = Red then
Printf.fprintf de "R "
else
Printf.fprintf de "B ";
end
else
print_marker de (x,y) 2;
end
|AntHill Black -> if carte_food.(x).(y) > 0 then
Printf.fprintf de "%d " carte_food.(x).(y)
else
begin
if carte_ant_id.(x).(y) >= 0 then
begin
if carte_ant_col.(x).(y) = Red then
Printf.fprintf de "R "
else
Printf.fprintf de "B ";
end
else
print_marker de (x,y) 3;
end
|Clear -> if carte_food.(x).(y) > 0 then
Printf.fprintf de "%d " carte_food.(x).(y)
else
begin
if carte_ant_id.(x).(y) >= 0 then
begin
if carte_ant_col.(x).(y) = Red then
Printf.fprintf de "R "
else
Printf.fprintf de "B ";
end
else
print_marker de (x,y) 1;
end;
done;
Printf.fprintf de "\n"
done;;
let print_map2() =
let de = open_out "E:\\Informatique\\ICFP\\dessin2" in
for x = 0 to (x_dim - 1) do
if x mod 2 = 1 then
Printf.fprintf de " ";
for y = 0 to (y_dim - 1) do
match carte_phys.(x).(y) with
|Rock -> Printf.fprintf de "# "
|AntHill Red -> if carte_food.(x).(y) > 0 then
Printf.fprintf de "%d " carte_food.(x).(y)
else
begin
if carte_ant_id.(x).(y) >= 0 then
begin
if carte_ant_col.(x).(y) = Red then
Printf.fprintf de "R "
else
Printf.fprintf de "B ";
end
else
print_marker2 de (x,y) 2;
end
|AntHill Black -> if carte_food.(x).(y) > 0 then
Printf.fprintf de "%d " carte_food.(x).(y)
else
begin
if carte_ant_id.(x).(y) >= 0 then
begin
if carte_ant_col.(x).(y) = Red then
Printf.fprintf de "R "
else
Printf.fprintf de "B ";
end
else
print_marker2 de (x,y) 3;
end
|Clear -> if carte_food.(x).(y) > 0 then
Printf.fprintf de "%d " carte_food.(x).(y)
else
begin
if carte_ant_id.(x).(y) >= 0 then
begin
if carte_ant_col.(x).(y) = Red then
Printf.fprintf de "R "
else
Printf.fprintf de "B ";
end
else
print_marker2 de (x,y) 1;
end;
done;
Printf.fprintf de "\n"
done;;
let print_tab t =
for i = 0 to (Array.length t - 1) do
Printf.printf "%d - %d\n" (fst t.(i)) (snd t.(i))
done;;
play 100000;;
print_map();;
print_map2();;
code: Flip 50 119 35
Turn Left 2
Flip 5 10 3
Turn Left 4
Flip 4 10 5
Turn Left 6
Flip 3 10 7
Turn Left 8
Flip 2 10 9
Turn Left 10
Flip 30 100 118
Mark 0 12
Sense Ahead 98 13 Food
Sense Ahead 15 14 Marker 5
Flip 6 19 15
Move 11 16
Flip 2 17 18
Turn Left 15
Turn Right 15
Flip 2 20 22
Turn Left 21
Turn Left 24
Turn Right 23
Turn Right 24
Move 11 11
Move 26 25
PickUp 27 27
Turn Left 28
Turn Left 29
Turn Left 62
Sense Ahead 99 31 Food
Sense Ahead 41 32 Marker 5
Sense Ahead 42 33 Marker 4
Sense Ahead 43 34 Marker 3
Sense Ahead 44 36 Marker 2
Flip 50 126 45
Flip 6 37 38
Move 30 38
Flip 2 39 40
Turn Left 118
Turn Right 118
Flip 30 46 37
Flip 25 46 37
Flip 20 46 37
Flip 15 46 37
Flip 50 136 66
Flip 6 56 47
Turn Left 48
Flip 5 56 49
Turn Left 50
Flip 4 56 51
Turn Left 52
Flip 3 56 53
Turn Left 54
Flip 2 56 55
Turn Left 56
Move 30 46
Move 58 57
PickUp 59 59
Turn Left 60
Turn Left 61
Turn Left 62
Sense Ahead 72 63 Marker 5
Sense Ahead 67 64 Marker 4
Sense Ahead 68 65 Marker 3
Sense Ahead 69 70 Marker 2
Flip 50 144 71
Mark 5 72
Mark 4 72
Mark 3 72
Mark 2 72
Flip 6 10 1
Sense Ahead 73 153 Home
Move 74 74
Drop 118
Sense Ahead 86 76 Marker 0
Turn Left 77
Sense Ahead 86 78 Marker 0
Turn Left 79
Sense Ahead 86 80 Marker 0
Turn Left 81
Sense Ahead 86 82 Marker 0
Turn Left 83
Sense Ahead 86 84 Marker 0
Turn Left 85
Sense Ahead 86 87 Marker 0
Move 62 87
Flip 4 97 88
Turn Left 89
Flip 3 97 90
Turn Left 91
Flip 3 97 92
Turn Left 93
Flip 2 97 94
Turn Left 95
Flip 2 97 96
Turn Left 97
Move 62 87
Sense Ahead 13 25 Home
Sense Ahead 31 57 Home
Sense Here 102 104 Marker 5
Mark 4 102
Unmark 5 114
Sense Here 104 106 Marker 4
Mark 3 105
Unmark 4 114
Sense Here 107 109 Marker 3
Mark 2 108
Unmark 3 114
Sense Here 110 114 Marker 2
Unmark 2 114
Unmark 2 115
Sense Here 114 115 Marker 1
Unmark 1 114
Move 100 115
Flip 2 116 117
Turn Left 114
Turn Right 114
Sense Ahead 99 31 Food
Flip 2 120 121
Move 124 121
Turn Left 122
Move 125 123
Turn Right 120
Mark 0 120
Mark 0 122
Turn Left 127
Turn Left 128
Turn Left 129
Flip 2 130 131
Move 134 131
Turn Left 132
Move 135 133
Turn Right 130
Mark 0 130
Mark 0 132
Turn Left 137
Flip 2 138 139
Move 142 139
Turn Left 140
Move 143 141
Turn Right 138
Mark 1 138
Mark 1 140
Turn Right 145
Turn Right 146
Flip 2 147 148
Move 151 148
Turn Left 149
Move 152 150
Turn Right 147
Mark 1 147
Mark 1 149
Sense Ahead 158 154 Marker 0
Sense LeftAhead 155 156 Marker 0
Turn Left 158
Sense RightAhead 157 159 Marker 0
Turn Right 158
Move 167 167
Sense Ahead 164 160 Marker 1
Sense LeftAhead 161 162 Marker 1
Turn Left 164
Sense RightAhead 163 165 Marker 1
Turn Right 164
Move 182 182
Move 153 166
Turn Left 165
Sense Ahead 169 168 Marker 0
Turn Left 167
Move 170 167
Sense Ahead 178 171 Marker 5
Sense Ahead 174 172 Marker 4
Sense Ahead 175 173 Marker 3
Sense Ahead 176 174 Marker 2
Mark 5 178
Mark 4 178
Mark 3 178
Mark 2 178
Sense Ahead 179 167 Home
Move 180 180
Drop 118
Sense Ahead 183 182 Marker 1
Turn Left 183
Move 184 182
Sense Ahead 193 185 Marker 5
Sense Ahead 188 186 Marker 4
Sense Ahead 189 187 Marker 3
Sense Ahead 190 188 Marker 2
Mark 5 193
Mark 4 193
Mark 3 193
Mark 2 193
Sense Ahead 193 182 Home
Move 194 194
Drop 118
Plus que demain pour débugger la jolie fourmi et prier...:-\
J'suis tout mouru, moi. §censuré§
__________________
Allez jeter un œil à mon portfolio !
Signaler ce message à un modérateur | IP: Logguée Temps en ligne : 103 Jours, 6 Heures, 14 Minutes, 38 Secondes en ligne
|