1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
|
/*
* Programm XBLAST V1.2.14 or higher
* (C) by Oliver Vogel (e-mail: vogel@ikp.uni-koeln.de)
* May 9th 1996
* started August 1993
*
* Bot by Didier PLANTET (e-mail: plantet@info.enserb.u-bordeaux.fr)
* and Grgoire ROBERT (e-mail : robert@info.enserb.u-bordeaux.fr)
* File: bot.c
* Bot IA ...
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public Licences as published
* by the Free Software Foundation; either version 2; or (at your option)
* any later version
*
* This program is distributed in the hope that it will entertaining,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILTY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Publis License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "xblast.h"
#define _BOT_C
#define BOMB_STEP 2
#define NUM_FUSES 3
#define PROB_POSER 10
#define PROB_SWAP 100
#define BONUS_EXPLOSE 40
#define BONUS_TUE 60
#define BONUS_SIMPLE 100
#define BONUS_EXTRA 200
#define MALUS_MORT -1000
#define SLOW_SPEED 16
#define NORMAL_SPEED 8
#define FAST_SPEED 4
typedef struct coord
{
short x, y;
short temps;
short malus;
struct coord *suivant;
} coord;
static int fuse_times[NUM_FUSES] = { SHORT_FUSE, BOMB_TIME, LONG_FUSE };
/* Tableau des bombes */
/*static Explosion *laby_bomb[MAZE_W][MAZE_H];*/
/* Liste des bombes */
static Explosion bombes_tmp[100];
/* Tableau des cases dangereuses : temps avant explosion */
static int laby_perf[MAZE_W][MAZE_H];
/* Nb de points dans chaque direction */
static int vote[NB_DIR];
/* Vaut VRAI si je pose */
static int vote_poser;
/* Vaut VRAI si je swappe */
static int vote_swap;
/* Vaut VRAI si j'effectue une action spciale (appui sur +) */
static int vote_action_speciale;
/* Tableau des cases visites (boolen) */
static int laby_visit[MAZE_W][MAZE_H];
/* Tableau des cases disparaissant */
static int laby_shrink[MAZE_W][MAZE_H];
static int perf_max[NB_DIR];
static coord *file;
static int gameTime;
static BMPlayer *statut_joueurs;
/* Mon numro moi */
static int num_bot;
static int nb_joueurs;
static int nb_ennemis_vivants;
static int temps_jeu;
/* La duree de deplacement entre 2 cases */
static int duree_deplacement;
/* Score accord au bonus du niveau */
static int bonus_extra;
int dirige_vers_bonus (int x, int y, int dir);
/* Fouf lenteur -- *//* static int trace; */
void
SetBotTime (int game_time)
{
gameTime = game_time;
}
coord *
creer_coord (int x, int y, int temps, int malus)
{
coord *c = (coord *) malloc (sizeof (coord));
c->x = x;
c->y = y;
c->temps = temps;
c->malus = malus;
c->suivant = NULL;
return c;
}
void
enfiler (int x, int y, int temps, int malus)
{
coord *tmpc;
coord *c = creer_coord (x, y, temps, malus);
if (file == NULL)
file = c;
else {
tmpc = file;
while (tmpc->suivant != NULL)
tmpc = tmpc->suivant;
tmpc->suivant = c;
}
}
coord *
defiler (void)
{
coord *c = file;
file = file->suivant;
return c;
}
/* Renvoie le nb de murs m'entourant */
int
test_murs (BMPlayer * ps)
{
int x = ps->x / BLOCK_WIDTH;
int y = ps->y / BLOCK_HEIGHT + 1;
int nb_murs = 0;
if (CheckMaze (x, y - 1)) {
vote[UP] = MALUS_MORT;
nb_murs++;
}
if (CheckMaze (x - 1, y)) {
vote[LEFT] = MALUS_MORT;
nb_murs++;
}
if (CheckMaze (x, y + 1)) {
vote[DOWN] = MALUS_MORT;
nb_murs++;
}
if (CheckMaze (x + 1, y)) {
vote[RIGHT] = MALUS_MORT;
nb_murs++;
}
return nb_murs;
}
/*Explosion *
foundBomb (int x, int y)
{
Explosion *p;
for (p = expl_list; p != NULL; p = p->next)
if (p->x == x && p->y == y)
return p;
return NULL;
}*/
Explosion *
bombe_trouvee_tmp (int x, int y)
{
int i;
for (i = 0; i < 100; i++)
if (bombes_tmp[i].range != -1 && bombes_tmp[i].x == x && bombes_tmp[i].y == y)
return &bombes_tmp[i];
return NULL;
}
/*void
developpe_bombe (int range, int mazex, int mazey, int type)
{
Explosion *p;
int i,j;
// right
for (i = 1; (i <= range) && CheckMazeOpen(mazex+i-1,mazey) ; i ++)
if (mazex+i < MAZE_W)
if (laby_perf[mazex][mazey] + i < laby_perf[mazex+i][mazey])
{
laby_perf[mazex+i][mazey] = laby_perf[mazex][mazey] + i;
p = CheckBomb (mazex+i, mazey);
if (p != NULL && p->dir == GoStop)
developpe_bombe (p->range, mazex+i, mazey, BMTnormal);
}
// Left
for (i = 1; (i <= range) && CheckMazeOpen(mazex-i+1,mazey) ; i ++)
if (mazex-i >= 0)
if (laby_perf[mazex][mazey] + i < laby_perf[mazex-i][mazey])
{
laby_perf[mazex-i][mazey] = laby_perf[mazex][mazey] + i;
p = CheckBomb (mazex-i, mazey);
if (p != NULL && p->dir == GoStop)
developpe_bombe (p->range, mazex-i, mazey, BMTnormal);
}
// Down
for (i = 1; (i <= range) && CheckMazeOpen(mazex,mazey+i-1) ; i ++)
if (mazey+i < MAZE_H)
if (laby_perf[mazex][mazey] + i < laby_perf[mazex][mazey+i])
{
laby_perf[mazex][mazey+i] = laby_perf[mazex][mazey] + i;
p = CheckBomb (mazex, mazey+i);
if (p != NULL && p->dir == GoStop)
developpe_bombe (p->range, mazex, mazey+i, BMTnormal);
}
// Up
for (i = 1; (i <= range) && CheckMazeOpen(mazex,mazey-i+1) ; i ++)
if (mazey-i >= 0)
if (laby_perf[mazex][mazey] + i < laby_perf[mazex][mazey-i])
{
laby_perf[mazex][mazey-i] = laby_perf[mazex][mazey] + i;
p = CheckBomb (mazex, mazey-i);
if (p != NULL && p->dir == GoStop)
developpe_bombe (p->range, mazex, mazey-i, BMTnormal);
}
if (type == BMTnapalm)
for (i= -2; i<=2; i++) {
if (mazex+i < MAZE_W && mazex+i >= 0)
developpe_bombe (range/(ABS(i)+1), mazex+i, mazey, BMTnormal);
if (mazey+i < MAZE_H && mazey+i >= 0)
developpe_bombe (range/(ABS(i)+1), mazex, mazey+i, BMTnormal);
}
if (type == BMTgrenade)
if (range == 1) {
developpe_bombe(0, mazex-1, mazey-1, BMTblastnow);
developpe_bombe(0, mazex+1, mazey-1, BMTblastnow);
developpe_bombe(0, mazex-1, mazey+1, BMTblastnow);
developpe_bombe(0, mazex+1, mazey+1, BMTblastnow);
} else {
for (i = -((range)-1); i<=((range)-1); i++) {
for (j = -((range)-1); j<=((range)-1); j++) {
developpe_bombe (1, mazex+i, mazey+j, BMTblastnow);
}
}
}
}*/
void
developpe_bombe_tmp (int range, int mazex, int mazey, int type, int count)
{
// Explosion *p;
int i, j;
/* right */
for (i = 1; (i <= range) && CheckMazeOpen (mazex + i - 1, mazey); i++)
if (mazex + i < MAZE_W)
if (laby_perf[mazex][mazey] + i < laby_perf[mazex + i][mazey])
laby_perf[mazex + i][mazey] = laby_perf[mazex][mazey] + i * count;
/* Left */
for (i = 1; (i <= range) && CheckMazeOpen (mazex - i + 1, mazey); i++)
if (mazex - i >= 0)
if (laby_perf[mazex][mazey] + i < laby_perf[mazex - i][mazey])
laby_perf[mazex - i][mazey] = laby_perf[mazex][mazey] + i * count;
/* Down */
for (i = 1; (i <= range) && CheckMazeOpen (mazex, mazey + i - 1); i++)
if (mazey + i < MAZE_H)
if (laby_perf[mazex][mazey] + i < laby_perf[mazex][mazey + i])
laby_perf[mazex][mazey + i] = laby_perf[mazex][mazey] + i * count;
/* Up */
for (i = 1; (i <= range) && CheckMazeOpen (mazex, mazey - i + 1); i++)
if (mazey - i >= 0)
if (laby_perf[mazex][mazey] + i < laby_perf[mazex][mazey - i])
laby_perf[mazex][mazey - i] = laby_perf[mazex][mazey] + i * count;
if (type == BMTnapalm)
for (i = -2; i <= 2; i++) {
if (mazex + i < MAZE_W && mazex + i >= 0)
developpe_bombe_tmp (range / (ABS (i) + 1), mazex + i, mazey, BMTnormal, count);
if (mazey + i < MAZE_H && mazey + i >= 0)
developpe_bombe_tmp (range / (ABS (i) + 1), mazex, mazey + i, BMTnormal, count);
}
if (type == BMTgrenade) {
if (range == 1) {
developpe_bombe_tmp (0, mazex - 1, mazey - 1, BMTblastnow, count);
developpe_bombe_tmp (0, mazex + 1, mazey - 1, BMTblastnow, count);
developpe_bombe_tmp (0, mazex - 1, mazey + 1, BMTblastnow, count);
developpe_bombe_tmp (0, mazex + 1, mazey + 1, BMTblastnow, count);
}
else {
for (i = -((range) - 1); i <= ((range) - 1); i++) {
for (j = -((range) - 1); j <= ((range) - 1); j++) {
developpe_bombe_tmp (1, mazex + i, mazey + j, BMTblastnow, count);
}
}
}
}
}
/* Traduit une direction en dx et dy */
void
conversion_direction (int dir, int *dx, int *dy)
{
*dx = 0;
*dy = 0;
switch (dir) {
case UP:
*dy = -1;
break;
case DOWN:
*dy = 1;
break;
case LEFT:
*dx = -1;
break;
case RIGHT:
*dx = 1;
}
}
/* Les bonus extras sont-ils positifs ou ngatifs ? */
void
def_score_extra (BMPlayer * ps)
{
bonus_extra = BONUS_EXTRA;
/* La tortue */
if (specialExtraFunc == SpecialExtraSlow) {
if (!ps->iniextra_flags) {
bonus_extra = -BONUS_SIMPLE / 2;
}
else {
if (!ps->revextra_flags)
bonus_extra = -BONUS_SIMPLE / 2;
else
bonus_extra = 0; /* Si je suis dj lent, reprendre une tortue ne change rien */
}
}
/* Le "bonus" invisible qui fait tourner */
if (specialExtraFunc == SpecialExtraStunOthers) {
bonus_extra = -2 * BONUS_SIMPLE;
}
/* La seringue */
if (specialExtraFunc == SpecialExtraJunkie && ps->junkie == 0) {
/* Si j'y ai dj touch, j'ai intrt en reprendre... */
bonus_extra = -5 * BONUS_SIMPLE;
}
/* La mort immdiate */
if (specialExtraFunc == SpecialExtraPoison) {
bonus_extra = -10 * BONUS_SIMPLE;
}
}
/* Un bonus sur la case ? */
int
score_bonus (int x, int y)
{
int bonus;
bonus = GetBlockExtra (x, y);
if (bonus == BTBomb || bonus == BTRange)
bonus = BONUS_SIMPLE + 200;
else if (bonus == BTSpecial || bonus == BTExtra) {
if (specialExtraFunc != SpecialExtraPoison) {
bonus = bonus_extra;
}
else {
bonus = -BONUS_SIMPLE;
}
}
else /* if (bonus == BTSwapper)
bonus = BONUS_EXTRA;
else */ if (bonus == BTEvil)
bonus = -BONUS_SIMPLE;
else
bonus = 0;
return bonus;
}
/* Est-il intressant de poser sur cette case ? */
int
score_explose (int x, int y, int portee_bombe)
{
int explose = 0;
int dir, dx, dy;
int i;
for (dir = 1; dir < NB_DIR; dir++) {
conversion_direction (dir, &dx, &dy);
i = 1;
while (CheckMazeFree (x + i * dx, y + i * dy) && i <= portee_bombe)
i++;
/* Y a-t-il un mur dtruire ? Et sinon, un bonus ? */
if (GetBlockExtra (x + i * dx, y + i * dy) == BTExtra)
explose += BONUS_EXPLOSE;
else
explose -= (score_bonus (x + i * dx, y + i * dy) / 4);
}
explose += 75;
return explose;
}
/* Est-ce que poser ici va menacer un autre joueur ? */
int
score_tue (int x, int y, int portee_bombe)
{
int tue = 0;
int xmin = -1, xmax = -1, ymin = -1, ymax = -1;
int j, jx, jy;
int points;
BMPlayer *ps;
/* Quelles cases puis-je atteindre ? */
for (j = 1; j <= portee_bombe; j++) {
if (xmin == -1 && (!CheckMazeFree (x - j, y) || j == portee_bombe))
xmin = x - j;
if (xmax == -1 && (!CheckMazeFree (x + j, y) || j == portee_bombe))
xmax = x + j;
if (ymin == -1 && (!CheckMazeFree (x, y - j) || j == portee_bombe))
ymin = y - j;
if (ymax == -1 && (!CheckMazeFree (x, y + j) || j == portee_bombe))
ymax = y + j;
}
nb_ennemis_vivants = 0;
for (j = 0; j < nb_joueurs; j++) {
ps = statut_joueurs + j;
/* Le joueur n'est pas le bot et vit encore */
if ((j != num_bot) && (ps->lives != 0)) {
jx = ps->x / BLOCK_WIDTH;
jy = ps->y / BLOCK_HEIGHT + 1;
points = BONUS_TUE;
/* Si le joueur est mon partenaire.... je vais viter de le tuer ! */
if (ps->team == (statut_joueurs + num_bot)->team)
points = -points;
else
nb_ennemis_vivants++;
/* Je suis sur la mme colonne */
if ((x == jx) && ((ymin <= jy) && (jy <= ymax)))
tue += points;
/* Je suis sur la mme ligne (et pas sur la mme colonne) */
if ((y == jy) && (x != jx) && ((xmin <= jx) && (jx <= xmax)))
tue += points;
/* Si le joueur a une mauvaise mort (poseuse, lenteur, mini, non-poseuse,
malfunction, teleport, ou *seringue*), je dois l'viter */
if ((x == jx) && (y == jy)) {
if ((ps->illness == IllBomb) ||
(ps->illness == IllSlow) ||
(ps->illness == IllMini) ||
(ps->illness == IllEmpty) ||
(ps->illness == IllMalfunction) || (ps->illness == IllTeleport) || (ps->junkie))
tue -= BONUS_SIMPLE;
}
/* sinon, j'essaie toujours de m'en approcher (s'il n'est pas mon partenaire) */
else
tue += points;
}
}
return tue;
}
/* Est-ce que je risque de me faire shrinker sur cette case ? */
int
score_shrink (int x, int y, int temps)
{
int score = 0;
temps += temps_jeu;
if (laby_shrink[x][y] - temps <= 16)
score = MALUS_MORT;
else if (laby_shrink[x][y] - temps <= 50)
score = -BONUS_EXTRA;
else if (laby_shrink[x][y] - temps <= 100)
score = -BONUS_SIMPLE;
return score;
}
/* Teste le danger et l'intrt d'une case... puis poursuit le parcours par niveau */
void
teste_case (coord * c, int dir_init, BMPlayer * ps)
{
int perf = laby_perf[c->x][c->y] - c->temps;
int portee_bombe = (ps->illness == IllMini) ? 1 : ps->range;
int score, malus;
int invincible = ps->invincible - c->temps;
int tourne = ps->stunned - c->temps;
int dir, dx, dy;
if (invincible > 0)
perf += invincible;
if (tourne < 0)
tourne = 0;
/* Une bombe explosera sur le passage */
if (perf <= 4)
return;
/* La case disparatra */
if (score_shrink (c->x, c->y, c->temps) == MALUS_MORT)
return;
score = score_bonus (c->x, c->y);
if (score <= -500)
return;
/* Mise jour du malus (score ngatif le + faible du chemin) */
malus = MIN (c->malus, score);
/* Calcul du score de la case */
score += score_explose (c->x, c->y, portee_bombe);
score += score_tue (c->x, c->y, portee_bombe);
score += score_shrink (c->x, c->y, c->temps);
/* Mise jour de la performance maximale de la direction dir_init */
perf += score;
if (perf > 10 * LONG_FUSE)
perf += malus;
perf_max[dir_init] = MAX (perf_max[dir_init], perf);
for (dir = 1; dir < NB_DIR; dir++) {
conversion_direction (dir, &dx, &dy);
/* Si je ne suis pas dj pass par l, s'il n'y a ni mur, ni bombe, je place la case dans la file */
if (!laby_visit[c->x + dx][c->y + dy] && !CheckMaze (c->x + dx, c->y + dy)
) {
if (!ps->kick) {
if (!CheckBomb (c->x + dx, c->y + dy)) {
enfiler (c->x + dx, c->y + dy, c->temps + duree_deplacement + tourne, malus);
laby_visit[c->x + dx][c->y + dy] = 1;
}
}
else {
enfiler (c->x + dx, c->y + dy, c->temps + duree_deplacement + tourne, malus);
laby_visit[c->x + dx][c->y + dy] = 1;
}
}
}
}
/* Remplissage du tableau laby_shrink (en dbut de niveau) */
void
init_laby_shrink ()
{
ShrinkGeneric *shrink_ptr = GetShrinkPtr ();
XBScrambleData *scramble = GetScrDraw ();
int temps;
int x, y;
unsigned mask;
for (x = 0; x < MAZE_W; x++)
for (y = 0; y < MAZE_H; y++)
laby_shrink[x][y] = 2 * GAME_TIME;
/* La liste pointe par shrink_ptr se termine par une cellule (2 * GAME_TIME, 0, 0) */
while (shrink_ptr->time < 2 * GAME_TIME) {
temps = shrink_ptr->time;
x = shrink_ptr->x;
y = shrink_ptr->y;
if (laby_shrink[x][y] > temps)
laby_shrink[x][y] = temps;
shrink_ptr++;
}
/* Blocs surgissant sur le plateau */
temps = scramble->time - 4;
for (y = 0; y < MAZE_H; y++) {
if (0 != scramble->row[y]) {
for (x = 0, mask = 1; x < MAZE_W; x++, mask <<= 1) {
if (mask & scramble->row[y]) {
if (laby_shrink[x][y] > temps)
laby_shrink[x][y] = temps;
}
}
}
}
/* for (y = 0; y < MAZE_H; y++) {
for (x = 0; x < MAZE_W; x++)
fprintf (stderr, "%d ", laby_shrink[x][y]);
fprintf (stderr, "\n");
}*/
}
/* Aucune case n'a t visite (dbut d'un parcours par niveau) */
void
init_laby_visit (int x, int y)
{
int mazex, mazey;
for (mazex = 0; mazex < MAZE_W; mazex++)
for (mazey = 0; mazey < MAZE_H; mazey++)
laby_visit[mazex][mazey] = 0;
/* memset (&laby_visit, 0, MAZE_W * MAZE_H * sizeof (int));*/
laby_visit[x][y] = 1;
}
static BMDirection turn_clockwise[MAX_DIR] = {
GoStop, GoRight, GoUp, GoLeft, GoDown, GoDefault
};
static BMDirection turn_anticlockwise[MAX_DIR] = {
GoStop, GoLeft, GoDown, GoRight, GoUp, GoDefault
};
static BMDirection turn_opposite[MAX_DIR] = {
GoStop, GoDown, GoRight, GoUp, GoLeft, GoDefault
};
void
calc_laby_perf ()
{
int player;
int i, j, k;
int dx, dy;
int temps;
Explosion *p;
Explosion *p2;
/* On traite d'abord les bombes en train d'exploser (count > 0) */
for (i = 0; i < 100; i++) {
p = &bombes_tmp[i];
if (p->range == -1)
continue;
if (p->count < 0)
continue;
if (laby_perf[p->x][p->y] > -p->count) {
laby_perf[p->x][p->y] = -p->count;
developpe_bombe_tmp (p->range, p->x, p->y, p->type, -p->count);
}
else
developpe_bombe_tmp (p->range, p->x, p->y, BMTnormal, -p->count);
p->range = -1;
}
for (temps = 0; temps < LONG_FUSE; temps++) { /* On deplace case par case */
for (i = 0; i < 100; i++) { /* Pour chaque bombe */
p = &bombes_tmp[i];
if (p->range == -1)
continue;
if (temps == -p->count || laby_perf[p->x][p->y] <= temps) { /* On explose la */
if (laby_perf[p->x][p->y] > -p->count) {
laby_perf[p->x][p->y] = -p->count;
developpe_bombe_tmp (p->range, p->x, p->y, p->type, -p->count);
}
else
developpe_bombe_tmp (p->range, p->x, p->y, BMTnormal, -p->count);
p->range = -1;
continue;
}
if (p->dir == GoStop) {
continue;
}
conversion_direction (p->dir, &dx, &dy);
/* Si on cogne une bombe */
if (p->dx * dx >= 0 && p->dy * dy >= 0 && bombe_trouvee_tmp (p->x + dx, p->y + dy)) {
if (doBombClick == BombClickNone) {
p->dir = GoStop;
p->dx = 0;
p->dy = 0;
}
else if (doBombClick == BombClickInitial) {
p->dir = initialBombDir;
conversion_direction (p->dir, (int *)&p->dx, (int *)&p->dy);
}
else if (doBombClick == BombClickThru) {
}
else if (doBombClick == BombClickSnooker) {
p2 = bombe_trouvee_tmp (p->x + dx, p->y + dy);
p2->dir = p->dir;
/* On met a 0 l'offset de l'autre direction */
p2->dx = p2->dx * ABS (dx);
p2->dy = p2->dy * ABS (dy);
/* La bombe qui cogne arrete de bouger */
p->dir = GoStop;
p->dx = 0;
p->dy = 0;
}
else if (doBombClick == BombClickContact) {
p->dir = GoStop;
p->dx = 0;
p->dy = 0;
if (laby_perf[p->x][p->y] > -p->count)
laby_perf[p->x][p->y] = -p->count;
developpe_bombe_tmp (p->range, p->x, p->y, p->type, -p->count);
bombes_tmp[i].range = -1;
}
else if (doBombClick == BombClickContact) {
p->dir = turn_clockwise[p->dir];
p->dx = 0;
p->dy = 0;
}
else if (doBombClick == BombClickAnticlockwise) {
p->dir = turn_anticlockwise[p->dir];
p->dx = 0;
p->dy = 0;
}
else if (doBombClick == BombClickRandomdir) {
p->dir = (int)(((float)rand () / (RAND_MAX + 1.0)) * (4)) + 1;
p->dx = 0;
p->dy = 0;
}
else if (doBombClick == BombClickRebound) {
p->dir = turn_opposite[p->dir];
}
}
/* Ou un mur */
else if (p->dx == 0 && p->dy == 0 && !CheckMazeFree (p->x + dx, p->y + dy)) {
if (doWallClick == BombClickNone) {
p->dir = GoStop;
p->dx = 0;
p->dy = 0;
}
else if (doWallClick == BombClickInitial) {
p->dir = initialBombDir;
conversion_direction (p->dir, (int *)&p->dx, (int *)&p->dy);
}
else if (doWallClick == BombClickThru) {
}
else if (doWallClick == BombClickContact) {
p->dir = GoStop;
p->dx = 0;
p->dy = 0;
if (laby_perf[p->x][p->y] > -p->count)
laby_perf[p->x][p->y] = -p->count;
developpe_bombe_tmp (p->range, p->x, p->y, p->type, -p->count);
bombes_tmp[i].range = -1;
}
else if (doWallClick == BombClickContact) {
p->dir = turn_clockwise[p->dir];
p->dx = 0;
p->dy = 0;
}
else if (doWallClick == BombClickAnticlockwise) {
p->dir = turn_anticlockwise[p->dir];
p->dx = 0;
p->dy = 0;
}
else if (doWallClick == BombClickRandomdir) {
p->dir = (BMDirection) (int)((float)rand () / (RAND_MAX + 1.0)) * MAX_DIR;
p->dx = 0;
p->dy = 0;
}
else if (doWallClick == BombClickRebound) {
p->dir = turn_opposite[p->dir];
}
}
/* Un joueur */
else {
for (player = 0; player < nb_joueurs; player++) {
if ((statut_joueurs[player].invincible == 0)
&& (ABS (p->x * BLOCK_WIDTH + p->dx - statut_joueurs[player].x)
< BOMB_STUN_X)
&& (ABS (p->y * BLOCK_HEIGHT + p->dy
- statut_joueurs[player].y - BLOCK_HEIGHT) < BOMB_STUN_Y))
break;
}
if (player < nb_joueurs) {
if (doPlayerClick == BombClickNone) {
p->dir = GoStop;
p->dx = 0;
p->dy = 0;
}
else if (doPlayerClick == BombClickInitial) {
p->dir = initialBombDir;
conversion_direction (p->dir, (int *)&p->dx, (int *)&p->dy);
}
else if (doPlayerClick == BombClickThru) {
}
else if (doPlayerClick == BombClickContact) {
p->dir = GoStop;
p->dx = 0;
p->dy = 0;
if (laby_perf[p->x][p->y] > -p->count)
laby_perf[p->x][p->y] = -p->count;
developpe_bombe_tmp (p->range, p->x, p->y, p->type, -p->count);
bombes_tmp[i].range = -1;
}
else if (doPlayerClick == BombClickContact) {
p->dir = turn_clockwise[p->dir];
p->dx = 0;
p->dy = 0;
}
else if (doPlayerClick == BombClickAnticlockwise) {
p->dir = turn_anticlockwise[p->dir];
p->dx = 0;
p->dy = 0;
}
else if (doPlayerClick == BombClickRandomdir) {
p->dir = (int)(((float)rand () / (RAND_MAX + 1.0)) * (4)) + 1;
p->dx = 0;
p->dy = 0;
}
else if (doPlayerClick == BombClickRebound) {
p->dir = turn_opposite[p->dir];
}
}
}
conversion_direction (p->dir, &dx, &dy);
p->dy += dy * BOMB_VY;
p->dx += dx * BOMB_VX;
if (p->dx * dx >= BLOCK_WIDTH / 2) {
p->dx -= dx * BLOCK_WIDTH;
p->x += dx;
}
if (p->dy * dy >= BLOCK_HEIGHT / 2) {
p->dy -= dy * BLOCK_HEIGHT;
p->y += dy;
}
if (p->x < 0)
p->x = 0;
if (p->y < 0)
p->y = 0;
/* On aime pas tres bien etre sur la trajectoire d'une bombe */
laby_perf[p->x][p->y] = MIN (laby_perf[p->x][p->y], 50 * LONG_FUSE - 500 + temps * 4);
}
for (i = 0; i < 100; i++) { /* Pour chaque bombe */
p = &bombes_tmp[i];
if (p->range == -1)
continue;
/* Les bombes en train d'exploser ne se repoduisent pas ... */
if (p->count <= 0)
continue;
if (p->type == BMTfungus) { /* On developpe les bombes fungus ... */
if (p->count == (fuse_times[curBombTime] * 3 / 5)) {
for (j = -1; j <= 1; j++) {
if ((p->x + j < MAZE_W) && (p->x + j > -1)
&& !CheckMazeSolid (p->x + j, p->y)) {
/* On trouve un emplacement libre ... */
for (k = 0; k < 100; k++)
if (bombes_tmp[k].range == -1)
break;
bombes_tmp[k].x = p->x + j;
bombes_tmp[k].y = p->y;
bombes_tmp[k].range = p->range;
bombes_tmp[k].type = BMTfungus;
bombes_tmp[k].dir = GoStop;
bombes_tmp[k].count = fuse_times[curBombTime];
}
if ((p->y + j < MAZE_H) && (p->y + j > -1)
&& !CheckMazeSolid (p->x, p->y + j)) {
/* On trouve un emplacement libre ... */
for (k = 0; k < 100; k++)
if (bombes_tmp[k].range == -1)
break;
bombes_tmp[k].x = p->x;
bombes_tmp[k].y = p->y + j;
bombes_tmp[k].range = p->range;
bombes_tmp[k].type = BMTfungus;
bombes_tmp[k].dir = GoStop;
bombes_tmp[k].count = fuse_times[curBombTime];
}
}
}
}
}
}
}
void
init_laby_perf ()
{
int i;
int mazex, mazey;
Explosion *p;
for (mazex = 0; mazex < MAZE_W; mazex++)
for (mazey = 0; mazey < MAZE_H; mazey++)
laby_perf[mazex][mazey] = 50 * LONG_FUSE;
for (i = 0; i < 100; i++)
bombes_tmp[i].range = -1;
for (p = exploList, i = 1; p != NULL; p = p->next, i++)
bombes_tmp[i] = *p;
calc_laby_perf ();
}
void
init_laby_perf_pose (int x, int y, int range, int count, int type)
{
int i;
int mazex, mazey;
Explosion *p;
for (mazex = 0; mazex < MAZE_W; mazex++)
for (mazey = 0; mazey < MAZE_H; mazey++)
laby_perf[mazex][mazey] = 50 * LONG_FUSE;
for (i = 0; i < 100; i++)
bombes_tmp[i].range = -1;
for (p = exploList, i = 1; p != NULL; p = p->next, i++)
bombes_tmp[i] = *p;
bombes_tmp[i].x = x;
bombes_tmp[i].y = y;
bombes_tmp[i].range = range;
bombes_tmp[i].count = -count;
bombes_tmp[i].type = type;
calc_laby_perf ();
}
void
init_laby_perf_biscotte ()
{
int i;
int mazex, mazey;
Explosion *p;
for (mazex = 0; mazex < MAZE_W; mazex++)
for (mazey = 0; mazey < MAZE_H; mazey++)
laby_perf[mazex][mazey] = 50 * LONG_FUSE;
for (i = 0; i < 100; i++)
bombes_tmp[i].range = -1;
for (p = exploList, i = 1; p != NULL; p = p->next, i++) {
bombes_tmp[i] = *p;
if (p->player)
if (p->player->id == num_bot)
bombes_tmp[i].count = 0;
}
calc_laby_perf ();
}
void
parcours_par_niveau (BMPlayer * ps)
{
coord *c;
int dir;
int x = ps->x / BLOCK_WIDTH;
int y = ps->y / BLOCK_HEIGHT + 1;
int dx, dy;
int malus;
int portee_bombe = (ps->illness == IllMini) ? 1 : ps->range;
/* for (dir = 0; dir < NB_DIR; dir++)
perf_max[dir] = 0;
*/
perf_max[STOP] = score_shrink (x, y, ps->stunned);
/* Ajout de la scurit et de l'invincibilit du joueur si la case ne se fait pas shrinker immdiatement */
if (perf_max[STOP] > MALUS_MORT)
perf_max[STOP] += laby_perf[x][y] + ps->invincible;
/* Ajout des bonus explose et tue si la case est sre */
if (perf_max[STOP] == 50 * LONG_FUSE) {
perf_max[STOP] += score_explose (x, y, portee_bombe);
perf_max[STOP] += score_tue (x, y, portee_bombe);
}
perf_max[STOP] += 60;
for (dir = 1; dir < NB_DIR; dir++) {
conversion_direction (dir, &dx, &dy);
init_laby_visit (x, y);
/* Eviter mur et shrink immdiat */
if (!CheckMaze (x + dx, y + dy) && score_shrink (x + dx, y + dy, ps->stunned) > MALUS_MORT
&& (dirige_vers_bonus (x, y, dir) != -1))
if (!CheckBomb (x + dx, y + dy)) {
malus = MIN (0, score_bonus (x + dx, y + dy));
enfiler (x + dx, y + dy, duree_deplacement + ps->stunned, malus);
while (file) {
c = defiler ();
teste_case (c, dir, ps);
free (c);
}
}
}
}
/* Renvoie VRAI s'il est possible et intressant de poser une bombe */
int
souhaite_poser_bombe (BMPlayer * ps)
{
int score;
int mazex, mazey;
int portee_bombe = (ps->illness == IllMini) ? 1 : ps->range;
// int j;
mazex = ps->x / BLOCK_WIDTH;
mazey = ps->y / BLOCK_HEIGHT + 1;
/* Est-il possible de poser ? */
/* Pas de bombe sur la case */
if (CheckBomb (mazex, mazey))
return XBFalse;
/* Je n'ai ni la non poseuse, ni la tlporte, ni la mal-function */
if (ps->illness == IllEmpty || ps->illness == IllTeleport || ps->illness == IllMalfunction)
return XBFalse;
/* Il me reste des bombes... */
if (ps->bombs == 0)
return XBFalse;
/* Est-il intressant de poser ? */
score = score_explose (mazex, mazey, portee_bombe) + score_tue (mazex, mazey, portee_bombe);
// fprintf(stderr," socre expl %i \n",score);
if (score < 0)
return XBFalse;
/* Aucune raison particulire de poser... au hasard prs */
if (score == 0 && (int)(((float)rand () / (RAND_MAX + 1.0)) * (PROB_POSER)) != 0)
return XBFalse;
/* S'il reste au moins un autre joueur vivant, j'essaie de poser */
return (nb_ennemis_vivants > 0);
}
/* Renvoie VRAI si je me dirige vers un bonus */
int
dirige_vers_bonus (int x, int y, int dir)
{
int dx, dy;
conversion_direction (dir, &dx, &dy);
if ((CheckBonuses2 (x + dx, y + dy)) && (specialExtraFunc == SpecialExtraPoison)) { //fprintf(stderr," field poisoned\n");
return -1; // POISON!!!
}
else {
return CheckBonuses (x + dx, y + dy);
}
}
/* Choix de la meilleure direction */
static void
choix_direction (int *choix_dir, int *max_perf)
{
int dir = 0, dir1 = 0;
static int old_dir = 0;
*choix_dir = STOP;
*max_perf = 0;
for (dir = 0; dir < NB_DIR; dir++) {
/* Ajout d'un petit bonus alatoire si la case est sre */
if (perf_max[dir] > 10 * LONG_FUSE)
perf_max[dir] += (int)(((float)rand () / (RAND_MAX + 1.0)) * (10)); //
// GameRandomNumber1 (10);
/* Je choisis la destination ayant la meilleure performance */
// if(dir==old_dir && dir!=0) perf_max[dir]+=50;
if (dir == old_dir && dir == 0)
perf_max[dir] -= 100;
if (perf_max[dir] > *max_perf) {
*max_perf = perf_max[dir];
*choix_dir = dir;
}
else if ((perf_max[dir] == *max_perf) &&
((int)((float)rand () / (RAND_MAX + 1.0)) * (5) == dir))
*choix_dir = dir;
}
for (dir = 0; dir < NB_DIR; dir++) {
for (dir1 = 0; dir1 < NB_DIR; dir1++) {
if (perf_max[dir] == perf_max[dir1] && dir != dir1) {
if (dir < dir1) {
if (dir == old_dir)
perf_max[dir] += 75;
else
perf_max[dir]++;
}
}
}
}
for (dir = 0; dir < NB_DIR; dir++) {
// fprintf(stderr,"dir %i prfmax %i olddir %i\n",dir, perf_max[dir],old_dir);
if (perf_max[dir] > *max_perf) {
*max_perf = perf_max[dir];
*choix_dir = dir;
}
}
for (dir = 0; dir < NB_DIR; dir++) {
perf_max[dir] = 0;
}
old_dir = *choix_dir;
}
/* Renvoie VRAI si je dcide d'utiliser la tlcommande MAINTENANT */
int
test_biscotte (BMPlayer * ps)
{
int declenche = XBFalse;
int mes_bombes = 0;
int securite_init;
Explosion *bombe;
int x, y;
x = ps->x / BLOCK_WIDTH;
y = ps->y / BLOCK_HEIGHT + 1;
securite_init = laby_perf[x][y];
/* Parcours de toutes les bombes du plateau */
for (bombe = exploList; bombe != NULL; bombe = bombe->next)
/* Si cette bombe m'appartient... */
if (bombe->player == ps) {
mes_bombes++;
/* ... je la fais exploser ! */
/* laby_perf[bombe->x][bombe->y] = 0;
developpe_bombe (bombe->range, bombe->x, bombe->y, bombe->type); */
init_laby_perf_biscotte ();
}
if ((mes_bombes > 0) && ((laby_perf[x][y] == securite_init) || (ps->invincible > 5)))
declenche = XBTrue;
return declenche;
}
/* Renvoie VRAI si j'ai envie de swapper MAINTENANT.*/
int
test_swap (BMPlayer * ps, int perf)
{
int vote_swap = XBFalse;
int partenaire;
int equipe_complete = XBFalse;
int joueur;
/* Swap alatoire si j'ai au moins 2 swaps */
/* if (ps->swapposition > 1)
vote_swap = (GameRandomNumber1 (PROB_SWAP) == 0); */
/* Si nous jouons par quipe */
if (statut_joueurs->team == (statut_joueurs + 1)->team) {
partenaire = ((num_bot) / 2) * 2 + 1 - (num_bot % 2);
/* Si mon partenaire est mort */
if ((statut_joueurs + partenaire)->lives == 0) {
for (joueur = 0; joueur < nb_joueurs; joueur += 2)
/* Si les deux joueurs d'une autre quipe sont encore vivants. */
if (((statut_joueurs + joueur)->team != ps->team)
&& ((statut_joueurs + joueur)->lives > 0)
&& ((statut_joueurs + joueur + 1)->lives > 0))
equipe_complete = XBTrue;
/* S'il n'y a pas d'quipe complte... je swappe ! */
if (!equipe_complete)
vote_swap = XBTrue;
}
}
/* Je swappe si je suis coinc entre 4 murs (et que l'on ne joue pas par quipe) */
else if (ps->teleport == 0 && test_murs (ps) == 4)
vote_swap = XBTrue;
/* Je swappe si je vais mourir */
if (ps->dying || perf <= duree_deplacement)
vote_swap = XBTrue;
return vote_swap;
}
void
actions (BMPlayer * ps)
{
int i;
int dx = 0, dy = 0;
static int olddx = 0, olddy = 0;
int dir;
int max_perf;
int choix_dir, prec_choix_dir;
int x, y;
int duree_meche, portee_bombe, type_bombe;
x = ps->x / BLOCK_WIDTH;
y = ps->y / BLOCK_HEIGHT + 1;
portee_bombe = (ps->illness == IllMini) ? 1 : ps->range;
type_bombe = BMTdefault;
def_score_extra (ps);
/* Remplissage du tableau my_maze */
init_laby_perf ();
/* Je cherche les cases les plus sres, en partant dans toutes les directions */
parcours_par_niveau (ps);
/* Choix de la meilleure direction */
choix_direction (&choix_dir, &max_perf);
prec_choix_dir = choix_dir;
/* Et si j'essayais de poser une tit' bombe ? */
vote_poser = XBFalse;
if (souhaite_poser_bombe (ps)) {
/* Calcul de la dure de mche */
duree_meche = fuse_times[curBombTime];
/* Calcul des effets de l'explosion de cette bombe */
/* if (laby_perf[x][y] > duree_meche)
laby_perf[x][y] = duree_meche;
developpe_bombe (portee_bombe, x, y, type_bombe); */
// init_laby_perf_pose (x, y, portee_bombe, duree_meche, type_bombe);
/* Je cherche les cases les plus sres, en partant dans toutes les directions */
parcours_par_niveau (ps);
/* Est-ce que poser me laisse la vie sauve ? */
for (dir = 0; dir < NB_DIR; dir++) {
if (perf_max[dir] > 10 * LONG_FUSE || duree_meche < ps->invincible) {
vote_poser = XBTrue;
break;
}
// fprintf(stderr," perf_max %i ",perf_max[dir]);
}
// fprintf(stderr," dest %i \n",10 * LONG_FUSE);
/* Si oui, je pose... et choisis la direction de dpart */
if (vote_poser) {
choix_direction (&choix_dir, &max_perf);
/* Je ne pose pas si j'ai dcid d'aller vers un bonus (risque de mourir) */
/* Remarque : mthode provisoire amliorer... */
if (dirige_vers_bonus (x, y, choix_dir)) {
// fprintf(stderr, " go for bonus!\n");
vote_poser = XBFalse;
// choix_dir = prec_choix_dir;
}
/*je ne pose pas si il ny a place pour ca (Skywalker) */
if (!(ps->remote_control > 0)) {
i = 1;
dx = 1;
conversion_direction (choix_dir, &dx, &dy);
if (!CheckBomb (x - olddx, y - olddy))
i = 0;
/* pas verifier si ma position est libre */
if (dx - 1 != 0 && dy != 0)
if ( //CheckBomb (x-olddx, y-olddy)&&
CheckMazeFree2 (x + dx - 1, y + dy) && !CheckBomb (x + dx - 1, y + dy)) {
i = 0;
}
if (dx != 0 && dy + 1 != 0)
if ( //CheckBomb (x-olddx, y-olddy)&&
CheckMazeFree2 (x + dx, y + dy + 1) && !CheckBomb (x + dx, y + dy + 1)) {
i = 0;
}
if (dx != 0 && dy - 1 != 0)
if ( //CheckBomb (x-olddx, y-olddy)&&
CheckMazeFree2 (x + dx, y + dy - 1) && !CheckBomb (x + dx, y + dy - 1)) {
i = 0;
}
if (dx + 1 != 0 && dy != 0)
/* verifier si il y a place pour escape de la bomb posee */
if ( //CheckBomb (x-olddx, y-olddy)&&
CheckMazeFree2 (x + dx + 1, y + dy) && !CheckBomb (x + dx + 1, y + dy)) {
i = 0;
}
if (i) {
vote_poser = XBFalse;
}
if (olddx == -dx && olddy == -dy) {
vote_poser = XBFalse;
}
if (ps->invincible > 5 && ps->remote_control > 0) {
vote_poser = XBTrue;
}
}
// if(
}
}
/* Si je vais mourir, j'essaie de toute faon de poser et de changer de case. */
if (max_perf <= 30) {
vote[STOP] -= 300;
vote_poser = XBTrue;
}
/* Est-ce que j'effectue une action spciale ? */
vote_action_speciale = XBFalse;
/* Si j'ai la tlcommande (biscotte pour les intimes) */
if (ps->remote_control > 0 && (max_perf > 10 * LONG_FUSE || ps->invincible > 5))
if (test_biscotte (ps)) {
vote_action_speciale = XBTrue;
choix_dir = STOP;
vote_poser = XBFalse;
}
/* Si je peux morpher, je morphe */
if (ps->num_morph > 0) {
vote_action_speciale = XBTrue;
}
/* Si je peux me tlporter et que je risque de mourir */
if (ps->teleport > 0 && max_perf < 50) {
vote_action_speciale = XBTrue;
choix_dir = STOP;
vote_poser = XBFalse;
}
/* Si j'ai des bombes spciales */
if (ps->special_bombs > 0) {
/* Si ce sont des bombes explosant immdiatement
if (get_current_level ()->bomb.buttonBMT == BMTblastnow)
algo simpliste modifier
if (vote_poser && ps->invincible > 5)
{
vote_action_speciale = XBTrue;
vote_poser = XBFalse;
} */
}
/* Ai-je envie de swapper ? */
vote_swap = XBFalse;
/* if (ps->swapper > 0 && test_swap (ps, max_perf))
vote_swap = XBTrue; */
vote[choix_dir] += 200;
olddy = dy;
olddx = dx;
}
/* Inversion des directions */
int
inversion (int dir)
{
switch (dir) {
case UP:
return DOWN;
case DOWN:
return UP;
case LEFT:
return RIGHT;
case RIGHT:
return LEFT;
default:
return dir;
}
}
/* Mouvement faire si je suis coinc entre deux cases */
int
decoince (int dir)
{
static int compteur = 0;
int nouv_dir = GoDefault;
/* Pour viter de gigoter entre 2 bombes */
compteur++;
if (compteur > 4) {
compteur = 0;
nouv_dir = dir;
}
return nouv_dir;
}
/* Retourne VRAI si je peux tuer des ennemis */
int
repose_en_mourant (BMPlayer * ps)
{
int mazex, mazey;
int portee_bombe;
mazex = (int)(ps->x + 0.5 * BLOCK_WIDTH) / BLOCK_WIDTH;
mazey = (int)(ps->y + 0.5 * BLOCK_HEIGHT) / BLOCK_HEIGHT + 1;
portee_bombe = (ps->illness == IllMini) ? 1 : ps->range;
if (score_tue (mazex, mazey, portee_bombe) >= 0 && nb_ennemis_vivants > 0)
return XBTrue;
else
return XBFalse;
}
void
gestionBot (BMPlayer * player_stat, PlayerAction * player_action, int numero_bot, int num_player)
{
int i, j;
int max = MALUS_MORT;
int choice = -1;
int mazex, mazey;
int inverse;
BMPlayer *ps;
PlayerAction *pa;
/* Fouf lenteur -- *//* trace = 0; */
/* Fouf lenteur ++ *//* fprintf(stderr, "gestionBot\n"); */
/* Fouf lenteur ++ *//* fflush(stderr); */
ps = player_stat + numero_bot;
pa = player_action + numero_bot;
statut_joueurs = player_stat;
num_bot = numero_bot;
nb_joueurs = num_player;
mazex = ps->x / BLOCK_WIDTH;
mazey = ps->y / BLOCK_HEIGHT + 1;
/* Suis-je rapide ? */
if (ps->illness == IllRun)
duree_deplacement = FAST_SPEED;
else /* Suis-je Lent ? */ if (ps->illness == IllSlow)
duree_deplacement = SLOW_SPEED;
else
duree_deplacement = NORMAL_SPEED;
temps_jeu = gameTime;
/* Dbut d'un niveau */
if (temps_jeu == 1)
init_laby_shrink ();
/* Suis-je invers ? */
if (ps->illness == IllReverse)
inverse = XBTrue;
else
inverse = XBFalse;
/* Si je me trouve entre deux cases */
/* Fouf lenteur -- *//* if ((ps->x % BLOCK_WIDTH) != 0 || (ps->y % BLOCK_HEIGHT) != 0) */
/* Fouf lenteur ++ */ if (((ps->x % BLOCK_WIDTH) != 0 || (ps->y % BLOCK_HEIGHT) != 0)
|| ((ps->d_ist == GoStop) && (temps_jeu % 3))) {
switch (ps->d_ist) {
case GoUp:
/* kick si est possible */
if (CheckBomb (mazex, mazey) && !(ps->kick && CheckMazeFree2 (mazex, mazey - 1)))
pa->dir = decoince (GoDown);
break;
case GoDown:
if (CheckBomb (mazex, mazey + 1) && !(ps->kick && CheckMazeFree2 (mazex, mazey + 2)))
pa->dir = decoince (GoUp);
break;
case GoLeft:
if (CheckBomb (mazex, mazey) && !(ps->kick && CheckMazeFree2 (mazex - 1, mazey)))
pa->dir = decoince (GoRight);
break;
case GoRight:
if (CheckBomb (mazex + 1, mazey) && !(ps->kick && CheckMazeFree2 (mazex + 2, mazey)))
pa->dir = decoince (GoLeft);
break;
default:
break;
}
/* Si je meurs, je pose */
if (ps->dying)
pa->bomb = repose_en_mourant (ps);
if (inverse)
pa->dir = inversion (pa->dir);
return;
}
if (pa->dir == GoStop && !(temps_jeu & 1))
return;
/* Initialisation */
for (i = 0; i < NB_DIR; i++)
vote[i] = 0;
test_murs (ps); /* Don't walk into walls ... */
/* Choix de la bonne direction et des actions effectuer */
actions (ps);
/* getBonuses (ps);
putBombs (ps); break the walls ... */
/* randChoice (); */
for (j = 0; j < NB_DIR; j++)
if (vote[j] > max) {
/* Fouf lenteur -- *//* if (trace) printf ("Ok for %d %d\n", j, vote[j]); */
max = vote[j];
choice = j;
}
/* Fouf lenteur -- *//* else */
/* Fouf lenteur -- *//* if (trace) printf ("Not ok for %d %d\n", j, vote[j]); */
switch (choice) {
case STOP:
/* Fouf lenteur -- *//* pa->dir = GoStop; */
/* Fouf lenteur ++ */ if (ps->d_ist == GoStop) {
/* Fouf lenteur ++ */ pa->dir = GoDefault;
/* Fouf lenteur ++ *//* fprintf(stderr, "GoDefault (already stop)\n"); */
/* Fouf lenteur ++ */ }
else {
/* Fouf lenteur ++ */ pa->dir = GoStop;
/* Fouf lenteur ++ *//* fprintf(stderr, "GoStop (stop NOW *********)\n"); */
/* Fouf lenteur ++ */ }
break;
case UP:
pa->dir = GoUp;
/* Fouf lenteur ++ *//* fprintf(stderr, "GoUp\n"); */
break;
case LEFT:
pa->dir = GoLeft;
/* Fouf lenteur ++ *//* fprintf(stderr, "GoLeft\n"); */
break;
case DOWN:
pa->dir = GoDown;
/* Fouf lenteur ++ *//* fprintf(stderr, "GoDown\n"); */
break;
case RIGHT:
pa->dir = GoRight;
/* Fouf lenteur ++ *//* fprintf(stderr, "GoRight\n"); */
break;
}
/* Fouf lenteur ++ *//* fflush(stderr); */
/* Ai-je dcid de poser ? */
if (vote_poser)
pa->bomb = XBTrue;
/* Ai-je dcid de faire une action spciale ? */
if (vote_action_speciale)
pa->special = XBTrue;
/* Ai-je envie de swapper ?
if (vote_swap)
pa->swap = XBTrue; */
if (inverse)
pa->dir = inversion (pa->dir);
}
/* BMFuncData :
special_init : bonus EXTRA au dpart
special_game : jeu spcial (bombes hantes, lances par les murs, ...)
special_extra : bonus EXTRA trouver
special_key : action du +
*/
|