25#if defined(__GNUC__) || defined(__clang__)
26#pragma GCC diagnostic push
27#pragma GCC diagnostic ignored "-Wold-style-cast"
29#include "nonstdlibs/VariadicTable.h"
30#if defined(__GNUC__) || defined(__clang__)
31#pragma GCC diagnostic pop
40#define WIN32_LEAN_AND_MEAN
48 SetConsoleOutputCP(65001);
51 GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &consoleMode);
53 consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
54 SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), consoleMode);
55 std::cout <<
"Experimental Windows VT processing enabled." << std::endl;
58#define enableWindowsVTProcessing()
76 return std::accumulate(
77 vec.begin(), vec.end(), std::string(), [](
const std::string & s,
int v) {
78 return s.empty() ? std::to_string(v) : s +
" " + std::to_string(v);
82void get_hsi(std::vector<Stock> stocks_list, std::vector<float> & hsi_history) {
84 std::string filesave =
86 std::vector<float> total;
87 for (
unsigned int i = 0; i < stocks_list.size(); i++) {
89 stocks_list[i].get_price() / stocks_list[i].get_initial_price() * 1000 *
90 static_cast<float>(std::pow(2, stocks_list[i].get_split_count())));
93 hsi = std::reduce(total.begin(), total.end()) / total.size();
94 hsi_history.emplace_back(hsi);
96 fout.open(filesave.c_str(), std::ios::app);
112 std::vector<std::string> defaultColumns = {
113 "#",
"Category",
"Name",
"$Price",
"Change", R
"(%Change)", "#Has",
"#Max"};
114 VariadicTable<
unsigned int, std::string, std::string, float, float, float,
115 unsigned int,
unsigned int>
116 defaultTable(defaultColumns);
118 defaultColumns.emplace_back(
" Mean ");
119 defaultColumns.emplace_back(
" SD ");
120 defaultColumns.emplace_back(
" up ");
121 defaultColumns.emplace_back(
" low ");
122 defaultColumns.emplace_back(
"event_id");
125 VariadicTable<
unsigned int, std::string, std::string, float, float, float,
126 unsigned int,
unsigned int, float, float, float, float, std::string>
127 devTable({defaultColumns});
130 devTable.setColumnPrecision({0, 0, 0, 2, 2, 2, 0, 0, 1, 0, 0, 0, 0});
131 devTable.setColumnFormat({VariadicTableColumnFormat::AUTO,
132 VariadicTableColumnFormat::AUTO, VariadicTableColumnFormat::AUTO,
133 VariadicTableColumnFormat::FIXED, VariadicTableColumnFormat::FIXED,
134 VariadicTableColumnFormat::FIXED, VariadicTableColumnFormat::FIXED,
135 VariadicTableColumnFormat::FIXED, VariadicTableColumnFormat::FIXED,
136 VariadicTableColumnFormat::FIXED, VariadicTableColumnFormat::FIXED,
137 VariadicTableColumnFormat::FIXED, VariadicTableColumnFormat::AUTO});
138 for (
unsigned int i = 0; i < stocks_list.size(); i++) {
139 std::map<stock_modifiers, float> modifiers =
141 devTable.addRow(i + 1, stocks_list[i].category_name(),
142 stocks_list[i].get_name(), stocks_list[i].get_price(),
143 stocks_list[i].delta_price(),
144 stocks_list[i].delta_price_percentage() * 100,
145 stocks_list[i].get_quantity(),
150 devTable.print(std::cout);
155 defaultTable.setColumnPrecision({0, 0, 0, 2, 2, 2, 0, 0});
156 defaultTable.setColumnFormat(
157 {VariadicTableColumnFormat::AUTO, VariadicTableColumnFormat::AUTO,
158 VariadicTableColumnFormat::AUTO, VariadicTableColumnFormat::FIXED,
159 VariadicTableColumnFormat::FIXED, VariadicTableColumnFormat::FIXED,
160 VariadicTableColumnFormat::FIXED, VariadicTableColumnFormat::FIXED});
161 for (
unsigned int i = 0; i < stocks_list.size(); i++) {
162 defaultTable.addRow(i + 1, stocks_list[i].category_name(),
163 stocks_list[i].get_name(), stocks_list[i].get_price(),
164 stocks_list[i].delta_price(),
165 stocks_list[i].delta_price_percentage() * 100,
166 stocks_list[i].get_quantity(),
169 defaultTable.print(std::cout);
176 for (
unsigned int i = 0; i < stocks_list.size(); i++) {
177 std::string index = std::to_string(i + 1);
181 if (stocks_list[i].delta_price() > 0) {
184 else if (stocks_list[i].delta_price() < 0) {
194 std::cout << std::fixed << std::setprecision(2);
204 std::vector<Stock_event> ongoing_events = {};
205 for (
unsigned int i = 0; i < stocks_list.size(); i++) {
206 std::list<Stock_event> events = stocks_list[i].get_events();
211 if (event.duration > 0) {
213 if (std::find(ongoing_events.begin(), ongoing_events.end(), event) ==
214 ongoing_events.end()) {
215 ongoing_events.emplace_back(event);
220 return ongoing_events;
241 switch (event.type_of_event) {
243 for (
unsigned int i = 0; i < stocks_list.size(); i++) {
244 stocks_list[i].add_event(event);
248 for (
unsigned int i = 0; i < stocks_list.size(); i++) {
249 if (stocks_list[i].get_category() == event.category) {
250 stocks_list[i].add_event(event);
255 std::vector<unsigned int> stocks_indices_not_suitable = {};
256 while (!stocks_list.empty() &&
257 stocks_list.size() < stocks_indices_not_suitable.size()) {
260 Stock lucky_stock = stocks_list[choice];
262 stocks_indices_not_suitable.emplace_back(choice);
266 modified_event.
text = lucky_stock.
get_name() +
" " +
event.text;
285 for (
unsigned int i = 0; i < stocks_list.size(); i++) {
286 stocks_list[i].next_round();
291 std::vector<Stock> & stocks_list, std::vector<float> & hsi_history) {
292 std::string EMPTY_INPUT =
"";
293 std::string loadsave = EMPTY_INPUT;
294 while (loadsave.compare(EMPTY_INPUT) == 0) {
296 std::cin >> loadsave;
299 std::cin >> loadsave;
310 loadsave = EMPTY_INPUT;
313 std::cout <<
"Goodbye! Hope you had a good luck in the stock market!"
322 std::cout <<
"The game was compiled on " << __DATE__ <<
" at " << __TIME__
326 bool gameQuit =
false;
327 bool viewMode =
false;
334 std::vector<Stock> stocks_list;
337 stocks_list.emplace_back();
349 std::vector<float> hsi_history;
353 if (hsi_history.empty()) {
354 get_hsi(stocks_list, hsi_history);
359 <<
" %" << std::endl;
364 overlayEvent =
false;
368 integerInput(row, col,
"Select stock index to display (0 for HSI): ");
370 indexGraph < 0 || indexGraph >
static_cast<int>(stocks_list.size())) {
372 std::cout <<
"Index out of range!";
375 row, col,
"Select stock index to display (0 for HSI): ");
385 hsi_history[hsi_history.size() - 1]);
396 get_hsi(stocks_list, hsi_history);
A class that represents a stock object in the game.
void add_event(const Stock_event &event)
Add an event to the stock.
std::string get_name(void)
Get the name of the stock.
bool can_add_event(const Stock_event &event)
Check if we can add the event to the stock.
static const std::string DELETE_GAME
static const std::string EXIT_GAME
static const std::string NEW_GAME
static const std::string LOAD_GAME
static void sleep(int dur)
int integerInput(int row, int col, const std::string &message)
void optionsInput(int row, int col, float &balance, float tax, std::vector< Stock > &stocks, const std::vector< Stock_event > &events, bool &viewMode, bool &advance, bool &overlayEvent, bool &flush, bool &gameQuit)
(Declarations of) human-computer interactions functions.
void drawEventBar(int row, int col)
void drawButton(int row, int col)
void drawRoundInfo(int row, int col, int round, float balance, std::string player, float indexHSI)
void drawLogo(int row, int col)
Function declarations for drawing/display of various elements.
const std::vector< Stock_event > all_stock_events
The list of all events that can be applied to the stocks.
bool assertion_check_mutual_exclusivity(void)
Check if there are mutual exclusivity violations in all_stock_events.
std::vector< Stock_event > pick_events(const std::vector< Stock_event > &all_events, unsigned int num_events)
Pick a random event from the list of events.
void assertion_check_uniq_events(void)
Implements event-related data structures and (declarations of) such functions.
@ upper_limit
The upper limit of the stock price percentage change.
@ standard_deviation
Amount of variation of the stock price percentage change.
@ mean
The expectation of the stock price percentage change.
@ lower_limit
The lower limit of the stock price percentage change.
@ pick_random_stock
This event will apply to a randomly selected stock from all of the stocks available currently.
@ category
This event will apply to stocks within the specified category.
@ all_stocks
This event will apply to all stocks.
void loadstatus(unsigned int &rounds_played, vector< Stock > &stocks_list, float &balance, string &playerName, vector< float > &hsi_history)
Load an existing game status from .save files.
const std::string USER_SAVE_OPTION_PROMPT
void delsave(string &mode)
Delete a save.
void createplayer(string &playerName)
Create a player folder.
void savestatus(unsigned int rounds_played, vector< Stock > stocks_list, float balance, const string &playerName)
Save the game status into *.save files.
Header files for file operation functions related to the game.
bool checkValidInput(const std::string &input)
Check if the input is valid.
const std::string SAVE_FOLDER_PREFIX
const std::string SAVE_FILE_EXTENSION_TXT
void graph_plotting(const string &player, int stocknum, int width, int height)
Plot the graph of the stock price history to std::cout.
Declaration of graph plotting function.
#define enableWindowsVTProcessing()
mode
hiding mean/sd/uplim/lowlim/event_id columns in the table
const float trading_fees_percent
/ 100 means charging % more/portion of the money involved in stock operations.
void get_hsi(std::vector< Stock > stocks_list, std::vector< float > &hsi_history)
float balance
Player's balance.
void initializePlayerSaves(std::vector< Stock > &stocks_list, std::vector< float > &hsi_history)
void new_events_next_round(std::vector< Stock > &stocks_list)
Generate new events and apply them to the stocks.
void print_table(std::vector< Stock > stocks_list, float _playerBal, mode m=dev)
Print the table of stocks.
void next_round_routine(unsigned int &_rounds, std::vector< Stock > &stocks_list)
std::vector< Stock_event > get_ongoing_events(std::vector< Stock > stocks_list)
Get all the ongoing events.
unsigned int rounds_played
Number of rounds played.
std::string vectorToString(const std::vector< unsigned int > &vec)
std::string playerName
Player's name.
std::map< stock_modifiers, float > getProcessedModifiers(Stock stock)
Get the processed modifiers for the stock.
unsigned int random_integer(unsigned int max_integer)
python randint like function
Header file for random related functions.
void sortStocksList(std::vector< Stock > &stocks_list, SortingMethods sortMethod, SortingDirections sortDirection)
Sorts the stocks.
Declaration of the Stock class.
const int initial_stock_count
Initial stock count.
The data structure of an event that will be applied to the stocks.
std::string text
The text that will be displayed to the player.