Update with more pre-generated levels
Also clean up test code to not output unless erroring
This commit is contained in:
		
							parent
							
								
									dbfd932a64
								
							
						
					
					
						commit
						526451ad02
					
				
					 4 changed files with 59 additions and 19 deletions
				
			
		|  | @ -6,9 +6,14 @@ | ||||||
| namespace | namespace | ||||||
| { | { | ||||||
| 	// Helper function for generating unique unit ids during static init
 | 	// Helper function for generating unique unit ids during static init
 | ||||||
| 	unit_id_t get_unique_unit_id() | 	unit_id_t get_unique_unit_id(unit_id_t* set = nullptr) | ||||||
| 	{ | 	{ | ||||||
| 		static unit_id_t p = 0; | 		static unit_id_t p = 0; | ||||||
|  | 
 | ||||||
|  |         // If we have a set value, then set our int
 | ||||||
|  |         if( set ) | ||||||
|  |             p = *set; | ||||||
|  | 
 | ||||||
| 		return p++; | 		return p++; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -30,6 +35,13 @@ namespace | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // force a reset of the unit ID value
 | ||||||
|  | void forceResetUnitId() | ||||||
|  | { | ||||||
|  |     unit_id_t i = 0; | ||||||
|  |     get_unique_unit_id(&i); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // Get a unit from a visual
 | // Get a unit from a visual
 | ||||||
| CUnit CUnit::GetUnitFromVis( unitVis_c vis ) | CUnit CUnit::GetUnitFromVis( unitVis_c vis ) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -9,6 +9,9 @@ | ||||||
| 
 | 
 | ||||||
| #define UNIT_FORMATTER "UNIT:%u tm:%u vs:%c dr:%c ps:[%u,%u]" | #define UNIT_FORMATTER "UNIT:%u tm:%u vs:%c dr:%c ps:[%u,%u]" | ||||||
| 
 | 
 | ||||||
|  | // force a reset of the unit ID value
 | ||||||
|  | void forceResetUnitId(); | ||||||
|  | 
 | ||||||
| // Base unit type
 | // Base unit type
 | ||||||
| class CUnit | class CUnit | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -11,33 +11,61 @@ void AddUnitToGame( Team team, char vis, uvector2 vec, CTTRTSGame& game ) | ||||||
|     game.AddUnit(std::move(unit)); |     game.AddUnit(std::move(unit)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void OutputGame( CTTRTSGame& game ) | void OutputGame( CTTRTSGame&& game ) | ||||||
| { | { | ||||||
|     std::ofstream output; |     std::ofstream output; | ||||||
|     output.open (game.GetName() + ".txt"); |     output.open (game.GetName() + ".txt"); | ||||||
|     output << game.GetStateAsString(); |     output << game.GetStateAsString(); | ||||||
|     output.close(); |     output.close(); | ||||||
|  | 
 | ||||||
|  |     forceResetUnitId(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int main() | int main() | ||||||
| { | { | ||||||
|     // Basic 5v5 game
 |     // Tiny 2v2 Game
 | ||||||
|     { |     { | ||||||
|         CTTRTSGame game(21, 11); |         CTTRTSGame game(7, 5); | ||||||
|         game.SetName("Basic_5_v_5"); |         game.SetName("Tiny2v2"); | ||||||
| 
 | 
 | ||||||
|         AddUnitToGame( Team::Blue, '>', uvector2(1, 1), game); |         AddUnitToGame( Team::Blue, '>', uvector2(1, 1), game); | ||||||
|         AddUnitToGame( Team::Blue, '>', uvector2(1, 3), game); |         AddUnitToGame( Team::Blue, '>', uvector2(1, 3), game); | ||||||
|         AddUnitToGame( Team::Blue, '>', uvector2(1, 5), game); |  | ||||||
|         AddUnitToGame( Team::Blue, '>', uvector2(1, 7), game); |  | ||||||
|         AddUnitToGame( Team::Blue, '>', uvector2(1, 9), game); |  | ||||||
| 
 | 
 | ||||||
|         AddUnitToGame( Team::Red, '<', uvector2(19, 1), game); |         AddUnitToGame( Team::Red, '<', uvector2(5, 1), game); | ||||||
|         AddUnitToGame( Team::Red, '<', uvector2(19, 3), game); |         AddUnitToGame( Team::Red, '<', uvector2(5, 3), game); | ||||||
|         AddUnitToGame( Team::Red, '<', uvector2(19, 5), game); |  | ||||||
|         AddUnitToGame( Team::Red, '<', uvector2(19, 7), game); |  | ||||||
|         AddUnitToGame( Team::Red, '<', uvector2(19, 9), game); |  | ||||||
| 
 | 
 | ||||||
|         OutputGame(game); |         OutputGame(std::move(game)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // Basic 5v5 game
 | ||||||
|  |     { | ||||||
|  |         CTTRTSGame game(21, 11); | ||||||
|  |         game.SetName("Basic5v5"); | ||||||
|  | 
 | ||||||
|  |         for ( ucoord_t y : { 1,3,5,7,9 } ) | ||||||
|  |             AddUnitToGame( Team::Blue, '>', uvector2(1, y), game); | ||||||
|  | 
 | ||||||
|  |         for ( ucoord_t y : { 1,3,5,7,9 } ) | ||||||
|  |             AddUnitToGame( Team::Red, '<', uvector2(19, y), game); | ||||||
|  | 
 | ||||||
|  |         OutputGame(std::move(game)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // Chess 10v10 game
 | ||||||
|  |     { | ||||||
|  |         CTTRTSGame game(8, 8); | ||||||
|  |         game.SetName("Chess"); | ||||||
|  | 
 | ||||||
|  |         for ( ucoord_t y : { 0,1,2,3,4,5,6,7 } ) { | ||||||
|  |             AddUnitToGame(Team::Blue, '>', uvector2(0, y), game); | ||||||
|  |             AddUnitToGame(Team::Blue, '>', uvector2(1, y), game); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         for ( ucoord_t y : { 0,1,2,3,4,5,6,7 } ) { | ||||||
|  |             AddUnitToGame(Team::Red, '<', uvector2(6, y), game); | ||||||
|  |             AddUnitToGame(Team::Red, '<', uvector2(7, y), game); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         OutputGame(std::move(game)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -193,16 +193,13 @@ const char* tests() | ||||||
| // Main program entry point
 | // Main program entry point
 | ||||||
| int main() | int main() | ||||||
| { | { | ||||||
| 	std::cout<<"Running tests"<<std::endl; |  | ||||||
| 
 |  | ||||||
| 	const char* res = tests(); | 	const char* res = tests(); | ||||||
| 
 | 
 | ||||||
| 	if( res ) | 	if( res ) | ||||||
| 	{ | 	{ | ||||||
| 		std::cout<<"Tests failed - "<<res<<std::endl; | 		std::cout<<"ERROR: "<<res<<std::endl; | ||||||
| 		return -1; | 		return -1; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	std::cout<<"Tests succeeded"<<std::endl; |  | ||||||
| 	return 0; | 	return 0; | ||||||
| }; | }; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue