#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QApplication>
#include <QListWidget>
#include <QMainWindow>
#include <QDialog>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QMenuBar>
#include <QMenu>
#include <QLabel>
#include <QString>
#include <string>
#include <vector>
#include <ostream>
#include <fstream>
#include <sstream>
#include <iostream>
#include <cmath>
using std::vector;
using std::iostream;
using std::ostream;
using std::fstream;
{
Q_OBJECT
public:
MainWindow();
void analyze_deck();
public slots:
void read_deck
(const QString &fileName
);
void refresh_deck();
void save_analysis(const std::string &fileName);
void button_pushed(int x);
signals:
private:
void createH_bx_main(); // for main layout
void createH_bx_lst(); //for horizontal button box of main list
void createH_bx_bd(); //"" bad list
void createH_bx_gd(); //"" good list
void createV_bx_lst(); //vertical for main list
void createV_bx_bd(); //""bad list
void createV_bx_gd(); //"" good
void createV_bx_rslt(); //for results
void create_menu(); // for buttons
void create_actions();
//const int output_number = 4;
//const int btns_main_menu = 11;
QLabel *results
[10];
//evens are descriptive, odds are numbers
};
double nfomf(int n, int m, int k); //n factorial over m factorial for k terms.
int list_sizes[3]; // amount in main/bad/good
int monster_count = 0;// monster/spell/trap
int spell_count = 0;
int trap_count = 0;
int whereami[3]; //main/bad/good
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QApplication>
#include <QListWidget>
#include <QMainWindow>
#include <QDialog>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QMenuBar>
#include <QMenu>
#include <QLabel>
#include <QString>
#include <string>
#include <vector>
#include <ostream>
#include <fstream>
#include <sstream>
#include <iostream>
#include <cmath>
using std::vector;
using std::iostream;
using std::ostream;
using std::fstream;
class QAction;
class QGroupBox;
class QLabel;
class QPushButton;
class QHBoxLayout;
class QVBoxLayout;
class QListWidget;
class QMenuBar;
class QMenu;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
void analyze_deck();
QListWidgetItem *items_a[10];
public slots:
void read_deck(const QString &fileName);
void refresh_deck();
void save_analysis(const std::string &fileName);
void current_list_itemM(QListWidgetItem *item);
void current_list_itemB(QListWidgetItem *item);
void current_list_itemG(QListWidgetItem *item);
void button_pushed(int x);
signals:
private:
void createH_bx_main(); // for main layout
void createH_bx_lst(); //for horizontal button box of main list
void createH_bx_bd(); //"" bad list
void createH_bx_gd(); //"" good list
void createV_bx_lst(); //vertical for main list
void createV_bx_bd(); //""bad list
void createV_bx_gd(); //"" good
void createV_bx_rslt(); //for results
void create_menu(); // for buttons
void create_actions();
//const int output_number = 4;
//const int btns_main_menu = 11;
QHBoxLayout *h_mn_p; //main
QHBoxLayout *h_lst_p; //list
QHBoxLayout *h_bd_p; //bad
QHBoxLayout *h_gd_p; //good
QVBoxLayout *v_lst_p;//list
QVBoxLayout *v_bd_p;//bad
QVBoxLayout *v_gd_p;//good
QVBoxLayout *v_rslt_p;//results (vert)
QMenu *file;
QMenu *analyze;
QLabel *results[10]; //evens are descriptive, odds are numbers
QPushButton *btns_a[6];
QAction *exitAction;
QAction *analyzeAction;
QAction *refreshAction;
QAction *readAction;
QAction *saveAction;
QListWidget *rslt_lst;
QListWidget *bd_lst;
QListWidget *gd_lst;
};
QString current_file;
double nfomf(int n, int m, int k); //n factorial over m factorial for k terms.
int list_sizes[3]; // amount in main/bad/good
QListWidget *mn_lst;
int monster_count = 0;// monster/spell/trap
int spell_count = 0;
int trap_count = 0;
int whereami[3]; //main/bad/good
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
using namespace std;
void save_analysis(const std::string &fileName)
{
}
double nfomf(int n, int m, int k)
{
double answer = 1;
while((n-k+1) <= m)
{
k--;
m--;
}
for(int j = 0; j < k; j++)
{
answer = answer*(n-j)/(m-j);
}
return answer;
}
void analyze_deck()
{
double total_cards = monster_count + spell_count + trap_count;
//no monsters:
double no_m = nfomf(total_cards - monster_count, total_cards,6);
//no spells
double no_s = nfomf(total_cards - spell_count, total_cards,6);
//no traps
double no_t = nfomf(total_cards - trap_count, total_cards,6);
//all bad
double allb = nfomf(total_cards - list_sizes[1], total_cards, 6);
//at least 1 good
double al1g = 1 - nfomf(total_cards - list_sizes[2], total_cards, 6);
items_a[1]->setText(no_m_s);
items_a[3]->setText(no_s_s);
items_a[5]->setText(no_t_s);
items_a[7]->setText(allb_s);
items_a[9]->setText(al1g_s);
}
/*
*returns the line number of the
* card's id number.
*/
int read_number(const std::string idnum)
{
int iter = 0;
std::ifstream infile(".../numbers.txt");
std::string line;
while(std::getline(infile, line))
{
if(line == idnum)
{
infile.close();
return iter;
iter++;
}
}
infile.close();
return 0;
}
/*
*returns the name of the card with the
*id number.
*/
std::string read_name(const std::string idnum)
{
int line_number = read_number(idnum);
std::ifstream infile(".../names");
std::string line;
for(int i = 0; i < line_number; i++)
{
getline(infile, line);
}
infile.close();
getline(infile, line);
return line;
}
/*
*returns the type of the card, and writes overall
*balance to vector ctd.
*/
int read_type(const std::string idnum)
{
int line_number = read_number(idnum);
std::ifstream infile("...types.txt");
std::string line;
for(int i = 0; i < line_number; i++)
{
getline(infile, line);
}
getline(infile, line);
int type_number = atoi(line.c_str());
if (type_number %16 == 1)
{
infile.close();
monster_count++;
return 0;
}
else if(type_number %16 == 2)
{
infile.close();
spell_count++;
return 1;
}
else
{
infile.close();
trap_count++;
return 2;
}
}
/*reads deck.txt file, adds the cards' names to the main list widget,
*and finds the type distribution
*/
void read_deck
(const QString &fileName
) {
list_sizes[0] = 0;
list_sizes[1] = 0;
list_sizes[2] = 0;
monster_count = 0;
spell_count = 0;
trap_count = 0;
current_file = fileName;
std::string current_card;
std::ifstream infile("filename.txt");
int passed_main = 0;
std::string line;
while(std::getline(infile, line))
{
if(line == "#main")
{
passed_main++;
}
else if(line == "#extra")
{
passed_main++;
}
else if(passed_main == 1)
{
current_card = read_name(line);
current_card_q
= QString::fromUtf8(current_card.
c_str());
new_item->setText((current_card_q));
mn_lst->QListWidget::addItem(new_item);
list_sizes[0]++;
read_type(current_card);
}
}
}
void refresh_deck()
{
{
read_deck(current_file);
}
}
void MainWindow::create_actions()
{
readAction
= new QAction(tr
("Read new deck"),
this);
QObject::connect(readAction,
SIGNAL(triggered
()),
this,
SLOT(read_deck
(const QString &fileName
)));
refreshAction
= new QAction(tr
("Reload current deck"),
this);
QObject::connect(refreshAction,
SIGNAL(triggered
()),
this,
SLOT(refresh_deck
()));
saveAction
= new QAction(tr
("Save results to file"),
this);
QObject::connect(saveAction,
SIGNAL(triggered
()),
this,
SLOT(save_analysis
()));
analyzeAction
= new QAction(tr
("Perform deck analysis"),
this);
QObject::connect(analyzeAction,
SIGNAL(triggered
()),
this,
SLOT(analyze_deck
()));
QObject::connect(exitAction,
SIGNAL(triggered
()),
qApp,
SLOT(quit
()));
}
void MainWindow::createV_bx_rslt()
{
v_rslt_p->QVBoxLayout::addWidget(rslt_lst);
for(int i = 0; i < 10; i++)
{
rslt_lst->addItem(items_a[i]);
}
items_a[0]->setText(tr("Probability of starting with no Monster cards"));
//items_a[1]->setText((""));
items_a[2]->setText(tr("Probability of starting with no Spell cards"));
//items_a[3]->setText((""));
items_a[4]->setText(("Probability of starting with no trap cards"));
//items_a[5]->setText((""));
items_a[6]->setText(("Probability of starting with a dead hand"));
//items_a[7]->setText((""));
items_a[8]->setText(tr("Probability of at least one key card in opening hand"));
//items_a[9]->setText((""));
}
void MainWindow::createH_bx_lst()
{
h_lst_p->QHBoxLayout::addWidget(btns_a[0]);
h_lst_p->QHBoxLayout::addWidget(btns_a[1]);
}
void MainWindow::createH_bx_bd()
{
h_bd_p->addWidget(btns_a[2]);
h_bd_p->addWidget(btns_a[3]);
}
void MainWindow::createH_bx_gd()
{
h_gd_p->QHBoxLayout::addWidget(btns_a[4]);
h_gd_p->QHBoxLayout::addWidget(btns_a[5]);
}
void MainWindow::createV_bx_lst()
{
v_lst_p->QVBoxLayout::addWidget(mn_lst);
createH_bx_lst();
v_lst_p->QVBoxLayout::addLayout(h_lst_p);
}
void MainWindow::createV_bx_bd()
{
v_bd_p->QVBoxLayout::addWidget(bd_lst);
createH_bx_bd();
v_bd_p->QVBoxLayout::addLayout(h_bd_p);
}
void MainWindow::createV_bx_gd()
{
v_gd_p->QVBoxLayout::addWidget(gd_lst);
createH_bx_gd();
v_gd_p->QVBoxLayout::addLayout(h_gd_p);
}
void MainWindow::create_menu()
{
file = menuBar()->addMenu(tr("&File"));
file->addAction(readAction);
file->addAction(refreshAction);
file->addAction(exitAction);
analyze = menuBar()->addMenu(tr("&Analysis"));
analyze->addAction(analyzeAction);
analyze->addAction(saveAction);
}
void MainWindow::createH_bx_main()
{
createV_bx_lst();
createV_bx_bd();
createV_bx_gd();
createV_bx_rslt();
h_mn_p->QHBoxLayout::addLayout(v_lst_p);
h_mn_p->QHBoxLayout::addLayout(v_bd_p);
h_mn_p->QHBoxLayout::addLayout(v_gd_p);
h_mn_p->QHBoxLayout::addLayout(v_rslt_p);
}
MainWindow::MainWindow()
{
createH_bx_main();
create_actions();
create_menu();
setLayout(h_mn_p);
setWindowTitle(tr("Yu-gi-oh Deck Analyzer: Beware the Monte Carlo Fallacy"));
}
#include "mainwindow.h"
using namespace std;
void save_analysis(const std::string &fileName)
{
}
double nfomf(int n, int m, int k)
{
double answer = 1;
while((n-k+1) <= m)
{
k--;
m--;
}
for(int j = 0; j < k; j++)
{
answer = answer*(n-j)/(m-j);
}
return answer;
}
void analyze_deck()
{
double total_cards = monster_count + spell_count + trap_count;
//no monsters:
double no_m = nfomf(total_cards - monster_count, total_cards,6);
//no spells
double no_s = nfomf(total_cards - spell_count, total_cards,6);
//no traps
double no_t = nfomf(total_cards - trap_count, total_cards,6);
//all bad
double allb = nfomf(total_cards - list_sizes[1], total_cards, 6);
//at least 1 good
double al1g = 1 - nfomf(total_cards - list_sizes[2], total_cards, 6);
QString no_m_s = QString::number(no_m);
QString no_s_s = QString::number(no_s);
QString no_t_s = QString::number(no_t);
QString allb_s = QString::number(allb);
QString al1g_s = QString::number(al1g);
items_a[1]->setText(no_m_s);
items_a[3]->setText(no_s_s);
items_a[5]->setText(no_t_s);
items_a[7]->setText(allb_s);
items_a[9]->setText(al1g_s);
}
/*
*returns the line number of the
* card's id number.
*/
int read_number(const std::string idnum)
{
int iter = 0;
std::ifstream infile(".../numbers.txt");
std::string line;
while(std::getline(infile, line))
{
if(line == idnum)
{
infile.close();
return iter;
iter++;
}
}
infile.close();
return 0;
}
/*
*returns the name of the card with the
*id number.
*/
std::string read_name(const std::string idnum)
{
int line_number = read_number(idnum);
std::ifstream infile(".../names");
std::string line;
for(int i = 0; i < line_number; i++)
{
getline(infile, line);
}
infile.close();
getline(infile, line);
return line;
}
/*
*returns the type of the card, and writes overall
*balance to vector ctd.
*/
int read_type(const std::string idnum)
{
int line_number = read_number(idnum);
std::ifstream infile("...types.txt");
std::string line;
for(int i = 0; i < line_number; i++)
{
getline(infile, line);
}
getline(infile, line);
int type_number = atoi(line.c_str());
if (type_number %16 == 1)
{
infile.close();
monster_count++;
return 0;
}
else if(type_number %16 == 2)
{
infile.close();
spell_count++;
return 1;
}
else
{
infile.close();
trap_count++;
return 2;
}
}
/*reads deck.txt file, adds the cards' names to the main list widget,
*and finds the type distribution
*/
void read_deck(const QString &fileName)
{
list_sizes[0] = 0;
list_sizes[1] = 0;
list_sizes[2] = 0;
monster_count = 0;
spell_count = 0;
trap_count = 0;
current_file = fileName;
std::string current_card;
QString current_card_q;
std::ifstream infile("filename.txt");
int passed_main = 0;
std::string line;
while(std::getline(infile, line))
{
if(line == "#main")
{
passed_main++;
}
else if(line == "#extra")
{
passed_main++;
}
else if(passed_main == 1)
{
current_card = read_name(line);
current_card_q = QString::fromUtf8(current_card.c_str());
QListWidgetItem *new_item = new QListWidgetItem;
new_item->setText((current_card_q));
mn_lst->QListWidget::addItem(new_item);
list_sizes[0]++;
read_type(current_card);
}
}
}
void refresh_deck()
{
{
read_deck(current_file);
}
}
void MainWindow::create_actions()
{
readAction = new QAction(tr("Read new deck"), this);
QObject::connect(readAction, SIGNAL(triggered()), this, SLOT(read_deck(const QString &fileName)));
refreshAction = new QAction(tr("Reload current deck"), this);
QObject::connect(refreshAction, SIGNAL(triggered()), this, SLOT(refresh_deck()));
saveAction = new QAction(tr("Save results to file"), this);
QObject::connect(saveAction, SIGNAL(triggered()), this, SLOT(save_analysis()));
analyzeAction = new QAction(tr("Perform deck analysis"), this);
QObject::connect(analyzeAction, SIGNAL(triggered()), this, SLOT(analyze_deck()));
QObject::connect(exitAction,SIGNAL(triggered()), qApp, SLOT(quit()));
}
void MainWindow::createV_bx_rslt()
{
v_rslt_p = new QVBoxLayout;
QListWidget *rslt_lst = new QListWidget(this);
v_rslt_p->QVBoxLayout::addWidget(rslt_lst);
for(int i = 0; i < 10; i++)
{
items_a[i] = new QListWidgetItem;
rslt_lst->addItem(items_a[i]);
}
items_a[0]->setText(tr("Probability of starting with no Monster cards"));
//items_a[1]->setText((""));
items_a[2]->setText(tr("Probability of starting with no Spell cards"));
//items_a[3]->setText((""));
items_a[4]->setText(("Probability of starting with no trap cards"));
//items_a[5]->setText((""));
items_a[6]->setText(("Probability of starting with a dead hand"));
//items_a[7]->setText((""));
items_a[8]->setText(tr("Probability of at least one key card in opening hand"));
//items_a[9]->setText((""));
}
void MainWindow::createH_bx_lst()
{
h_lst_p = new QHBoxLayout;
btns_a[0] = new QPushButton(tr("To &Bad"));
btns_a[1] = new QPushButton(tr("To &Good"));
h_lst_p->QHBoxLayout::addWidget(btns_a[0]);
h_lst_p->QHBoxLayout::addWidget(btns_a[1]);
}
void MainWindow::createH_bx_bd()
{
h_bd_p = new QHBoxLayout;
btns_a[2] = new QPushButton(tr("To &Main"), this);
btns_a[3] = new QPushButton(tr("To &Good"), this);
h_bd_p->addWidget(btns_a[2]);
h_bd_p->addWidget(btns_a[3]);
}
void MainWindow::createH_bx_gd()
{
h_gd_p = new QHBoxLayout;
btns_a[5] = new QPushButton(tr("To &Deleterious"));
btns_a[4] = new QPushButton(tr("To &Main"));
h_gd_p->QHBoxLayout::addWidget(btns_a[4]);
h_gd_p->QHBoxLayout::addWidget(btns_a[5]);
}
void MainWindow::createV_bx_lst()
{
v_lst_p = new QVBoxLayout;
QListWidget *mn_lst = new QListWidget(this);
v_lst_p->QVBoxLayout::addWidget(mn_lst);
createH_bx_lst();
v_lst_p->QVBoxLayout::addLayout(h_lst_p);
}
void MainWindow::createV_bx_bd()
{
v_bd_p = new QVBoxLayout;
QListWidget *bd_lst = new QListWidget(this);
v_bd_p->QVBoxLayout::addWidget(bd_lst);
createH_bx_bd();
v_bd_p->QVBoxLayout::addLayout(h_bd_p);
}
void MainWindow::createV_bx_gd()
{
v_gd_p = new QVBoxLayout;
QListWidget *gd_lst = new QListWidget(this);
v_gd_p->QVBoxLayout::addWidget(gd_lst);
createH_bx_gd();
v_gd_p->QVBoxLayout::addLayout(h_gd_p);
}
void MainWindow::create_menu()
{
file = menuBar()->addMenu(tr("&File"));
file->addAction(readAction);
file->addAction(refreshAction);
file->addAction(exitAction);
analyze = menuBar()->addMenu(tr("&Analysis"));
analyze->addAction(analyzeAction);
analyze->addAction(saveAction);
}
void MainWindow::createH_bx_main()
{
createV_bx_lst();
createV_bx_bd();
createV_bx_gd();
createV_bx_rslt();
QHBoxLayout *h_mn_p = new QHBoxLayout;
h_mn_p->QHBoxLayout::addLayout(v_lst_p);
h_mn_p->QHBoxLayout::addLayout(v_bd_p);
h_mn_p->QHBoxLayout::addLayout(v_gd_p);
h_mn_p->QHBoxLayout::addLayout(v_rslt_p);
}
MainWindow::MainWindow()
{
createH_bx_main();
create_actions();
create_menu();
setLayout(h_mn_p);
setWindowTitle(tr("Yu-gi-oh Deck Analyzer: Beware the Monte Carlo Fallacy"));
}
To copy to clipboard, switch view to plain text mode
Bookmarks