added basic bot that can follow the path
This commit is contained in:
parent
404f32a414
commit
5f56e91549
2
Makefile
2
Makefile
|
@ -11,7 +11,7 @@ testL: bin/back
|
|||
bin/back levels/test.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4 bots/dumb5 bots/dumb6
|
||||
|
||||
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
|
||||
bin/back levels/simple.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4
|
||||
|
|
|
@ -1 +1 @@
|
|||
202 90
|
||||
270 100
|
||||
|
|
|
@ -58,9 +58,10 @@ let cols = read_int wdht whi in
|
|||
|
||||
(*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
|
||||
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;
|
||||
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)
|
||||
you : integer telling you who you are
|
||||
(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
|
||||
*)
|
||||
|
||||
|
|
|
@ -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
|
BIN
bots/follow
BIN
bots/follow
Binary file not shown.
BIN
bots/follow.cmi
BIN
bots/follow.cmi
Binary file not shown.
BIN
bots/follow.cmx
BIN
bots/follow.cmx
Binary file not shown.
|
@ -1,3 +1,6 @@
|
|||
exception PT of int * int ;;
|
||||
Random.self_init () ;;
|
||||
|
||||
(* parsing output.txt *)
|
||||
type player = {
|
||||
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;*)
|
||||
|
||||
let map = Array.make_matrix lines cols (-1) in
|
||||
let map = Array.make_matrix lines cols '.' in
|
||||
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;
|
||||
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)
|
||||
you : integer telling you who you are
|
||||
(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
|
||||
*)
|
||||
|
||||
() ;;
|
||||
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
|
||||
|
|
BIN
bots/follow.o
BIN
bots/follow.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
111
lastActions.txt
111
lastActions.txt
|
@ -1,44 +1,67 @@
|
|||
379.298997 -90.460396
|
||||
-411.933782 -102.829478
|
||||
529.790599 106.085366
|
||||
199.425937 -339.933600
|
||||
-95.896503 -427.381434
|
||||
621.489630 -271.395621
|
||||
-91.910447 -431.083935
|
||||
532.790163 -251.126350
|
||||
-441.742872 -379.482434
|
||||
-156.873311 -631.713832
|
||||
-401.488913 234.715098
|
||||
105.077659 284.150054
|
||||
524.564488 78.261213
|
||||
276.789079 -499.510206
|
||||
-381.421657 -316.021931
|
||||
-523.227183 -149.848072
|
||||
101.368066 -470.891248
|
||||
-443.642759 -24.105970
|
||||
-184.386517 489.797115
|
||||
-240.105707 -570.235746
|
||||
-243.737743 -542.014315
|
||||
10.519746 -514.182691
|
||||
-195.243675 -309.577683
|
||||
332.009157 395.515767
|
||||
-176.294945 -347.245183
|
||||
175.812024 -404.875378
|
||||
387.383699 270.406430
|
||||
519.318908 3.851934
|
||||
258.416467 -497.716698
|
||||
383.335139 -130.461029
|
||||
17.811949 406.832575
|
||||
202.002036 -232.264703
|
||||
-73.837280 619.550755
|
||||
87.161172 -536.662133
|
||||
-264.435947 -410.760055
|
||||
488.070671 158.002418
|
||||
488.103030 -214.321833
|
||||
-571.397831 -78.964646
|
||||
-404.666249 112.426128
|
||||
577.348182 -253.487910
|
||||
151.737589 322.901126
|
||||
-394.690142 -402.872287
|
||||
-145.130089 -320.154490
|
||||
-493.847237 -180.188736
|
||||
15.283312 -168.132427
|
||||
-3.875293 -217.394574
|
||||
-2.300064 -222.591425
|
||||
-15.045042 -169.714650
|
||||
1.082855 -227.095122
|
||||
178.596429 21.737178
|
||||
-4.391650 -207.233032
|
||||
-12.266175 -227.148929
|
||||
-16.871035 -209.846368
|
||||
187.346942 6.343882
|
||||
201.031828 14.624638
|
||||
20.884507 -226.513802
|
||||
-23.428113 -219.487861
|
||||
6.668101 177.977553
|
||||
-8.282273 188.856052
|
||||
-8.118353 -220.432417
|
||||
214.969311 8.139475
|
||||
-20.975506 -163.732759
|
||||
19.505170 178.521445
|
||||
14.059300 -208.287419
|
||||
-13.582572 202.643783
|
||||
165.257843 -14.161400
|
||||
183.897469 2.030179
|
||||
232.650472 20.227691
|
||||
-8.214584 205.892621
|
||||
184.797474 15.493847
|
||||
186.741640 -16.724432
|
||||
20.334129 231.449697
|
||||
-15.194962 -197.016532
|
||||
185.222560 20.876855
|
||||
164.962028 0.223672
|
||||
-10.536891 227.902529
|
||||
-2.041096 -197.446820
|
||||
209.887356 -11.992982
|
||||
0.000248 165.684814
|
||||
23.335144 -220.548384
|
||||
192.922489 17.561281
|
||||
218.486970 5.907496
|
||||
18.563320 169.000059
|
||||
-8.025218 -216.899723
|
||||
-19.987451 203.963417
|
||||
220.426775 -11.794697
|
||||
-184.439240 -5.946276
|
||||
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
|
||||
|
|
|
@ -5,3 +5,7 @@ name, elo
|
|||
./bots/dumb4 1392
|
||||
./bots/dumb5 540
|
||||
./bots/dumb6 562
|
||||
./bots/follow1 525
|
||||
./bots/follow2 499
|
||||
./bots/follow3 548
|
||||
./bots/follow4 509
|
||||
|
|
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
24
output.txt
24
output.txt
|
@ -1,18 +1,16 @@
|
|||
4
|
||||
0 (3 0) (24.83 26.41)
|
||||
1 (4 5) (73.32 64.02)
|
||||
2 (3 4) (90.21 27.10)
|
||||
3 (6 4) (41.16 68.33)
|
||||
2
|
||||
0 (1 2) (74.74 30.15)
|
||||
1 (1 2) (64.27 43.70)
|
||||
2 (1 2) (41.29 41.90)
|
||||
3 (1 3) (74.08 81.17)
|
||||
3
|
||||
|
||||
7 8
|
||||
...S....
|
||||
..35....
|
||||
..24....
|
||||
...24...
|
||||
...353E.
|
||||
...215..
|
||||
........
|
||||
5 9
|
||||
31114.314
|
||||
S...035.0
|
||||
.E..25..0
|
||||
.0..31115
|
||||
.2115....
|
||||
|
||||
100 200 5 0.90 0.80 0.20
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ double playerSpeedModifier(int nPl) {
|
|||
// -12% if in the lead, and +12% if last
|
||||
if(maxRemD-minRemD >= 0.0001) {
|
||||
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);
|
||||
} else {
|
||||
return 1.0;
|
||||
|
|
|
@ -5,3 +5,7 @@ name, elo
|
|||
./bots/dumb4 1392
|
||||
./bots/dumb5 540
|
||||
./bots/dumb6 562
|
||||
./bots/follow1 525
|
||||
./bots/follow2 499
|
||||
./bots/follow3 548
|
||||
./bots/follow4 509
|
||||
|
|
Loading…
Reference in New Issue