From bb16c32bde58cba70e4877aa2d3ebd04332eb575 Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Tue, 4 Jan 2022 13:35:02 +0100 Subject: linux compile and imgs --- game/ai/action.cpp | 150 ++++++++++++++++++++++++++--------------------------- 1 file changed, 75 insertions(+), 75 deletions(-) (limited to 'game/ai/action.cpp') diff --git a/game/ai/action.cpp b/game/ai/action.cpp index 63218ba..d85eb4d 100644 --- a/game/ai/action.cpp +++ b/game/ai/action.cpp @@ -1,76 +1,76 @@ -#include "action.h" - -bool ai::compare_action(ai::action a, ai::action b) { - return (a.heuristic < b.heuristic); -} - -std::string ai::action::to_string () { - if (type == actype::attack) { - if (abs(x-mx)+abs(y-my) != 0) { - return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" - + " move " + - "[" + std::to_string(mx) + ", " + std::to_string(my) + "]" - + " attack " + - "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; - } else { - return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" - + " attack " + - "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; - } - } - if (type == actype::heal) { - if (abs(x-mx)+abs(y-my) != 0) { - return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" - + " move " + - "[" + std::to_string(mx) + ", " + std::to_string(my) + "]" - + " heal " + - "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; - } else { - return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" - + " heal " + - "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; - } - } - if (type == actype::convert) { - if (abs(x-mx)+abs(y-my) != 0) { - return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" - + " move " + - "[" + std::to_string(mx) + ", " + std::to_string(my) + "]" - + " convert " + - "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; - } else { - return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" - + " convert " + - "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; - } - } - if (type == actype::move) { - return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" - + " move " + - "[" + std::to_string(mx) + ", " + std::to_string(my) + "]"; - } - if (type == actype::build) { - if (abs(x-mx)+abs(y-my) != 0) { - return "[" + std::to_string(x) + ", " + std::to_string(y) - + "]" + " move " + - "[" + std::to_string(mx) + ", " + std::to_string(my) - + "]" + " build " + - std::to_string(v); - } else { - return "[" + std::to_string(mx) + ", " + std::to_string(my) - + "]" + " build " + - std::to_string(v); - } - } - if (type == actype::train) { - return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" + - " train " + std::to_string(v); - } - if (type == actype::trade) { - return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" + - " trade " + std::to_string(v); - } - if (type == actype::tech) { - return "tech " + std::to_string(v); - } +#include "action.h" + +bool ai::compare_action(ai::action a, ai::action b) { + return (a.heuristic < b.heuristic); +} + +std::string ai::action::to_string () { + if (type == actype::attack) { + if (abs(x-mx)+abs(y-my) != 0) { + return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" + + " move " + + "[" + std::to_string(mx) + ", " + std::to_string(my) + "]" + + " attack " + + "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; + } else { + return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" + + " attack " + + "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; + } + } + if (type == actype::heal) { + if (abs(x-mx)+abs(y-my) != 0) { + return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" + + " move " + + "[" + std::to_string(mx) + ", " + std::to_string(my) + "]" + + " heal " + + "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; + } else { + return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" + + " heal " + + "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; + } + } + if (type == actype::convert) { + if (abs(x-mx)+abs(y-my) != 0) { + return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" + + " move " + + "[" + std::to_string(mx) + ", " + std::to_string(my) + "]" + + " convert " + + "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; + } else { + return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" + + " convert " + + "[" + std::to_string(tx) + ", " + std::to_string(ty) + "]"; + } + } + if (type == actype::move) { + return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" + + " move " + + "[" + std::to_string(mx) + ", " + std::to_string(my) + "]"; + } + if (type == actype::build) { + if (abs(x-mx)+abs(y-my) != 0) { + return "[" + std::to_string(x) + ", " + std::to_string(y) + + "]" + " move " + + "[" + std::to_string(mx) + ", " + std::to_string(my) + + "]" + " build " + + std::to_string(v); + } else { + return "[" + std::to_string(mx) + ", " + std::to_string(my) + + "]" + " build " + + std::to_string(v); + } + } + if (type == actype::train) { + return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" + + " train " + std::to_string(v); + } + if (type == actype::trade) { + return "[" + std::to_string(x) + ", " + std::to_string(y) + "]" + + " trade " + std::to_string(v); + } + if (type == actype::tech) { + return "tech " + std::to_string(v); + } } \ No newline at end of file -- cgit v1.2.3-54-g00ecf