Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created January 3, 2022 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/db366e6bef991a386d01a58dcae1fdc9 to your computer and use it in GitHub Desktop.
Save parzibyte/db366e6bef991a386d01a58dcae1fdc9 to your computer and use it in GitHub Desktop.
EstadisticasDeJugador obtener_estadisticas(string nick)
{
EstadisticasDeJugador estadisticas;
estadisticas.empates = 0;
estadisticas.partidas_ganadas = 0;
estadisticas.partidas_perdidas = 0;
estadisticas.total_movimientos = 0;
ifstream archivo(nombre_archivo_resultados(nick).c_str());
string linea, resultado, movimientos;
while (getline(archivo, linea))
{
stringstream input_stringstream(linea);
getline(input_stringstream, resultado, DELIMITADOR_RESULTADOS);
getline(input_stringstream, movimientos, DELIMITADOR_RESULTADOS);
if (resultado == RESULTADO_EMPATE)
{
estadisticas.empates++;
}
else if (resultado == RESULTADO_GANA)
{
estadisticas.partidas_ganadas++;
}
else if (resultado == RESULTADO_PIERDE)
{
estadisticas.partidas_perdidas++;
}
estadisticas.total_movimientos += atoi(movimientos.c_str());
}
double total_partidas = estadisticas.partidas_ganadas + estadisticas.partidas_perdidas + estadisticas.empates;
estadisticas.porcentaje_ganadas = (estadisticas.partidas_ganadas * 100) / total_partidas;
estadisticas.porcentaje_perdidas = (estadisticas.partidas_perdidas * 100) / total_partidas;
estadisticas.porcentaje_empatadas = (estadisticas.empates * 100) / total_partidas;
estadisticas.promedio_movimientos = estadisticas.total_movimientos / total_partidas;
return estadisticas;
}
void ver_estadisticas(string nick)
{
EstadisticasDeJugador estadisticas = obtener_estadisticas(nick);
cout << "Mostrando estadisticas para " << nick << "\n";
cout << "Porcentaje de partidas ganadas: " << estadisticas.porcentaje_ganadas << " %\n";
cout << "Porcentaje de partidas perdidas: " << estadisticas.porcentaje_perdidas << " %\n";
cout << "Porcentaje de partidas empatadas: " << estadisticas.porcentaje_empatadas << " %\n";
cout << "Promedio de movimientos " << estadisticas.promedio_movimientos << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment