Advanced Strategic Command
ai-move1.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 
10 #include <iostream>
11 
12 #include "ai-move1.h"
13 #include "../loaders.h"
14 #include "unittestutil.h"
15 #include "../turncontrol.h"
16 #include "../gamemap.h"
17 
19 {
20  auto_ptr<GameMap> game ( startMap("unittest-ai-simpleattack.map"));
21 
22  Vehicle* veh = game->getField(3,9)->vehicle;
23 
24  assertOrThrow( veh != NULL );
25  assertOrThrow( veh->damage == 0 );
26 
27  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
28 
29  assertOrThrow( veh->damage > 0 );
30 }
31 
32 
34 {
35 
36  auto_ptr<GameMap> game ( startMap("unittest-ai-mam.map"));
37 
38  Vehicle* veh = game->getField(3,9)->vehicle;
39 
40  assertOrThrow( veh != NULL );
41  assertOrThrow( veh->damage == 0 );
42 
43  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
44 
45  /* a single unit will not make this much damage.
46  The point of this test is that the AI should move MoveAttackMove - capable units
47  out of the way to continue attacking with further units */
48 
49  assertOrThrow( veh->damage >= 35 );
50 }
51 
53 {
54 
55  auto_ptr<GameMap> game ( startMap("unittest-ai-hemming.map"));
56 
57  Vehicle* veh = game->getField(3,9)->vehicle;
58 
59  assertOrThrow( veh != NULL );
60  assertOrThrow( veh->damage == 0 );
61 
62  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
63 
64  /* a single unit will not make this much damage.
65  The point of this test is that the AI should move MoveAttackMove - capable units
66  out of the way to continue attacking with further units */
67 
68  assertOrThrow( veh->damage >= 64 );
69 }
70 
71 
75 {
76 
77  auto_ptr<GameMap> game ( startMap("unittest-ai-carrier.map"));
78 
79  Vehicle* veh = game->getField(2,7)->vehicle;
80 
81  assertOrThrow( veh != NULL );
82  assertOrThrow( veh->damage == 0 );
83 
84  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
85 
86  assertOrThrow( veh->damage >= 70 );
87 }
88 
89 
93 {
94 
95  auto_ptr<GameMap> game ( startMap("unittest-ai-conquer.map"));
96 
97  Vehicle* veh = game->getField(8,4)->vehicle;
98  Building* bld = game->getField( 14,9 )->building;
99 
100  assertOrThrow( veh != NULL );
101  assertOrThrow( veh->damage == 0 );
102 
103  assertOrThrow( bld != NULL );
104  assertOrThrow( bld->getOwner() == 0 );
105 
106  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
107  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
108  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
109  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
110 
111  assertOrThrow( bld->getOwner() == 1 );
112 }
113 
114 
118 {
119 
120  auto_ptr<GameMap> game ( startMap("unittest-ai-conquer2.map"));
121 
122  Vehicle* veh = game->getField(3,5)->vehicle;
123  Building* bld = game->getField(4,8)->building;
124 
125  assertOrThrow( veh != NULL );
126 
127  assertOrThrow( bld != NULL );
128  assertOrThrow( bld->getOwner() == 0 );
129 
130  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
131 
132  assertOrThrow( bld->getOwner() == 0 );
133 }
134 
135 
139 {
140  auto_ptr<GameMap> game ( startMap("unittest-ai-conquer3.map"));
141 
142  Vehicle* veh = game->getField(3,5)->vehicle;
143  Building* bld = game->getField(4,8)->building;
144 
145  assertOrThrow( veh != NULL );
146 
147  assertOrThrow( bld != NULL );
148  assertOrThrow( bld->getOwner() == 0 );
149 
150  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
151 
152  assertOrThrow( bld->getOwner() == 1 );
153 }
154 
157 {
158  auto_ptr<GameMap> game ( startMap("unittest-ai-heli.map"));
159 
160  Vehicle* heli = game->getField(7,10)->vehicle;
161 
162  assertOrThrow( heli != NULL );
163 
164  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
165  next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
166 
167  // at least one attack
168  assertOrThrow( heli->getExperience_offensive() >= 1 );
169 
170  // attacked from flying level
171  assertOrThrow( heli->damage == 0 );
172 
173 }
174 
176 {
177  testAiMovement1();
178  testAiMovement2();
179  testAiMovement3();
180  testAiMovement4();
181  testAiMovement5();
182  testAiMovement6();
183  testAiMovement7();
185 }
void testAiMovement6()
the trooper should not conquer this building, because it would immediately be conquered back ...
Definition: ai-move1.cpp:117
int damage
Damage. 0 is no damage, when damage reaches 100 the container is destroyed.
#define assertOrThrow(expr)
Definition: errors.h:69
int getOwner() const
returns the number of the player this vehicle/building belongs to
void testAiHeliMovement1()
the helicopter should attack from a height where the tank can't retaliate
Definition: ai-move1.cpp:156
void testAiMovement7()
the trooper should conquer this building, because the contents of tte building are more worth than th...
Definition: ai-move1.cpp:138
void testAiMovement2()
Definition: ai-move1.cpp:33
void testAiMovement1()
Definition: ai-move1.cpp:18
void next_turn(GameMap *gamemap, const NextTurnStrategy &nextTurnStrategy, MapDisplayInterface *display, int playerView)
void testAiMovement()
Definition: ai-move1.cpp:175
MapField * getField(const BuildingType::LocalCoordinate &localCoordinates) const
returns the pointer to the field which the given part of the building is standing on ...
Definition: buildings.cpp:399
GameMap * startMap(const ASCString &filename)
void testAiMovement4()
the AI should disembark all helicopters from the carrier and attack with them.
Definition: ai-move1.cpp:74
void testAiMovement5()
the trooper should conquer the building , but try to evade the view of the player (if he steps into v...
Definition: ai-move1.cpp:92
void testAiMovement3()
Definition: ai-move1.cpp:52
Building * building
Definition: mapfield.h:102
An actual building on the map, which references a BuildingType Buildings have an owner,.
Definition: buildings.h:38
int getExperience_offensive() const
Definition: vehicle.cpp:253