Skip to content
Snippets Groups Projects
Commit 4bfdc32a authored by belkhiritaha's avatar belkhiritaha
Browse files

Merge branch 'qlearn' into render

parents 5834b2eb 463166e3
No related branches found
No related tags found
No related merge requests found
Showing
with 195 additions and 845 deletions
......@@ -7,12 +7,12 @@
3 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 3
3 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 3
1 1 1 1 1 1 1 1 1 2 1 1 0 0 0 0 0 0 0 3
1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 3
1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 3
1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 3
1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 3
1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 3
1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 3
1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 2 0 0 3
1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 3
1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3
......
-1.000000 -inf -1.190000 -inf
-1.190000 -1.190000 -1.000000 -inf
-1.000000 -1.190000 -1.000000 -inf
-1.000000 -1.000000 -1.000000 -inf
-1.000000 -1.000000 -1.000000 -inf
-1.190000 -1.000000 -1.000000 -inf
-1.361000 -1.190000 -1.376390 -inf
-1.532000 -1.361000 -1.383680 -inf
-1.395029 -1.532729 -1.689212 -inf
-1.578082 -1.378100 -1.702407 -inf
-1.824410 -1.564319 -1.691253 -inf
-1.768814 -1.994997 -1.863283 -inf
-1.994704 -2.051209 -1.849391 -inf
-2.044997 -2.206757 -2.262592 -inf
-2.440452 -2.452623 -2.343919 -inf
-2.757888 -2.733185 -2.627175 -inf
-3.088093 -3.200140 -3.080662 -inf
-3.343086 -3.379787 -3.403086 -inf
-3.497348 -3.547127 -3.492962 -inf
-inf -3.421983 -3.451184 -inf
-1.190000 -inf -1.190000 -1.000000
-1.000000 -1.000000 -1.000000 -1.190000
-1.000000 -1.000000 -1.000000 -1.000000
-1.090000 -1.000000 -1.000000 -1.000000
-1.171000 -1.000000 -1.000000 -1.000000
-1.259290 -1.090000 -1.259290 -1.000000
-1.274526 -1.243900 -1.171000 -1.203490
-1.273141 -1.252000 -1.252729 -1.188829
-1.430022 -1.252000 -1.260675 -1.368317
-1.336499 -1.392624 -1.332985 -1.355851
-1.434470 -1.266580 -1.404361 -1.321021
-1.511063 -1.413692 -1.383949 -1.400190
-1.467169 -1.544410 -1.501672 -1.531239
-1.512297 -1.603711 -1.563439 -1.684449
-1.653081 -1.688996 -1.672427 -1.950719
-2.021357 -1.912729 -1.893814 -2.069844
-3.140385 -2.832285 -2.763769 -3.306056
-3.955379 -3.606667 -3.450486 -3.503844
-3.567915 -3.695889 -3.451203 -3.736225
-inf -3.529443 -3.573409 -3.414411
-1.190000 -inf -1.207100 -1.190000
-1.190000 -1.190000 -1.530290 -1.000000
-1.090000 -1.090000 -1.090000 -1.000000
-1.171000 -1.090000 -1.179829 -1.090000
-1.179100 -1.317610 -1.267236 -1.000000
-1.186390 -1.309510 -1.259290 -1.171000
-1.179100 -1.252000 -1.171000 -1.187929
-1.273870 -1.252729 -1.171000 -1.259290
-1.267375 -1.259290 -1.267309 -1.280431
-1.335602 -1.266580 -1.268621 -1.423461
-1.346021 -1.412373 -1.258590 -1.295456
-1.269277 -1.348659 -1.233574 -1.297431
-1.361554 -1.260085 -1.338439 -1.374995
-1.378945 -1.391239 -1.328858 -1.383717
-1.438402 -1.397380 -1.239980 -1.698503
-1.809267 -1.609927 -1.113920 -2.153879
-2.548759 -1.936148 -1.015972 -2.854478
-3.859337 -2.822364 -2.024726 -4.550208
-3.589498 -3.158208 -2.906713 -3.523647
-inf -3.569966 -3.505507 -3.410577
-1.369100 -inf -1.378100 -1.190000
-1.171000 -1.171000 -1.186390 -1.243900
-1.171000 -1.179100 -1.186390 -1.090000
-1.252000 -1.252000 -1.186390 -1.098100
-1.274526 -1.252000 -1.259290 -1.243900
-1.260019 -1.259290 -1.339480 -1.279702
-1.267375 -1.332190 -1.252000 -1.186390
-1.267309 -1.392624 -1.179829 -1.266580
-1.260019 -1.339480 -1.186390 -1.266580
-1.243900 -1.259290 -1.282399 -1.266580
-1.226349 -1.171000 -1.206416 -1.179100
-0.882723 -1.000000 -1.000000 -1.011022
-0.802630 -0.975094 -1.047852 -0.989829
-0.486221 -0.942083 -1.016550 -1.002075
-0.118187 -0.886520 -1.121548 -1.083150
-0.018397 -0.470081 -1.086955 -1.054113
-0.011940 -0.033613 -0.945208 -0.930457
-0.935624 -0.011922 -0.955519 -1.835603
-3.210355 -1.017876 -2.345841 -3.243106
-inf -2.896436 -3.049362 -3.472517
-1.689212 -inf -1.190000 -1.378100
-1.259290 -1.261000 -1.252729 -1.171000
-1.259290 -1.171000 -1.252000 -1.090000
-1.338751 -1.171000 -1.252000 -1.179100
-1.260019 -1.252000 -1.179100 -1.259290
-1.253385 -1.179100 -1.410995 -1.277019
-1.274592 -1.259290 -1.477852 -1.200241
-1.187119 -1.253385 -1.187119 -1.358507
-1.267965 -1.252000 -1.358507 -1.267309
-1.345217 -1.418212 -1.287648 -1.273870
-1.294376 -1.332919 -1.392525 -1.253385
-1.006310 -1.003680 -0.874718 -0.953790
-1.427997 -1.391871 -1.529160 -1.347910
-1.381111 -1.354477 -1.361728 -1.444646
-1.567280 -1.467420 -1.514941 -1.288825
-1.637911 -1.811399 -1.617595 -1.106206
-1.932561 -1.960507 -2.121865 -1.029891
-2.498283 -1.944624 -2.251005 -1.027884
-2.547130 -1.973039 -2.125232 -1.961613
-inf -3.018743 -3.161089 -3.107456
-1.190000 -inf -1.379639 -1.393490
-1.171000 -1.203490 -1.186390 -1.259290
-1.098100 -1.252729 -1.179100 -1.179100
-1.331461 -1.090000 -1.090000 -1.259290
-1.353849 -1.309510 -1.259290 -1.186390
-1.423461 -1.331461 -1.338751 -1.259290
-1.332919 -1.337366 -1.399185 -1.399185
-1.339546 -1.351946 -1.179100 -1.266580
-1.346697 -1.332919 -1.274526 -1.332919
-1.384160 -1.338751 -1.425364 -1.406993
-1.405088 -1.534795 -1.398529 -1.516554
-1.040073 -1.054098 -0.970361 -0.875032
-1.425912 -1.351322 -1.324436 -1.453143
-1.280496 -1.499886 -1.344945 -1.358548
-1.389585 -1.400406 -1.403037 -1.509901
-1.617630 -1.554393 -1.622217 -1.565006
-1.809677 -1.817522 -1.791177 -1.778189
-1.921811 -1.993106 -1.856683 -1.857693
-2.497732 -2.145088 -1.939081 -2.109896
-inf -3.189297 -3.180340 -3.371026
-1.369100 -inf -1.408880 -1.361000
-1.179100 -1.188100 -1.098100 -1.180639
-1.179100 -1.171000 -1.098100 -1.179829
-1.346041 -1.171000 -1.171000 -1.090000
-1.266580 -1.252000 -1.252000 -1.259290
-1.261390 -1.259290 -1.252000 -1.274526
-1.411651 -1.265851 -1.396415 -1.286854
-1.268621 -1.275832 -1.259290 -1.260019
-1.267309 -1.324900 -1.265851 -1.273936
-1.345805 -1.347353 -1.331461 -1.371052
-1.236078 -1.275248 -1.304220 -1.305553
-0.990000 -1.000000 -1.000000 -0.893880
-1.188497 -1.230708 -1.167538 -1.186317
-1.278000 -1.331486 -1.291506 -1.288361
-1.534855 -1.398456 -1.338131 -1.346822
-1.543267 -1.635416 -1.393827 -1.508820
-1.724255 -1.689897 -1.188104 -1.712686
-1.944209 -1.907644 -1.033427 -2.131846
-3.567624 -1.948260 -1.033885 -2.533026
-inf -2.974550 -3.248477 -3.830528
-1.523000 -inf -1.562780 -1.378100
-1.179100 -1.261000 -1.178785 -1.090000
-1.171000 -1.171000 -1.179100 -1.090000
-1.090000 -1.171000 -1.098100 -1.259290
-1.179100 -1.171000 -1.090000 -1.186390
-1.179100 -1.179100 -1.171000 -1.187119
-1.171000 -1.179100 -1.179011 -1.427129
-1.338751 -1.179100 -1.090000 -1.098100
-1.331461 -1.171000 -1.171000 -1.266580
-1.169290 -1.179100 -1.090000 -1.435146
-1.000000 -0.990000 -0.987769 -0.989019
-0.989100 -1.000000 -1.011499 -0.961947
-0.964693 -0.977283 -1.000000 -1.000000
-0.887620 -1.000000 -0.995749 -1.010087
-0.764549 -0.969522 -1.027758 -1.027485
-0.174707 -0.932140 -1.075050 -1.132154
-0.028571 -0.574286 -1.115535 -1.115571
-0.019993 -0.059079 -0.964205 -0.949670
-1.879418 -0.019851 -0.950197 -0.954661
-inf -2.051121 -4.042522 -3.743356
-1.368785 -inf -1.620358 -1.532000
-1.178839 -1.202796 -1.157965 -1.186390
-1.243900 -1.090000 -1.232260 -1.179100
-1.179100 -1.090000 -1.162960 -1.090000
-1.171000 -1.090000 -1.164504 -1.098100
-1.251911 -1.171000 -1.155472 -1.098100
-1.090000 -1.171000 -1.167938 -1.090000
-1.171000 -1.090000 -1.168925 -1.090000
-1.090000 -1.243900 -1.087286 -1.171000
-1.087769 -1.171000 -1.117679 -1.090000
-0.982989 -0.979195 -1.000000 -1.000000
-1.252000 -1.303196 -1.334754 -1.242036
-1.178876 -1.356206 -1.179829 -1.167822
-1.267965 -1.324900 -1.291613 -1.289681
-1.372802 -1.403720 -1.460564 -1.349175
-1.519479 -1.419022 -1.582994 -1.316397
-1.732430 -1.675313 -2.237688 -1.136994
-1.909044 -1.989308 -2.433671 -1.040851
-3.114239 -2.008591 -2.403708 -1.030242
-inf -2.905800 -3.184640 -3.167967
-0.916062 -inf -0.793245 -1.027125
-0.988048 -0.855616 -1.005229 -0.981000
-0.989100 -0.900135 -0.998100 -0.987561
-1.000000 -0.929524 -0.990000 -0.990000
-0.910363 -0.985820 -0.996067 -0.990000
-0.975201 -0.909190 -0.998100 -0.988364
-0.920448 -0.982726 -0.997825 -1.000000
-1.000000 -0.986584 -0.858456 -0.998100
-0.894019 -1.000000 -1.000000 -0.997856
-0.318780 -0.884067 -1.000000 -0.897150
-0.884504 -0.990000 -0.989100 -0.944473
-1.005423 -0.860833 -0.955815 -1.002499
-1.281087 -1.285830 -1.434611 -1.265851
-1.481948 -1.404360 -1.350029 -1.413419
-1.728541 -1.555035 -1.611277 -1.552140
-1.822870 -1.782175 -1.796053 -1.756710
-1.980119 -1.990595 -1.908611 -1.875865
-2.058139 -2.074935 -1.976116 -1.914492
-1.966907 -1.970717 -2.070191 -1.918097
-inf -2.779824 -2.821660 -2.832813
-1.008283 -inf -0.645265 -0.937575
-1.279336 -1.214224 -1.462260 -1.330605
-1.259217 -1.171000 -1.388703 -1.298411
-1.187119 -1.252000 -1.346041 -1.235229
-1.259290 -1.259136 -1.187119 -1.233368
-1.178905 -1.252000 -1.186390 -1.162827
-1.271642 -1.179100 -1.186390 -1.235652
-1.003718 -0.988202 -0.809075 -0.933875
-1.390339 -1.220346 -1.308319 -1.232627
-1.186225 -1.243900 -1.282334 -1.157508
-1.167153 -1.171000 -1.259290 -1.161883
-0.990000 -0.981000 -0.988290 -0.911556
-1.382926 -1.356908 -1.367458 -1.429578
-1.456967 -1.546454 -1.474114 -1.490542
-1.725740 -1.638381 -1.568412 -1.698547
-1.809485 -1.827217 -1.889700 -1.823907
-1.915849 -1.992321 -1.902918 -1.870406
-1.926829 -2.030821 -1.911947 -1.969340
-2.023768 -1.988775 -1.940554 -1.902809
-inf -2.261222 -2.595927 -3.077046
-1.186536 -inf -0.463627 -0.742170
-1.581293 -1.436816 -1.696308 -1.559471
-1.513040 -1.451894 -1.523334 -1.469315
-1.405746 -1.428481 -1.355817 -1.390372
-1.266580 -1.332190 -1.353914 -1.266001
-1.326711 -1.259290 -1.281743 -1.252000
-1.356326 -1.273141 -1.286030 -1.265496
-1.043896 -1.002781 -0.930127 -0.818598
-1.400432 -1.394398 -1.438210 -1.461852
-1.333641 -1.364412 -1.364542 -1.319270
-1.299444 -1.187119 -1.260800 -1.265759
-0.996163 -1.000000 -0.884320 -1.000000
-1.406402 -1.400716 -1.386823 -1.420789
-1.546754 -1.544922 -1.516207 -1.574603
-1.608164 -1.775492 -1.612741 -1.657365
-1.788630 -1.831710 -1.779433 -1.829938
-1.795851 -1.827833 -1.921397 -1.914886
-1.851835 -1.825131 -1.861666 -1.966624
-1.950163 -1.906508 -2.005882 -1.880233
-inf -2.522436 -2.427286 -2.467780
-1.259296 -inf -0.766887 -0.461536
-1.665457 -1.479790 -1.631091 -1.761652
-1.480469 -1.545284 -1.495632 -1.554805
-1.267309 -1.547194 -1.361249 -1.443230
-1.266580 -1.339480 -1.361466 -1.339480
-1.267309 -1.259290 -1.259290 -1.397800
-1.293022 -1.273870 -1.300702 -1.309510
-1.054573 -1.002411 -0.570925 -0.952494
-1.555874 -1.359554 -1.393895 -1.338751
-1.397701 -1.332190 -1.598953 -1.492469
-1.228295 -1.280949 -1.409692 -1.396415
-0.747897 -0.990000 -1.025067 -0.985958
-1.107400 -0.908636 -0.422233 -1.067528
-1.561866 -1.472254 -1.538319 -1.534292
-1.813467 -1.762789 -1.782639 -1.727405
-1.881132 -1.955160 -1.840478 -1.907351
-1.848998 -2.014198 -1.882161 -1.902772
-1.887072 -1.905786 -1.949056 -1.885126
-1.925140 -1.969565 -1.939812 -1.907642
-inf -2.505704 -2.276125 -2.501201
-1.057881 -inf -0.944788 -0.634637
-1.554037 -1.411393 -1.511086 -1.551221
-1.639308 -1.414327 -1.346041 -1.380434
-1.367101 -1.411651 -1.417556 -1.439608
-1.450877 -1.333641 -1.379501 -1.404434
-1.445241 -1.413488 -1.529648 -1.383949
-1.427922 -1.495881 -1.716782 -1.512625
-1.203405 -1.199512 -0.441354 -0.660553
-1.498295 -1.415745 -1.855886 -1.560621
-1.420099 -1.601380 -1.656429 -1.610245
-1.438161 -1.459790 -1.547830 -1.462381
-1.174497 -1.416264 -1.347831 -1.380582
-1.163331 -1.063593 -0.022658 -0.697853
-1.936043 -1.286523 -1.668704 -1.496625
-1.963702 -1.866364 -2.017954 -1.828380
-1.976854 -1.945608 -2.028212 -1.962653
-1.998500 -1.928212 -2.022953 -1.968984
-1.954119 -2.024707 -2.020627 -1.953050
-1.980605 -1.901276 -1.869908 -1.867647
-inf -2.292454 -2.256263 -2.475180
-1.016270 -inf -0.964507 -0.858809
-1.268031 -1.352817 -1.309510 -1.267309
-1.260019 -1.340858 -1.260019 -1.274526
-1.424773 -1.405090 -1.267309 -1.283114
-1.461401 -1.472734 -1.439188 -1.427266
-1.441072 -1.477917 -1.583033 -1.521668
-1.477087 -1.660737 -1.716175 -1.623345
-1.155930 -1.227464 -0.802219 -0.436576
-1.706446 -1.464798 -1.575498 -1.634510
-1.669485 -1.613358 -1.622735 -1.702471
-1.596887 -1.607150 -1.755347 -1.613259
-1.037634 -1.612817 -1.557840 -1.592602
-1.036972 -0.984830 -0.000056 -0.209656
-1.963188 -1.034864 -1.835727 -1.968498
-2.086387 -1.868348 -2.048069 -2.142270
-2.111327 -2.101618 -2.101851 -2.144267
-2.040221 -2.112903 -2.034237 -2.036388
-1.893842 -2.019550 -1.967203 -2.099129
-1.863421 -1.998667 -1.841067 -1.755362
-inf -2.088082 -2.460433 -2.234936
-1.000000 -inf -0.977751 -0.945759
-1.179829 -1.239935 -1.171000 -1.200087
-1.179100 -1.326278 -1.171000 -1.098100
-1.519424 -1.259290 -1.268621 -1.179100
-1.501597 -1.477136 -1.497412 -1.537936
-1.445011 -1.557586 -1.555693 -1.375834
-1.361165 -1.434606 -1.397132 -1.612645
-0.998019 -1.028819 -0.946931 -0.664293
-1.607543 -1.404478 -1.592530 -1.477092
-1.751102 -1.672983 -1.643189 -1.665511
-1.662424 -1.716631 -1.714336 -1.867994
-1.000477 -1.970992 -1.766186 -1.794894
-0.903968 -0.909273 -0.000000 -0.003293
-2.562571 -1.000003 -1.876140 -1.985717
-2.263142 -1.890527 -1.890806 -2.268394
-2.142357 -1.985613 -1.876615 -2.313040
-1.909874 -1.800853 -1.811640 -2.104342
-1.901128 -1.831606 -1.852334 -1.921275
-1.828096 -1.878006 -1.789696 -1.903682
-inf -2.258108 -2.422836 -2.261226
-0.972900 -inf -1.000000 -0.986991
-1.171000 -1.170100 -1.169737 -1.105294
-1.243900 -1.171000 -1.238014 -1.090000
-1.370477 -1.265851 -1.284662 -1.273870
-1.360707 -1.532609 -1.380831 -1.535221
-1.462066 -1.412902 -1.329011 -1.442629
-1.289810 -1.272966 -1.333981 -1.299830
-1.025746 -1.018433 -0.897279 -0.836113
-1.584184 -1.434697 -1.361674 -1.693373
-1.583346 -1.530081 -1.073606 -1.818937
-1.661980 -1.763548 -1.000436 -2.097706
-1.016372 -1.904940 -1.000001 -1.901078
-0.900001 -0.900002 -0.000000 -0.000001
-1.900000 -1.000028 -1.000001 -1.900053
-1.898532 -1.897075 -1.000001 -2.674947
-1.924059 -1.874956 -1.000032 -2.591110
-1.780767 -1.795372 -1.023477 -1.941508
-1.774040 -1.763409 -1.868031 -1.771457
-1.867126 -1.834776 -1.847219 -1.855420
-inf -2.392856 -2.403379 -2.279017
-1.000000 -inf -1.000000 -1.000000
-0.970589 -1.000000 -1.000000 -1.000000
-0.887214 -1.000000 -1.000000 -0.998100
-0.788744 -0.967574 -0.990000 -1.006185
-0.731135 -0.886802 -1.032135 -1.082467
-0.968495 -0.732710 -1.000430 -1.019179
-0.802521 -1.000000 -1.017093 -1.005045
-0.652438 -0.947867 -1.099562 -0.893283
-0.216734 -0.841766 -1.066045 -1.169901
-0.002778 -0.503845 -1.052343 -1.022613
-0.000000 -0.025443 -0.916752 -0.911382
-0.000000 -0.000000 -0.900001 -0.900001
-0.000000 -0.000000 -0.900001 -0.000000
-0.000000 -0.000000 -0.900001 -0.900001
-0.000000 -0.000000 -0.900001 -0.900001
-0.003120 -0.000000 -0.903279 -0.900986
-1.791932 -0.000157 -1.036553 -1.010784
-2.861328 -2.044838 -2.534797 -2.360986
-2.463632 -2.485309 -2.523583 -2.386452
-inf -2.415571 -2.495139 -2.440289
-1.000000 -inf -1.000000 -1.000000
-1.090000 -1.000000 -1.000000 -1.000000
-1.251740 -1.090000 -1.000000 -1.090000
-1.090000 -1.309510 -1.167948 -1.153143
-1.346368 -1.324407 -1.341527 -1.339636
-1.324900 -1.353127 -1.337388 -1.246879
-1.442364 -1.338717 -1.478926 -1.377363
-1.857562 -1.663049 -1.750021 -1.625799
-1.429645 -1.480925 -1.732252 -1.318521
-1.529018 -1.667692 -1.785498 -1.096562
-1.834785 -1.880187 -2.624210 -1.000528
-1.886213 -1.911043 -3.464990 -1.000001
-1.900002 -1.900013 -3.609933 -1.000001
-1.900002 -1.900001 -3.609570 -1.000001
-1.902252 -1.899010 -3.566851 -1.000001
-1.925841 -1.914439 -3.359947 -1.000064
-1.998382 -1.729073 -2.519400 -1.039856
-1.931830 -1.836975 -2.088987 -2.290557
-2.040930 -2.076616 -2.028734 -1.957818
-inf -2.524423 -2.490572 -2.482602
-1.190000 -inf -inf -1.000000
-0.990000 -1.000000 -inf -1.000000
-0.965243 -1.000000 -inf -1.000000
-0.918246 -0.978035 -inf -0.990000
-0.880885 -0.940696 -inf -1.000756
-1.220378 -0.883744 -inf -0.999698
-1.765118 -1.963803 -inf -2.172251
-1.799148 -2.030748 -inf -1.747152
-2.519589 -2.054340 -inf -1.959744
-2.608199 -2.411973 -inf -2.297660
-2.789825 -2.752551 -inf -2.730903
-3.487426 -3.501424 -inf -2.890008
-4.417293 -4.366354 -inf -2.899993
-4.290668 -4.526839 -inf -2.899901
-4.280457 -3.892130 -inf -2.893227
-3.412551 -3.397797 -inf -2.889127
-2.948439 -3.203982 -inf -2.698169
-2.882439 -2.821165 -inf -2.663542
-2.562179 -2.820959 -inf -2.574594
-inf -2.568826 -inf -2.460059
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <math.h>
#include <time.h>
#define M_PI 3.14159265358979323846
#define MAPSIZE 20
int running = 1;
void readMapFromFile(char * filename, int map[][MAPSIZE]){
FILE * fp;
fp = fopen(filename, "r");
if(fp == NULL){
printf("Error opening file\n");
exit(1);
}
int i, j;
for(i = 0; i < MAPSIZE; i++){
for(j = 0; j < MAPSIZE; j++){
fscanf(fp, "%d", &map[i][j]);
}
}
fclose(fp);
}
typedef struct Ball {
int x;
int y;
int radius;
int weight;
int isGrounded;
} Ball_t;
void printMap(int map[][MAPSIZE]){
int i, j;
for(i = 0; i < MAPSIZE; i++){
for(j = 0; j < MAPSIZE; j++){
printf("%d ", map[i][j]);
}
printf("\n");
}
}
#define GRAVITY 1
int hitAngle;
int hitIntensity;
void moveBall(Ball_t * ball, int choice){
switch (choice)
{
case 0:
ball->x += 1;
break;
case 1:
ball->x -= 1;
break;
case 2:
ball->y += 1;
break;
case 3:
ball->y -= 1;
break;
}
}
void drawMap(SDL_Renderer * renderer, int map[][MAPSIZE], Ball_t * ball){
int i, j;
for(i = 0; i < MAPSIZE; i++){
for(j = 0; j < MAPSIZE; j++){
if (i == ball->y && j == ball->x){
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderDrawPoint(renderer, j, i);
}
else if (map[i][j] == 1){
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderDrawPoint(renderer, j, i);
}
else if (map[i][j] == 2){
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderDrawPoint(renderer, j, i);
}
}
}
}
float *** allocateAndInitiateQ(){
float *** q = malloc(sizeof(int **) * MAPSIZE);
int i, j, k;
for(i = 0; i < MAPSIZE; i++){
q[i] = malloc(sizeof(float *) * MAPSIZE);
for(j = 0; j < MAPSIZE; j++){
q[i][j] = malloc(sizeof(float) * 4);
if (i > 0 && i < MAPSIZE - 1 && j > 0 && j < MAPSIZE - 1){
for(k = 0; k < 4; k++){
q[i][j][k] = -1;
}
}
else if (i == 0 && j == 0){
int kPossibleValues[2] = {0, 2};
for(k = 0; k < 2; k++){
q[i][j][kPossibleValues[k]] = -1;
}
q[i][j][3] = -INFINITY;
q[i][j][1] = -INFINITY;
}
else if (i == 0 && j == MAPSIZE - 1){
int kPossibleValues[2] = {1, 2};
for(k = 0; k < 2; k++){
q[i][j][kPossibleValues[k]] = -1;
}
q[i][j][0] = -INFINITY;
q[i][j][3] = -INFINITY;
}
else if (i == MAPSIZE - 1 && j == 0){
int kPossibleValues[2] = {0, 3};
for(k = 0; k < 2; k++){
q[i][j][kPossibleValues[k]] = -1;
}
q[i][j][1] = -INFINITY;
q[i][j][2] = -INFINITY;
}
else if (i == MAPSIZE - 1 && j == MAPSIZE - 1){
int kPossibleValues[2] = {1, 3};
for(k = 0; k < 2; k++){
q[i][j][kPossibleValues[k]] = -1;
}
q[i][j][0] = -INFINITY;
q[i][j][2] = -INFINITY;
}
else if (j == MAPSIZE - 1){
int kPossibleValues[3] = {1, 2, 3};
for(k = 0; k < 3 ;k++){
q[i][j][kPossibleValues[k]] = -1;
}
q[i][j][0] = -INFINITY;
}
else if (i == MAPSIZE - 1){
int kPossibleValues[3] = {0, 1, 3};
for(k = 0; k < 3; k++){
q[i][j][kPossibleValues[k]] = -1;
}
q[i][j][2] = -INFINITY;
}
else if (j == 0){
int kPossibleValues[3] = {0, 2, 3};
for(k = 0; k < 3; k++){
q[i][j][kPossibleValues[k]] = -1;
}
q[i][j][1] = -INFINITY;
}
else if (i == 0){
int kPossibleValues[3] = {0, 1, 2};
for(k = 0; k < 3; k++){
q[i][j][kPossibleValues[k]] = -1;
}
q[i][j][3] = -INFINITY;
}
}
}
return q;
}
int argmax(float * arr, int size){
int i;
float max = arr[0];
int maxIndex = 0;
printf("argmax: %f ", arr[0]);
for(i = 1; i < size; i++){
printf("%f ", arr[i]);
if (arr[i] > max){
max = arr[i];
maxIndex = i;
}
}
printf("\n");
return maxIndex;
}
int take_action(Ball_t * ball, float *** Q, float eps){
int action;
int proba = rand() % 100;
if (proba < eps * 100){
if (ball->x > 0 && ball->x < MAPSIZE - 1 && ball->y > 0 && ball->y < MAPSIZE - 1){
action = rand() % 4;
}
else if (ball->x == 0 && ball->y > 0 && ball->y < MAPSIZE - 1){
int possibleActions[3] = {0, 3, 2};
action = possibleActions[rand() % 3];
}
else if (ball->x == MAPSIZE - 1 && ball->y > 0 && ball->y < MAPSIZE - 1){
int possibleActions[3] = {1, 3, 2};
action = possibleActions[rand() % 3];
}
else if (ball->y == 0 && ball->x > 0 && ball->x < MAPSIZE - 1){
int possibleActions[3] = {0, 1, 2};
action = possibleActions[rand() % 3];
}
else if (ball->y == MAPSIZE - 1 && ball->x > 0 && ball->x < MAPSIZE - 1){
int possibleActions[3] = {0, 1, 3};
action = possibleActions[rand() % 3];
}
else if (ball->x == 0 && ball->y == 0){
int possibleActions[2] = {0, 2};
action = possibleActions[rand() % 2];
}
else if (ball->x == 0 && ball->y == MAPSIZE - 1){
int possibleActions[2] = {0, 3};
action = possibleActions[rand() % 2];
}
else if (ball->x == MAPSIZE - 1 && ball->y == 0){
int possibleActions[2] = {1, 2};
action = possibleActions[rand() % 2];
}
else if (ball->x == MAPSIZE - 1 && ball->y == MAPSIZE - 1){
int possibleActions[2] = {1, 3};
action = possibleActions[rand() % 2];
}
else{
action = rand() % 4;
}
}
else{
action = argmax(Q[ball->y][ball->x],4);
//printf("wtf");
}
return action;
}
int setReward(Ball_t * ball, int map[][MAPSIZE]){
if (map[ball->y][ball->x] == 1){
return 0;
}
else if (map[ball->y][ball->x] == 2){
return 1;
}
else if (map[ball->y][ball->x] == 3){
return -2;
}
else{
return -1;
}
}
void printQ(float *** Q){
int i, j, k;
for(i = 0; i < MAPSIZE; i++){
for(j = 0; j < MAPSIZE; j++){
printf("Q for %d %d: ", i, j);
for(k = 0; k < 4; k++){
printf("%f ", Q[i][j][k]);
}
printf("\n");
}
printf("\n");
}
}
void writeQ(float *** Q){
int i, j, k;
FILE * fp = fopen("q.txt", "w+");
for(i = 0; i < MAPSIZE; i++){
for(j = 0; j < MAPSIZE; j++){
for(k = 0; k < 4; k++){
fprintf(fp, "%f ", Q[i][j][k]);
}
fprintf(fp, "\n");
}
fprintf(fp, "\n");
}
fflush(fp);
fclose(fp);
}
typedef struct path_t{
int x;
int y;
struct path_t * next;
} path_t;
// chain list to track the path taken
void insertPointToPath(path_t ** head, int x, int y){
path_t * newPoint = (path_t *)malloc(sizeof(path_t));
newPoint->x = x;
newPoint->y = y;
newPoint->next = *head;
*head = newPoint;
}
int checkIfPointInPath(path_t * head, int x, int y){
path_t * current = head;
while(current != NULL){
if (current->x == x && current->y == y){
return 1;
}
current = current->next;
}
return 0;
}
void freePath(path_t * head){
path_t * current = head;
while(current != NULL){
path_t * temp = current;
current = current->next;
free(temp);
}
}
int main(){
Ball_t ball;
ball.weight = 100;
ball.isGrounded = 1;
path_t * path = NULL;
path = (path_t *)malloc(sizeof(path_t));
srand(time(NULL));
int map[MAPSIZE][MAPSIZE];
readMapFromFile("map.txt", map);
//printMap(map);
float *** Q = allocateAndInitiateQ();
for (int i = 0; i < 10; i++){
freePath(path);
path = (path_t *)malloc(sizeof(path_t));
ball.x = rand() % MAPSIZE;
ball.y = rand() % MAPSIZE;
while (running){
if (map[ball.y][ball.x] == 2){
printf("%d : found at %d %d\n", i, ball.x, ball.y);
running = 0;
}
int action = take_action(&ball, Q, 0.5);
printf("[%d] Action: %d\n", i, action);
int reward = setReward(&ball, map);
printf("[%d] Reward: %d\n", i, reward);
printf("Ball: %d %d\n", ball.x, ball.y);
fflush(stdout);
Ball_t * nextBall = malloc(sizeof(Ball_t));
nextBall->x = ball.x;
nextBall->y = ball.y;
nextBall->weight = ball.weight;
nextBall->isGrounded = ball.isGrounded;
moveBall(nextBall, action);
printf("Next Ball: %d, %d\n", nextBall->x, nextBall->y);
int nextAction = argmax(Q[nextBall->y][nextBall->x],4);
Q[ball.y][ball.x][action] = Q[ball.y][ball.x][action] + 0.1 * (reward + 0.9 * Q[nextBall->y][nextBall->x][nextAction] - Q[ball.y][ball.x][action]);
printf("Q: %f\n", Q[ball.y][ball.x][action] + 0.1 * (reward + 0.9 * Q[nextBall->y][nextBall->x][nextAction] - Q[ball.y][ball.x][action]));
moveBall(&ball, action);
}
running = 1;
}
//printQ(Q);
writeQ(Q);
// use Q after training
ball.x = rand() % MAPSIZE;
ball.y = rand() % MAPSIZE;
// use Q
SDL_Window *window;
SDL_Renderer *renderer;
if (SDL_Init(SDL_INIT_VIDEO) != 0){
printf("Couldn't create window.");
exit(EXIT_FAILURE);
}
window = SDL_CreateWindow("Test Apprentissage", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_RESIZABLE);
if (window == NULL){
printf("Couldn't create window");
exit(EXIT_FAILURE);
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE | SDL_RENDERER_PRESENTVSYNC);
if (renderer == NULL){
printf("Couldn't create renderer.");
exit(EXIT_FAILURE);
}
while (running){
//
drawMap(renderer, map, &ball);
if (map[ball.y][ball.x] == 2){
printf("found at final %d %d\n", ball.x, ball.y);
running = 0;
}
int action = take_action(&ball, Q, 0.1);
printf("Action: %d\n", action);
int reward = setReward(&ball, map);
printf("Reward: %d\n", reward);
moveBall(&ball, action);
printf("Ball: %d %d\n", ball.x, ball.y);
fflush(stdout);
}
}
\ No newline at end of file
......@@ -5,6 +5,9 @@ int game_state;
int main(){
float ***** Q = allocateAndInitiateQ();
writeQ(Q);
running = 1;
game_state = GAME;
readMapFromFile("map.txt");
......
......@@ -17,6 +17,7 @@
#include "render.h"
#include "gest_event.h"
#include "map.h"
#include "qlearn.h"
#define MENU 0
......
......@@ -30,6 +30,30 @@ void initPlayer(){
player.viewAngle = 0;
}
void hitBall(){
//printf("map edges: %d %d\n", BLOCK_SIZE * MAP_WIDTH/2, BLOCK_SIZE *MAP_HEIGHT/2);
//printf("ray1: %d %d\n", ray1[0], ray1[1]);
int angleMin = RD * atan2((MAP_WIDTH/2)*BLOCK_SIZE - player.x, player.y);
int angleMax = 90 + RD * atan2((MAP_WIDTH/2)*BLOCK_SIZE - player.x, MAP_HEIGHT * BLOCK_SIZE - player.y);
int currAngle = (int) ((player.angle) * RD +90) %360;
//printf("player angle: %d\n",(int) ((player.angle) * RD +90) %360 );
printf("distance to ball: %f\n", sqrt(pow(ball.x - player.x, 2) + pow(ball.y - player.y, 2))/BLOCK_SIZE);
if (sqrt(pow(player.x - ball.x, 2) + pow(player.y - ball.y, 2))/BLOCK_SIZE < HIT_RANGE){
if (currAngle < angleMax && currAngle > angleMin){
printf("hit\n");
if (player.isHitting){
ball.x = player.x;
ball.y = player.y;
}
printf("valid hit\n");
}
else {
printf("unvalid hit\n");
}
}
//}
}
void manageMovement(){
float x_increment = (Keys[0] - Keys[2]) * player.deltax + (Keys[3] - Keys[1]) * sin(player.angle);
float y_increment = (Keys[0] - Keys[2]) * player.deltay + (Keys[1] - Keys[3]) * cos(player.angle);
......@@ -45,4 +69,5 @@ void manageMovement(){
void managePlayer(){
manageMovement();
hitBall();
}
\ No newline at end of file
......@@ -9,6 +9,8 @@
#define ENTITIES_LEFT 2
#define ENTITIES_RIGHT 3
#define HIT_RANGE 2
#define MOVEMENT_SPEED 2
typedef struct player{
float x;
......@@ -17,6 +19,7 @@ typedef struct player{
int w;
int speed;
int isMoving;
int isHitting;
int direction;
int HPMax;
int currentHP;
......
#include "qlearn.h"
void moveAgent(agent_t * agent, int choice){
switch (choice)
{
case BACK:
agent->x += 1*agent->speed; //Avancer
break;
case FOWARD:
agent->x -= 1*agent->speed; // reculer
break;
case UP:
agent->y += 1*agent->speed;
break;
case DOWN:
agent->y -= 1*agent->speed;
break;
case WAIT:
break;
}
}
float ***** allocateAndInitiateQ(){
int i,j,k,l,m;
float ***** q = malloc(sizeof(float ****) * NUMBER_ZONE_RECEIVER); /// alloc player zone
if (q==NULL)
{
printf("problème d'allocation \n");
exit(1);
}
for(i = 0; i < NUMBER_ZONE_RECEIVER; i++){
q[i] = malloc(sizeof(float ***) * NUMBER_ZONE_SHOOTER ); // alloc shooter zone
if (q[i]==NULL)
{
printf("problème d'allocation \n");
exit(1);
}
for(j = 0; j< NUMBER_ZONE_SHOOTER; j++){
q[i][j] = malloc(sizeof(float **) * 3 ); // alloc angle hauteur
if (q[i][j]==NULL)
{
printf("problème d'allocation \n");
exit(1);
}
for(k = 0; k <3 ; k++){
q[i][j][k] = malloc(sizeof(float *) * 5 ); // alloc angle plat
if (q[i][j][k]==NULL)
{
printf("problème d'allocation \n");
exit(1);
}
for(l = 0; l<5 ; l++){
q[i][j][k][l] = malloc(sizeof(float ) * 5); //alloc action
if (q[i][j][k][l]==NULL)
{
printf("problème d'allocation \n");
exit(1);
}
for (m=0;m <5;m++){
q[i][j][k][l][m]=0;
}
}
}
}
}
return q;
}
void writeQ(float *****Q){
int i, j, k, l, m ;
FILE * fp = fopen("q.txt", "w+");
for(i = 0; i < NUMBER_ZONE_RECEIVER; i++){
for(j = 0; j < NUMBER_ZONE_SHOOTER; j++){
for(k = 0; k < 3; k++){
for(l= 0; l < 5; l++){
for(m= 0; m <5; m++){
fprintf(fp, "%f ", Q[i][j][k][l][m]);
}
}
}
fprintf(fp, "\n");
}
fprintf(fp, "\n");
}
fflush(fp);
fclose(fp);
}
\ No newline at end of file
#ifndef Q_LEARN
#define Q_LEARN
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//#include "ball.h"
#include "math.h"
#include "map.h"
#define NUMBER_ZONE_SHOOTER 4
#define NUMBER_ZONE_RECEIVER 4
#define FOWARD 0//<--
#define BACK 1 //-->
#define UP 2
#define DOWN 3
#define WAIT 4
typedef struct agent {
int x;
int y;
int heigth;
int weight;
int speed;
} agent_t;
void moveAgent(agent_t * agent, int choice);
float ***** allocateAndInitiateQ();
void writeQ(float *****Q);
#endif
\ No newline at end of file
......@@ -18,6 +18,8 @@ SDL_Texture * playerTexture;
int ** rays;
int raysListLength = 0;
int * ray1;
int * ray2;
rayInfo_t raysListHead;
......@@ -69,6 +71,10 @@ void initRays(){
}
}
int isRaysListEmpty(){
return raysListLength == 0;
}
void addRayToList(int x, int y){
if (raysListLength < 2 * NB_RAYS){
*rays[raysListLength] = x;
......@@ -391,6 +397,21 @@ void castRays(int map[][MAP_WIDTH]){
}
}
// draw the ray in the minimap
if (r == 0){
//printf("%d %d\n", (int)rx, (int)ry);
ray1[0] = (int)rx;
ray1[1] = (int)ry;
//printf("ray1 %d %d\n", ray1[0], ray1[1]);
//printf("ray2 %d %d\n", ray2[0], ray2[1]);
}
if (r == NB_RAYS - 1){
//printf("%d %d\n", (int)rx, (int)ry);
ray2[0] = (int)rx;
ray2[1] = (int)ry;
printf("ray1 %d %d\n", ray1[0]/BLOCK_SIZE, ray1[1]/BLOCK_SIZE);
printf("ray2 %d %d\n", ray2[0]/BLOCK_SIZE, ray2[1]/BLOCK_SIZE);
}
//printf("raylistlength %d\n", raysListLength);
addRayToList(rx, ry);
addRayToList(rx2, ry2);
......@@ -410,7 +431,7 @@ void drawEnnemy(){
int ennemyHeight = 200;
//printf("%f %f\n", ennemyAngle, player.angle - (FOV_ANGLE)/2 * DR);
//printf("%f\n", player.angle * RD);
if (ennemyAngle >= player.angle - (FOV_ANGLE)/2 * DR && ennemyAngle <= player.angle + (FOV_ANGLE)/2 * DR){
rect.x = screenDimension.w/2 + (screenDimension.w * tan(ennemyAngle - player.angle)) * sqrt(3) * 0.5;
......@@ -422,7 +443,7 @@ void drawEnnemy(){
destRect.y = 0;
destRect.w = 64;
destRect.h = 64;
printf("%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h);
//printf("%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h);
SDL_RenderCopy(renderer, playerTexture, &destRect, &rect);
}
}
......@@ -449,7 +470,7 @@ void drawBall(){
destRect.y = 0;
destRect.w = 64;
destRect.h = 64;
printf("%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h);
//printf("%d %d %d %d\n", rect.x, rect.y, rect.w, rect.h);
SDL_RenderCopy(renderer, playerTexture, &destRect, &rect);
}
}
......@@ -546,6 +567,9 @@ void mainLoop(){
crowdTexture = loadTexture("Res/crowd.png");
playerTexture = loadTexture("Res/player_sprite.png");
ray1 = malloc(sizeof(int) * 2);
ray2 = malloc(sizeof(int) * 2);
unsigned int a = SDL_GetTicks();
unsigned int b = SDL_GetTicks();
double delta = 0;
......
......@@ -12,6 +12,7 @@
#define DOF 100
#define BLOCK_SIZE 64
#define DR 0.0174533
#define RD 57.2958
#define FOV_ANGLE 120
#define pi 3.14159265358979323846
#define NB_RAYS (screenDimension.w)
......@@ -31,6 +32,8 @@ extern SDL_Window *window;
extern SDL_Renderer *renderer;
extern SDL_DisplayMode screenDimension;
extern int * ray1;
extern int * ray2;
void mainLoop();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment