added basic bot that can follow the path

This commit is contained in:
Alexandre 2025-05-24 20:37:51 +02:00
parent 404f32a414
commit 5f56e91549
20 changed files with 191 additions and 68 deletions

View File

@ -11,7 +11,7 @@ testL: bin/back
bin/back levels/test.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4 bots/dumb5 bots/dumb6 bin/back levels/test.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4 bots/dumb5 bots/dumb6
test: bin/back test: bin/back
bin/back levels/test.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4 bin/back levels/long.txt bots/follow1 bots/follow2 bots/follow3 bots/follow4
ez: bin/back ez: bin/back
bin/back levels/simple.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4 bin/back levels/simple.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4

View File

@ -1 +1 @@
202 90 270 100

BIN
bin/back

Binary file not shown.

View File

@ -58,9 +58,10 @@ let cols = read_int wdht whi in
(*Printf.printf "dims : %d %d\n" lines cols;*) (*Printf.printf "dims : %d %d\n" lines cols;*)
let map = Array.make_matrix lines cols (-1) in let map = Array.make_matrix lines cols '.' in
for i= 0 to lines-1 do for i= 0 to lines-1 do
String.iteri (fun j ch -> map.(i).(j) <- (int_of_char ch)) (input_line file) String.iteri (fun j ch -> map.(i).(j) <- ch) (input_line file)
done; done;
ignore (input_line file); ignore (input_line file);
@ -87,7 +88,7 @@ VARIABLES :
players : list containing data relative to all players (struct is defined at the top of the code) players : list containing data relative to all players (struct is defined at the top of the code)
you : integer telling you who you are you : integer telling you who you are
(lines, cols) : the dimension of the map (lines, cols) : the dimension of the map
map : an int array array containing each tile as an integer map : a char array array containing each tile as an integer
metadata : see above metadata : see above
*) *)

View File

