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