aboutsummaryrefslogtreecommitdiff
path: root/game/ai/action.cpp
blob: d85eb4d6ebd70e223357d2fb18661ca7e3e16c40 (plain)
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
#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);
    }
}