Skip to content
Snippets Groups Projects
Commit 94cc3750 authored by TheHresvelgian's avatar TheHresvelgian
Browse files

Organizing code

parent 2e96a776
Branches
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
using namespace std; using namespace std;
vector<Player*> playerList; vector<Player*> playerList;
vector<Player*> sortedRankings;
class Tournament class Tournament
......
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
#ifndef CHECKMATE_FUNCTIONS_H #ifndef CHECKMATE_FUNCTIONS_H
#define CHECKMATE_FUNCTIONS_H #define CHECKMATE_FUNCTIONS_H
using namespace std;
void newPlayer(int id); void newPlayer(int id);
void searchByID(int id);
void searchByName(string name);
void sortRanking();
void printRanking();
#endif //CHECKMATE_FUNCTIONS_H #endif //CHECKMATE_FUNCTIONS_H
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
using namespace std; using namespace std;
extern vector<Player*>playerList;
Player::Player() Player::Player()
{ {
firstName = ""; firstName = "";
...@@ -21,9 +23,9 @@ Player::Player() ...@@ -21,9 +23,9 @@ Player::Player()
score = 0.0f; score = 0.0f;
} }
Player::Player(string name, string surName, string clubName, int rating, int playerID, float score) Player::Player(string givenName, string surName, string clubName, int rating, int ID, float currentScore)
{ {
setPlayer(name,surName,clubName,rating,playerID,score); setPlayer(givenName,surName,clubName,rating,ID, currentScore);
} }
void Player::setPlayer(string nm, string srNm, string clbNm, int rtng, int plyrID, float scr) void Player::setPlayer(string nm, string srNm, string clbNm, int rtng, int plyrID, float scr)
...@@ -52,7 +54,13 @@ void Player::printPlayer() ...@@ -52,7 +54,13 @@ void Player::printPlayer()
void Player::calculateScore() void Player::calculateScore()
{ {
float tempScore = 0.0f;
for (int i = 0; i < results.size(); ++i)
{
tempScore += results[i];
}
score = tempScore / 2;
} }
/** /**
...@@ -69,7 +77,7 @@ void Player::writeToFilePlayer(ofstream &out) ...@@ -69,7 +77,7 @@ void Player::writeToFilePlayer(ofstream &out)
<< setw(80) << club << setw(80) << club
<< "\n"; << "\n";
} }
|
/** /**
* Read one player from file * Read one player from file
* *
...@@ -90,3 +98,4 @@ int Player::currentRank(int id) ...@@ -90,3 +98,4 @@ int Player::currentRank(int id)
{ {
} }
...@@ -14,7 +14,8 @@ using namespace std; ...@@ -14,7 +14,8 @@ using namespace std;
class Player class Player
{ {
private: public:
string firstName; string firstName;
string lastName; string lastName;
string club; string club;
...@@ -24,15 +25,14 @@ class Player ...@@ -24,15 +25,14 @@ class Player
float score; float score;
public: vector <int> results; //stores the results of each match, 0 for loss, 1 for draw and 2 for win
vector <int> results;
vector <Player*> playedAgainst; vector <Player*> playedAgainst;
vector<bool> wasWhite; vector<bool> wasWhite;
Player(); Player();
Player(string name, string surName, string clubName, int rating, int playerID, float score); Player(string name, string surName, string clubName, int rating, int playerID, float score);
virtual void setPlayer(string nm, string , string clbNm, int rtng, int plyrID, float score); void setPlayer(string nm, string , string clbNm, int rtng, int plyrID, float score);
virtual void printPlayer(); virtual void printPlayer();
virtual void calculateScore(); virtual void calculateScore();
virtual void writeToFilePlayer(ofstream &out); virtual void writeToFilePlayer(ofstream &out);
......
#include <string> // string
#include <vector> // vector
#include <fstream> // ifstream, ofstream
#include "player.h"
#include "LesData2.h"
#include "functions.h"
using namespace std;
extern vector<Player*>playerList;
extern vector<Player*> sortedRankings;
void printRanking()
{
sortRanking();
float currentScoreTP = sortedRankings[0]->score;
int currentPlace = 1;
for (int i = 0; i < sortedRankings.size(); ++i)
{
if (currentScoreTP > sortedRankings[i]->score)
{
currentScoreTP = sortedRankings[i]->score;
currentPlace++;
}
cout << endl << currentPlace
<< "\t" << sortedRankings[i]->score << "pts"
<< "\t" << sortedRankings[i]->lastName
<< ", " << sortedRankings[i]->firstName;
}
}
\ No newline at end of file
#include <iostream> // cout, cin
#include <string> // STRING-KLASSEN
#include "player.h"
#include "LesData2.h"
#include "functions.h"
void searchByID(int id)
{
}
\ No newline at end of file
#include <iostream> // cout, cin
#include <string> // STRING-KLASSEN
#include "player.h"
#include "LesData2.h"
#include "functions.h"
void searchByName(string name)
{
}
\ No newline at end of file
#include <vector> // vector
#include "player.h"
using namespace std;
extern vector<Player*>playerList;
extern vector<Player*> sortedRankings;
void sortRanking() {
sortedRankings.clear();
float currentHigh;
vector<Player *> listUnsorted = playerList;
vector<Player *> leadingPlayers;
vector<int> listIndex;
do {
for (int i = 0; i < listUnsorted.size(); i++) {
if (listUnsorted[i]->score > currentHigh) {
//listUnsorted[i]->calculateScore();
leadingPlayers.clear();
leadingPlayers.push_back(listUnsorted[i]);
listIndex.push_back(i);
} else if (listUnsorted[i]->score == currentHigh) {
leadingPlayers.push_back(listUnsorted[i]);
}
}
for (int i = 0; i < leadingPlayers.size(); i++) {
sortedRankings.push_back(leadingPlayers[i]);
}
leadingPlayers.clear();
for (int i = 0; i < listIndex.size(); ++i) {
listUnsorted[listIndex[i]] = listUnsorted[listUnsorted.size() - 1];
listUnsorted.pop_back();
}
listIndex.clear();
} while (listUnsorted.size() > 0);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment