fork/slippc
git clone https://git.julia.blue/fork/slippc
46ef8c0
testing
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 -> timer = s .timer ; 53a -> end_type = s .end_type ; 54a -> lras_player = s .lras ; 55a -> ap [0 ].tag_player = s .player [a -> ap [0 ].port ].tag ; 56a -> ap [1 ].tag_player = s .player [a -> ap [1 ].port ].tag ; 57a -> ap [0 ].tag_css = s .player [a -> ap [0 ].port ].tag_css ; 58a -> ap [1 ].tag_css = s .player [a -> ap [1 ].port ].tag_css ; 59a -> ap [0 ].tag_code = s .player [a -> ap [0 ].port ].tag_code ; 60a -> ap [1 ].tag_code = s .player [a -> ap [1 ].port ].tag_code ; 61 62a -> ap [0 ].start_stocks = s .player [a -> ap [0 ].port ].start_stocks ; 63a -> ap [1 ].start_stocks = s .player [a -> ap [1 ].port ].start_stocks ; 64a -> ap [0 ].color = s .player [a -> ap [0 ].port ].color ; 65a -> ap [1 ].color = s .player [a -> ap [1 ].port ].color ; 66a -> ap [0 ].team_id = s .player [a -> ap [0 ].port ].team_id ; 67a -> ap [1 ].team_id = s .player [a -> ap [1 ].port ].team_id ; 68a -> ap [0 ].player_type = s .player [a -> ap [0 ].port ].player_type ; 69a -> ap [1 ].player_type = s .player [a -> ap [1 ].port ].player_type ; 70a -> ap [0 ].cpu_level = s .player [a -> ap [0 ].port ].cpu_level ; 71a -> ap [1 ].cpu_level = s .player [a -> ap [1 ].port ].cpu_level ; 72 73a -> ap [0 ].end_stocks = s .player [a -> ap [0 ].port ].end_stocks ; 74a -> ap [1 ].end_stocks = s .player [a -> ap [1 ].port ].end_stocks ; 75a -> ap [0 ].end_pct = s .player [a -> ap [0 ].port ].frame [s .frame_count - 1 ].percent_pre ; 76a -> ap [1 ].end_pct = s .player [a -> ap [1 ].port ].frame [s .frame_count - 1 ].percent_pre ; 77a -> ap [0 ].char_id = s .player [a -> ap [0 ].port ].ext_char_id ; 78a -> ap [1 ].char_id = s .player [a -> ap [1 ].port ].ext_char_id ; 79a -> stage_id = s .stage ; 80a -> ap [0 ].char_name = CharExt ::name [a -> ap [0 ].char_id ]; 81a -> ap [1 ].char_name = CharExt ::name [a -> ap [1 ].char_id ]; 82a -> stage_name = Stage ::name [s .stage ]; 83a -> winner_port = s .winner_id ; 84} 85 86void Analyzer ::summarizeInteractions (const SlippiReplay & s ,Analysis * a )const { 87// std::cout << " Summarizing player interactions" << std::endl; 88for (unsigned f = (PLAYABLE_FRAME - LOAD_FRAME );f < s .frame_count ;++ f ) { 89unsigned d = a -> dynamics [f ]; 90++ (a -> ap [0 ].dyn_counts [d ]);//Increase the counter for dynamics across all frames 91if (d > Dynamic ::DEFENSIVE && d < Dynamic ::OFFENSIVE ) { 92//Index is the same for the 2nd player for neutral dynamics 93++ (a -> ap [1 ].dyn_counts [d ]); 94 }else { 95//Index is inverted for the 2nd player for non-neutral dynamics 96++ (a -> ap [1 ].dyn_counts [Dynamic ::__LAST - d ]); 97 } 98 } 99// std::cout << std::fixed; //Show floats in fixed representation 100// for (unsigned p = 0; p < 2; ++p) { 101// // std::cout << " From the perspective of port " << int(a->ap[p].port+1) << " (" << a->ap[p].char_name << "):" << std::endl; 102// for (unsigned i = 0; i < Dynamic::__LAST; ++i) { 103// std::string n = std::to_string(a->ap[p].dyn_counts[i]); 104// std::string pct = std::to_string((100*float(a->ap[p].dyn_counts[i])/s.frame_count)).substr(0,5); 105// std::cout << " " << SPACE[6-n.length()] << n << " frames (" << pct 106// << "% of game) spent in " << Dynamic::name[i] << std::endl; 107// } 108// } 109} 110 111void Analyzer ::countLCancels (const SlippiReplay & s ,Analysis * a )const { 112for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 113SlippiPlayer p = s .player [a -> ap [pi ].port ]; 114unsigned cancels_hit = 0 ; 115unsigned cancels_miss = 0 ; 116unsigned last_state = 0 ; 117for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 118if (last_state == 0 ) { 119if (p .frame [f ].l_cancel == 1 ) { 120cancels_hit += 1 ; 121 }else if (p .frame [f ].l_cancel == 2 ) { 122cancels_miss += 1 ; 123 } 124 } 125last_state = p .frame [f ].l_cancel ; 126 } 127 128a -> ap [pi ].l_cancels_hit = cancels_hit ; 129a -> ap [pi ].l_cancels_missed = cancels_miss ; 130float cancels_pct = 100 * ((float )cancels_hit / (cancels_hit + cancels_miss )); 131// std::cout << " Hit " << cancels_hit << "/" << cancels_hit+cancels_miss << " l cancels (" << cancels_pct << "%)" << std::endl; 132 } 133} 134 135void Analyzer ::countButtons (const SlippiReplay & s ,Analysis * a )const { 136for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 137SlippiPlayer p = s .player [a -> ap [pi ].port ]; 138uint16_t last_buttons = 0 ; 139float last_ax = 0 ; 140float last_ay = 0 ; 141float last_cx = 0 ; 142float last_cy = 0 ; 143for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 144// Add buttons pressed this frame to button count 145uint16_t cur_buttons = p .frame [f ].buttons ; 146uint16_t new_buttons = cur_buttons & (cur_buttons ^last_buttons ); 147new_buttons &=0x0F70 ;//Mask out unused bits 148a -> ap [pi ].button_count += countBits (new_buttons ); 149last_buttons = cur_buttons ; 150 151// Check analog stick for movement 152float cur_ax = p .frame [f ].joy_x ; 153float cur_ay = p .frame [f ].joy_y ; 154a -> ap [pi ].astick_count += checkStickMovement (cur_ax ,cur_ay ,last_ax ,last_ay ); 155last_ax = cur_ax ; 156last_ay = cur_ay ; 157 158// Check C stick for movement 159float cur_cx = p .frame [f ].c_x ; 160float cur_cy = p .frame [f ].c_y ; 161a -> ap [pi ].cstick_count += checkStickMovement (cur_cx ,cur_cy ,last_cx ,last_cy ); 162last_cx = cur_cx ; 163last_cy = cur_cy ; 164 } 165 } 166} 167 168void Analyzer ::countTechs (const SlippiReplay & s ,Analysis * a )const { 169for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 170SlippiPlayer p = s .player [a -> ap [pi ].port ]; 171unsigned techs_hit = 0 ; 172unsigned walltechs_hit = 0 ;//And ceiling techs 173unsigned walljumps_hit = 0 ; 174unsigned walljumptechs_hit = 0 ; 175unsigned techs_missed = 0 ; 176bool teching = false; 177 178for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 179if (inTechState (p .frame [f ])) { 180if (notteching ) { 181teching = true; 182if (p .frame [f ].action_pre <=Action ::DownSpotD ) { 183++ techs_missed ; 184 }else if (p .frame [f ].action_pre <=Action ::PassiveStandB ) { 185++ techs_hit ; 186 }else if (p .frame [f ].action_pre == Action ::PassiveWallJump ) { 187if (inDamagedState (p .frame [f - 1 ])|| inTumble (p .frame [f - 1 ])) { 188++ walljumptechs_hit ; 189 }else { 190++ walljumps_hit ; 191 } 192 }else { 193++ walltechs_hit ;//Or ceiling techs 194 } 195 } 196 }else { 197teching = false; 198 } 199 } 200 201a -> ap [pi ].techs = techs_hit ; 202a -> ap [pi ].walltechs = walltechs_hit ; 203a -> ap [pi ].walljumps = walljumps_hit ; 204a -> ap [pi ].walltechjumps = walljumptechs_hit ; 205a -> ap [pi ].missed_techs = techs_missed ; 206 207// std::cout << " Hit " << techs_hit << " grounded techs" << std::endl; 208// std::cout << " Hit " << walltechs_hit << " wall techs" << std::endl; 209// std::cout << " Hit " << walljumps_hit << " wall jumps" << std::endl; 210// std::cout << " Hit " << walljumptechs_hit << " wall jump techs" << std::endl; 211// std::cout << " Missed " << techs_missed << " techs" << std::endl; 212 } 213} 214 215void Analyzer ::countDashdances (const SlippiReplay & s ,Analysis * a )const { 216for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 217SlippiPlayer p = s .player [a -> ap [pi ].port ]; 218unsigned dashdances = 0 ; 219for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 220if (isDashdancing (p ,f )) { 221++ dashdances ; 222 } 223 } 224 225a -> ap [pi ].dashdances = dashdances ; 226// std::cout << " Dashdanced " << dashdances << " times" << std::endl; 227 } 228} 229 230//Code adapted from Fizzi's 231void Analyzer ::countAirdodgesAndWavelands (const SlippiReplay & s ,Analysis * a )const { 232for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 233SlippiPlayer p = s .player [a -> ap [pi ].port ]; 234int airdodges = 0 ; 235unsigned wavelands = 0 ; 236unsigned wavedashes = 0 ; 237bool airdodging = false; 238for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 239if (maybeWavelanding (p ,f )) {//Waveland detection by Fizzi 240//Look at the last 8 frames (including this one) re Fizzi 241bool foundAirdodge = false; 242bool foundJumpsquat = false; 243bool foundOther = false; 244for (unsigned i = 1 ;i < 8 ;++ i ) { 245if (isAirdodging (p .frame [f - i ])) { 246foundAirdodge = true; 247 }else if (isInJumpsquat (p .frame [f - i ])) { 248foundJumpsquat = true; 249break ; 250 }else { 251foundOther = true; 252 } 253 } 254if (foundAirdodge ) { 255if ((notfoundJumpsquat )&& (notfoundOther )) { 256continue ;//If the airdodge is the only animation we found, proceed 257 }else { 258-- airdodges ;//Otherwise, subtract it from our airdodge count and keep checkings 259 } 260 } 261if (foundJumpsquat ) {//If we were in jumpsquat at all recently, we're wavedashing 262++ wavedashes ; 263 }else if (foundOther ) {//If we were in any other animation besides airdodge, it's a waveland 264++ wavelands ; 265 }//Otherwise, nothing special happened 266 }else if (isAirdodging (p .frame [f ])) { 267if (notairdodging ) { 268++ airdodges ; 269airdodging = true; 270 } 271 }else { 272airdodging = false; 273 } 274 } 275 276// it's possible the logic above outputs a negative airdodge count -> use a minimum as workaround: 277a -> ap [pi ].airdodges = airdodges > 0 ?airdodges :0 ; 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 492DOUT3 (" " <<f <<" (" <<frameAsTimer (f ,s .timer ) <<") P1 " 493 <<Dynamic ::name [cur_dynamic ]); 494 } 495 496} 497 498void Analyzer ::analyzePunishes (const SlippiReplay & s ,Analysis * a )const { 499const SlippiPlayer * p = & (s .player [a -> ap [0 ].port ]); 500const SlippiPlayer * o = & (s .player [a -> ap [1 ].port ]); 501unsigned pa = 0 ;//Running tally of player attacks 502unsigned oa = 0 ;//Running tally of opponent attacks 503unsigned pn = 0 ;//Running tally of player punishes 504unsigned on = 0 ;//Running tally of opponent punishes 505unsigned oLastInHitsun = 0 ; 506unsigned pLastInHitsun = 0 ; 507unsigned cur_dyn = a -> dynamics [FIRST_FRAME ]; 508unsigned last_dyn = a -> dynamics [FIRST_FRAME ]; 509Punish * pPunishes = a -> ap [0 ].punishes ; 510Punish * oPunishes = a -> ap [1 ].punishes ; 511Attack * pAttacks = a -> ap [0 ].attacks ; 512Attack * oAttacks = a -> ap [1 ].attacks ; 513 514for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 515SlippiFrame pf = p -> frame [f ]; 516SlippiFrame of = o -> frame [f ]; 517cur_dyn = a -> dynamics [f ]; 518 519oLastInHitsun = isInHitstun (o -> frame [f ]) ?f :oLastInHitsun ; 520pLastInHitsun = isInHitstun (p -> frame [f ]) ?f :pLastInHitsun ; 521bool oPoked = ((f - oLastInHitsun )< POKE_THRES );//Check if opponent has been poked recently 522bool pPoked = ((f - pLastInHitsun )< POKE_THRES );//Check if we have been poked recently 523 524//Check if we counter-attacked (switched from defense to offense or vice versa) 525if (cur_dyn <=Dynamic ::DEFENSIVE && last_dyn >=Dynamic ::OFFENSIVE ) { 526++ a -> ap [1 ].counters ;//If we went from offense to defense, we were countered 527 }else if (cur_dyn >=Dynamic ::OFFENSIVE && last_dyn <=Dynamic ::DEFENSIVE ) { 528++ a -> ap [0 ].counters ;//If we went from defense to offense, we countered 529 } 530 531//Check if either player lost a stock 532if (pf .stocks < p -> frame [f - 1 ].stocks ) { 533unsigned ddir = deathDirection (* p ,f ); 534if (oa > 0 ) { 535oAttacks [oa - 1 ].kill_dir = ddir ; 536 } 537if (oPunishes [on ].num_moves > 0 ) { 538oPunishes [on ].kill_dir = ddir ;//TODO: filter out self-destructs somehow 539 }else if (on > 0 ) { 540oPunishes [on - 1 ].kill_dir = ddir ; 541 } 542if (cur_dyn == Dynamic ::EDGEGUARDING ) { 543++ (a -> ap [1 ].reverse_edgeguards ); 544 }else if (cur_dyn != Dynamic ::RECOVERING && ddir != Dir ::UP ) { 545++ (a -> ap [0 ].self_destructs ); 546 } 547 } 548if (of .stocks < o -> frame [f - 1 ].stocks ) { 549unsigned ddir = deathDirection (* o ,f ); 550if (pa > 0 ) { 551pAttacks [pa - 1 ].kill_dir = ddir ; 552 } 553if (pPunishes [pn ].num_moves > 0 ) { 554pPunishes [pn ].kill_dir = ddir ; 555 }else if (pn > 0 ) { 556pPunishes [pn - 1 ].kill_dir = ddir ; 557 } 558if (cur_dyn == Dynamic ::RECOVERING ) { 559++ (a -> ap [0 ].reverse_edgeguards ); 560 }else if (cur_dyn != Dynamic ::EDGEGUARDING && ddir != Dir ::UP ) { 561++ (a -> ap [1 ].self_destructs ); 562 } 563 } 564 565//Check if either player has dropped a punish off an opening 566bool pPunishEnd = false; 567bool oPunishEnd = false; 568if (f == s .frame_count - 1 ) { 569pPunishEnd = true; 570oPunishEnd = true; 571 }else if (cur_dyn != Dynamic ::POKING ) { 572if (cur_dyn > Dynamic ::DEFENSIVE && notpPoked ) { 573//If the opponent had a punish going and they are no longer on offense, end their punish 574oPunishEnd = true; 575 } 576if (cur_dyn < Dynamic ::OFFENSIVE && notoPoked ) { 577//If we had a punish going and we are no longer on offense, end our punish 578pPunishEnd = true; 579 } 580 } 581 582//Update punish counter for ended punishes 583if (pPunishEnd && pa > 0 ) { 584if (pPunishes [pn ].num_moves > 0 ) { 585pPunishes [pn ].end_frame = f ; 586pPunishes [pn ].end_pct = of .percent_pre ; 587pPunishes [pn ].last_move_id = pf .hit_with ; 588if (pPunishes [pn ].num_moves > pAttacks [pa - 1 ].hit_id ) { 589a -> ap [0 ].neutral_wins += 1 ; 590 }else { 591a -> ap [0 ].pokes += 1 ; 592 } 593++ pn ; 594 } 595 } 596if (oPunishEnd && oa > 0 ) { 597if (oPunishes [on ].num_moves > 0 ) { 598oPunishes [on ].end_frame = f ; 599oPunishes [on ].end_pct = pf .percent_pre ; 600oPunishes [on ].last_move_id = of .hit_with ; 601if (oPunishes [on ].num_moves > oAttacks [oa - 1 ].hit_id ) { 602a -> ap [1 ].neutral_wins += 1 ; 603 }else { 604a -> ap [1 ].pokes += 1 ; 605 } 606++ on ; 607 } 608 } 609 610//If the opponent just took damage 611float o_damage_taken = of .percent_pre - o -> frame [f - 1 ].percent_pre ; 612if (o_damage_taken > 0 ) { 613//Check for bubble damage 614pAttacks [pa ].move_id = (isOffscreen (of )&& o_damage_taken == 1 ) ?Move ::BUBBLE :pf .hit_with ; 615//Last frame we actually took damage; frame before that gives us the animation frame our move hit 616pAttacks [pa ].anim_frame = p -> frame [f - 2 ].action_fc ; 617pAttacks [pa ].punish_id = pn ; 618if (//Check if this is a consecutive hit from a multihit move 619pa > 0 && //If this isn't our first move 620pAttacks [pa ].move_id == pAttacks [pa - 1 ].move_id && //If the last move we hit with had the same id 621pAttacks [pa ].anim_frame > pAttacks [pa - 1 ].anim_frame && //If the action frame counter is higher 622//If the gap between animation and game frames is less than max hitlag for the move 623//Formula: https://www.ssbwiki.com/Freeze_frame 624 (f - pAttacks [pa ].anim_frame <= (pAttacks [pa - 1 ].frame - pAttacks [pa - 1 ].anim_frame + (pAttacks [pa - 1 ].damage /3 + 3 )))) { 625pAttacks [pa ].hit_id = pAttacks [pa - 1 ].hit_id + 1 ; 626 }else { 627pAttacks [pa ].hit_id = 1 ; 628++ (a -> ap [0 ].move_counts [pAttacks [pa ].move_id ]); 629 } 630pAttacks [pa ].frame = f ; 631pAttacks [pa ].damage = o_damage_taken ; 632a -> ap [0 ].dyn_damage [cur_dyn ]+= o_damage_taken ;//Dynamic is normal for player 633pAttacks [pa ].opening = cur_dyn ;//Dynamic is normal for player 634pAttacks [pa ].kill_dir = Dir ::NEUT ; 635++ pa ; 636//If this is the start of a combo 637if (pPunishes [pn ].num_moves == 0 ) { 638pPunishes [pn ].start_frame = f ; 639pPunishes [pn ].start_pct = o -> frame [f - 1 ].percent_pre ; 640pPunishes [pn ].stocks = o -> frame [f - 1 ].stocks ; 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 ].stocks = p -> frame [f - 1 ].stocks ; 682oPunishes [on ].kill_dir = Dir ::NEUT ; 683 } 684a -> ap [1 ].damage_dealt += p_damage_taken ; 685oPunishes [on ].end_frame = f ; 686oPunishes [on ].end_pct = pf .percent_pre ; 687oPunishes [on ].last_move_id = of .hit_with ; 688oPunishes [on ].num_moves += 1 ; 689 } 690 691last_dyn = cur_dyn ;//Update the last dynamic 692 } 693} 694 695void Analyzer ::analyzeCancels (const SlippiReplay & s ,Analysis * a )const { 696for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 697const SlippiPlayer * p = & (s .player [a -> ap [pi ].port ]); 698Attack * attacks = a -> ap [pi ].attacks ; 699for (unsigned i = 0 ;attacks [i ].frame > 0 ;++ i ) { 700unsigned f = attacks [i ].frame ; 701if (attacks [i ].move_id >=Move ::NAIR && attacks [i ].move_id <=Move ::DAIR ) { 702unsigned last_frame = attacks [i ].frame + 60 ; 703if (last_frame > s .frame_count ) { 704last_frame = s .frame_count ; 705 } 706for (unsigned f = attacks [i ].frame ;f < last_frame ;++ f ) { 707//Check if we had the opportunity to edge cancel 708if (didEdgeCancelAerial (p -> frame [f ])) { 709attacks [i ].cancel_type = Cancel ::EDGE ; 710break ; 711 } 712//Check if we had the opportunity to teeter cancel 713if (didTeeterCancelAerial (p -> frame [f ])) { 714attacks [i ].cancel_type = Cancel ::TEETER ; 715break ; 716 } 717//Check if we had the opportunity to autocancel 718if (didAutoCancelAerial (p -> frame [f ])) { 719attacks [i ].cancel_type = Cancel ::AUTO ; 720break ; 721 } 722//Check if we had the opportunity to L cancel 723if (p -> frame [f ].l_cancel > 0 ) { 724if (p -> frame [f ].l_cancel == 1 ) { 725attacks [i ].cancel_type = Cancel ::L ; 726 } 727break ; 728 } 729 } 730 } 731 } 732 } 733} 734 735void Analyzer ::analyzeShield (const SlippiReplay & s ,Analysis * a )const { 736for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 737const SlippiPlayer * p = & (s .player [a -> ap [pi ].port ]); 738for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 739float shield_damage = (p -> frame [f ].shield - p -> frame [f - 1 ].shield ); 740if (shield_damage > 0 ) { 741a -> ap [pi ].shield_time += 1 ; 742a -> ap [pi ].shield_damage += shield_damage ; 743if (p -> frame [f ].shield < a -> ap [pi ].shield_lowest ) { 744a -> ap [pi ].shield_lowest = p -> frame [f ].shield ; 745 } 746 } 747 } 748 } 749} 750 751unsigned Analyzer ::countTransitions (const SlippiReplay & s ,Analysis * a ,unsigned pnum ,bool (* cb )(const SlippiFrame & ))const { 752SlippiPlayer p = s .player [a -> ap [pnum ].port ]; 753unsigned counter = 0 ; 754bool active = false; 755for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 756if (cb (p .frame [f ])) { 757if (notactive ) { 758++ counter ; 759active = true; 760 } 761 }else { 762active = false; 763 } 764 } 765return counter ; 766} 767 768unsigned Analyzer ::countTransitions (const SlippiReplay & s ,Analysis * a ,unsigned pnum ,bool (* cb )(const SlippiPlayer & ,const unsigned ))const { 769SlippiPlayer p = s .player [a -> ap [pnum ].port ]; 770unsigned counter = 0 ; 771bool active = false; 772for (unsigned f = (- LOAD_FRAME );f < s .frame_count ;++ f ) { 773if (cb (p ,f )) { 774if (notactive ) { 775++ counter ; 776active = true; 777 } 778 }else { 779active = false; 780 } 781 } 782return counter ; 783} 784 785void Analyzer ::countBasicAnimations (const SlippiReplay & s ,Analysis * a )const { 786for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 787a -> ap [pi ].state_changes = countTransitions (s ,a ,pi ,didActionStateChange ); 788 789a -> ap [pi ].ledge_grabs = countTransitions (s ,a ,pi ,isOnLedge ); 790a -> ap [pi ].rolls = countTransitions (s ,a ,pi ,isRolling ); 791a -> ap [pi ].spotdodges = countTransitions (s ,a ,pi ,isSpotdodging ); 792a -> ap [pi ].powershields = countTransitions (s ,a ,pi ,didPowerShield ); 793a -> ap [pi ].grabs = countTransitions (s ,a ,pi ,isGrabbing ); 794a -> ap [pi ].taunts = countTransitions (s ,a ,pi ,isTaunting ); 795a -> ap [pi ].meteor_cancels = countTransitions (s ,a ,pi ,didMeteorCancel ); 796a -> ap [pi ].hits_blocked = countTransitions (s ,a ,pi ,isInShieldstun ); 797a -> ap [pi ].edge_cancel_aerials = countTransitions (s ,a ,pi ,didEdgeCancelAerial ); 798a -> ap [pi ].edge_cancel_specials = countTransitions (s ,a ,pi ,didEdgeCancelSpecial ); 799a -> ap [pi ].teeter_cancel_aerials = countTransitions (s ,a ,pi ,didTeeterCancelAerial ); 800a -> ap [pi ].teeter_cancel_specials = countTransitions (s ,a ,pi ,didTeeterCancelSpecial ); 801a -> ap [pi ].no_impact_lands = countTransitions (s ,a ,pi ,didNoImpactLand ); 802a -> ap [pi ].shield_drops = countTransitions (s ,a ,pi ,didShieldDrop ); 803a -> ap [pi ].pivots = countTransitions (s ,a ,pi ,didPivot ); 804a -> ap [pi ].short_hops = countTransitions (s ,a ,pi ,didShortHop ); 805a -> ap [pi ].full_hops = countTransitions (s ,a ,pi ,didHop )- a -> ap [pi ].short_hops ; 806 807a -> ap [pi ].shield_breaks = countTransitions (s ,a ,1 - pi ,isShieldBroken ); 808a -> ap [pi ].grab_escapes = countTransitions (s ,a ,1 - pi ,isReleasing ); 809a -> ap [pi ].shield_stabs = countTransitions (s ,a ,1 - pi ,wasShieldStabbed ); 810a -> ap [pi ].stage_spikes = countTransitions (s ,a ,1 - pi ,wasStageSpiked ); 811 } 812} 813 814void Analyzer ::showActionStates (const SlippiReplay & s ,Analysis * a )const { 815const SlippiPlayer * p = & (s .player [a -> ap [0 ].port ]); 816const SlippiPlayer * o = & (s .player [a -> ap [1 ].port ]); 817for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 818SlippiFrame pf = p -> frame [f ]; 819DOUT2 (" " <<f <<" (" <<frameAsTimer (f ,s .timer ) <<") P1 " 820 <<Action ::name [pf .action_pre ] <<" " 821 <<" -> " 822 <<" " <<Action ::name [pf .action_post ]); 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 } 829} 830 831void Analyzer ::countPhantoms (const SlippiReplay & s ,Analysis * a )const { 832const SlippiPlayer * p = & (s .player [a -> ap [0 ].port ]); 833const SlippiPlayer * o = & (s .player [a -> ap [1 ].port ]); 834for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 835if (wasHitByPhantom (* p ,* o ,f )) { 836++ (a -> ap [1 ].phantom_hits ); 837 } 838if (wasHitByPhantom (* o ,* p ,f )) { 839++ (a -> ap [0 ].phantom_hits ); 840 } 841 } 842} 843 844void Analyzer ::countLedgedashes (const SlippiReplay & s ,Analysis * a )const { 845for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 846const SlippiPlayer * p = & (s .player [a -> ap [pi ].port ]); 847unsigned galint = 0 ; 848bool offledge = false; 849for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 850if (galint > 0 ) { 851-- galint ; 852if (notoffledge ) { 853offledge = didReleaseLedge (* p ,f ); 854continue ; 855 } 856SlippiFrame pf = p -> frame [f ]; 857bool landed = isLanding (p -> frame [f - 1 ])&& (notisLanding (pf ))&& (notisAirborne (pf )); 858if ((didNoImpactLand (pf )|| landed )&& (notisInHitlag (pf ))&& (notisInHitstun (pf ))) { 859if (a -> ap [pi ].max_galint < galint ) { 860a -> ap [pi ].max_galint = galint ; 861 } 862a -> ap [pi ].galint_ledgedashes += 1 ; 863a -> ap [pi ].mean_galint += galint ; 864f += galint ; 865galint = 0 ; 866offledge = false; 867 } 868 } 869if (didCliffCatchEnd (* p ,f )) { 870galint = 30 ; 871if (didReleaseLedge (* p ,f )) { 872offledge = true; 873 } 874 } 875 } 876if (a -> ap [pi ].galint_ledgedashes > 0 ) { 877a -> ap [pi ].mean_galint /=a -> ap [pi ].galint_ledgedashes ; 878 } 879 } 880} 881 882void Analyzer ::countMoves (const SlippiReplay & s ,Analysis * a )const { 883for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 884const SlippiPlayer * p = & (s .player [a -> ap [pi ].port ]); 885const unsigned pid = p -> ext_char_id ; 886bool was_throw = false; 887bool was_normal = false; 888bool was_special = false; 889bool was_misc = false; 890bool was_grab = false; 891bool was_pummel = false; 892for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 893SlippiFrame pf = p -> frame [f ]; 894if (isThrowing (pf )) { 895if (!(was_throw )) { 896++ (a -> ap [pi ].used_throws ); 897 } 898was_throw = true; 899 }else if (isUsingNormalMove (pf )) { 900if (!(was_normal )) { 901++ (a -> ap [pi ].used_norm_moves ); 902 } 903was_normal = true; 904 }else if (isUsingSpecialMove (pf ,pid )) { 905if (!(was_special )) { 906++ (a -> ap [pi ].used_spec_moves ); 907 } 908was_special = true; 909 }else if (isUsingMiscMove (pf )) { 910if (!(was_misc )) { 911++ (a -> ap [pi ].used_misc_moves ); 912 } 913was_misc = true; 914 }else if (isUsingGrab (pf )) { 915if (!(was_grab )) { 916++ (a -> ap [pi ].used_grabs ); 917 } 918was_grab = true; 919 }else if (isUsingPummel (pf )) { 920if (!(was_pummel )) { 921++ (a -> ap [pi ].used_pummels ); 922 } 923was_pummel = true; 924 }else { 925was_throw = false; 926was_normal = false; 927was_special = false; 928was_misc = false; 929was_grab = false; 930was_pummel = false; 931 } 932 } 933a -> ap [pi ].total_moves_used = a -> ap [pi ].used_throws + a -> ap [pi ].used_norm_moves 934+ a -> ap [pi ].used_spec_moves + a -> ap [pi ].used_misc_moves + a -> ap [pi ].used_grabs + a -> ap [pi ].used_pummels ; 935// std::cout << "Player " << pi+1 << " attempted: " << std::endl; 936// std::cout << " " << a->ap[pi].used_throws << " used_throws" << std::endl; 937// std::cout << " " << a->ap[pi].used_norm_moves << " used_norm_moves" << std::endl; 938// std::cout << " " << a->ap[pi].used_spec_moves << " used_spec_moves" << std::endl; 939// std::cout << " " << a->ap[pi].used_misc_moves << " used_misc_moves" << std::endl; 940// std::cout << " " << a->ap[pi].used_grabs << " used_grabs" << std::endl; 941// std::cout << " " << a->ap[pi].used_pummels << " used_pummels" << std::endl; 942// std::cout << " " << a->ap[pi].total_moves_used << " used_total_moves" << std::endl; 943 } 944} 945 946void Analyzer ::countActionability (const SlippiReplay & s ,Analysis * a )const { 947for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 948const SlippiPlayer * p = & (s .player [a -> ap [pi ].port ]); 949bool was_in_hitstun = false; 950unsigned hitstun_times = 0 ;//Number of times we enter hitstun 951unsigned hitstun_act = 0 ;//Total number of frames we take to act out of hitstun 952unsigned hitstun_act_cur = 0 ;//Current number of frames we take to act out of hitstun 953bool was_in_shieldstun = false; 954unsigned shieldstun_times = 0 ;//Number of times we enter shieldstun 955unsigned shieldstun_act = 0 ;//Total number of frames we take to act out of shieldstun 956unsigned shieldstun_act_cur = 0 ;//Current number of frames we take to act out of shieldstun 957bool was_in_wait = false; 958unsigned wait_times = 0 ;//Number of times we enter wait 959unsigned wait_act = 0 ;//Total number of frames we take to act out of wait 960unsigned wait_act_cur = 0 ;//Current number of frames we take to act out of wait 961for (unsigned f = FIRST_FRAME ;f < s .frame_count ;++ f ) { 962SlippiFrame pf = p -> frame [f ]; 963 964// Count the number of frames we take to act out of hitstun 965if (isInHitstun (pf )) { 966if (!was_in_hitstun ) { 967was_in_hitstun = true; 968++ hitstun_times ; 969hitstun_act_cur = 0 ; 970 } 971 }else if (was_in_hitstun ) { 972if ( 973inTumble (pf )|| 974isInDamageAnimation (pf )|| 975isInAnyWait (pf )) { 976++ hitstun_act_cur ; 977++ hitstun_act ; 978 }else { 979if ((MAX_WAIT < hitstun_act_cur )|| wasStageSpiked (pf )|| inMissedTechState (pf )) { 980-- hitstun_times ;//We're not trying to act out of stun 981 }else { 982// std::cout << "hitstun act " << hitstun_act_cur << std::endl; 983hitstun_act += hitstun_act_cur ; 984 } 985was_in_hitstun = false; 986 } 987 } 988 989// Count the number of frames we take to act out of shieldstun 990unsigned max_shield_wait = MAX_WAIT ; 991if (isInShieldstun (pf )) { 992if (!was_in_shieldstun ) { 993was_in_shieldstun = true; 994++ shieldstun_times ; 995shieldstun_act_cur = 0 ; 996 }else if (shieldstun_act_cur > 0 ) { 997//We might be waiting in shield due to shield pressure, 998// so break the MAX_WAIT limit in these cases 999max_shield_wait = MAX_WAIT + shieldstun_act_cur ; 1000 } 1001 }else if (was_in_shieldstun ) { 1002if (isInShield (pf )) { 1003++ shieldstun_act_cur ; 1004 }else { 1005if ((max_shield_wait < shieldstun_act_cur ) ) { 1006-- shieldstun_times ;//We're not trying to act out of stun 1007 }else { 1008// std::cout << "shieldstun act " << shieldstun_act_cur << std::endl; 1009shieldstun_act += shieldstun_act_cur ; 1010 } 1011was_in_shieldstun = false; 1012 } 1013 } 1014 1015// Count the number of frames we take to act out of shieldstun 1016if (isInAnyWait (pf )) { 1017if (!was_in_wait ) { 1018was_in_wait = true; 1019++ wait_times ; 1020wait_act_cur = 0 ; 1021 }else { 1022++ wait_act_cur ; 1023 } 1024 }else if (was_in_wait ) { 1025if ((MAX_WAIT < wait_act_cur ) ) { 1026-- wait_times ;//We're not trying to act out of wait 1027 }else { 1028// std::cout << "wait act " << wait_act_cur << std::endl; 1029wait_act += wait_act_cur ; 1030 } 1031was_in_wait = false; 1032 } 1033 1034 } 1035 1036a -> ap [pi ].hitstun_times = hitstun_times ; 1037a -> ap [pi ].hitstun_act_frames = hitstun_act ; 1038a -> ap [pi ].shieldstun_times = shieldstun_times ; 1039a -> ap [pi ].shieldstun_act_frames = shieldstun_act ; 1040a -> ap [pi ].wait_times = wait_times ; 1041a -> ap [pi ].wait_act_frames = wait_act ; 1042 } 1043} 1044 1045void Analyzer ::computeTrivialInfo (const SlippiReplay & s ,Analysis * a )const { 1046for (unsigned pi = 0 ;pi < 2 ;++ pi ) { 1047// Get damage per opening 1048a -> ap [pi ].total_openings = a -> ap [pi ].neutral_wins + a -> ap [pi ].pokes ; 1049if (a -> ap [pi ].total_openings > 0 ) { 1050a -> ap [pi ].mean_opening_percent = a -> ap [pi ].damage_dealt /a -> ap [pi ].total_openings ; 1051 } 1052 1053// Get openings per kill and percent per kill 1054unsigned o_end_stocks = a -> ap [1 - pi ].end_stocks ; 1055unsigned o_stocks_lost = a -> ap [1 - pi ].start_stocks - o_end_stocks ; 1056if (o_stocks_lost > 0 ) { 1057a -> ap [pi ].mean_kill_openings = float (a -> ap [pi ].total_openings ) /o_stocks_lost ; 1058float damage_dealt = a -> ap [pi ].damage_dealt ; 1059if (o_end_stocks > 0 ) { 1060//Need to not include stocks we didn't take in our computation 1061damage_dealt -= a -> ap [1 - pi ].end_pct ; 1062 } 1063a -> ap [pi ].mean_kill_percent = damage_dealt /o_stocks_lost ; 1064a -> ap [1 - pi ].mean_death_percent = a -> ap [pi ].mean_kill_percent ; 1065 } 1066 1067// Get actions per minute 1068unsigned total_actions = 1069a -> ap [pi ].button_count + a -> ap [pi ].cstick_count + a -> ap [pi ].astick_count ; 1070a -> ap [pi ].apm = total_actions * (3600.0f /a -> game_length ); 1071 1072// Get action states per minute 1073a -> ap [pi ].aspm = a -> ap [pi ].state_changes * (3600.0f /a -> game_length ); 1074 1075// Get total number of moves landed and move accuracy 1076a -> ap [pi ].total_moves_landed = 0 ; 1077for (unsigned i = 0 ;i < Move ::__LAST ;++ i ) { 1078a -> ap [pi ].total_moves_landed += a -> ap [pi ].move_counts [i ]; 1079 } 1080if (a -> ap [pi ].total_moves_used > 0 ) { 1081a -> ap [pi ].move_accuracy = float (a -> ap [pi ].total_moves_landed ) /float (a -> ap [pi ].total_moves_used ); 1082 } 1083 1084// Get average actionability 1085a -> ap [pi ].actionability = 0 ; 1086if (a -> ap [pi ].shieldstun_times > 0 ) { 1087a -> ap [pi ].actionability += float (a -> ap [pi ].shieldstun_act_frames ) /a -> ap [pi ].shieldstun_times ; 1088 } 1089if (a -> ap [pi ].hitstun_times > 0 ) { 1090a -> ap [pi ].actionability += float (a -> ap [pi ].hitstun_act_frames ) /a -> ap [pi ].hitstun_times ; 1091 } 1092if (a -> ap [pi ].wait_times > 0 ) { 1093a -> ap [pi ].actionability += float (a -> ap [pi ].wait_act_frames ) /a -> ap [pi ].wait_times ; 1094 } 1095a -> ap [pi ].actionability /=3.0f ; 1096 1097// Get number of times we won neutral relative to time spent in neutral / defense 1098unsigned neut_frames = 1099a -> ap [pi ].dyn_counts [Dynamic ::TRADING ]+ 1100a -> ap [pi ].dyn_counts [Dynamic ::POKING ]+ 1101a -> ap [pi ].dyn_counts [Dynamic ::NEUTRAL ]+ 1102a -> ap [pi ].dyn_counts [Dynamic ::POSITIONING ]+ 1103a -> ap [pi ].dyn_counts [Dynamic ::FOOTSIES ]+ 1104a -> ap [pi ].dyn_counts [Dynamic ::RECOVERING ]+ 1105a -> ap [pi ].dyn_counts [Dynamic ::ESCAPING ]+ 1106a -> ap [pi ].dyn_counts [Dynamic ::PUNISHED ]+ 1107a -> ap [pi ].dyn_counts [Dynamic ::GROUNDING ]+ 1108a -> ap [pi ].dyn_counts [Dynamic ::PRESSURED ]+ 1109a -> ap [pi ].dyn_counts [Dynamic ::DEFENSIVE ] 1110 ; 1111if (neut_frames > 0 ) { 1112a -> ap [pi ].neutral_wins_per_min = a -> ap [pi ].total_openings / (float (neut_frames ) /3600.0f ); 1113 } 1114 } 1115} 1116 1117Analysis * Analyzer ::analyze (const SlippiReplay & s ) { 1118DOUT1 (" Analyzing replay" ); 1119 1120Analysis * a = new Analysis (s .frame_count );//Structure for holding the analysis so far 1121 1122//Verify this is a 1 v 1 match; can't analyze otherwise 1123if (notget1v1Ports (s ,a )) { 1124FAIL (" Not a two player match; refusing to analyze further" ); 1125a -> success = false; 1126return a ; 1127 } 1128 1129DOUT1 (" Analyzing basic game info" ); 1130getBasicGameInfo (s ,a ); 1131 1132//Interaction-level stats 1133DOUT1 (" Analyzing player interactions" ); 1134analyzeInteractions (s ,a ); 1135DOUT1 (" Summarizing player interactions" ); 1136summarizeInteractions (s ,a ); 1137DOUT1 (" Analyzing players' punishes" ); 1138analyzePunishes (s ,a ); 1139DOUT1 (" Analyzing players' cancelling techniques" ); 1140analyzeCancels (s ,a ); 1141DOUT1 (" Analyzing players' shielding" ); 1142analyzeShield (s ,a ); 1143 1144//Player-level stats 1145DOUT1 (" Computing statistics based on animations" ); 1146countBasicAnimations (s ,a ); 1147DOUT1 (" Computing air / ground time for each player" ); 1148computeAirtime (s ,a ); 1149DOUT1 (" Counting l cancels" ); 1150countLCancels (s ,a ); 1151DOUT1 (" Counting techs" ); 1152countTechs (s ,a ); 1153DOUT1 (" Counting dashdances" ); 1154countDashdances (s ,a ); 1155DOUT1 (" Counting airdodges, wavelands, and wavedashes" ); 1156countAirdodgesAndWavelands (s ,a ); 1157DOUT1 (" Counting phantom hits" ); 1158countPhantoms (s ,a ); 1159DOUT1 (" Counting button pushes" ); 1160countButtons (s ,a ); 1161DOUT1 (" Counting ledgedashes" ); 1162countLedgedashes (s ,a ); 1163DOUT1 (" Counting act out of wait / stun" ); 1164countActionability (s ,a ); 1165DOUT1 (" Counting number of moves used" ); 1166countMoves (s ,a ); 1167 1168DOUT1 (" Computing trivial match info" ); 1169computeTrivialInfo (s ,a ); 1170 1171//Debug stuff 1172if (_debug >=2 ) { 1173DOUT2 (" Showing action states" ); 1174showActionStates (s ,a ); 1175 } 1176 1177a -> success = true; 1178DOUT1 (" Successfully analyzed replay!" ); 1179return a ; 1180} 1181 1182}