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
|
/*
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
*/
#ifndef __SIM__H__
#define __SIM__H__
#include <time.h>
#include "units_info.h"
#define MAX_ROUNDS 6 // количество раундов в битве
// нормализует ресурсы (делает их кратными 100)
#define NORMALIZE_DEBRIS(__x) (((__x)/100)*100)
// структура описывающая игрока
typedef struct
{
int armory, // броня
shield, // щиты
attack, // атака
unit[UNITS_COUNT], // юниты
count; // общее число юнитов
} gamer_info;
// ресурсы
typedef struct
{
int metal, crystal, deut;
} resource;
// структура описывающая задание для симулятора
typedef struct
{
gamer_info attacker; // инфа о первом игроке
gamer_info defender; // инфа о втором игроке
int simulations; // количество симуляций
time_t work_time; // время которое можно считать
int forks_count; // количество параллельных процессов для расчета
resource defender_resource;
} sim_info;
// ресурсы в потерях
typedef struct
{
long long metal, crystal, deut, structure, total;
} debris_resources;
// потери
typedef struct
{
debris_resources fleet, ground, all;
} debris_info;
// потери сведенные в одну структуру
typedef struct
{
long long ldata_begin[0];
debris_info attacker, defender, both;
struct
{
long long fleet, all;
} recyclers; // переработчики
long long ldata_end[0];
int idata_begin[0];
struct
{
int fleet, all;
} moon; // шанс луны
int idata_end[0];
} debris;
// результат симуляции
typedef struct
{
struct
{
int unit[UNITS_COUNT]; // по сколько юнитов выжило
int count; // всего юнитов
long long capacity; // вместимость
} attacker, defender;
debris debris; // общие потери
int who_win; // кто выиграл
int rounds; // количество раундов
resource attacker_plunder; // сколько ресов забрал атакер
struct
{
int small, large;
} chargo; // сколько транспортов треба
} sim_result, * psim_result;
// результат многих симуляций
typedef struct
{
int sim_count; // количество симуляций
sim_info task; // начальное задание симуляции
struct //
{ // среднее количество
double unit[UNITS_COUNT]; // флотов и обломков
long long capacity; // и средняя вместимость
} attacker, defender; //
//
debris debris; //
struct //
{ //
int min, max; //
double average; //
} rounds; // количество раундов
struct
{
int attacker, defender;
} wins; // количество побед
resource attacker_plunder; // среднее количество забранных ресов
struct
{
int small, large;
} chargo; // количество транспортов
sim_result best_attacker, // лучшая симуляция для атакующего
worst_attacker, // худшая симуляция для атакующего
best_defender, // лучшая симуляция для защитника
worst_defender, // худшая симуляция для защитника
max_debris, // симуляция с максимальными обломками
min_debris; // симуляция с минимальными обломками
} sims_result;
enum { NO_WIN, ATTACKER_WIN, DEFENDER_WIN };
sims_result * simulator(const sim_info * sim);
#endif // __SIM__H__
|