Skip to content

Commit

Permalink
changed structure of almost everything + eff fix
Browse files Browse the repository at this point in the history
  • Loading branch information
arnxxau committed May 3, 2022
1 parent 6c24d51 commit 781b3cf
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 220 deletions.
2 changes: 0 additions & 2 deletions BinTree.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

using namespace std;



// A BinTree<T> implements binary trees with values of type T.
template <typename T>
class BinTree {
Expand Down
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
OPCIONS = -D_JUDGE_ -D_GLIBCXX_DEBUG -O2 -Wall -Wextra -Werror -Wno-sign-compare -std=c++11
flags = -D_JUDGE_ -D_GLIBCXX_DEBUG -O2 -Wall -Wextra -Werror -Wno-sign-compare -std=c++11
#
G++ = g++
#
program.exe: program.o player.o tournament.o ranking.o categories.o circuit.o
$(G++) -o program.exe program.o player.o tournament.o ranking.o categories.o circuit.o
g++ -o program.x program.o player.o tournament.o ranking.o categories.o circuit.o
#
program.o: program.cc
$(G++) -c program.cc $(OPCIONS)
g++ -c program.cc $(flags)
#
player.o: player.cc player.hh
$(G++) -c player.cc $(OPCIONS)
g++ -c player.cc $(flags)
#
tournament.o: tournament.cc tournament.hh
$(G++) -c tournament.cc $(OPCIONS)
g++ -c tournament.cc $(flags)
#
ranking.o: ranking.cc ranking.hh
$(G++) -c ranking.cc $(OPCIONS)
g++ -c ranking.cc $(flags)
#
categories.o: categories.cc categories.hh
$(G++) -c categories.cc $(OPCIONS)
g++ -c categories.cc $(flags)
#
circuit.o: circuit.cc circuit.hh
$(G++) -c circuit.cc $(OPCIONS)
g++ -c circuit.cc $(flags)
#
clean:
rm -f *.o
rm -f *.exe
rm -f *.x
6 changes: 3 additions & 3 deletions categories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ void categories::read_categories() {
this -> points_per_level = points_per_level;
}

int categories::get_points(int category, int level) const {
int categories::get_points(const int& category, const int& level) const {
return points_per_level[category - 1][level - 1];
}

std::string categories::get_name(int category) const {
std::string categories::get_name(const int& category) const {
return names[category - 1];
}

Expand All @@ -40,7 +40,7 @@ int categories::get_max_lvl() const {
}


void categories::print_categories(){
void categories::print_categories() const{
for (int i = 0; i < max_categories; ++i) {
std::cout << names[i];
for (int j = 0; j < max_lvl; ++j)
Expand Down
6 changes: 3 additions & 3 deletions categories.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public:
\pre <em>cierto</em>
\post Retorna los puntos que hay que sumar al jugador en función de la categoría y el nivel introducidos.
*/
int get_points(int category, int level) const;
int get_points(const int& category, const int& level) const;

/** @brief Consultora para el nombre de la categoría.
\pre El entero debe existir entre 1 y max_categories.
\post Retorna el nombre de la categoría introducida.
*/
std::string get_name(int category) const;
std::string get_name(const int& category) const;

/** @brief Consultora para el nivel de un nombre de una categoría.
Expand Down Expand Up @@ -80,7 +80,7 @@ public:
\pre <em>cierto</em>
\post Se habrán imprimido los datos por pantalla.
*/
void print_categories();
void print_categories() const;
};

#endif
36 changes: 4 additions & 32 deletions circuit.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#include "circuit.hh"

circuit::circuit(categories cat) {
this -> cat = cat;
}
circuit::circuit() {}

void circuit::read_tournaments() {
cin >> n_tournaments;
string name;
int level;
for (int i = 0; i < n_tournaments; ++i) {
cin >> name >> level;
tournament tour(name, level, cat);
tournament tour(name, level);
tournaments.insert(make_pair(name, tour));
}
}
Expand All @@ -33,11 +31,11 @@ int circuit::get_n_tournaments() const {
return n_tournaments;
}

void circuit::print_tournaments() {
void circuit::print_tournaments(const categories& c) const {
std::cout << n_tournaments << std::endl;
map<std::string, tournament>::const_iterator it = tournaments.begin();
while (it != tournaments.end()) {
it -> second.print_tournament();
it -> second.print_tournament(c);
++it;
}

Expand All @@ -46,29 +44,3 @@ void circuit::print_tournaments() {
bool circuit::exists_tournament(const std::string& name) const {
return tournaments.end() != tournaments.find(name);
}

void circuit::read_players() {
cin >> n_players;
string name;
for (int i = 0; i < n_players; ++i) {
cin >> name;
global_rank.add_player(player(name));
}
}

void circuit::add_player(const player& p) {
global_rank.add_player(p);
++n_players;
}

void circuit::remove_player(const std::string& name) {
global_rank.remove_player(name);
}

ranking circuit::get_global_ranking() {
return global_rank;
}

categories circuit::get_categories() {
return cat;
}
47 changes: 4 additions & 43 deletions circuit.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
class circuit
{
private:
int n_players = 0, n_tournaments = 0; // n_players -> P, n_tournaments -> T
map<std::string, tournament> tournaments;
ranking global_rank;
categories cat;
int n_tournaments = 0; // n_players -> P
std::map<std::string, tournament> tournaments;

public:

Expand All @@ -33,7 +31,7 @@ public:
\pre <em>cierto<em>
\post El resultado es un circuito vacio con las categorías introducidas.
*/
circuit(categories cat);
circuit();

// tournaments

Expand Down Expand Up @@ -77,51 +75,14 @@ public:
\pre <em>cierto</em>
\post Se habrán imprimido todos los torneos del circuito.
*/
void print_tournaments();
void print_tournaments(const categories& c) const;

/** @brief Operación de consulta para la disponibilidad de torneos.
\pre <em>cierto</em>
\post Devuelve verdadero si ya existe previamente el torneo en el circuito, y en el caso contrario, falso.
*/
bool exists_tournament(const std::string& name) const;

// players

/** @brief Operación de lectura para jugadores.
\pre P es mayor o igual a 0.
\post El resultado es un ranking con los jugadores leídos.
*/
void read_players();

/** @brief Operación de añadido para jugadores. Usa esencialmente las operaciones de ranking.
\pre El jugador no existe en la lista.
\post El resultado es el mismo ranking pero con el jugador nuevo añadido en la última posición y n_players + 1
*/
void add_player(const player& p);

/** @brief Operación de borrado para jugadores. Usa esencialmente las operaciones de ranking.
\pre El jugador existe en la lista.
\post El resultado es el mismo ranking pero sin el jugador implícito y n_players - 1. Consultar la clase ranking para un mayor detalle.
*/
void remove_player(const std::string& name);

/** @brief Operación de consulta.
\pre <em>cierto</em>
\post Retorna el ranking global del circuito.
*/
ranking get_global_ranking();

/** @brief Operación de consulta.
\pre <em>cierto</em>
\post Retorna las categorías del circuito.
*/
categories get_categories();
};

#endif
20 changes: 7 additions & 13 deletions player.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "player.hh"

player::player(std::string name) {
player::player(const std::string name, const int& rank_pos) {
this -> name = name;
this -> rank_pos = rank_pos;
}

std::string player::get_name() const {
Expand Down Expand Up @@ -44,16 +45,9 @@ void player::modify_total_points(int points) {
}

void player::print_player() const {
std::cout << name << " Rk:" << rank_pos << " Ps:" << total_points << " Ts:" << player_stats.played_tours << " WM:" << player_stats.matches_won_lost.first
<< " LM:" << player_stats.matches_won_lost.second << " WS:" << player_stats.sets_won_lost.first << " LS:" <<
player_stats.sets_won_lost.second << " WG:" << player_stats.games_won_lost.first << " LG:" <<
player_stats.games_won_lost.second << std::endl;
/*
std::cout << "games won and lost -> " << player_stats.games_won_lost.first
<< player_stats.games_won_lost.second << std::endl;
std::cout << "sets won and lost -> " << player_stats.sets_won_lost.first
<< player_stats.sets_won_lost.second << std::endl;
std::cout << "matches won and lost -> " << player_stats.matches_won_lost.first
<< player_stats.matches_won_lost.second << std::endl;
*/
std::cout << name << " Rk:" << rank_pos << " Ps:" << total_points
<< " Ts:" << player_stats.played_tours << " WM:" << player_stats.matches_won_lost.first
<< " LM:" << player_stats.matches_won_lost.second << " WS:" << player_stats.sets_won_lost.first
<< " LS:" << player_stats.sets_won_lost.second << " WG:" << player_stats.games_won_lost.first
<< " LG:" << player_stats.games_won_lost.second << std::endl;
}
3 changes: 1 addition & 2 deletions player.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define AKIRA_PLAYER_HH

#ifndef NO_DIAGRAM
#include <string>
#include <iostream>
#endif

Expand Down Expand Up @@ -37,7 +36,7 @@ public:
\pre <em>cierto</em>
\post El resultado es un jugador con 0 puntos iniciales, todas las estadísticas a 0 junto con su correspondiente nombre.
*/
player(std::string name);
player(const std::string name, const int& rank_pos);


/** @brief Modificadora de posición en el rango global.
Expand Down
Loading

0 comments on commit 781b3cf

Please sign in to comment.