@ -1 +1,4 @@
ocamlfind ocamlopt bots/follow.ml -o bots/follow ocamlfind ocamlopt bots/follow.ml -o bots/follow1
ocamlfind ocamlopt bots/follow.ml -o bots/follow2
ocamlfind ocamlopt bots/follow.ml -o bots/follow3
ocamlfind ocamlopt bots/follow.ml -o bots/follow4

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,3 +1,6 @@
exception PT of int * int ;;
Random.self_init () ;;
(* parsing output.txt *) (* parsing output.txt *)
type player = { type player = {
chx : int; (* X chunk, is in [0, lines[ *) chx : int; (* X chunk, is in [0, lines[ *)
@ -58,9 +61,10 @@ let cols = read_int wdht whi in
(*Printf.printf "dims : %d %d\n" lines cols;*) (*Printf.printf "dims : %d %d\n" lines cols;*)
let map = Array.make_matrix lines cols (-1) in let map = Array.make_matrix lines cols '.' in
for i= 0 to lines-1 do for i= 0 to lines-1 do
String.iteri (fun j ch -> map.(i).(j) <- (int_of_char ch)) (input_line file) String.iteri (fun j ch -> map.(i).(j) <- ch) (input_line file)
done; done;
ignore (input_line file); ignore (input_line file);
@ -87,11 +91,97 @@ VARIABLES :
players : list containing data relative to all players (struct is defined at the top of the code) players : list containing data relative to all players (struct is defined at the top of the code)
you : integer telling you who you are you : integer telling you who you are
(lines, cols) : the dimension of the map (lines, cols) : the dimension of the map
map : an int array array containing each tile as an integer map : a char array array containing each tile as an integer
metadata : see above metadata : see above
*) *)
() ;; let getDirs = function
| '0' -> 5
| '1' -> 10
| '2' -> 3
| '3' -> 6
| '4' -> 12
| '5' -> 9
| 'S' -> 15
| _ -> 0
in
let getS () =
try
for i = 0 to lines -1 do
for j = 0 to cols -1 do
if map.(i).(j) = 'S' then
raise (PT (i,j))
done
done;
failwith "no start ?"
with
| PT (x,y) -> (x,y)
in
let getPath mp =
let path = Array.make_matrix lines cols '.' in
let vstd = Hashtbl.create 100 in
let halt = ref false in
let rec aux (i,j) =
if i >= 0 && j >= 0 && i < lines && j < cols then begin
if mp.(i).(j) = 'E' then
halt := true
else if not !halt && path.(i).(j) <> ',' && Hashtbl.find_opt vstd (i,j) = None then begin
Hashtbl.add vstd (i,j) 1;
let ds = getDirs mp.(i).(j) in
if not !halt && ds mod 2 = 1 then begin
path.(i).(j) <- '^';
aux (i-1,j);
end;
if not !halt && (ds/2) mod 2 = 1 then begin
path.(i).(j) <- '>';
aux (i,j+1);
end;
if not !halt && (ds/4) mod 2 = 1 then begin
path.(i).(j) <- 'v';
aux (i+1,j);
end;
if not !halt && (ds/8) mod 2 = 1 then begin
path.(i).(j) <- '<';
aux (i,j-1);
end;
if not !halt then path.(i).(j) <- ','
end
end
in aux (getS ());
path
in
let pth = getPath map in
(*
Array.iter (
fun ln -> Array.iter (
fun c -> print_char c;
) ln;
print_endline ""
) pth;
*)
let ans = open_out "answer.txt" in
match pth.(players.(you).chx).(players.(you).chy) with
| '>' -> Printf.fprintf ans "0 100\n"
| 'v' -> Printf.fprintf ans "90 100\n"
| '<' -> Printf.fprintf ans "180 100\n"
| '^' -> Printf.fprintf ans "270 100\n"
| _ -> Printf.fprintf ans "%d 100\n" (Random.int 360)
;
close_out ans ;;
(* (*
write two integers (angle (0-360, integer) and power (0-100, integer)) to answer.txt write two integers (angle (0-360, integer) and power (0-100, integer)) to answer.txt

Binary file not shown.

BIN
bots/follow1 Executable file

Binary file not shown.

BIN
bots/follow2 Executable file

Binary file not shown.

BIN
bots/follow3 Executable file

Binary file not shown.

BIN
bots/follow4 Executable file

Binary file not shown.

View File

@ -1,44 +1,67 @@
379.298997 -90.460396 15.283312 -168.132427
-411.933782 -102.829478 -3.875293 -217.394574
529.790599 106.085366 -2.300064 -222.591425
199.425937 -339.933600 -15.045042 -169.714650
-95.896503 -427.381434 1.082855 -227.095122
621.489630 -271.395621 178.596429 21.737178
-91.910447 -431.083935 -4.391650 -207.233032
532.790163 -251.126350 -12.266175 -227.148929
-441.742872 -379.482434 -16.871035 -209.846368
-156.873311 -631.713832 187.346942 6.343882
-401.488913 234.715098 201.031828 14.624638
105.077659 284.150054 20.884507 -226.513802
524.564488 78.261213 -23.428113 -219.487861
276.789079 -499.510206 6.668101 177.977553
-381.421657 -316.021931 -8.282273 188.856052
-523.227183 -149.848072 -8.118353 -220.432417
101.368066 -470.891248 214.969311 8.139475
-443.642759 -24.105970 -20.975506 -163.732759
-184.386517 489.797115 19.505170 178.521445
-240.105707 -570.235746 14.059300 -208.287419
-243.737743 -542.014315 -13.582572 202.643783
10.519746 -514.182691 165.257843 -14.161400
-195.243675 -309.577683 183.897469 2.030179
332.009157 395.515767 232.650472 20.227691
-176.294945 -347.245183 -8.214584 205.892621
175.812024 -404.875378 184.797474 15.493847
387.383699 270.406430 186.741640 -16.724432
519.318908 3.851934 20.334129 231.449697
258.416467 -497.716698 -15.194962 -197.016532
383.335139 -130.461029 185.222560 20.876855
17.811949 406.832575 164.962028 0.223672
202.002036 -232.264703 -10.536891 227.902529
-73.837280 619.550755 -2.041096 -197.446820
87.161172 -536.662133 209.887356 -11.992982
-264.435947 -410.760055 0.000248 165.684814
488.070671 158.002418 23.335144 -220.548384
488.103030 -214.321833 192.922489 17.561281
-571.397831 -78.964646 218.486970 5.907496
-404.666249 112.426128 18.563320 169.000059
577.348182 -253.487910 -8.025218 -216.899723
151.737589 322.901126 -19.987451 203.963417
-394.690142 -402.872287 220.426775 -11.794697
-145.130089 -320.154490 -184.439240 -5.946276
-493.847237 -180.188736 202.999492 3.017057
-197.157589 5.350030
-19.131913 211.412648
-177.314902 -0.421059
8.650374 216.687713
-211.519919 -4.182964
-225.827554 19.255477
-186.604445 -0.413666
-220.995867 1.579061
-196.286611 3.300536
-215.596596 15.150045
-177.279262 -8.471317
-221.220200 -17.991671
-212.905471 -21.910692
-207.860142 19.681900
-167.551422 7.668736
-224.129291 -8.870528
17.515601 -183.742930
-211.725099 11.037961
-9.316739 -175.104654
8.854149 223.062188
-0.000750 -194.960110
-216.098329 0.274767
17.444249 -210.184344

View File

@ -5,3 +5,7 @@ name, elo
./bots/dumb4 1392 ./bots/dumb4 1392
./bots/dumb5 540 ./bots/dumb5 540
./bots/dumb6 562 ./bots/dumb6 562
./bots/follow1 525
./bots/follow2 499
./bots/follow3 548
./bots/follow4 509

Binary file not shown.

View File

@ -1,18 +1,16 @@
4 4
0 (3 0) (24.83 26.41) 0 (1 2) (74.74 30.15)
1 (4 5) (73.32 64.02) 1 (1 2) (64.27 43.70)
2 (3 4) (90.21 27.10) 2 (1 2) (41.29 41.90)
3 (6 4) (41.16 68.33) 3 (1 3) (74.08 81.17)
2 3
7 8 5 9
...S.... 31114.314
..35.... S...035.0
..24.... .E..25..0
...24... .0..31115
...353E. .2115....
...215..
........
100 200 5 0.90 0.80 0.20 100 200 5 0.90 0.80 0.20

View File

@ -85,7 +85,7 @@ double playerSpeedModifier(int nPl) {
// -12% if in the lead, and +12% if last // -12% if in the lead, and +12% if last
if(maxRemD-minRemD >= 0.0001) { if(maxRemD-minRemD >= 0.0001) {
double theta = (remainingD[nPl]-minRemD)/(maxRemD-minRemD); double theta = (remainingD[nPl]-minRemD)/(maxRemD-minRemD);
printf("%lf\n", theta); //printf("%lf\n", theta);
return (1.0 + (24.0*theta-12.0)/100.0); return (1.0 + (24.0*theta-12.0)/100.0);
} else { } else {
return 1.0; return 1.0;

View File

@ -5,3 +5,7 @@ name, elo
./bots/dumb4 1392 ./bots/dumb4 1392
./bots/dumb5 540 ./bots/dumb5 540
./bots/dumb6 562 ./bots/dumb6 562
./bots/follow1 525
./bots/follow2 499
./bots/follow3 548
./bots/follow4 509