summaryrefslogtreecommitdiffstats
path: root/C++/Polymorphism/PolymorphismTooCool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'C++/Polymorphism/PolymorphismTooCool.cpp')
-rw-r--r--C++/Polymorphism/PolymorphismTooCool.cpp205
1 files changed, 205 insertions, 0 deletions
diff --git a/C++/Polymorphism/PolymorphismTooCool.cpp b/C++/Polymorphism/PolymorphismTooCool.cpp
new file mode 100644
index 0000000..472817b
--- /dev/null
+++ b/C++/Polymorphism/PolymorphismTooCool.cpp
@@ -0,0 +1,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/>.
+ */