fork/slippc
git clone https://git.julia.blue/fork/slippc
70622c9
0.7.0
1#include "analyzer.h" 2 3//Debug output convenience macros 4#define DOUT1 (s ) if (_debug >= 1) { std::cout << s; } 5#define DOUT2 (s ) if (_debug >= 2) { std::cout << s; } 6 7namespace slip { 8 9Analyzer ::Analyzer (int debug_level ) { 10_debug = debug_level ; 11} 12 13Analyzer ::~Analyzer () { 14//Nothing to do yet 15} 16 17bool Analyzer ::get1v1Ports (const SlippiReplay & s ,Analysis * a )const { 18unsigned num_players = 0 ; 19for (uint8_t i = 0 ;i < 4 ;++ i ) { 20if (s .player [i ].player_type != 3 ) { 21if (num_players == 2 ) { 22return false; 23 } 24a -> ap [num_players ++ ].port = i ; 25 } 26if (i == 3 && num_players != 2 ) { 27return false; 28 } 29 } 30DOUT1 ("Players found on ports " <<a -> ap [0 ].port <<" and " <<a -> ap [1 ].port << std::endl ); 31return true; 32} 33 34void Analyzer ::computeAirtime (const SlippiReplay & s ,Analysis * a )const { 35for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 36SlippiPlayer p = s .player [a -> ap [pi ].port ]; 37unsigned airframes = 0 ; 38for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 39airframes += p .frame [f ].airborne ; 40 } 41 42a -> ap [pi ].air_frames = airframes ; 43// float aircount = 100*((float)airframes / s.last_frame); 44// std::cout << " Airborne for " << aircount << "% of match" << std::endl; 45 } 46} 47 48void Analyzer ::getBasicGameInfo (const SlippiReplay & s ,Analysis * a )const { 49a -> original_file = s .original_file ; 50a -> slippi_version = s .slippi_version ; 51a -> parser_version = s .parser_version ; 52a -> analyzer_version = ANALYZER_VERSION ; 53a -> game_time = s .start_time ; 54a -> game_length = s .frame_count ; 55a -> timer = s .timer ; 56a -> ap [0 ].tag_player = s .player [a -> ap [0 ].port ].tag ; 57a -> ap [1 ].tag_player = s .player [a -> ap [1 ].port ].tag ; 58a -> ap [0 ].tag_css = s .player [a -> ap [0 ].port ].tag_css ; 59a -> ap [1 ].tag_css = s .player [a -> ap [1 ].port ].tag_css ; 60a -> ap [0 ].tag_code = s .player [a -> ap [0 ].port ].tag_code ; 61a -> ap [1 ].tag_code = s .player [a -> ap [1 ].port ].tag_code ; 62 63a -> ap [0 ].start_stocks = s .player [a -> ap [0 ].port ].start_stocks ; 64a -> ap [1 ].start_stocks = s .player [a -> ap [1 ].port ].start_stocks ; 65a -> ap [0 ].color = s .player [a -> ap [0 ].port ].color ; 66a -> ap [1 ].color = s .player [a -> ap [1 ].port ].color ; 67a -> ap [0 ].team_id = s .player [a -> ap [0 ].port ].team_id ; 68a -> ap [1 ].team_id = s .player [a -> ap [1 ].port ].team_id ; 69a -> ap [0 ].player_type = s .player [a -> ap [0 ].port ].player_type ; 70a -> ap [1 ].player_type = s .player [a -> ap [1 ].port ].player_type ; 71a -> ap [0 ].cpu_level = s .player [a -> ap [0 ].port ].cpu_level ; 72a -> ap [1 ].cpu_level = s .player [a -> ap [1 ].port ].cpu_level ; 73 74a -> ap [0 ].end_stocks = s .player [a -> ap [0 ].port ].end_stocks ; 75a -> ap [1 ].end_stocks = s .player [a -> ap [1 ].port ].end_stocks ; 76a -> ap [0 ].end_pct = s .player [a -> ap [0 ].port ].frame [s .frame_count - 1 ].percent_pre ; 77a -> ap [1 ].end_pct = s .player [a -> ap [1 ].port ].frame [s .frame_count - 1 ].percent_pre ; 78a -> ap [0 ].char_id = s .player [a -> ap [0 ].port ].ext_char_id ; 79a -> ap [1 ].char_id = s .player [a -> ap [1 ].port ].ext_char_id ; 80a -> stage_id = s .stage ; 81a -> ap [0 ].char_name = CharExt ::name [a -> ap [0 ].char_id ]; 82a -> ap [1 ].char_name = CharExt ::name [a -> ap [1 ].char_id ]; 83a -> stage_name = Stage ::name [s .stage ]; 84a -> winner_port = s .winner_id ; 85} 86 87void Analyzer ::summarizeInteractions (const SlippiReplay & s ,Analysis * a )const { 88// std::cout << " Summarizing player interactions" << std::endl; 89for (unsigned f = (PLAYABLE_FRAME - LOAD_FRAME );f < s .frame_count ;++ f ) { 90unsigned d = a -> dynamics [f ]; 91++ (a -> ap [0 ].dyn_counts [d ]);//Increase the counter for dynamics across all frames 92if (d > Dynamic ::DEFENSIVE && d < Dynamic ::OFFENSIVE ) { 93//Index is the same for the 2nd player for neutral dynamics 94++ (a -> ap [1 ].dyn_counts [d ]); 95 }else { 96//Index is inverted for the 2nd player for non-neutral dynamics 97++ (a -> ap [1 ].dyn_counts [Dynamic ::__LAST - d ]); 98 } 99 } 100// std::cout << std::fixed; //Show floats in fixed representation 101// for (unsigned p = 0; p < 2; ++p) { 102// // std::cout << " From the perspective of port " << int(a->ap[p].port+1) << " (" << a->ap[p].char_name << "):" << std::endl; 103// for (unsigned i = 0; i < Dynamic::__LAST; ++i) { 104// std::string n = std::to_string(a->ap[p].dyn_counts[i]); 105// std::string pct = std::to_string((100*float(a->ap[p].dyn_counts[i])/s.frame_count)).substr(0,5); 106// std::cout << " " << SPACE[6-n.length()] << n << " frames (" << pct 107// << "% of game) spent in " << Dynamic::name[i] << std::endl; 108// } 109// } 110} 111 112void Analyzer ::countLCancels (const SlippiReplay & s ,Analysis * a )const { 113for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 114SlippiPlayer p = s .player [a -> ap [pi ].port ]; 115unsigned cancels_hit = 0 ; 116unsigned cancels_miss = 0 ; 117unsigned last_state = 0 ; 118for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 119if (last_state == 0 ) { 120if (p .frame [f ].l_cancel == 1 ) { 121cancels_hit += 1 ; 122 }else if (p .frame [f ].l_cancel == 2 ) { 123cancels_miss += 1 ; 124 } 125 } 126last_state = p .frame [f ].l_cancel ; 127 } 128 129a -> ap [pi ].l_cancels_hit = cancels_hit ; 130a -> ap [pi ].l_cancels_missed = cancels_miss ; 131float cancels_pct = 100 * ((float )cancels_hit / (cancels_hit + cancels_miss )); 132// std::cout << " Hit " << cancels_hit << "/" << cancels_hit+cancels_miss << " l cancels (" << cancels_pct << "%)" << std::endl; 133 } 134} 135 136void Analyzer ::countButtons (const SlippiReplay & s ,Analysis * a )const { 137for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 138SlippiPlayer p = s .player [a -> ap [pi ].port ]; 139uint16_t last_buttons = 0 ; 140float last_ax = 0 ; 141float last_ay = 0 ; 142float last_cx = 0 ; 143float last_cy = 0 ; 144for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 145// Add buttons pressed this frame to button count 146uint16_t cur_buttons = p .frame [f ].buttons ; 147uint16_t new_buttons = cur_buttons & (cur_buttons ^last_buttons ); 148new_buttons &=0x0F70 ;//Mask out unused bits 149a -> ap [pi ].button_count += countBits (new_buttons ); 150last_buttons = cur_buttons ; 151 152// Check analog stick for movement 153float cur_ax = p .frame [f ].joy_x ; 154float cur_ay = p .frame [f ].joy_y ; 155a -> ap [pi ].astick_count += checkStickMovement (cur_ax ,cur_ay ,last_ax ,last_ay ); 156last_ax = cur_ax ; 157last_ay = cur_ay ; 158 159// Check C stick for movement 160float cur_cx = p .frame [f ].c_x ; 161float cur_cy = p .frame [f ].c_y ; 162a -> ap [pi ].cstick_count += checkStickMovement (cur_cx ,cur_cy ,last_cx ,last_cy ); 163last_cx = cur_cx ; 164last_cy = cur_cy ; 165 } 166 } 167} 168 169void Analyzer ::countTechs (const SlippiReplay & s ,Analysis * a )const { 170for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 171SlippiPlayer p = s .player [a -> ap [pi ].port ]; 172unsigned techs_hit = 0 ; 173unsigned walltechs_hit = 0 ;//And ceiling techs 174unsigned walljumps_hit = 0 ; 175unsigned walljumptechs_hit = 0 ; 176unsigned techs_missed = 0 ; 177bool teching = false; 178 179for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 180if (inTechState (p .frame [f ])) { 181if (notteching ) { 182teching = true; 183if (p .frame [f ].action_pre <=Action ::DownSpotD ) { 184++ techs_missed ; 185 }else if (p .frame [f ].action_pre <=Action ::PassiveStandB ) { 186++ techs_hit ; 187 }else if (p .frame [f ].action_pre == Action ::PassiveWallJump ) { 188if (inDamagedState (p .frame [f - 1 ])|| inTumble (p .frame [f - 1 ])) { 189++ walljumptechs_hit ; 190 }else { 191++ walljumps_hit ; 192 } 193 }else { 194++ walltechs_hit ;//Or ceiling techs 195 } 196 } 197 }else { 198teching = false; 199 } 200 } 201 202a -> ap [pi ].techs = techs_hit ; 203a -> ap [pi ].walltechs = walltechs_hit ; 204a -> ap [pi ].walljumps = walljumps_hit ; 205a -> ap [pi ].walltechjumps = walljumptechs_hit ; 206a -> ap [pi ].missed_techs = techs_missed ; 207 208// std::cout << " Hit " << techs_hit << " grounded techs" << std::endl; 209// std::cout << " Hit " << walltechs_hit << " wall techs" << std::endl; 210// std::cout << " Hit " << walljumps_hit << " wall jumps" << std::endl; 211// std::cout << " Hit " << walljumptechs_hit << " wall jump techs" << std::endl; 212// std::cout << " Missed " << techs_missed << " techs" << std::endl; 213 } 214} 215 216void Analyzer ::countDashdances (const SlippiReplay & s ,Analysis * a )const { 217for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 218SlippiPlayer p = s .player [a -> ap [pi ].port ]; 219unsigned dashdances = 0 ; 220for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 221if (isDashdancing (p ,f )) { 222++ dashdances ; 223 } 224 } 225 226a -> ap [pi ].dashdances = dashdances ; 227// std::cout << " Dashdanced " << dashdances << " times" << std::endl; 228 } 229} 230 231//Code adapted from Fizzi's 232void Analyzer ::countAirdodgesAndWavelands (const SlippiReplay & s ,Analysis * a )const { 233for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 234SlippiPlayer p = s .player [a -> ap [pi ].port ]; 235unsigned airdodges = 0 ; 236unsigned wavelands = 0 ; 237unsigned wavedashes = 0 ; 238bool airdodging = false; 239for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 240if (maybeWavelanding (p ,f )) {//Waveland detection by Fizzi 241//Look at the last 8 frames (including this one) re Fizzi 242bool foundAirdodge = false; 243bool foundJumpsquat = false; 244bool foundOther = false; 245for (unsigned i = 1 ;i < 8 ;++ i ) { 246if (isAirdodging (p .frame [f - i ])) { 247foundAirdodge = true; 248 }else if (isInJumpsquat (p .frame [f - i ])) { 249foundJumpsquat = true; 250break ; 251 }else { 252foundOther = true; 253 } 254 } 255if (foundAirdodge ) { 256if ((notfoundJumpsquat )&& (notfoundOther )) { 257continue ;//If the airdodge is the only animation we found, proceed 258 }else { 259-- airdodges ;//Otherwise, subtract it from our airdodge count and keep checkings 260 } 261 } 262if (foundJumpsquat ) {//If we were in jumpsquat at all recently, we're wavedashing 263++ wavedashes ; 264 }else if (foundOther ) {//If we were in any other animation besides airdodge, it's a waveland 265++ wavelands ; 266 }//Otherwise, nothing special happened 267 }else if (isAirdodging (p .frame [f ])) { 268if (notairdodging ) { 269++ airdodges ; 270airdodging = true; 271 } 272 }else { 273airdodging = false; 274 } 275 } 276 277a -> ap [pi ].airdodges = airdodges ; 278a -> ap [pi ].wavelands = wavelands ; 279a -> ap [pi ].wavedashes = wavedashes ; 280// std::cout << " Airdodged " << airdodges << " times" << std::endl; 281// std::cout << " Wavelanded " << wavelands << " times" << std::endl; 282// std::cout << " Wavedashed " << wavedashes << " times" << std::endl; 283 } 284} 285 286void Analyzer ::analyzeInteractions (const SlippiReplay & s ,Analysis * a )const { 287// std::cout << " Analyzing player interactions" << std::endl; 288const SlippiPlayer * p = & (s .player [a -> ap [0 ].port ]); 289const SlippiPlayer * o = & (s .player [a -> ap [1 ].port ]); 290 291unsigned cur_dynamic = Dynamic ::POSITIONING ;// Current dynamic in effect 292 293unsigned oLastInHitsun = 0 ;//Last frame opponent was stuck in hitstun 294unsigned pLastInHitsun = 0 ;//Last frame we were stuck in hitstun 295unsigned oLastGrounded = 0 ;//Last frame opponent touched solid ground 296unsigned pLastGrounded = 0 ;//Last frame we touched solid ground' 297bool oHitThisFrame = false; 298bool pHitThisFrame = false; 299bool oHitLastFrame = false; 300bool pHitLastFrame = false; 301 302//All interactions analyzed from perspective of p (lower port player) 303for (unsigned f = (PLAYABLE_FRAME - LOAD_FRAME );f < s .frame_count ;++ f ) { 304//Important variables for each frame 305SlippiFrame of = o -> frame [f ]; 306SlippiFrame pf = p -> frame [f ]; 307oHitLastFrame = oHitThisFrame ; 308oHitThisFrame = false; 309bool oInHitstun = isInHitstun (of ); 310if (oInHitstun ) { 311oLastInHitsun = f ; 312if (of .percent_post > o -> frame [f - 1 ].percent_post ) { 313oHitThisFrame = true;//Check if opponent was hit this frame by looking at % last frame 314 } 315 } 316pHitLastFrame = pHitThisFrame ; 317pHitThisFrame = false; 318bool pInHitstun = isInHitstun (pf ); 319if (pInHitstun ) { 320pLastInHitsun = f ; 321if (pf .percent_post > p -> frame [f - 1 ].percent_post ) { 322pHitThisFrame = true;//Check if we were hit this frame by looking at % last frame 323 } 324 } 325bool oAirborne = isAirborne (of ); 326if (notoAirborne ) {oLastGrounded = f ; } 327bool pAirborne = isAirborne (pf ); 328if (notpAirborne ) {pLastGrounded = f ; } 329bool oIsGrabbed = isGrabbed (of ); 330bool pIsGrabbed = isGrabbed (pf ); 331bool oOnLedge = isOnLedge (of ); 332bool pOnLedge = isOnLedge (pf ); 333bool oShielding = isShielding (of ); 334bool pShielding = isShielding (pf ); 335bool oInShieldstun = isInShieldstun (of ); 336bool pInShieldstun = isInShieldstun (pf ); 337bool oTeching = inFloorTechState (of ); 338bool pTeching = inFloorTechState (pf ); 339bool oThrown = isThrown (of ); 340bool pThrown = isThrown (pf ); 341bool oHitOffStage = isOffStage (s ,of )&& oInHitstun ;//Check if opponent is in hitstun offstage 342bool pHitOffStage = isOffStage (s ,pf )&& pInHitstun ;//Check if we are in hitstun offstage 343bool oPoked = ((f - oLastInHitsun )< POKE_THRES );//Check if opponent has been poked recently 344bool pPoked = ((f - pLastInHitsun )< POKE_THRES );//Check if we have been poked recently 345 346//If we're airborne and haven't touched the ground since last entering hitstun, we're being punished 347bool oBeingPunished = oAirborne && (oLastGrounded < oLastInHitsun ); 348bool pBeingPunished = pAirborne && (pLastGrounded < pLastInHitsun ); 349 350//If we also haven't been in hitstun for at least SHARK_THRES frames, we're being sharked 351bool oBeingSharked = oBeingPunished && ((f - oLastInHitsun )> SHARK_THRES ); 352bool pBeingSharked = pBeingPunished && ((f - pLastInHitsun )> SHARK_THRES ); 353 354//Determine whether neutral would be considered footsies or positioning 355// unsigned neut_dyn = ( oPoked || pPoked ) ? Dynamic::POKING 356// : ((playerDistance(pf,of) > FOOTSIE_THRES) ? Dynamic::POSITIONING : Dynamic::FOOTSIES); 357unsigned neut_dyn = ((playerDistance (pf ,of )> FOOTSIE_THRES ) ?Dynamic ::POSITIONING :Dynamic ::FOOTSIES ); 358 359//First few checks are largely agnostic to cur_dynamic 360if (isDead (of )|| isDead (pf )) { 361cur_dynamic = Dynamic ::POSITIONING ; 362 }else if (oHitOffStage && cur_dynamic != Dynamic ::RECOVERING ) {//If the opponent is offstage and in hitstun, they're being [possibly reverse] edgeguarded 363cur_dynamic = Dynamic ::EDGEGUARDING ; 364 }else if (pHitOffStage && cur_dynamic != Dynamic ::EDGEGUARDING ) {//If we're offstage and in hitstun, we're being [possibly reverse] edgeguarded 365cur_dynamic = Dynamic ::RECOVERING ; 366 }else if (oIsGrabbed ) {//If we grab the opponent in neutral, it's pressure; on offense, it's a techchase 367if (cur_dynamic != Dynamic ::PRESSURING ) {//Need this to prevent grabs from overwriting themselves 368cur_dynamic = (cur_dynamic >=Dynamic ::OFFENSIVE ) ?Dynamic ::TECHCHASING :Dynamic ::PRESSURING ; 369 } 370 }else if (pIsGrabbed ) {//If we are grabbed by the opponent in neutral, we're pressured; on defense, we're techchased 371if (cur_dynamic != Dynamic ::PRESSURED ) {//Need this to prevent grabs from overwriting themselves 372cur_dynamic = (cur_dynamic <=Dynamic ::DEFENSIVE ) ?Dynamic ::ESCAPING :Dynamic ::PRESSURED ; 373 } 374 }else if (oShielding ) {//If our opponent is in shield, we are pressureing 375cur_dynamic = Dynamic ::PRESSURING ; 376 }else if (pShielding ) {//If we are in shield, we are pressured 377cur_dynamic = Dynamic ::PRESSURED ; 378 }else if (oTeching ) {//If opponent is teching, we are techchasing 379cur_dynamic = Dynamic ::TECHCHASING ; 380 }else if (pTeching ) {//If we are teching, we are escaping a techchase 381cur_dynamic = Dynamic ::ESCAPING ; 382 }else if (oInHitstun && pInHitstun ) {//If we're both in hitstun and neither of us are offstage, it's a trade 383// cur_dynamic = Dynamic::TRADING; 384cur_dynamic = Dynamic ::POKING ;//Update 2019-11-05: trading is no longer a used dynamic; now just poking 385 }else {//Everything else depends on the cur_dynamic 386switch (cur_dynamic ) { 387case Dynamic ::PRESSURING : 388if (oHitLastFrame && notoIsGrabbed ) {//If opponent was actually hit last frame by a non pummel, we're punishing 389cur_dynamic = Dynamic ::PUNISHING ; 390 }else if (oThrown ) {//If the opponent is being thrown, this is a techchase opportunity 391cur_dynamic = Dynamic ::TECHCHASING ; 392 }else if ((notoInHitstun )&& (notoShielding )&& (notoOnLedge )&& (notoAirborne )) {//If the opponent touches the ground w/o shielding, we're back to neutral 393cur_dynamic = neut_dyn ; 394 } 395break ; 396case Dynamic ::PRESSURED : 397if (pHitLastFrame && notpIsGrabbed ) {//If we were actually hit last frame by a non pummel, we're being punishied 398cur_dynamic = Dynamic ::PUNISHED ; 399 }else if (pThrown ) {//If we are being thrown, opponent has a techchase opportunity 400cur_dynamic = Dynamic ::ESCAPING ; 401 }else if ((notpInHitstun )&& (notpShielding )&& (notpOnLedge )&& (notpAirborne )) {//If we touch the ground w/o shielding, we're back to neutral 402cur_dynamic = neut_dyn ; 403 } 404break ; 405case Dynamic ::EDGEGUARDING : 406if (oOnLedge || (notoAirborne && notoPoked )) {//If they make it back, we're back to neutral 407cur_dynamic = neut_dyn ; 408 } 409break ; 410case Dynamic ::RECOVERING : 411if (pOnLedge || (notpAirborne && notpPoked )) {//If we make it back, we're back to neutral 412cur_dynamic = neut_dyn ; 413 } 414break ; 415case Dynamic ::TECHCHASING : 416if (oHitLastFrame && (notoTeching )&& oAirborne ) { 417cur_dynamic = Dynamic ::PUNISHING ;//If we started comboing an opponent after the techchase, it's a punish 418 }else if ((notoInHitstun )&& (notoIsGrabbed )&& (notoThrown )&& (notoTeching )&& (notoShielding )) { 419cur_dynamic = oAirborne ?Dynamic ::SHARKING :neut_dyn ;//If the opponent escaped our tech chase, back to neutral it is 420 } 421break ; 422case Dynamic ::ESCAPING : 423if (pHitLastFrame && (notpTeching )&& pAirborne ) { 424cur_dynamic = Dynamic ::PUNISHED ;//If we started comboing an opponent after the techchase, it's a punish 425 }else if ((notpInHitstun )&& (notpIsGrabbed )&& (notpThrown )&& (notpTeching )&& (notpShielding )) { 426cur_dynamic = pAirborne ?Dynamic ::GROUNDING :neut_dyn ;//If we escaped our opponent's tech chase, back to neutral it is 427 } 428break ; 429case Dynamic ::PUNISHING : 430if (oBeingSharked ) {//If we let too much hitstun elapse, but our opponent is still airborne, we're sharking 431cur_dynamic = Dynamic ::SHARKING ; 432 }else if ((notoAirborne )&& (notoPoked )) {//If our opponent has outright landed, we're back to neutral 433cur_dynamic = neut_dyn ; 434 } 435break ; 436case Dynamic ::PUNISHED : 437if (pBeingSharked ) {//If we survive punishes long enough, but are still airborne, we're being sharked 438cur_dynamic = Dynamic ::GROUNDING ; 439 }else if ((notpAirborne )&& (notpPoked )) {//If we have outright landed, we're back to neutral 440cur_dynamic = neut_dyn ; 441 } 442break ; 443case Dynamic ::SHARKING : 444if (oHitLastFrame ) { 445cur_dynamic = Dynamic ::PUNISHING ;//If we hit our opponent LAST frame, we're comboing again 446 }else if (pInHitstun ) {//If our opponent hits us while sharking, we're back to poking 447cur_dynamic = Dynamic ::POKING ; 448 }else if (notoAirborne ) {//If our opponent has outright landed, we're back to neutral 449cur_dynamic = neut_dyn ; 450 } 451break ; 452case Dynamic ::GROUNDING : 453if (pHitLastFrame ) { 454cur_dynamic = Dynamic ::PUNISHED ;//If our opponent hit us LAST frame, we're being comboed again 455 }else if (oInHitstun ) {//If we hit our opponent while grounding, we're back to poking 456cur_dynamic = Dynamic ::POKING ; 457 }else if (notpAirborne ) {//If we have outright landed, we're back to neutral 458cur_dynamic = neut_dyn ; 459 } 460break ; 461case Dynamic ::POKING : 462if (oPoked && oHitThisFrame ) { 463cur_dynamic = Dynamic ::PUNISHING ;//If we have poked our opponent recently and hit them again, we're punishing 464 }else if (pPoked && pHitThisFrame ) { 465cur_dynamic = Dynamic ::PUNISHED ;//If we have been poked recently and got hit again, we're being punished 466 }else if (oBeingSharked && notpPoked ) { 467cur_dynamic = Dynamic ::SHARKING ;//If we'd otherwise be considered as punishing, we're sharking 468 }else if (pBeingSharked && notoPoked ) { 469cur_dynamic = Dynamic ::GROUNDING ;//If we'd otherwise be considered as being punished, we're being sharked 470 }else { 471cur_dynamic = (oPoked || pPoked ) ?Dynamic ::POKING :neut_dyn ;//We're in neutral if nobody has been hit recently 472 } 473break ; 474case Dynamic ::POSITIONING : 475case Dynamic ::FOOTSIES : 476case Dynamic ::TRADING : 477if (oBeingSharked ) { 478cur_dynamic = Dynamic ::SHARKING ;//If we are sharking, update accordingly 479 }else if (pBeingSharked ) { 480cur_dynamic = Dynamic ::GROUNDING ;//If we are being sharked, update accordingly 481 }else { 482cur_dynamic = (oPoked || pPoked ) ?Dynamic ::POKING :neut_dyn ;//If we were trading before, we're in neutral now that we're no longer trading 483 } 484break ; 485default : 486break ; 487 } 488 } 489 490//Aggregate results 491a -> dynamics [f ]= cur_dynamic ;//Set the dynamic for this frame to the current dynamic computed 492DOUT1 (" " <<f <<" (" <<frameAsTimer (f ,s .timer ) <<") P1 " 493 <<Dynamic ::name [cur_dynamic ] <<" " 494 << std::endl ); 495 } 496 497} 498 499void Analyzer ::analyzePunishes (const SlippiReplay & s ,Analysis * a )const { 500const SlippiPlayer * p = & (s .player [a -> ap [0 ].port ]); 501const SlippiPlayer * o = & (s .player [a -> ap [1 ].port ]); 502unsigned pa = 0 ;//Running tally of player attacks 503unsigned oa = 0 ;//Running tally of opponent attacks 504unsigned pn = 0 ;//Running tally of player punishes 505unsigned on = 0 ;//Running tally of opponent punishes 506unsigned oLastInHitsun = 0 ; 507unsigned pLastInHitsun = 0 ; 508unsigned cur_dyn = a -> dynamics [FIRST_FRAME ]; 509unsigned last_dyn = a -> dynamics [FIRST_FRAME ]; 510Punish * pPunishes = a -> ap [0 ].punishes ; 511Punish * oPunishes = a -> ap [1 ].punishes ; 512Attack * pAttacks = a -> ap [0 ].attacks ; 513Attack * oAttacks = a -> ap [1 ].attacks ; 514 515for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 516SlippiFrame pf = p -> frame [f ]; 517SlippiFrame of = o -> frame [f ]; 518cur_dyn = a -> dynamics [f ]; 519 520oLastInHitsun = isInHitstun (o -> frame [f ]) ?f :oLastInHitsun ; 521pLastInHitsun = isInHitstun (p -> frame [f ]) ?f :pLastInHitsun ; 522bool oPoked = ((f - oLastInHitsun )< POKE_THRES );//Check if opponent has been poked recently 523bool pPoked = ((f - pLastInHitsun )< POKE_THRES );//Check if we have been poked recently 524 525//Check if we counter-attacked (switched from defense to offense or vice versa) 526if (cur_dyn <=Dynamic ::DEFENSIVE && last_dyn >=Dynamic ::OFFENSIVE ) { 527++ a -> ap [1 ].counters ;//If we went from offense to defense, we were countered 528 }else if (cur_dyn >=Dynamic ::OFFENSIVE && last_dyn <=Dynamic ::DEFENSIVE ) { 529++ a -> ap [0 ].counters ;//If we went from defense to offense, we countered 530 } 531 532//Check if either player lost a stock 533if (pf .stocks < p -> frame [f - 1 ].stocks ) { 534unsigned ddir = deathDirection (* p ,f ); 535if (oa > 0 ) { 536oAttacks [oa - 1 ].kill_dir = ddir ; 537 } 538if (oPunishes [on ].num_moves > 0 ) { 539oPunishes [on ].kill_dir = ddir ;//TODO: filter out self-destructs somehow 540 }else if (on > 0 ) { 541oPunishes [on - 1 ].kill_dir = ddir ; 542 } 543if (cur_dyn == Dynamic ::EDGEGUARDING ) { 544++ (a -> ap [1 ].reverse_edgeguards ); 545 }else if (cur_dyn != Dynamic ::RECOVERING && ddir != Dir ::UP ) { 546++ (a -> ap [0 ].self_destructs ); 547 } 548 } 549if (of .stocks < o -> frame [f - 1 ].stocks ) { 550unsigned ddir = deathDirection (* o ,f ); 551if (pa > 0 ) { 552pAttacks [pa - 1 ].kill_dir = ddir ; 553 } 554if (pPunishes [pn ].num_moves > 0 ) { 555pPunishes [pn ].kill_dir = ddir ; 556 }else if (pn > 0 ) { 557pPunishes [pn - 1 ].kill_dir = ddir ; 558 } 559if (cur_dyn == Dynamic ::RECOVERING ) { 560++ (a -> ap [0 ].reverse_edgeguards ); 561 }else if (cur_dyn != Dynamic ::EDGEGUARDING && ddir != Dir ::UP ) { 562++ (a -> ap [1 ].self_destructs ); 563 } 564 } 565 566//Check if either player has dropped a punish off an opening 567bool pPunishEnd = false; 568bool oPunishEnd = false; 569if (f == s .frame_count - 1 ) { 570pPunishEnd = true; 571oPunishEnd = true; 572 }else if (cur_dyn != Dynamic ::POKING ) { 573if (cur_dyn > Dynamic ::DEFENSIVE && notpPoked ) { 574//If the opponent had a punish going and they are no longer on offense, end their punish 575oPunishEnd = true; 576 } 577if (cur_dyn < Dynamic ::OFFENSIVE && notoPoked ) { 578//If we had a punish going and we are no longer on offense, end our punish 579pPunishEnd = true; 580 } 581 } 582 583//Update punish counter for ended punishes 584if (pPunishEnd && pa > 0 ) { 585if (pPunishes [pn ].num_moves > 0 ) { 586pPunishes [pn ].end_frame = f ; 587pPunishes [pn ].end_pct = of .percent_pre ; 588pPunishes [pn ].last_move_id = pf .hit_with ; 589if (pPunishes [pn ].num_moves > pAttacks [pa - 1 ].hit_id ) { 590a -> ap [0 ].neutral_wins += 1 ; 591 }else { 592a -> ap [0 ].pokes += 1 ; 593 } 594++ pn ; 595 } 596 } 597if (oPunishEnd && oa > 0 ) { 598if (oPunishes [on ].num_moves > 0 ) { 599oPunishes [on ].end_frame = f ; 600oPunishes [on ].end_pct = pf .percent_pre ; 601oPunishes [on ].last_move_id = of .hit_with ; 602if (oPunishes [on ].num_moves > oAttacks [oa - 1 ].hit_id ) { 603a -> ap [1 ].neutral_wins += 1 ; 604 }else { 605a -> ap [1 ].pokes += 1 ; 606 } 607++ on ; 608 } 609 } 610 611//If the opponent just took damage 612float o_damage_taken = of .percent_pre - o -> frame [f - 1 ].percent_pre ; 613if (o_damage_taken > 0 ) { 614//Check for bubble damage 615pAttacks [pa ].move_id = (isOffscreen (of )&& o_damage_taken == 1 ) ?Move ::BUBBLE :pf .hit_with ; 616//Last frame we actually took damage; frame before that gives us the animation frame our move hit 617pAttacks [pa ].anim_frame = p -> frame [f - 2 ].action_fc ; 618pAttacks [pa ].punish_id = pn ; 619if (//Check if this is a consecutive hit from a multihit move 620pa > 0 && //If this isn't our first move 621pAttacks [pa ].move_id == pAttacks [pa - 1 ].move_id && //If the last move we hit with had the same id 622pAttacks [pa ].anim_frame > pAttacks [pa - 1 ].anim_frame && //If the action frame counter is higher 623//If the gap between animation and game frames is less than max hitlag for the move 624//Formula: https://www.ssbwiki.com/Freeze_frame 625 (f - pAttacks [pa ].anim_frame <= (pAttacks [pa - 1 ].frame - pAttacks [pa - 1 ].anim_frame + (pAttacks [pa - 1 ].damage /3 + 3 )))) { 626pAttacks [pa ].hit_id = pAttacks [pa - 1 ].hit_id + 1 ; 627 }else { 628pAttacks [pa ].hit_id = 1 ; 629++ (a -> ap [0 ].move_counts [pAttacks [pa ].move_id ]); 630 } 631pAttacks [pa ].frame = f ; 632pAttacks [pa ].damage = o_damage_taken ; 633a -> ap [0 ].dyn_damage [cur_dyn ]+= o_damage_taken ;//Dynamic is normal for player 634pAttacks [pa ].opening = cur_dyn ;//Dynamic is normal for player 635pAttacks [pa ].kill_dir = Dir ::NEUT ; 636++ pa ; 637//If this is the start of a combo 638if (pPunishes [pn ].num_moves == 0 ) { 639pPunishes [pn ].start_frame = f ; 640pPunishes [pn ].start_pct = o -> frame [f - 1 ].percent_pre ; 641pPunishes [pn ].kill_dir = Dir ::NEUT ; 642 } 643a -> ap [0 ].damage_dealt += o_damage_taken ; 644pPunishes [pn ].end_frame = f ; 645pPunishes [pn ].end_pct = of .percent_pre ; 646pPunishes [pn ].last_move_id = pf .hit_with ; 647pPunishes [pn ].num_moves += 1 ; 648 } 649 650//If we just took damage 651float p_damage_taken = pf .percent_pre - p -> frame [f - 1 ].percent_pre ; 652if (p_damage_taken > 0 ) { 653//Check for bubble damage 654oAttacks [oa ].move_id = (isOffscreen (pf )&& p_damage_taken == 1 ) ?Move ::BUBBLE :of .hit_with ; 655//Last frame we actually took damage; frame before that gives us the animation frame our move hit 656oAttacks [oa ].anim_frame = o -> frame [f - 2 ].action_fc ; 657oAttacks [oa ].punish_id = on ; 658if (//Check if this is a consecutive hit from a multihit move 659oa > 0 && //If this isn't our first move 660oAttacks [oa ].move_id == oAttacks [oa - 1 ].move_id && //If the last move we hit with had the same id 661oAttacks [oa ].anim_frame > oAttacks [oa - 1 ].anim_frame && //If the action frame counter is higher 662//If the gap between animation and game frames is less than max hitlag for the move 663 (f - oAttacks [oa ].anim_frame <= (oAttacks [oa - 1 ].frame - oAttacks [oa - 1 ].anim_frame + (oAttacks [oa - 1 ].damage /3 + 3 )))) { 664oAttacks [oa ].hit_id = oAttacks [oa - 1 ].hit_id + 1 ; 665 }else { 666oAttacks [oa ].hit_id = 1 ; 667++ (a -> ap [1 ].move_counts [oAttacks [oa ].move_id ]); 668 } 669oAttacks [oa ].frame = f ; 670oAttacks [oa ].damage = p_damage_taken ; 671//Dynamic needs to be flipped around for opponent 672int oDynamic = (cur_dyn > Dynamic ::OFFENSIVE || cur_dyn < Dynamic ::DEFENSIVE ) ?Dynamic ::__LAST - cur_dyn :cur_dyn ; 673a -> ap [1 ].dyn_damage [oDynamic ]+= p_damage_taken ;//Dynamic needs to be flipped around for opponent 674oAttacks [oa ].opening = oDynamic ; 675oAttacks [oa ].kill_dir = Dir ::NEUT ; 676++ oa ; 677//If this is the start of a combo 678if (oPunishes [on ].num_moves == 0 ) { 679oPunishes [on ].start_frame = f ; 680oPunishes [on ].start_pct = p -> frame [f - 1 ].percent_pre ; 681oPunishes [on ].kill_dir = Dir ::NEUT ; 682 } 683a -> ap [1 ].damage_dealt += p_damage_taken ; 684oPunishes [on ].end_frame = f ; 685oPunishes [on ].end_pct = pf .percent_pre ; 686oPunishes [on ].last_move_id = of .hit_with ; 687oPunishes [on ].num_moves += 1 ; 688 } 689 690last_dyn = cur_dyn ;//Update the last dynamic 691 } 692} 693 694void Analyzer ::analyzeCancels (const SlippiReplay & s ,Analysis * a )const { 695for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 696const SlippiPlayer * p = & (s .player [a -> ap [pi ].port ]); 697Attack * attacks = a -> ap [pi ].attacks ; 698for (unsigned i = 0 ;attacks [i ].frame > 0 ;++ i ) { 699unsigned f = attacks [i ].frame ; 700if (attacks [i ].move_id >=Move ::NAIR && attacks [i ].move_id <=Move ::DAIR ) { 701unsigned last_frame = attacks [i ].frame + 60 ; 702if (last_frame > s .frame_count ) { 703last_frame = s .frame_count ; 704 } 705for (unsigned f = attacks [i ].frame ;f < last_frame ;++ f ) { 706//Check if we had the opportunity to edge cancel 707if (didEdgeCancelAerial (p -> frame [f ])) { 708attacks [i ].cancel_type = Cancel ::EDGE ; 709break ; 710 } 711//Check if we had the opportunity to teeter cancel 712if (didTeeterCancelAerial (p -> frame [f ])) { 713attacks [i ].cancel_type = Cancel ::TEETER ; 714break ; 715 } 716//Check if we had the opportunity to autocancel 717if (didAutoCancelAerial (p -> frame [f ])) { 718attacks [i ].cancel_type = Cancel ::AUTO ; 719break ; 720 } 721//Check if we had the opportunity to L cancel 722if (p -> frame [f ].l_cancel > 0 ) { 723if (p -> frame [f ].l_cancel == 1 ) { 724attacks [i ].cancel_type = Cancel ::L ; 725 } 726break ; 727 } 728 } 729 } 730 } 731 } 732} 733 734void Analyzer ::analyzeShield (const SlippiReplay & s ,Analysis * a )const { 735for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 736const SlippiPlayer * p = & (s .player [a -> ap [pi ].port ]); 737for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 738float shield_damage = (p -> frame [f ].shield - p -> frame [f - 1 ].shield ); 739if (shield_damage > 0 ) { 740a -> ap [pi ].shield_time += 1 ; 741a -> ap [pi ].shield_damage += shield_damage ; 742if (p -> frame [f ].shield < a -> ap [pi ].shield_lowest ) { 743a -> ap [pi ].shield_lowest = p -> frame [f ].shield ; 744 } 745 } 746 } 747 } 748} 749 750unsigned Analyzer ::countTransitions (const SlippiReplay & s ,Analysis * a ,unsigned pnum ,bool (* cb )(const SlippiFrame & ))const { 751SlippiPlayer p = s .player [a -> ap [pnum ].port ]; 752unsigned counter = 0 ; 753bool active = false; 754for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 755if (cb (p .frame [f ])) { 756if (notactive ) { 757++ counter ; 758active = true; 759 } 760 }else { 761active = false; 762 } 763 } 764return counter ; 765} 766 767unsigned Analyzer ::countTransitions (const SlippiReplay & s ,Analysis * a ,unsigned pnum ,bool (* cb )(const SlippiPlayer & ,const unsigned ))const { 768SlippiPlayer p = s .player [a -> ap [pnum ].port ]; 769unsigned counter = 0 ; 770bool active = false; 771for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 772if (cb (p ,f )) { 773if (notactive ) { 774++ counter ; 775active = true; 776 } 777 }else { 778active = false; 779 } 780 } 781return counter ; 782} 783 784void Analyzer ::countBasicAnimations (const SlippiReplay & s ,Analysis * a )const { 785for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 786a -> ap [pi ].state_changes = countTransitions (s ,a ,pi ,didActionStateChange ); 787 788a -> ap [pi ].ledge_grabs = countTransitions (s ,a ,pi ,isOnLedge ); 789a -> ap [pi ].rolls = countTransitions (s ,a ,pi ,isRolling ); 790a -> ap [pi ].spotdodges = countTransitions (s ,a ,pi ,isSpotdodging ); 791a -> ap [pi ].powershields = countTransitions (s ,a ,pi ,didPowerShield ); 792a -> ap [pi ].grabs = countTransitions (s ,a ,pi ,isGrabbing ); 793a -> ap [pi ].taunts = countTransitions (s ,a ,pi ,isTaunting ); 794a -> ap [pi ].meteor_cancels = countTransitions (s ,a ,pi ,didMeteorCancel ); 795a -> ap [pi ].hits_blocked = countTransitions (s ,a ,pi ,isInShieldstun ); 796a -> ap [pi ].edge_cancel_aerials = countTransitions (s ,a ,pi ,didEdgeCancelAerial ); 797a -> ap [pi ].edge_cancel_specials = countTransitions (s ,a ,pi ,didEdgeCancelSpecial ); 798a -> ap [pi ].teeter_cancel_aerials = countTransitions (s ,a ,pi ,didTeeterCancelAerial ); 799a -> ap [pi ].teeter_cancel_specials = countTransitions (s ,a ,pi ,didTeeterCancelSpecial ); 800a -> ap [pi ].no_impact_lands = countTransitions (s ,a ,pi ,didNoImpactLand ); 801a -> ap [pi ].shield_drops = countTransitions (s ,a ,pi ,didShieldDrop ); 802a -> ap [pi ].pivots = countTransitions (s ,a ,pi ,didPivot ); 803a -> ap [pi ].short_hops = countTransitions (s ,a ,pi ,didShortHop ); 804a -> ap [pi ].full_hops = countTransitions (s ,a ,pi ,didHop )- a -> ap [pi ].short_hops ; 805 806a -> ap [pi ].shield_breaks = countTransitions (s ,a ,1 - pi ,isShieldBroken ); 807a -> ap [pi ].grab_escapes = countTransitions (s ,a ,1 - pi ,isReleasing ); 808a -> ap [pi ].shield_stabs = countTransitions (s ,a ,1 - pi ,wasShieldStabbed ); 809a -> ap [pi ].stage_spikes = countTransitions (s ,a ,1 - pi ,wasStageSpiked ); 810 } 811} 812 813void Analyzer ::showActionStates (const SlippiReplay & s ,Analysis * a )const { 814const SlippiPlayer * p = & (s .player [a -> ap [0 ].port ]); 815const SlippiPlayer * o = & (s .player [a -> ap [1 ].port ]); 816for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 817SlippiFrame pf = p -> frame [f ]; 818DOUT2 (" " <<f <<" (" <<frameAsTimer (f ,s .timer ) <<") P1 " 819 <<Action ::name [pf .action_pre ] <<" " 820 <<" -> " 821 <<" " <<Action ::name [pf .action_post ] 822 << std::endl ); 823SlippiFrame of = o -> frame [f ]; 824DOUT2 (" " <<f <<" (" <<frameAsTimer (f ,s .timer ) <<") P2 " 825 <<Action ::name [of .action_pre ] <<" " 826 <<" -> " 827 <<" " <<Action ::name [of .action_post ] 828 << std::endl ); 829 } 830} 831 832void Analyzer ::countPhantoms (const SlippiReplay & s ,Analysis * a )const { 833const SlippiPlayer * p = & (s .player [a -> ap [0 ].port ]); 834const SlippiPlayer * o = & (s .player [a -> ap [1 ].port ]); 835for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 836if (wasHitByPhantom (* p ,* o ,f )) { 837++ (a -> ap [1 ].phantom_hits ); 838 } 839if (wasHitByPhantom (* o ,* p ,f )) { 840++ (a -> ap [0 ].phantom_hits ); 841 } 842 } 843} 844 845void Analyzer ::countLedgedashes (const SlippiReplay & s ,Analysis * a )const { 846for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 847const SlippiPlayer * p = & (s .player [a -> ap [pi ].port ]); 848unsigned galint = 0 ; 849bool offledge = false; 850for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 851if (galint > 0 ) { 852-- galint ; 853if (notoffledge ) { 854offledge = didReleaseLedge (* p ,f ); 855continue ; 856 } 857SlippiFrame pf = p -> frame [f ]; 858bool landed = isLanding (p -> frame [f - 1 ])&& (notisLanding (pf ))&& (notisAirborne (pf )); 859if ((didNoImpactLand (pf )|| landed )&& (notisInHitlag (pf ))&& (notisInHitstun (pf ))) { 860if (a -> ap [pi ].max_galint < galint ) { 861a -> ap [pi ].max_galint = galint ; 862 } 863a -> ap [pi ].galint_ledgedashes += 1 ; 864a -> ap [pi ].mean_galint += galint ; 865f += galint ; 866galint = 0 ; 867offledge = false; 868 } 869 } 870if (didCliffCatchEnd (* p ,f )) { 871galint = 30 ; 872if (didReleaseLedge (* p ,f )) { 873offledge = true; 874 } 875 } 876 } 877if (a -> ap [pi ].galint_ledgedashes > 0 ) { 878a -> ap [pi ].mean_galint /=a -> ap [pi ].galint_ledgedashes ; 879 } 880 } 881} 882 883void Analyzer ::countMoves (const SlippiReplay & s ,Analysis * a )const { 884for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 885const SlippiPlayer * p = & (s .player [a -> ap [pi ].port ]); 886const unsigned pid = p -> ext_char_id ; 887bool was_throw = false; 888bool was_normal = false; 889bool was_special = false; 890bool was_misc = false; 891bool was_grab = false; 892bool was_pummel = false; 893for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 894SlippiFrame pf = p -> frame [f ]; 895if (isThrowing (pf )) { 896if (!(was_throw )) { 897++ (a -> ap [pi ].used_throws ); 898 } 899was_throw = true; 900 }else if (isUsingNormalMove (pf )) { 901if (!(was_normal )) { 902++ (a -> ap [pi ].used_norm_moves ); 903 } 904was_normal = true; 905 }else if (isUsingSpecialMove (pf ,pid )) { 906if (!(was_special )) { 907++ (a -> ap [pi ].used_spec_moves ); 908 } 909was_special = true; 910 }else if (isUsingMiscMove (pf )) { 911if (!(was_misc )) { 912++ (a -> ap [pi ].used_misc_moves ); 913 } 914was_misc = true; 915 }else if (isUsingGrab (pf )) { 916if (!(was_grab )) { 917++ (a -> ap [pi ].used_grabs ); 918 } 919was_grab = true; 920 }else if (isUsingPummel (pf )) { 921if (!(was_pummel )) { 922++ (a -> ap [pi ].used_pummels ); 923 } 924was_pummel = true; 925 }else { 926was_throw = false; 927was_normal = false; 928was_special = false; 929was_misc = false; 930was_grab = false; 931was_pummel = false; 932 } 933 } 934a -> ap [pi ].total_moves_used = a -> ap [pi ].used_throws + a -> ap [pi ].used_norm_moves 935+ a -> ap [pi ].used_spec_moves + a -> ap [pi ].used_misc_moves + a -> ap [pi ].used_grabs + a -> ap [pi ].used_pummels ; 936// std::cout << "Player " << pi+1 << " attempted: " << std::endl; 937// std::cout << " " << a->ap[pi].used_throws << " used_throws" << std::endl; 938// std::cout << " " << a->ap[pi].used_norm_moves << " used_norm_moves" << std::endl; 939// std::cout << " " << a->ap[pi].used_spec_moves << " used_spec_moves" << std::endl; 940// std::cout << " " << a->ap[pi].used_misc_moves << " used_misc_moves" << std::endl; 941// std::cout << " " << a->ap[pi].used_grabs << " used_grabs" << std::endl; 942// std::cout << " " << a->ap[pi].used_pummels << " used_pummels" << std::endl; 943// std::cout << " " << a->ap[pi].total_moves_used << " used_total_moves" << std::endl; 944 } 945} 946 947void Analyzer ::countActionability (const SlippiReplay & s ,Analysis * a )const { 948for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 949const SlippiPlayer * p = & (s .player [a -> ap [pi ].port ]); 950bool was_in_hitstun = false; 951unsigned hitstun_times = 0 ;//Number of times we enter hitstun 952unsigned hitstun_act = 0 ;//Total number of frames we take to act out of hitstun 953unsigned hitstun_act_cur = 0 ;//Current number of frames we take to act out of hitstun 954bool was_in_shieldstun = false; 955unsigned shieldstun_times = 0 ;//Number of times we enter shieldstun 956unsigned shieldstun_act = 0 ;//Total number of frames we take to act out of shieldstun 957unsigned shieldstun_act_cur = 0 ;//Current number of frames we take to act out of shieldstun 958bool was_in_wait = false; 959unsigned wait_times = 0 ;//Number of times we enter wait 960unsigned wait_act = 0 ;//Total number of frames we take to act out of wait 961unsigned wait_act_cur = 0 ;//Current number of frames we take to act out of wait 962for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 963SlippiFrame pf = p -> frame [f ]; 964 965// Count the number of frames we take to act out of hitstun 966if (isInHitstun (pf )) { 967if (!was_in_hitstun ) { 968was_in_hitstun = true; 969++ hitstun_times ; 970hitstun_act_cur = 0 ; 971 } 972 }else if (was_in_hitstun ) { 973if ( 974inTumble (pf )|| 975isInDamageAnimation (pf )|| 976isInAnyWait (pf )) { 977++ hitstun_act_cur ; 978++ hitstun_act ; 979 }else { 980if ((MAX_WAIT < hitstun_act_cur )|| wasStageSpiked (pf )|| inMissedTechState (pf )) { 981-- hitstun_times ;//We're not trying to act out of stun 982 }else { 983// std::cout << "hitstun act " << hitstun_act_cur << std::endl; 984hitstun_act += hitstun_act_cur ; 985 } 986was_in_hitstun = false; 987 } 988 } 989 990// Count the number of frames we take to act out of shieldstun 991unsigned max_shield_wait = MAX_WAIT ; 992if (isInShieldstun (pf )) { 993if (!was_in_shieldstun ) { 994was_in_shieldstun = true; 995++ shieldstun_times ; 996shieldstun_act_cur = 0 ; 997 }else if (shieldstun_act_cur > 0 ) { 998//We might be waiting in shield due to shield pressure, 999// so break the MAX_WAIT limit in these cases 1000max_shield_wait = MAX_WAIT + shieldstun_act_cur ; 1001 } 1002 }else if (was_in_shieldstun ) { 1003if (isInShield (pf )) { 1004++ shieldstun_act_cur ; 1005 }else { 1006if ((max_shield_wait < shieldstun_act_cur ) ) { 1007-- shieldstun_times ;//We're not trying to act out of stun 1008 }else { 1009// std::cout << "shieldstun act " << shieldstun_act_cur << std::endl; 1010shieldstun_act += shieldstun_act_cur ; 1011 } 1012was_in_shieldstun = false; 1013 } 1014 } 1015 1016// Count the number of frames we take to act out of shieldstun 1017if (isInAnyWait (pf )) { 1018if (!was_in_wait ) { 1019was_in_wait = true; 1020++ wait_times ; 1021wait_act_cur = 0 ; 1022 }else { 1023++ wait_act_cur ; 1024 } 1025 }else if (was_in_wait ) { 1026if ((MAX_WAIT < wait_act_cur ) ) { 1027-- wait_times ;//We're not trying to act out of wait 1028 }else { 1029// std::cout << "wait act " << wait_act_cur << std::endl; 1030wait_act += wait_act_cur ; 1031 } 1032was_in_wait = false; 1033 } 1034 1035 } 1036 1037a -> ap [pi ].hitstun_times = hitstun_times ; 1038a -> ap [pi ].hitstun_act_frames = hitstun_act ; 1039a -> ap [pi ].shieldstun_times = shieldstun_times ; 1040a -> ap [pi ].shieldstun_act_frames = shieldstun_act ; 1041a -> ap [pi ].wait_times = wait_times ; 1042a -> ap [pi ].wait_act_frames = wait_act ; 1043 } 1044} 1045 1046void Analyzer ::computeTrivialInfo (const SlippiReplay & s ,Analysis * a )const { 1047for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 1048// Get damage per opening 1049a -> ap [pi ].total_openings = a -> ap [pi ].neutral_wins + a -> ap [pi ].pokes ; 1050if (a -> ap [pi ].total_openings > 0 ) { 1051a -> ap [pi ].mean_opening_percent = a -> ap [pi ].damage_dealt /a -> ap [pi ].total_openings ; 1052 } 1053 1054// Get openings per kill and percent per kill 1055unsigned o_end_stocks = a -> ap [1 - pi ].end_stocks ; 1056unsigned o_stocks_lost = a -> ap [1 - pi ].start_stocks - o_end_stocks ; 1057if (o_stocks_lost > 0 ) { 1058a -> ap [pi ].mean_kill_openings = float (a -> ap [pi ].total_openings ) /o_stocks_lost ; 1059float damage_dealt = a -> ap [pi ].damage_dealt ; 1060if (o_end_stocks > 0 ) { 1061//Need to not include stocks we didn't take in our computation 1062damage_dealt -= a -> ap [1 - pi ].end_pct ; 1063 } 1064a -> ap [pi ].mean_kill_percent = damage_dealt /o_stocks_lost ; 1065a -> ap [1 - pi ].mean_death_percent = a -> ap [pi ].mean_kill_percent ; 1066 } 1067 1068// Get actions per minute 1069unsigned total_actions = 1070a -> ap [pi ].button_count + a -> ap [pi ].cstick_count + a -> ap [pi ].astick_count ; 1071a -> ap [pi ].apm = total_actions * (3600.0f /a -> game_length ); 1072 1073// Get action states per minute 1074a -> ap [pi ].aspm = a -> ap [pi ].state_changes * (3600.0f /a -> game_length ); 1075 1076// Get total number of moves landed and move accuracy 1077a -> ap [pi ].total_moves_landed = 0 ; 1078for (unsigned i = 0 ;i < Move ::__LAST ;++ i ) { 1079a -> ap [pi ].total_moves_landed += a -> ap [pi ].move_counts [i ]; 1080 } 1081if (a -> ap [pi ].total_moves_used > 0 ) { 1082a -> ap [pi ].move_accuracy = float (a -> ap [pi ].total_moves_landed ) /float (a -> ap [pi ].total_moves_used ); 1083 } 1084 1085// Get average actionability 1086a -> ap [pi ].actionability = 0 ; 1087if (a -> ap [pi ].shieldstun_times > 0 ) { 1088a -> ap [pi ].actionability += float (a -> ap [pi ].shieldstun_act_frames ) /a -> ap [pi ].shieldstun_times ; 1089 } 1090if (a -> ap [pi ].hitstun_times > 0 ) { 1091a -> ap [pi ].actionability += float (a -> ap [pi ].hitstun_act_frames ) /a -> ap [pi ].hitstun_times ; 1092 } 1093if (a -> ap [pi ].wait_times > 0 ) { 1094a -> ap [pi ].actionability += float (a -> ap [pi ].wait_act_frames ) /a -> ap [pi ].wait_times ; 1095 } 1096a -> ap [pi ].actionability /=3.0f ; 1097 1098// Get number of times we won neutral relative to time spent in neutral / defense 1099unsigned neut_frames = 1100a -> ap [pi ].dyn_counts [Dynamic ::TRADING ]+ 1101a -> ap [pi ].dyn_counts [Dynamic ::POKING ]+ 1102a -> ap [pi ].dyn_counts [Dynamic ::NEUTRAL ]+ 1103a -> ap [pi ].dyn_counts [Dynamic ::POSITIONING ]+ 1104a -> ap [pi ].dyn_counts [Dynamic ::FOOTSIES ]+ 1105a -> ap [pi ].dyn_counts [Dynamic ::RECOVERING ]+ 1106a -> ap [pi ].dyn_counts [Dynamic ::ESCAPING ]+ 1107a -> ap [pi ].dyn_counts [Dynamic ::PUNISHED ]+ 1108a -> ap [pi ].dyn_counts [Dynamic ::GROUNDING ]+ 1109a -> ap [pi ].dyn_counts [Dynamic ::PRESSURED ]+ 1110a -> ap [pi ].dyn_counts [Dynamic ::DEFENSIVE ] 1111 ; 1112if (neut_frames > 0 ) { 1113a -> ap [pi ].neutral_wins_per_min = a -> ap [pi ].total_openings / (float (neut_frames ) /3600.0f ); 1114 } 1115 } 1116} 1117 1118Analysis * Analyzer ::analyze (const SlippiReplay & s ) { 1119DOUT1 ("Analyzing replay" << std::endl ); 1120 1121Analysis * a = new Analysis (s .frame_count );//Structure for holding the analysis so far 1122 1123//Verify this is a 1 v 1 match; can't analyze otherwise 1124if (notget1v1Ports (s ,a )) { 1125 std::cerr <<" Not a two player match; refusing to analyze further" << std::endl ; 1126a -> success = false; 1127return a ; 1128 } 1129 1130DOUT1 (" Analyzing basic game info" << std::endl ); 1131getBasicGameInfo (s ,a ); 1132 1133//Interaction-level stats 1134DOUT1 (" Analyzing player interactions" << std::endl ); 1135analyzeInteractions (s ,a ); 1136DOUT1 (" Summarizing player interactions" << std::endl ); 1137summarizeInteractions (s ,a ); 1138DOUT1 (" Analyzing players' punishes" << std::endl ); 1139analyzePunishes (s ,a ); 1140DOUT1 (" Analyzing players' cancelling techniques" << std::endl ); 1141analyzeCancels (s ,a ); 1142DOUT1 (" Analyzing players' shielding" << std::endl ); 1143analyzeShield (s ,a ); 1144 1145//Player-level stats 1146DOUT1 (" Computing statistics based on animations" << std::endl ); 1147countBasicAnimations (s ,a ); 1148DOUT1 (" Computing air / ground time for each player" << std::endl ); 1149computeAirtime (s ,a ); 1150DOUT1 (" Counting l cancels" << std::endl ); 1151countLCancels (s ,a ); 1152DOUT1 (" Counting techs" << std::endl ); 1153countTechs (s ,a ); 1154DOUT1 (" Counting dashdances" << std::endl ); 1155countDashdances (s ,a ); 1156DOUT1 (" Counting airdodges, wavelands, and wavedashes" << std::endl ); 1157countAirdodgesAndWavelands (s ,a ); 1158DOUT1 (" Counting phantom hits" << std::endl ); 1159countPhantoms (s ,a ); 1160DOUT1 (" Counting button pushes" << std::endl ); 1161countButtons (s ,a ); 1162DOUT1 (" Counting ledgedashes" << std::endl ); 1163countLedgedashes (s ,a ); 1164DOUT1 (" Counting act out of wait / stun" << std::endl ); 1165countActionability (s ,a ); 1166DOUT1 (" Counting number of moves used" << std::endl ); 1167countMoves (s ,a ); 1168 1169DOUT1 (" Computing trivial match info" << std::endl ); 1170computeTrivialInfo (s ,a ); 1171 1172//Debug stuff 1173if (_debug >=2 ) { 1174DOUT2 (" Showing action states" << std::endl ); 1175showActionStates (s ,a ); 1176 } 1177 1178a -> success = true; 1179DOUT1 ("Successfully analyzed replay!" << std::endl ); 1180return a ; 1181} 1182 1183}