1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/*
Copyright (C) by Dmitry E. Oboukhov 2006, 2007
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this package; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include "report.h"
#ifdef __WIN32__
#define LPF "%I64d"
#else
#define LPF "%lld"
#endif
//===================================================================
// печатает флоты атакующего и защитника
//===================================================================
static void print_fleets(const int *attacker, const int *defender)
{
int i;
printf("\tAttacker\n");
for (i=0; i<UNITS_COUNT; i++)
{
if (attacker[i])
printf("\t\t%20s: %d\n", units[i].name, attacker[i]);
}
printf("\tDefender\n");
for (i=0; i<UNITS_COUNT; i++)
{
if (defender[i])
printf("\t\t%20s: %d\n", units[i].name, defender[i]);
}
}
//===================================================================
// печатает флоты атакующего и защитника (по результатам симуляции)
//===================================================================
static void print_fleets_result(const sim_result * sr)
{
print_fleets(sr->attacker.unit, sr->defender.unit);
}
//===================================================================
// Печатает результаты симуляции (задание)
//===================================================================
static void print_simulate_task(const sim_info * sim,
const char *title, int print_resources)
{
int i;
printf("\n[%s]\n", title);
print_fleets(sim->attacker.unit, sim->defender.unit);
if (print_resources)
{
printf("\n\t\t%20s: %d\n", "Defender metal",
sim->defender_resource.metal);
printf("\t\t%20s: %d\n", "Defender crystal",
sim->defender_resource.crystal);
printf("\t\t%20s: %d\n", "Defender deut",
sim->defender_resource.deut);
}
}
//===================================================================
// печатает средний результат
//===================================================================
static void print_average(const sims_result * sr)
{
int i;
printf("\n[Average simulation]\n\tAttacker\n");
for (i=0; i<UNITS_COUNT; i++)
{
if (sr->task.attacker.unit[i])
{
printf("\t\t%20s: %-8.2lf\n",
units[i].name, sr->attacker.unit[i]);
}
}
printf("\tDefender\n");
for (i=0; i<UNITS_COUNT; i++)
{
if (sr->task.defender.unit[i])
{
printf("\t\t%20s: %-8.2lf\n",
units[i].name, sr->defender.unit[i]);
}
}
printf("\n[Average capacity after combat]\n");
printf("Attacker: " LPF "\nDefender: " LPF "\n",
sr->attacker.capacity, sr->defender.capacity);
resource max_res=sr->task.defender_resource;
max_res.metal>>=1; max_res.crystal>>=1; max_res.deut>>=1;
int max_total=max_res.metal+max_res.crystal+max_res.deut;
int total=sr->attacker_plunder.metal+
sr->attacker_plunder.crystal+sr->attacker_plunder.deut;
printf("\n[Attacker plunder]\n");
printf(
" Metal: %10d (%3d%%)\n"
"Crystal: %10d (%3d%%)\n"
" Deut: %10d (%3d%%)\n"
" Total: %10d (%3d%%)\n"
"Needed Small chargo: %d\n"
"Needed Large chargo: %d\n",
sr->attacker_plunder.metal,
max_res.metal?sr->attacker_plunder.metal*100/max_res.metal:100,
sr->attacker_plunder.crystal,
max_res.crystal?sr->attacker_plunder.crystal*100/max_res.crystal:100,
sr->attacker_plunder.deut,
max_res.deut?sr->attacker_plunder.deut*100/max_res.deut:100,
total, max_total?total*100/max_total:100,
sr->chargo.small, sr->chargo.large);
}
//===================================================================
// печатает инфу о потерях
//===================================================================
static void print_debris(const debris *dbr,
const char *title)
{
printf("\n[%s]\n", title);
printf(
"Attacker loss: metal=" LPF " crystal=" LPF " deuterium=" LPF "\n"
"Defender loss: metal=" LPF " crystal=" LPF " deuterium=" LPF "\n"
"Common loss: metal=" LPF " crystal=" LPF " deuterium=" LPF "\n\n"
"Debris with ground: metal=" LPF " crystal=" LPF "\n"
"Debris without ground: metal=" LPF " crystal=" LPF "\n",
dbr->attacker.all.metal, dbr->attacker.all.crystal, dbr->attacker.all.deut,
dbr->defender.all.metal, dbr->defender.all.crystal, dbr->defender.all.deut,
dbr->both.all.metal, dbr->both.all.crystal, dbr->both.all.deut,
NORMALIZE_DEBRIS(dbr->both.all.metal*30/100),
NORMALIZE_DEBRIS(dbr->both.all.crystal*30/100),
NORMALIZE_DEBRIS(dbr->both.fleet.metal*30/100),
NORMALIZE_DEBRIS(dbr->both.fleet.crystal*30/100)
);
printf(
"Recyclers with ground: " LPF
"\nRecyclers without ground: " LPF "\n",
dbr->recyclers.all, dbr->recyclers.fleet);
printf(
"Chance moon with ground: %d%%\n"
"Chance moon without ground: %d%%\n",
dbr->moon.all, dbr->moon.fleet);
}
//===================================================================
// печатает результаты симуляции
//===================================================================
void print_report(const sims_result *sr)
{
print_simulate_task(&sr->task, "Simulate task", 1);
printf("\n[Simulate info]\n");
printf("Rounds: %1.2lf (%d, %d)\n",
sr->rounds.average, sr->rounds.min, sr->rounds.max);
printf("Simulations: %d\n", sr->sim_count);
printf("Attacker win: %d/%d (%d%%)\n",
sr->wins.attacker,
sr->sim_count,
100*sr->wins.attacker/sr->sim_count);
printf("Defender win: %d/%d (%d%%)\n",
sr->wins.defender,
sr->sim_count,
100*sr->wins.defender/sr->sim_count);
printf("\n[Best attacker]\n");
print_fleets_result(&sr->best_attacker);
printf("\n[Worst attacker]\n");
print_fleets_result(&sr->worst_attacker);
printf("\n[Best defender]\n");
print_fleets_result(&sr->best_defender);
printf("\n[Worst defender]\n");
print_fleets_result(&sr->worst_defender);
print_debris(&sr->debris, "Average debris");
print_debris(&sr->min_debris.debris, "Minimum debris");
print_debris(&sr->max_debris.debris, "Maximum debris");
print_average(sr);
}
//===================================================================
|