working on simple AI that just follows the path
This commit is contained in:
parent
34a7c5c49c
commit
d07f0fc126
4
Makefile
4
Makefile
|
@ -5,13 +5,13 @@ LFLAGS = -lSDL2 -lSDL2_image -lm
|
||||||
all: bin/back
|
all: bin/back
|
||||||
|
|
||||||
replay: bin/back
|
replay: bin/back
|
||||||
bin/back levels/straight.txt REP bots/dumb bots/dumb2 bots/dumb3 bots/dumb4
|
bin/back levels/test.txt REP bots/dumb bots/dumb2 bots/dumb3 bots/dumb4
|
||||||
|
|
||||||
testL: bin/back
|
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/dumb bots/dumb2 bots/dumb3 bots/dumb4
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
271 90
|
18 68
|
|
@ -0,0 +1,98 @@
|
||||||
|
(* parsing output.txt *)
|
||||||
|
type player = {
|
||||||
|
chx : int; (* X chunk, is in [0, lines[ *)
|
||||||
|
chy : int; (* Y chunk, is in [0, cols[ *)
|
||||||
|
posx : float; (* X coord, is in [0, roomSize[ *)
|
||||||
|
posy : float; (* Y coord, is in [0, roomSize[ *)
|
||||||
|
} ;;
|
||||||
|
|
||||||
|
let rec ln b = function | k when k < b -> 0 | k -> 1+ln b (k/b) in
|
||||||
|
let isDigit c = match (Char.code c) with | k when k >= 48 && k <= 57 -> true | _ -> false in
|
||||||
|
let rec pw x = function | 0 -> 1 | 1 -> x | n when n mod 2 = 0 -> pw (x*x) (n/2) | n -> x*pw (x*x) ((n-1)/2) in
|
||||||
|
let read_int (str : string) (i : int ref) =
|
||||||
|
let buf = ref 0 in
|
||||||
|
while !i < String.length str && not (isDigit str.[!i]) do
|
||||||
|
incr i;
|
||||||
|
done;
|
||||||
|
|
||||||
|
while !i < String.length str && isDigit str.[!i] do
|
||||||
|
buf := 10 * !buf + (Char.code str.[!i] - 48);
|
||||||
|
incr i
|
||||||
|
done;
|
||||||
|
!buf
|
||||||
|
in
|
||||||
|
let read_float (str : string) (i : int ref) =
|
||||||
|
let ent = read_int str i in
|
||||||
|
let frac = read_int str i in
|
||||||
|
(*Printf.printf "-> %d %d <-\n" ent frac;*)
|
||||||
|
(float_of_int ent +. (float_of_int frac) /. (float_of_int (pw 10 (1+ ln 10 frac))))
|
||||||
|
in
|
||||||
|
|
||||||
|
let file = open_in "output.txt" in
|
||||||
|
|
||||||
|
let nPlayers = int_of_string (input_line file) in
|
||||||
|
|
||||||
|
(*Printf.printf "np : %d\n" nPlayers;*)
|
||||||
|
|
||||||
|
let players = Array.make nPlayers {chx=0;chy=0;posx=0.;posy=0.} in
|
||||||
|
for i = 0 to nPlayers -1 do
|
||||||
|
let data = input_line file in
|
||||||
|
let i = ref 0 in
|
||||||
|
let idPlayer = read_int data i in
|
||||||
|
let chy = read_int data i in
|
||||||
|
let chx = read_int data i in
|
||||||
|
let posx = read_float data i in
|
||||||
|
let posy = read_float data i in
|
||||||
|
players.(idPlayer) <- {chx = chx; chy = chy; posx = posx; posy = posy}
|
||||||
|
done;
|
||||||
|
|
||||||
|
(*Printf.printf "players done\n";*)
|
||||||
|
|
||||||
|
let you = int_of_string (input_line file) in
|
||||||
|
ignore (input_line file);
|
||||||
|
|
||||||
|
let wdht = input_line file in
|
||||||
|
let whi = ref 0 in
|
||||||
|
let lines = read_int wdht whi in
|
||||||
|
let cols = read_int wdht whi in
|
||||||
|
|
||||||
|
(*Printf.printf "dims : %d %d\n" lines cols;*)
|
||||||
|
|
||||||
|
let map = Array.make_matrix lines cols (-1) in
|
||||||
|
for i= 0 to lines-1 do
|
||||||
|
String.iteri (fun j ch -> map.(i).(j) <- (int_of_char ch)) (input_line file)
|
||||||
|
done;
|
||||||
|
ignore (input_line file);
|
||||||
|
|
||||||
|
let meta = input_line file in
|
||||||
|
let metai = ref 0 in
|
||||||
|
|
||||||
|
(* metadata (constants relative to the map) *)
|
||||||
|
let roomSize = read_int meta metai in (* integer (meters) *)
|
||||||
|
let maximumSpeed = read_int meta metai in (* integer (meters/seconds) *)
|
||||||
|
let playerRadius = read_int meta metai in (* integer *)
|
||||||
|
let friction = read_float meta metai in (* float (between 0.0 and 1.0) *)
|
||||||
|
let restitutionFactor = read_float meta metai in (* float (between 0.0 and 1.0) *)
|
||||||
|
let trackDistance = read_float meta metai in (*
|
||||||
|
float (between 0.0 and 0.5) - this is the width of the black area on both side of the tracks
|
||||||
|
in other words, the width of the track is (except for start and finish) roomSize*(1-2*trackDistance)
|
||||||
|
*)
|
||||||
|
|
||||||
|
close_in file ;
|
||||||
|
(*Printf.printf "%d %d %d %f %f %f\n" roomSize maximumSpeed playerRadius friction restitutionFactor trackDistance ;;*)
|
||||||
|
|
||||||
|
(*
|
||||||
|
VARIABLES :
|
||||||
|
nPlayers : number of players in the match
|
||||||
|
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
|
||||||
|
metadata : see above
|
||||||
|
*)
|
||||||
|
|
||||||
|
() ;;
|
||||||
|
|
||||||
|
(*
|
||||||
|
write two integers (angle (0-360, integer) and power (0-100, integer)) to answer.txt
|
||||||
|
*)
|
|
@ -0,0 +1 @@
|
||||||
|
ocamlfind ocamlopt bots/follow.ml -o bots/follow
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,98 @@
|
||||||
|
(* parsing output.txt *)
|
||||||
|
type player = {
|
||||||
|
chx : int; (* X chunk, is in [0, lines[ *)
|
||||||
|
chy : int; (* Y chunk, is in [0, cols[ *)
|
||||||
|
posx : float; (* X coord, is in [0, roomSize[ *)
|
||||||
|
posy : float; (* Y coord, is in [0, roomSize[ *)
|
||||||
|
} ;;
|
||||||
|
|
||||||
|
let rec ln b = function | k when k < b -> 0 | k -> 1+ln b (k/b) in
|
||||||
|
let isDigit c = match (Char.code c) with | k when k >= 48 && k <= 57 -> true | _ -> false in
|
||||||
|
let rec pw x = function | 0 -> 1 | 1 -> x | n when n mod 2 = 0 -> pw (x*x) (n/2) | n -> x*pw (x*x) ((n-1)/2) in
|
||||||
|
let read_int (str : string) (i : int ref) =
|
||||||
|
let buf = ref 0 in
|
||||||
|
while !i < String.length str && not (isDigit str.[!i]) do
|
||||||
|
incr i;
|
||||||
|
done;
|
||||||
|
|
||||||
|
while !i < String.length str && isDigit str.[!i] do
|
||||||
|
buf := 10 * !buf + (Char.code str.[!i] - 48);
|
||||||
|
incr i
|
||||||
|
done;
|
||||||
|
!buf
|
||||||
|
in
|
||||||
|
let read_float (str : string) (i : int ref) =
|
||||||
|
let ent = read_int str i in
|
||||||
|
let frac = read_int str i in
|
||||||
|
(*Printf.printf "-> %d %d <-\n" ent frac;*)
|
||||||
|
(float_of_int ent +. (float_of_int frac) /. (float_of_int (pw 10 (1+ ln 10 frac))))
|
||||||
|
in
|
||||||
|
|
||||||
|
let file = open_in "output.txt" in
|
||||||
|
|
||||||
|
let nPlayers = int_of_string (input_line file) in
|
||||||
|
|
||||||
|
(*Printf.printf "np : %d\n" nPlayers;*)
|
||||||
|
|
||||||
|
let players = Array.make nPlayers {chx=0;chy=0;posx=0.;posy=0.} in
|
||||||
|
for i = 0 to nPlayers -1 do
|
||||||
|
let data = input_line file in
|
||||||
|
let i = ref 0 in
|
||||||
|
let idPlayer = read_int data i in
|
||||||
|
let chy = read_int data i in
|
||||||
|
let chx = read_int data i in
|
||||||
|
let posx = read_float data i in
|
||||||
|
let posy = read_float data i in
|
||||||
|
players.(idPlayer) <- {chx = chx; chy = chy; posx = posx; posy = posy}
|
||||||
|
done;
|
||||||
|
|
||||||
|
(*Printf.printf "players done\n";*)
|
||||||
|
|
||||||
|
let you = int_of_string (input_line file) in
|
||||||
|
ignore (input_line file);
|
||||||
|
|
||||||
|
let wdht = input_line file in
|
||||||
|
let whi = ref 0 in
|
||||||
|
let lines = read_int wdht whi in
|
||||||
|
let cols = read_int wdht whi in
|
||||||
|
|
||||||
|
(*Printf.printf "dims : %d %d\n" lines cols;*)
|
||||||
|
|
||||||
|
let map = Array.make_matrix lines cols (-1) in
|
||||||
|
for i= 0 to lines-1 do
|
||||||
|
String.iteri (fun j ch -> map.(i).(j) <- (int_of_char ch)) (input_line file)
|
||||||
|
done;
|
||||||
|
ignore (input_line file);
|
||||||
|
|
||||||
|
let meta = input_line file in
|
||||||
|
let metai = ref 0 in
|
||||||
|
|
||||||
|
(* metadata (constants relative to the map) *)
|
||||||
|
let roomSize = read_int meta metai in (* integer (meters) *)
|
||||||
|
let maximumSpeed = read_int meta metai in (* integer (meters/seconds) *)
|
||||||
|
let playerRadius = read_int meta metai in (* integer *)
|
||||||
|
let friction = read_float meta metai in (* float (between 0.0 and 1.0) *)
|
||||||
|
let restitutionFactor = read_float meta metai in (* float (between 0.0 and 1.0) *)
|
||||||
|
let trackDistance = read_float meta metai in (*
|
||||||
|
float (between 0.0 and 0.5) - this is the width of the black area on both side of the tracks
|
||||||
|
in other words, the width of the track is (except for start and finish) roomSize*(1-2*trackDistance)
|
||||||
|
*)
|
||||||
|
|
||||||
|
close_in file ;
|
||||||
|
(*Printf.printf "%d %d %d %f %f %f\n" roomSize maximumSpeed playerRadius friction restitutionFactor trackDistance ;;*)
|
||||||
|
|
||||||
|
(*
|
||||||
|
VARIABLES :
|
||||||
|
nPlayers : number of players in the match
|
||||||
|
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
|
||||||
|
metadata : see above
|
||||||
|
*)
|
||||||
|
|
||||||
|
() ;;
|
||||||
|
|
||||||
|
(*
|
||||||
|
write two integers (angle (0-360, integer) and power (0-100, integer)) to answer.txt
|
||||||
|
*)
|
Binary file not shown.
|
@ -1,53 +1,8 @@
|
||||||
-91.598146 124.327144
|
16.118180 135.441519
|
||||||
142.266681 -23.083685
|
15.256039 -174.406057
|
||||||
80.023571 -110.291019
|
104.496250 -148.082488
|
||||||
-209.326753 22.630339
|
191.197494 16.230970
|
||||||
68.505747 119.501330
|
-112.462982 -31.358173
|
||||||
107.060380 -114.069708
|
119.618077 -121.687300
|
||||||
-70.233012 -101.577163
|
104.527851 139.009942
|
||||||
147.160673 -72.086463
|
120.783208 54.245212
|
||||||
-140.110322 106.226989
|
|
||||||
135.086455 98.172637
|
|
||||||
56.107652 105.827274
|
|
||||||
35.854738 -152.398792
|
|
||||||
132.320996 -67.163737
|
|
||||||
176.181947 66.489059
|
|
||||||
130.017074 -31.088727
|
|
||||||
66.243545 115.114005
|
|
||||||
145.260991 -91.403980
|
|
||||||
-69.982160 -182.672565
|
|
||||||
35.887790 -183.222296
|
|
||||||
108.756771 95.947835
|
|
||||||
-49.680253 -115.091637
|
|
||||||
58.894910 114.835148
|
|
||||||
99.088389 -156.633565
|
|
||||||
-187.977088 -51.719528
|
|
||||||
-104.449063 -91.836921
|
|
||||||
-107.925240 138.542331
|
|
||||||
-94.113722 79.680583
|
|
||||||
-97.214088 -68.731116
|
|
||||||
-100.166986 -61.714426
|
|
||||||
-115.272316 110.207498
|
|
||||||
-96.395609 -136.982500
|
|
||||||
-43.753892 -133.340136
|
|
||||||
-66.862857 105.898787
|
|
||||||
91.865015 121.247073
|
|
||||||
-95.201198 111.796966
|
|
||||||
37.801519 -111.152427
|
|
||||||
53.162045 174.621969
|
|
||||||
-83.439530 168.654458
|
|
||||||
86.164970 159.092863
|
|
||||||
-62.380427 -152.204942
|
|
||||||
17.433048 133.218210
|
|
||||||
-105.950486 88.326322
|
|
||||||
-47.503687 -175.362014
|
|
||||||
-63.992977 156.620065
|
|
||||||
-155.337407 -113.318321
|
|
||||||
114.800901 120.609239
|
|
||||||
-11.129331 -159.843313
|
|
||||||
79.955484 139.639897
|
|
||||||
-150.338137 27.027579
|
|
||||||
-165.852701 9.876618
|
|
||||||
-166.712365 85.606507
|
|
||||||
102.833309 109.163228
|
|
||||||
-16.456985 -187.091529
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
name, elo
|
name, elo
|
||||||
./bots/dumb 1656
|
./bots/dumb 1595
|
||||||
./bots/dumb2 1542
|
./bots/dumb2 1570
|
||||||
./bots/dumb3 1633
|
./bots/dumb3 1576
|
||||||
./bots/dumb4 1481
|
./bots/dumb4 1447
|
||||||
./bots/dumb5 540
|
./bots/dumb5 540
|
||||||
./bots/dumb6 562
|
./bots/dumb6 562
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
5 9
|
||||||
|
31114.314
|
||||||
|
S...035.0
|
||||||
|
.E..25..0
|
||||||
|
.0..31115
|
||||||
|
.2115....
|
||||||
|
|
||||||
|
$
|
||||||
|
. = NULL
|
||||||
|
0 = Vertical
|
||||||
|
1 = Horizontal
|
||||||
|
2 = TopRight (NE)
|
||||||
|
3 = BottomRight (SE)
|
||||||
|
4 = BottomLeft (SW)
|
||||||
|
5 = TopLeft (NW)
|
||||||
|
S = Start
|
||||||
|
E = End
|
|
@ -2,6 +2,7 @@
|
||||||
.S11111114
|
.S11111114
|
||||||
E........0
|
E........0
|
||||||
2111111115
|
2111111115
|
||||||
|
|
||||||
$
|
$
|
||||||
. = NULL
|
. = NULL
|
||||||
0 = Vertical
|
0 = Vertical
|
||||||
|
|
BIN
obj/collisions.o
BIN
obj/collisions.o
Binary file not shown.
BIN
obj/structure.o
BIN
obj/structure.o
Binary file not shown.
22
output.txt
22
output.txt
|
@ -1,16 +1,16 @@
|
||||||
4
|
4
|
||||||
0 (3 0) (22.26 39.65)
|
0 (0 1) (30.90 71.34)
|
||||||
1 (1 3) (20.14 43.41)
|
1 (1 0) (5.60 61.29)
|
||||||
2 (2 0) (27.37 58.70)
|
2 (0 1) (15.00 61.48)
|
||||||
3 (2 0) (73.15 83.07)
|
3 (0 0) (70.64 69.26)
|
||||||
[3]
|
3
|
||||||
|
|
||||||
5 5
|
5 9
|
||||||
..S14
|
31114.314
|
||||||
....0
|
S...035.0
|
||||||
...35
|
.E..25..0
|
||||||
.E15.
|
.0..31115
|
||||||
.....
|
.2115....
|
||||||
|
|
||||||
100 200 5 0.90 0.80 0.20
|
100 200 5 0.90 0.80 0.20
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ void write_output(char* stream, level* lvl, int nPl) {
|
||||||
for(int p = 0; p < nPlayers; p++) {
|
for(int p = 0; p < nPlayers; p++) {
|
||||||
fprintf(ptr, "%d (%d %d) (%.2lf %.2lf)\n", p, players[p].c->chx, players[p].c->chy, players[p].c->pos.fx, players[p].c->pos.fy);
|
fprintf(ptr, "%d (%d %d) (%.2lf %.2lf)\n", p, players[p].c->chx, players[p].c->chy, players[p].c->pos.fx, players[p].c->pos.fy);
|
||||||
}
|
}
|
||||||
fprintf(ptr, "[%d]\n\n", nPl);
|
fprintf(ptr, "%d\n\n", nPl);
|
||||||
fprintf(ptr, "%d %d\n", lvl->lines, lvl->cols);
|
fprintf(ptr, "%d %d\n", lvl->lines, lvl->cols);
|
||||||
for(int l = 0; l < lvl->lines; l++) {
|
for(int l = 0; l < lvl->lines; l++) {
|
||||||
for(int c = 0; c < lvl->cols; c++) {
|
for(int c = 0; c < lvl->cols; c++) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
name, elo
|
name, elo
|
||||||
./bots/dumb 1656
|
./bots/dumb 1595
|
||||||
./bots/dumb2 1542
|
./bots/dumb2 1570
|
||||||
./bots/dumb3 1633
|
./bots/dumb3 1576
|
||||||
./bots/dumb4 1481
|
./bots/dumb4 1447
|
||||||
./bots/dumb5 540
|
./bots/dumb5 540
|
||||||
./bots/dumb6 562
|
./bots/dumb6 562
|
||||||
|
|
Loading…
Reference in New Issue