fork/slippc

git clone https://git.julia.blue/fork/slippc

Patrick CrainFixed GALINT computation error; added stats for damage done during each neutral interaction27331b7

0.4.0
9.8 KiB170 linesraw
1#include "analysis.h"
2
3//JSON Output shortcuts
4#define JFLT(i,k,n) SPACE[ILEV*(i)] << "\"" << (k) << "\" : " << float(n)
5#define JINT(i,k,n) SPACE[ILEV*(i)] << "\"" << (k) << "\" : " << int32_t(n)
6#define JUIN(i,k,n) SPACE[ILEV*(i)] << "\"" << (k) << "\" : " << uint32_t(n)
7#define JSTR(i,k,s) SPACE[ILEV*(i)] << "\"" << (k) << "\" : \"" << (s) << "\""
8#define JEND(a) ((a++ == 0) ? "\n" : ",\n")
9
10namespace slip {
11
12std::string Analysis::asJson() {
13  std::stringstream ss;
14  ss << "{" << std::endl;
15
16  ss << JSTR(0,"slippi_version",   slippi_version)  << ",\n";
17  ss << JSTR(0,"parser_version",   parser_version)  << ",\n";
18  ss << JSTR(0,"analyzer_version", analyzer_version)<< ",\n";
19  ss << JSTR(0,"game_time",        game_time)       << ",\n";
20  ss << JUIN(0,"stage_id",         stage_id)        << ",\n";
21  ss << JSTR(0,"stage_name",       stage_name)      << ",\n";
22  ss << JUIN(0,"game_length",      game_length)     << ",\n";
23
24  ss << "\"players\" : [\n";
25  for(unsigned p = 0; p < 2; ++p) {
26    ss << SPACE[ILEV] << "{\n";
27
28    ss << JUIN(1,"port",                   ap[p].port)                      << ",\n";
29    ss << JSTR(1,"tag_player",             escape_json(ap[p].tag_player))   << ",\n";
30    ss << JSTR(1,"tag_css",                escape_json(ap[p].tag_css))      << ",\n";
31    ss << JUIN(1,"char_id",                ap[p].char_id)                   << ",\n";
32    ss << JSTR(1,"char_name",              ap[p].char_name)                 << ",\n";
33    ss << JUIN(1,"player_type" ,           ap[p].player_type)               << ",\n";
34    ss << JUIN(1,"cpu_level" ,             ap[p].cpu_level)                 << ",\n";
35    ss << JUIN(1,"color"       ,           ap[p].color)                     << ",\n";
36    ss << JUIN(1,"team_id"     ,           ap[p].team_id)                   << ",\n";
37    ss << JUIN(1,"start_stocks",           ap[p].start_stocks)              << ",\n";
38    ss << JUIN(1,"end_stocks",             ap[p].end_stocks)                << ",\n";
39    ss << JUIN(1,"end_pct",                ap[p].end_pct)                   << ",\n";
40
41    ss << JUIN(1,"airdodges",              ap[p].airdodges)                 << ",\n";
42    ss << JUIN(1,"spotdodges",             ap[p].spotdodges)                << ",\n";
43    ss << JUIN(1,"rolls",                  ap[p].rolls)                     << ",\n";
44    ss << JUIN(1,"dashdances",             ap[p].dashdances)                << ",\n";
45    ss << JUIN(1,"l_cancels_hit",          ap[p].l_cancels_hit)             << ",\n";
46    ss << JUIN(1,"l_cancels_missed",       ap[p].l_cancels_missed)          << ",\n";
47    ss << JUIN(1,"techs",                  ap[p].techs)                     << ",\n";
48    ss << JUIN(1,"walltechs",              ap[p].walltechs)                 << ",\n";
49    ss << JUIN(1,"walljumps",              ap[p].walljumps)                 << ",\n";
50    ss << JUIN(1,"walltechjumps",          ap[p].walltechjumps)             << ",\n";
51    ss << JUIN(1,"missed_techs",           ap[p].missed_techs)              << ",\n";
52    ss << JUIN(1,"ledge_grabs",            ap[p].ledge_grabs)               << ",\n";
53    ss << JUIN(1,"air_frames",             ap[p].air_frames)                << ",\n";
54    ss << JUIN(1,"wavedashes",             ap[p].wavedashes)                << ",\n";
55    ss << JUIN(1,"wavelands",              ap[p].wavelands)                 << ",\n";
56    ss << JUIN(1,"neutral_wins",           ap[p].neutral_wins)              << ",\n";
57    ss << JUIN(1,"pokes",                  ap[p].pokes)                     << ",\n";
58    ss << JUIN(1,"counters",               ap[p].counters)                  << ",\n";
59    ss << JUIN(1,"powershields",           ap[p].powershields)              << ",\n";
60    ss << JUIN(1,"shield_breaks",          ap[p].shield_breaks)             << ",\n";
61    ss << JUIN(1,"grabs",                  ap[p].grabs)                     << ",\n";
62    ss << JUIN(1,"grab_escapes",           ap[p].grab_escapes)              << ",\n";
63    ss << JUIN(1,"taunts",                 ap[p].taunts)                    << ",\n";
64    ss << JUIN(1,"meteor_cancels",         ap[p].meteor_cancels)            << ",\n";
65    ss << JFLT(1,"damage_dealt",           ap[p].damage_dealt)              << ",\n";
66    ss << JUIN(1,"hits_blocked",           ap[p].hits_blocked)              << ",\n";
67    ss << JUIN(1,"shield_stabs",           ap[p].shield_stabs)              << ",\n";
68    ss << JUIN(1,"edge_cancel_aerials",    ap[p].edge_cancel_aerials)       << ",\n";
69    ss << JUIN(1,"edge_cancel_specials",   ap[p].edge_cancel_specials)      << ",\n";
70    ss << JUIN(1,"teeter_cancel_aerials",  ap[p].teeter_cancel_aerials)     << ",\n";
71    ss << JUIN(1,"teeter_cancel_specials", ap[p].teeter_cancel_specials)    << ",\n";
72    ss << JUIN(1,"phantom_hits",           ap[p].phantom_hits)              << ",\n";
73    ss << JUIN(1,"no_impact_lands",        ap[p].no_impact_lands)           << ",\n";
74    ss << JUIN(1,"shield_drops",           ap[p].shield_drops)              << ",\n";
75    ss << JUIN(1,"pivots",                 ap[p].pivots)                    << ",\n";
76    ss << JUIN(1,"reverse_edgeguards",     ap[p].reverse_edgeguards)        << ",\n";
77    ss << JUIN(1,"self_destructs",         ap[p].self_destructs)            << ",\n";
78    ss << JUIN(1,"stage_spikes",           ap[p].stage_spikes)              << ",\n";
79    ss << JUIN(1,"short_hops",             ap[p].short_hops)                << ",\n";
80    ss << JUIN(1,"full_hops",              ap[p].full_hops)                 << ",\n";
81    ss << JUIN(1,"shield_time",            ap[p].shield_time)               << ",\n";
82    ss << JFLT(1,"shield_damage",          ap[p].shield_damage)             << ",\n";
83    ss << JFLT(1,"shield_lowest",          ap[p].shield_lowest)             << ",\n";
84    ss << JUIN(1,"total_openings",         ap[p].total_openings)            << ",\n";
85    ss << JFLT(1,"mean_kill_openings",     ap[p].mean_kill_openings)        << ",\n";
86    ss << JFLT(1,"mean_kill_percent",      ap[p].mean_kill_percent)         << ",\n";
87    ss << JFLT(1,"mean_opening_percent",   ap[p].mean_opening_percent)      << ",\n";
88    ss << JUIN(1,"galint_ledgedashes",     ap[p].galint_ledgedashes)        << ",\n";
89    ss << JFLT(1,"mean_galint",            ap[p].mean_galint)               << ",\n";
90
91    ss << SPACE[ILEV] << "\"interaction_frames\" : {\n";
92    for(unsigned d = Dynamic::__LAST-1; d > 0; --d) {
93      ss << JUIN(2,Dynamic::name[d], ap[p].dyn_counts[d]) << ((d == 1) ? "\n" : ",\n");
94    }
95    ss << SPACE[ILEV] << "},\n";
96
97    ss << SPACE[ILEV] << "\"interaction_damage\" : {\n";
98    for(unsigned d = Dynamic::__LAST-1; d > 0; --d) {
99      ss << JFLT(2,Dynamic::name[d], ap[p].dyn_damage[d]) << ((d == 1) ? "\n" : ",\n");
100    }
101    ss << SPACE[ILEV] << "},\n";
102
103    ss << SPACE[ILEV] << "\"moves_landed\" : {\n";
104    unsigned _total_moves = 0;
105    for(unsigned d = 0; d < Move::__LAST; ++d) {
106      if ((ap[p].move_counts[d]) > 0) {
107        ss << JUIN(2,Move::name[d], ap[p].move_counts[d]) << ",\n";
108        _total_moves += ap[p].move_counts[d];
109      }
110    }
111    ss << JUIN(2,"_total", _total_moves) << "\n";
112    ss << SPACE[ILEV] << "},\n";
113
114    ss << SPACE[ILEV] << "\"attacks\" : [\n";
115    // move_id
116    // anim_frame
117    // punish_id
118    // frame
119    // damage
120    // opening
121    // kill_dir
122    for(unsigned i = 0; ap[p].attacks[i].frame > 0; ++i) {
123      ss << SPACE[2*ILEV] << "{" << std::endl;
124      ss << JUIN(2,"move_id",         ap[p].attacks[i].move_id)                        << ",\n";
125      ss << JSTR(2,"move_name",       Move::shortname[ap[p].attacks[i].move_id])       << ",\n";
126      ss << JUIN(2,"cancel_type",     ap[p].attacks[i].cancel_type)                    << ",\n";
127      ss << JSTR(2,"cancel_name",     Cancel::shortname[ap[p].attacks[i].cancel_type]) << ",\n";
128      ss << JUIN(2,"punish_id",       ap[p].attacks[i].punish_id)                      << ",\n";
129      ss << JUIN(2,"hit_id",          ap[p].attacks[i].hit_id)                         << ",\n";
130      ss << JUIN(2,"game_frame",      ap[p].attacks[i].frame)                          << ",\n";
131      ss << JUIN(2,"anim_frame",      ap[p].attacks[i].anim_frame)                     << ",\n";
132      ss << JFLT(2,"damage",          ap[p].attacks[i].damage)                         << ",\n";
133      ss << JSTR(2,"opening",         Dynamic::name[ap[p].attacks[i].opening])         << ",\n";
134      ss << JSTR(2,"kill_dir",        Dir::name[ap[p].attacks[i].kill_dir])            << "\n";
135      ss << SPACE[2*ILEV] << "}" << ((ap[p].attacks[i+1].frame > 0) ? ",\n" : "\n");
136    }
137    ss << SPACE[ILEV] << "],\n";
138
139    ss << SPACE[ILEV] << "\"punishes\" : [\n";
140    for(unsigned i = 0; ap[p].punishes[i].num_moves > 0; ++i) {
141      ss << SPACE[2*ILEV] << "{" << std::endl;
142      ss << JUIN(2,"start_frame",     ap[p].punishes[i].start_frame)                   << ",\n";
143      ss << JUIN(2,"end_frame",       ap[p].punishes[i].end_frame)                     << ",\n";
144      ss << JFLT(2,"start_pct",       ap[p].punishes[i].start_pct)                     << ",\n";
145      ss << JFLT(2,"end_pct",         ap[p].punishes[i].end_pct)                       << ",\n";
146      ss << JUIN(2,"num_moves",       ap[p].punishes[i].num_moves)                     << ",\n";
147      ss << JUIN(2,"last_move_id",    ap[p].punishes[i].last_move_id)                  << ",\n";
148      ss << JSTR(2,"last_move_name",  Move::shortname[ap[p].punishes[i].last_move_id]) << ",\n";
149      ss << JSTR(2,"opening",         "UNUSED")                                        << ",\n";
150      ss << JSTR(2,"kill_dir",        Dir::name[ap[p].punishes[i].kill_dir])           << "\n";
151      ss << SPACE[2*ILEV] << "}" << ((ap[p].punishes[i+1].num_moves > 0) ? ",\n" : "\n");
152    }
153    ss << SPACE[ILEV] << "]\n";
154
155    ss << SPACE[ILEV] << "}" << ( p== 0 ? ",\n" : "\n");
156  }
157  ss << "]\n";
158  ss << "}\n";
159  return ss.str();
160}
161
162void Analysis::save(const char* outfilename) {
163  std::ofstream fout;
164  fout.open(outfilename);
165  std::string j = asJson();
166  fout << j << std::endl;
167  fout.close();
168}
169
170}