ai-move1.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  ***************************************************************************/
00009 
00010 #include <iostream>
00011 
00012 #include "ai-move1.h"
00013 #include "../loaders.h"
00014 #include "unittestutil.h"
00015 #include "../turncontrol.h"
00016 #include "../gamemap.h"
00017 
00018 void testAiMovement1() 
00019 {
00020    auto_ptr<GameMap> game ( startMap("unittest-ai-simpleattack.map"));
00021    
00022    Vehicle* veh = game->getField(3,9)->vehicle;
00023    
00024    assertOrThrow( veh != NULL );
00025    assertOrThrow( veh->damage == 0 );
00026    
00027    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00028    
00029    assertOrThrow( veh->damage > 0 );
00030 }
00031 
00032 
00033 void testAiMovement2() 
00034 {
00035    
00036    auto_ptr<GameMap> game ( startMap("unittest-ai-mam.map"));
00037    
00038    Vehicle* veh = game->getField(3,9)->vehicle;
00039    
00040    assertOrThrow( veh != NULL );
00041    assertOrThrow( veh->damage == 0 );
00042    
00043    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00044    
00045    /*  a single unit will not make this much damage.
00046        The point of this test is that the AI should move MoveAttackMove - capable units 
00047        out of the way to continue attacking with further units */
00048    
00049    assertOrThrow( veh->damage >= 40 );
00050 }
00051 
00052 void testAiMovement3() 
00053 {
00054    
00055    auto_ptr<GameMap> game ( startMap("unittest-ai-hemming.map"));
00056    
00057    Vehicle* veh = game->getField(3,9)->vehicle;
00058    
00059    assertOrThrow( veh != NULL );
00060    assertOrThrow( veh->damage == 0 );
00061    
00062    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00063    
00064    /*  a single unit will not make this much damage.
00065    The point of this test is that the AI should move MoveAttackMove - capable units 
00066    out of the way to continue attacking with further units */
00067    
00068    assertOrThrow( veh->damage >= 70 );
00069 }
00070 
00071 
00074 void testAiMovement4() 
00075 {
00076    
00077    auto_ptr<GameMap> game ( startMap("unittest-ai-carrier.map"));
00078    
00079    Vehicle* veh = game->getField(2,7)->vehicle;
00080    
00081    assertOrThrow( veh != NULL );
00082    assertOrThrow( veh->damage == 0 );
00083    
00084    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00085    
00086    assertOrThrow( veh->damage >= 70 );
00087 }
00088 
00089 
00092 void testAiMovement5() 
00093 {
00094    
00095    auto_ptr<GameMap> game ( startMap("unittest-ai-conquer.map"));
00096    
00097    Vehicle* veh = game->getField(8,4)->vehicle;
00098    Building* bld = game->getField( 14,9 )->building;
00099    
00100    assertOrThrow( veh != NULL );
00101    assertOrThrow( veh->damage == 0 );
00102    
00103    assertOrThrow( bld != NULL );
00104    assertOrThrow( bld->getOwner() == 0 );
00105    
00106    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00107    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00108    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00109    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00110    
00111    assertOrThrow( bld->getOwner() == 1 );
00112 }
00113 
00114 
00117 void testAiMovement6() 
00118 {
00119    
00120    auto_ptr<GameMap> game ( startMap("unittest-ai-conquer2.map"));
00121    
00122    Vehicle* veh = game->getField(3,5)->vehicle;
00123    Building* bld = game->getField(4,8)->building;
00124    
00125    assertOrThrow( veh != NULL );
00126    
00127    assertOrThrow( bld != NULL );
00128    assertOrThrow( bld->getOwner() == 0 );
00129    
00130    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00131    
00132    assertOrThrow( bld->getOwner() == 0 );
00133 }
00134 
00135 
00138 void testAiMovement7() 
00139 {
00140    auto_ptr<GameMap> game ( startMap("unittest-ai-conquer3.map"));
00141    
00142    Vehicle* veh = game->getField(3,5)->vehicle;
00143    Building* bld = game->getField(4,8)->building;
00144    
00145    assertOrThrow( veh != NULL );
00146    
00147    assertOrThrow( bld != NULL );
00148    assertOrThrow( bld->getOwner() == 0 );
00149    
00150    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00151    
00152    assertOrThrow( bld->getOwner() == 1 );
00153 }
00154 
00156 void testAiHeliMovement1()
00157 {
00158    auto_ptr<GameMap> game ( startMap("unittest-ai-heli.map"));
00159    
00160    Vehicle* heli = game->getField(7,10)->vehicle;
00161    
00162    assertOrThrow( heli != NULL );
00163    
00164    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00165    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00166    
00167    // at least one attack
00168    assertOrThrow( heli->experience >= 1  );
00169    
00170    // attacked from flying level
00171    assertOrThrow( heli->damage == 0  );
00172   
00173 }
00174 
00175 void testAiMovement() 
00176 {
00177    testAiMovement1();
00178    testAiMovement2();
00179    testAiMovement3();
00180    testAiMovement4();
00181    testAiMovement5();
00182    testAiMovement6();
00183    testAiMovement7();
00184    testAiHeliMovement1();
00185 }

Generated on Mon May 14 01:31:39 2012 for Advanced Strategic Command by  doxygen 1.5.1