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
|
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <iostream>
#include "ai-move1.h"
#include "../loaders.h"
#include "unittestutil.h"
#include "../turncontrol.h"
#include "../gamemap.h"
void testAiMovement1()
{
auto_ptr<GameMap> game ( startMap("unittest-ai-simpleattack.map"));
Vehicle* veh = game->getField(3,9)->vehicle;
assertOrThrow( veh != NULL );
assertOrThrow( veh->damage == 0 );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
assertOrThrow( veh->damage > 0 );
}
void testAiMovement2()
{
auto_ptr<GameMap> game ( startMap("unittest-ai-mam.map"));
Vehicle* veh = game->getField(3,9)->vehicle;
assertOrThrow( veh != NULL );
assertOrThrow( veh->damage == 0 );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
/* a single unit will not make this much damage.
The point of this test is that the AI should move MoveAttackMove - capable units
out of the way to continue attacking with further units */
assertOrThrow( veh->damage >= 40 );
}
void testAiMovement3()
{
auto_ptr<GameMap> game ( startMap("unittest-ai-hemming.map"));
Vehicle* veh = game->getField(3,9)->vehicle;
assertOrThrow( veh != NULL );
assertOrThrow( veh->damage == 0 );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
/* a single unit will not make this much damage.
The point of this test is that the AI should move MoveAttackMove - capable units
out of the way to continue attacking with further units */
assertOrThrow( veh->damage >= 70 );
}
/** the AI should disembark all helicopters from the carrier and attack with them.
The carrier itself is not capable to attack the submarine */
void testAiMovement4()
{
auto_ptr<GameMap> game ( startMap("unittest-ai-carrier.map"));
Vehicle* veh = game->getField(2,7)->vehicle;
assertOrThrow( veh != NULL );
assertOrThrow( veh->damage == 0 );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
assertOrThrow( veh->damage >= 70 );
}
/** the trooper should conquer the building , but try to evade the view of the
player (if he steps into visiblity, the Artillery will attack) */
void testAiMovement5()
{
auto_ptr<GameMap> game ( startMap("unittest-ai-conquer.map"));
Vehicle* veh = game->getField(8,4)->vehicle;
Building* bld = game->getField( 14,9 )->building;
assertOrThrow( veh != NULL );
assertOrThrow( veh->damage == 0 );
assertOrThrow( bld != NULL );
assertOrThrow( bld->getOwner() == 0 );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
assertOrThrow( bld->getOwner() == 1 );
}
/** the trooper should not conquer this building, because it would immediately be
conquered back*/
void testAiMovement6()
{
auto_ptr<GameMap> game ( startMap("unittest-ai-conquer2.map"));
Vehicle* veh = game->getField(3,5)->vehicle;
Building* bld = game->getField(4,8)->building;
assertOrThrow( veh != NULL );
assertOrThrow( bld != NULL );
assertOrThrow( bld->getOwner() == 0 );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
assertOrThrow( bld->getOwner() == 0 );
}
/** the trooper should conquer this building, because the contents
of tte building are more worth than the lost unit*/
void testAiMovement7()
{
auto_ptr<GameMap> game ( startMap("unittest-ai-conquer3.map"));
Vehicle* veh = game->getField(3,5)->vehicle;
Building* bld = game->getField(4,8)->building;
assertOrThrow( veh != NULL );
assertOrThrow( bld != NULL );
assertOrThrow( bld->getOwner() == 0 );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
assertOrThrow( bld->getOwner() == 1 );
}
/** the helicopter should attack from a height where the tank can't retaliate*/
void testAiHeliMovement1()
{
auto_ptr<GameMap> game ( startMap("unittest-ai-heli.map"));
Vehicle* heli = game->getField(7,10)->vehicle;
assertOrThrow( heli != NULL );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
// at least one attack
assertOrThrow( heli->experience >= 1 );
// attacked from flying level
assertOrThrow( heli->damage == 0 );
}
void testAiMovement()
{
testAiMovement1();
testAiMovement2();
testAiMovement3();
testAiMovement4();
testAiMovement5();
testAiMovement6();
testAiMovement7();
testAiHeliMovement1();
}
|