00001
00002
#include <assert.h>
00003
#include <iostream>
00004
00005
#include "bsp.h"
00006
#include "game_bsp.h"
00007
#include "bsp_loader.h"
00008
00009
using namespace std;
00010
00011
00012
bool Test_Path_Finder_1();
00013
bool Test_Path_Finder_2();
00014
bool Test_Path_Finder_3();
00015
bool Test_Path_Finder_4();
00016
bool Test_Path_Finder_5();
00017
00018
void Test_Intersections_1();
00019
void Test_Intersections_2();
00020
00021
00022
Debugger Debug_File (
"output.txt");
00023
00024
00025
00026 void Test_Intersections()
00027 {
00028
Test_Intersections_1();
00029
Test_Intersections_2();
00030 }
00031
00032
00033
00034 void Test_Intersections_1()
00035 {
00036
cPoint2D p1;
00037
cPoint2D p2;
00038
cPoint2D p_inter;
00039
bool result;
00040
00041
00042
cGame_World * game =
new cGame_World();
00043
cBSP_Loader loader;
00044 loader.
Load(
"../test_levels/level_test_intersections.txt" , game);
00045 game->
Decorate();
00046
00047
00048
00049 p1.
Set(0,0);
00050 p2.
Set(100,0);
00051 cout <<
"TEST INTERSECTIONS 1 : ";
00052 result = game->
Do_Segment_Intersect_Walls(
cSeg(p1,p2) , p_inter );
00053
if( result )
00054 cout <<
"ERROR \n";
00055
else
00056 cout <<
"OK\n";
00057
00058 p1.
Set(0,0);
00059 p2.
Set(0,100);
00060 cout <<
"TEST INTERSECTIONS 2 : ";
00061 result = game->
Do_Segment_Intersect_Walls(
cSeg(p1,p2) , p_inter );
00062
if( result )
00063 cout <<
"ERROR \n";
00064
else
00065 cout <<
"OK\n";
00066
00067 p1.
Set(0,0);
00068 p2.
Set(90,10);
00069 cout <<
"TEST INTERSECTIONS 3 : ";
00070 result = game->
Do_Segment_Intersect_Walls(
cSeg(p1,p2) , p_inter );
00071
if( result )
00072 cout <<
"ERROR \n";
00073
else
00074 cout <<
"OK\n";
00075
00076 p1.
Set(0,0);
00077 p2.
Set(70,15);
00078 cout <<
"TEST INTERSECTIONS 4 : ";
00079 result = game->
Do_Segment_Intersect_Walls(
cSeg(p1,p2) , p_inter );
00080
if( result && p_inter.
Get_X() == 60 && p_inter.
Get_Y() == 13 )
00081 cout <<
"OK\n";
00082
else
00083 cout <<
"ERROR \n";
00084
00085 p1.
Set(50,50);
00086 p2.
Set(70,50);
00087 cout <<
"TEST INTERSECTIONS 5 : ";
00088 result = game->
Do_Segment_Intersect_Walls(
cSeg(p1,p2) , p_inter );
00089
if( result && p_inter.
Get_X() == 60 && p_inter.
Get_Y() == 50 )
00090 cout <<
"OK\n";
00091
else
00092 cout <<
"ERROR \n";
00093
00094 p1.
Set(50,50);
00095 p2.
Set(50,70);
00096 cout <<
"TEST INTERSECTIONS 6 : ";
00097 result = game->
Do_Segment_Intersect_Walls(
cSeg(p1,p2) , p_inter );
00098
if( result && p_inter.
Get_X() == 50 && p_inter.
Get_Y() == 60 )
00099 cout <<
"OK\n";
00100
else
00101 cout <<
"ERROR \n";
00102
00103 p1.
Set(50,50);
00104 p2.
Set(70,70);
00105 cout <<
"TEST INTERSECTIONS 7 : ";
00106 result = game->
Do_Segment_Intersect_Walls(
cSeg(p1,p2) , p_inter );
00107
if( result && p_inter.
Get_X() == 60 && p_inter.
Get_Y() == 60 )
00108 cout <<
"OK\n";
00109
else
00110 cout <<
"ERROR \n";
00111
00112 p1.
Set(10,10);
00113 p2.
Set(70,70);
00114 cout <<
"TEST INTERSECTIONS 8 : ";
00115 result = game->
Do_Segment_Intersect_Walls(
cSeg(p1,p2) , p_inter , 162);
00116
if( ! result )
00117 cout <<
"OK\n";
00118
else
00119 cout <<
"ERROR \n";
00120
00121 cout <<
"TEST INTERSECTIONS 9 : ";
00122 result = game->
Do_Segment_Intersect_Walls(
cSeg(p1,p2) , p_inter , 163);
00123
if( result && p_inter.
Get_X() == 20 && p_inter.
Get_Y() == 20 )
00124 cout <<
"OK\n";
00125
else
00126 cout <<
"ERROR \n";
00127
00128 }
00129
00130
00131
00132 void Test_Intersections_2()
00133 {
00134
cPoint2D p1;
00135
cPoint2D p2;
00136
cPoint2D p_inter;
00137
bool result;
00138
00139
00140
cGame_World * game =
new cGame_World();
00141
cBSP_Loader loader;
00142 loader.
Load(
"../test_levels/level_test_intersections_2.txt" , game);
00143 game->
Decorate();
00144
00145 cout <<
"TEST INTERSECTIONS WITH BALLS 1 : ";
00146 result= game->
Do_Ball_Intersect_Walls(20,20, 10);
00147
if( result )
00148 cout <<
"ERROR \n";
00149
else
00150 cout <<
"OK\n";
00151
00152 cout <<
"TEST INTERSECTIONS WITH BALLS 2 : ";
00153 result= game->
Do_Ball_Intersect_Walls(20,20, 10);
00154
if( result )
00155 cout <<
"ERROR \n";
00156
else
00157 cout <<
"OK\n";
00158
00159 cout <<
"TEST INTERSECTIONS WITH BALLS 3 : ";
00160 result= game->
Do_Ball_Intersect_Walls(350,300, 10);
00161
if( result )
00162 cout <<
"OK \n";
00163
else
00164 cout <<
"ERROR\n";
00165
00166 cout <<
"TEST INTERSECTIONS WITH BALLS 4 : ";
00167 result= game->
Do_Ball_Intersect_Walls(400,300, 10);
00168
if( result )
00169 cout <<
"OK \n";
00170
else
00171 cout <<
"ERROR\n";
00172
00173 cout <<
"TEST INTERSECTIONS WITH BALLS 5 : ";
00174 result= game->
Do_Ball_Intersect_Walls(450,300, 10);
00175
if( result )
00176 cout <<
"OK \n";
00177
else
00178 cout <<
"ERROR\n";
00179
00180 cout <<
"TEST INTERSECTIONS WITH BALLS 6 : ";
00181 result= game->
Do_Ball_Intersect_Walls(500,300, 10);
00182
if( result )
00183 cout <<
"OK \n";
00184
else
00185 cout <<
"ERROR\n";
00186
00187 cout <<
"TEST INTERSECTIONS WITH BALLS 7 : ";
00188 result= game->
Do_Ball_Intersect_Walls(550,300, 10);
00189
if( result )
00190 cout <<
"OK \n";
00191
else
00192 cout <<
"ERROR\n";
00193
00194 cout <<
"TEST INTERSECTIONS WITH BALLS 8 : ";
00195 result= game->
Do_Ball_Intersect_Walls(600,300, 10);
00196
if( result )
00197 cout <<
"OK \n";
00198
else
00199 cout <<
"ERROR\n";
00200
00201 }
00202
00203
00204
00205
00206 void Test_Path_Finder()
00207 {
00208
bool result;
00209
00210 cout <<
"TEST PATH_FINDER_1 : ";
00211 result =
Test_Path_Finder_1();
00212
if( result)
00213 cout <<
"OK\n";
00214
else
00215 cout <<
"ERROR \n";
00216
00217 cout <<
"TEST PATH_FINDER_2 : ";
00218 result =
Test_Path_Finder_2();
00219
if( result)
00220 cout <<
"OK\n";
00221
else
00222 cout <<
"ERROR \n";
00223
00224 cout <<
"TEST PATH_FINDER_3 : ";
00225 result =
Test_Path_Finder_3();
00226
if( result)
00227 cout <<
"OK\n";
00228
else
00229 cout <<
"ERROR \n";
00230
00231 cout <<
"TEST PATH_FINDER_4 : ";
00232 result =
Test_Path_Finder_4();
00233
if( result)
00234 cout <<
"OK\n";
00235
else
00236 cout <<
"ERROR \n";
00237
00238 cout <<
"TEST PATH_FINDER_5 : ";
00239 result =
Test_Path_Finder_5();
00240
if( result)
00241 cout <<
"OK\n";
00242
else
00243 cout <<
"ERROR \n";
00244 }
00245
00246
00247
00248
00249 bool Test_Path_Finder_1()
00250 {
00251
cPoint2D path[10];
00252
00253
cGame_World * game =
new cGame_World();
00254
cBSP_Loader loader;
00255 loader.
Load(
"../test_levels/level_test_pathfinder_1.txt" , game);
00256 game->
Decorate();
00257
00258
00259 std::vector<cPoint2D> Path;
00260 std::vector<cPoint2D>::iterator Path_itr;
00261 game->
Find_Path(
cPoint2D(5,5) ,
cPoint2D(95,95) , Path);
00262
00263 path[0].
X = 10;
00264 path[0].
Y = 95;
00265
00266 path[1].
X = 20;
00267 path[1].
Y = 5;
00268
00269 path[2].
X = 30;
00270 path[2].
Y = 95;
00271
00272 path[3].
X = 40;
00273 path[3].
Y = 5;
00274
00275 path[4].
X = 50;
00276 path[4].
Y = 95;
00277
00278 path[5].
X = 60;
00279 path[5].
Y = 5;
00280
00281 path[6].
X = 70;
00282 path[6].
Y = 95;
00283
00284 path[7].
X = 80;
00285 path[7].
Y = 5;
00286
00287 path[8].
X = 90;
00288 path[8].
Y = 95;
00289
00290 path[9].
X = 95;
00291 path[9].
Y = 95;
00292
00293
if( Path.size() != 10 )
return false;
00294
00295
int n=0;
00296
cPoint2D p;
00297
for( Path_itr=Path.begin() ; Path_itr != Path.end() ; Path_itr++)
00298 {
00299 p = (*Path_itr) ;
00300
if( !( p.
X == path[n].
X && p.
Y == path[n].
Y))
return false;
00301 n++;
00302 }
00303
00304
return true;
00305 }
00306
00307
00308
00309
00310
00311 bool Test_Path_Finder_2()
00312 {
00313
cGame_World * game =
new cGame_World();
00314
cBSP_Loader loader;
00315 loader.
Load(
"../test_levels/level_test_pathfinder_2.txt" , game);
00316 game->
Decorate();
00317
00318
00319
00320
bool result;
00321
00322 std::vector<cPoint2D> Path;
00323 result = game->
Find_Path(
cPoint2D(5,5) ,
cPoint2D(95,95) , Path);
00324
00325
return !result;
00326 }
00327
00328
00329
00330
00331
00332
00333
00334 bool Test_Path_Finder_3()
00335 {
00336
cPoint2D path[10];
00337
bool chemin_trouve;
00338
int n=0;
00339
cPoint2D p;
00340
cGame_World * game =
new cGame_World();
00341
cBSP_Loader loader;
00342 loader.
Load(
"../test_levels/level_test_pathfinder_3.txt" , game);
00343 game->
Decorate();
00344
00345
00346 std::vector<cPoint2D> Path;
00347 std::vector<cPoint2D>::iterator Path_itr;
00348
00349
00350
00351
00352 path[0].
X = 5;
00353 path[0].
Y = 20;
00354
00355 path[1].
X = 5;
00356 path[1].
Y = 60;
00357
00358 path[2].
X = 20;
00359 path[2].
Y = 85;
00360
00361 path[3].
X = 58;
00362 path[3].
Y = 62;
00363
00364 game->
Find_Path(
cPoint2D(18,18) ,
cPoint2D(58,62) , Path);
00365
00366
00367
if( Path.size() != 4 )
00368 {
00369 cout <<
"(001)";
00370
return false;
00371 }
00372
for( Path_itr=Path.begin() ; Path_itr != Path.end() ; Path_itr++)
00373 {
00374 p = (*Path_itr) ;
00375
if( !( p.
X == path[n].
X && p.
Y == path[n].
Y))
00376 {
00377
00378 cout <<
"(002)";
00379
return false;
00380 }
00381 n++;
00382 }
00383
00384
00385
00386 chemin_trouve = game->
Find_Path(
cPoint2D(18,18) ,
cPoint2D(58,58) , Path);
00387
if( chemin_trouve )
00388 {
00389 cout<<
"(003)";
00390
return false;
00391 }
00392
00393
00394
00395 n=0;
00396 Path.clear();
00397 game->
Find_Path(
cPoint2D(18,18) ,
cPoint2D(58,62) , Path);
00398
if( Path.size() != 4 )
00399 {
00400 cout <<
"(005)";
00401
return false;
00402 }
00403
for( Path_itr=Path.begin() ; Path_itr != Path.end() ; Path_itr++)
00404 {
00405 p = (*Path_itr) ;
00406
if( !( p.
X == path[n].
X && p.
Y == path[n].
Y))
00407 {
00408
00409 cout <<
"(006)";
00410
return false;
00411 }
00412 n++;
00413 }
00414
00415
00416
00417 path[0].
X = 20;
00418 path[0].
Y = 5;
00419
00420 path[1].
X = 60;
00421 path[1].
Y = 5;
00422
00423 path[2].
X = 85;
00424 path[2].
Y = 20;
00425
00426 path[3].
X = 62;
00427 path[3].
Y = 22;
00428
00429 n=0;
00430 Path.clear();
00431 game->
Find_Path(
cPoint2D(18,18) ,
cPoint2D(62,22) , Path);
00432
if( Path.size() != 4 )
00433 {
00434 cout <<
"(007)";
00435
return false;
00436 }
00437
for( Path_itr=Path.begin() ; Path_itr != Path.end() ; Path_itr++)
00438 {
00439 p = (*Path_itr) ;
00440
if( !( p.
X == path[n].
X && p.
Y == path[n].
Y))
00441 {
00442 cout <<
"(008)";
00443
return false;
00444 }
00445 n++;
00446 }
00447
00448
00449
return true;
00450
00451 }
00452
00453
00454
00455
00456
00457
00458 bool Test_Path_Finder_4()
00459 {
00460
cPoint2D path[20];
00461
00462
cGame_World * game =
new cGame_World();
00463
cBSP_Loader loader;
00464 loader.
Load(
"../test_levels/level_test_pathfinder_4.txt" , game);
00465 game->
Decorate();
00466
00467
00468
00469 std::vector<cPoint2D> Path;
00470 std::vector<cPoint2D>::iterator Path_itr;
00471 game->
Find_Path(
cPoint2D(55,82) ,
cPoint2D(63,83) , Path);
00472
00473 path[0].
X = 50;
00474 path[0].
Y = 95;
00475
00476 path[1].
X = 30;
00477 path[1].
Y = 90;
00478
00479 path[2].
X = 10;
00480 path[2].
Y = 80;
00481
00482 path[3].
X = 5;
00483 path[3].
Y = 50;
00484
00485 path[4].
X = 30;
00486 path[4].
Y = 5;
00487
00488 path[5].
X = 50;
00489 path[5].
Y = 10;
00490
00491 path[6].
X = 60;
00492 path[6].
Y = 40;
00493
00494 path[7].
X = 90;
00495 path[7].
Y = 5;
00496
00497 path[8].
X = 95;
00498 path[8].
Y = 50;
00499
00500 path[9].
X = 95;
00501 path[9].
Y = 80;
00502
00503 path[10].
X = 90;
00504 path[10].
Y = 95;
00505
00506 path[11].
X = 63;
00507 path[11].
Y = 83;
00508
00509
00510
00511
00512
if( Path.size() != 12 )
return false;
00513
00514
int n=0;
00515
cPoint2D p;
00516
for( Path_itr=Path.begin() ; Path_itr != Path.end() ; Path_itr++)
00517 {
00518 p = (*Path_itr) ;
00519
if( !( p.
X == path[n].
X && p.
Y == path[n].
Y))
return false;
00520 n++;
00521 }
00522
00523
return true;
00524 }
00525
00526
00527
00528
00529
00530
00531 bool Test_Path_Finder_5()
00532 {
00533
cPoint2D path[10];
00534
00535
cGame_World * game =
new cGame_World();
00536
cBSP_Loader loader;
00537 loader.
Load(
"../test_levels/level_test_pathfinder_5.txt" , game);
00538 game->
Decorate();
00539
00540
00541 std::vector<cPoint2D> Path;
00542 std::vector<cPoint2D>::iterator Path_itr;
00543 Path.clear();
00544 game->
Find_Path(
cPoint2D(3,40) ,
cPoint2D(85,80) , Path);
00545
00546 path[0].
X = 10;
00547 path[0].
Y = 40;
00548
00549 path[1].
X = 30;
00550 path[1].
Y = 92;
00551
00552 path[2].
X = 50;
00553 path[2].
Y = 95;
00554
00555 path[3].
X = 85;
00556 path[3].
Y = 80;
00557
00558
00559
if( Path.size() != 4 )
return false;
00560
00561
int n=0;
00562
cPoint2D p;
00563
for( Path_itr=Path.begin() ; Path_itr != Path.end() ; Path_itr++)
00564 {
00565 p = (*Path_itr) ;
00566
00567
if( !( p.
X == path[n].
X && p.
Y == path[n].
Y))
return false;
00568 n++;
00569 }
00570
00571
00572
return true;
00573 }