From 526451ad02f9d713513d7aa8187aea04dc15fd77 Mon Sep 17 00:00:00 2001 From: mdiluzio Date: Tue, 16 Dec 2014 22:35:56 +0000 Subject: [PATCH] Update with more pre-generated levels Also clean up test code to not output unless erroring --- source/game/unit.cpp | 16 +++++++++++-- source/game/unit.h | 3 +++ source/gen/gen.cpp | 54 +++++++++++++++++++++++++++++++++----------- source/test/test.cpp | 5 +--- 4 files changed, 59 insertions(+), 19 deletions(-) diff --git a/source/game/unit.cpp b/source/game/unit.cpp index 4bdaaa8..24d02af 100644 --- a/source/game/unit.cpp +++ b/source/game/unit.cpp @@ -4,11 +4,16 @@ #include // for std::map namespace -{ +{ // 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; + + // If we have a set value, then set our int + if( set ) + p = *set; + 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 CUnit CUnit::GetUnitFromVis( unitVis_c vis ) { diff --git a/source/game/unit.h b/source/game/unit.h index 90003b5..84a22f4 100644 --- a/source/game/unit.h +++ b/source/game/unit.h @@ -9,6 +9,9 @@ #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 class CUnit { diff --git a/source/gen/gen.cpp b/source/gen/gen.cpp index d598d89..6dd2d38 100644 --- a/source/gen/gen.cpp +++ b/source/gen/gen.cpp @@ -11,33 +11,61 @@ void AddUnitToGame( Team team, char vis, uvector2 vec, CTTRTSGame& game ) game.AddUnit(std::move(unit)); } -void OutputGame( CTTRTSGame& game ) +void OutputGame( CTTRTSGame&& game ) { std::ofstream output; output.open (game.GetName() + ".txt"); output << game.GetStateAsString(); output.close(); + + forceResetUnitId(); } int main() { - // Basic 5v5 game + // Tiny 2v2 Game { - CTTRTSGame game(21, 11); - game.SetName("Basic_5_v_5"); + CTTRTSGame game(7, 5); + game.SetName("Tiny2v2"); AddUnitToGame( Team::Blue, '>', uvector2(1, 1), 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(19, 3), game); - AddUnitToGame( Team::Red, '<', uvector2(19, 5), game); - AddUnitToGame( Team::Red, '<', uvector2(19, 7), game); - AddUnitToGame( Team::Red, '<', uvector2(19, 9), game); + AddUnitToGame( Team::Red, '<', uvector2(5, 1), game); + AddUnitToGame( Team::Red, '<', uvector2(5, 3), 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)); } } \ No newline at end of file diff --git a/source/test/test.cpp b/source/test/test.cpp index fdabe5b..0231552 100644 --- a/source/test/test.cpp +++ b/source/test/test.cpp @@ -193,16 +193,13 @@ const char* tests() // Main program entry point int main() { - std::cout<<"Running tests"<