summaryrefslogtreecommitdiffstats
path: root/C++/Polymorphism/PolymorphismTooCool.cpp
blob: 472817bfd3d275b0c32f737636fb2af9d6a06dd8 (plain) (blame)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Name: msglm
// Date: Nov-13-2022
// Program Name: Brutal Geo-politics
// Description: A civlization game with econoimcs and power where the goal is to take every tile on the board. This version is played by the AI


#include <iostream>
#include <string>
#include <array>
#include <random>
#include <vector>

using namespace std;

//classes
class civilization {
    public:
        //icon will represent the civilization on the map
        char icon; 
        //aggressiveness will represent how likely a civilization is to
        //aquire territory by stealing it rather than buying it.
        //higher = more likely to steal; lower = more likely to buy.

        ///AXED DUE TO TIME CONSTRAINTS
        //This will control the AI for the civilizations
        //float aggressiveness;

        //resources that each civlization has
        int manpower;
        int money;

        //The percentage of the economicOutput a civilization will take per turn from each of its territories.
        float taxRate;

        void quasiConstructor(default_random_engine & randNumGen, char chosenIcon) { 
            icon = chosenIcon;

            uniform_real_distribution<float> percent(0.0,1.0);
            aggressiveness = percent(randNumGen);
            taxRate = percent(randNumGen);
        }

};

//structs
class tile {
    public:
        //The current owner of a civilization
        civilization owner;

        //Dictates how much manpower is in a tile
        int manpower;
        float populationGrowth;
        //Compliance of a tile is how docile a tile is towards its master civilization
        //Compliance will lower if the master civilization is out of money or out of manpower
        //Compliance will also lower if taxes are too high (see economicOutputExpectation)
        //If compliance reaches zero, a revolt will happen and the current tile will become its own civilization
        int compliance;


        //The raw value of the tile; this amount of money will need to be exchanged to take a tile by purchasing
        int value;

        //The value, per turn, the tile generates.
        //If nobody owns the tile, the value of the tile will simply go up
        //If someone does own this tile, a percentage of that tile's economicOutput will be collected
        //by the master civilization in accordance with their tax rate.
        float economicOutput;

        //The percentage of economicOutput a tile expects to keep
        //If a tax rate goes over this amount, a tile will lower in its compliance.
        float economicOutputExpectation;

        //If a tile is a core tile, it will never revolt.
        //This status is reserved for the starting point of a civilization (the capital) or tiles that have been
        //annhilated after failing to revolt.
        bool coreTile;

        //If this tile is a wilderness tile, it has never been contacted by a civilization.
        //This means no one owns it and civilizations cannot be spawned out of them (except during game start).
        bool wilderness;

        //From my research, there is no good way to pass
        //parameters to a constructor function that belongs to an object
        //that's inside of an array.
        //Because of this, the following function must be called after the object it initalized
        //to be able to use a universal random number generator that doesn't involve global variables.
        //I would use global variables, but I also want points, so instead we get this:
        void quasiConstructor( default_random_engine & randNumGen ) { //Pass by reference because, in this instance for maximum performance
            wilderness = true;

            uniform_int_distribution<int> manpowerRange(1,100000);
            manpower = manpowerRange(randNumGen);

            uniform_real_distribution<float> populationGrowthRange(0.0,0.9);
            populationGrowth = populationGrowthRange(randNumGen);

            uniform_int_distribution<int> economicOutputRange(1,15000);
            economicOutput = economicOutputRange(randNumGen);

            value = economicOutput;

            uniform_real_distribution<float> economicOutputExpectationRange(0.0,0.9);
            economicOutputExpectation = economicOutputExpectationRange(randNumGen);
        }

        void claim(civilization claimant) {
            if (wilderness) {
                owner = claimant;
                wilderness = false;
            }

        }
        void popGrowth() { manpower = manpower + (populationGrowth*manpower); }
        //Revolt will succeed if the manpower of a tile is greater than 10% of its master's manpower
        //OR
        //if the economic value of a tile is greater than 10% of its master's money
        //if neither of these conditions are the case and the revolt fails, the tile's population will be evicerated and the tile
        //will becomine a coreTile, unable to revolt ever again.
        void revolt() {}

};

//functions


//TODO: figure out a way to pass the board without hard-coding 64 as the array size
//and without using a vector (because vectors are bloat).
//"declaration of ‘board’ as multidimensional array must have bounds for all dimensions except the first"
//there is literally zero reason for this to be the case and gives further reasoning to deprecate C/C++.
void printBoard(tile board[][64], unsigned int boardsize) {
    for(int xpos=0; xpos < boardsize; xpos++) {
        cout << endl;
        for (int ypos = 0; ypos < boardsize; ypos++) {
            if (board[xpos][ypos].wilderness) {
                cout << ".";
            } else {
                cout << board[xpos][ypos].owner.icon;
            }
        }
    }
}


int main() {

    //Create the board and all its glory
    const unsigned int SIZE = 64;
    const unsigned int CIVAMOUNT = 4;
    bool gameGoing;
    char winner;
    random_device rd;
    default_random_engine randNumGen(rd());
    tile playingBoard[SIZE][SIZE];
    for(int xpos = 0; xpos < SIZE; xpos++) {
        for (int ypos = 0; ypos < SIZE; ypos++) {
            playingBoard[xpos][ypos].quasiConstructor(randNumGen); 
        }
    }

    //Spawning some civilizations

    //this gets to be a vector due to the stack-based situation civilizations will exist in
    //civlizations can be born or die at a whim, they need to be able to be added to a stack as well.
    vector<civilization> civlist;
    uniform_int_distribution<int> randomSpot(0,SIZE);

    //TODO make this create CIVAMOUNT of civilizations, each with a random char representing it
    civlist.push_back(civilization());
    civlist.back().quasiConstructor(randNumGen, 'R');
    playingBoard[randomSpot(randNumGen)][randomSpot(randNumGen)].claim(civlist.back());

    civlist.push_back(civilization());
    civlist.back().quasiConstructor(randNumGen, 'U');
    playingBoard[randomSpot(randNumGen)][randomSpot(randNumGen)].claim(civlist.back());

    civlist.push_back(civilization());
    civlist.back().quasiConstructor(randNumGen, 'J');
    playingBoard[randomSpot(randNumGen)][randomSpot(randNumGen)].claim(civlist.back());

    //Turn system

    while (gameGoing) {
        for(civilization civ : civilist) {

        }

        }
    }


    //Check for win condition (3 turns where every tile is owned by one civ)
    
        //output each turn to a file
    printBoard(playingBoard, SIZE);

}

/*
   This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License Version 3 ONLY as published by the Free Software Foundation.

   This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License along with this program.  If not, see <https://www.gnu.org/licenses/>.
   */