Buggy code:
int numRoleMovesSimulated = 0 ; int numBranchesTaken = 0 ; int turnNum = 0 ; int lastOurGoal = underlyingStateMachine . getGoal ( sampleState , ourRole ) ; heuristic . tuningStartSampleGame ( ) ; while ( ! ( underlyingStateMachine . isTerminal ( sampleState ) ) ) { boolean roleWithChoiceSeen = false ; ForwardDeadReckonLegalMoveInfo [ ] jointMove = new ForwardDeadReckonLegalMoveInfo [ numRoles ] ; Set < Move > allMovesInState = new HashSet < > ( ) ; int choosingRoleIndex = - 2 ; turnNum ++ ; for ( int i = 0 ; i < ( numRoles ) ; i ++ ) { List < ForwardDeadReckonLegalMoveInfo > legalMoves = new ArrayList ( underlyingStateMachine . getLegalMoves ( sampleState , roleOrdering . roleIndexToRole ( i ) ) ) ; if ( ( legalMoves . size ( ) ) > 1 ) { if ( ( roleControlMasks [ i ] . size ( ) ) > 0 ) { if ( ( roleControlMasks [ i ] . intersectionSize ( sampleState ) ) == 0 ) { Sancho . LOGGER . debug ( "Eliminating<seq2seq4repair_space>role<seq2seq4repair_space>control<seq2seq4repair_space>props" ) ; } roleControlMasks [ i ] . intersect ( sampleState ) ; } Set < Move > previousChoices = roleMoves . get ( i ) ; if ( previousChoices != null ) { if ( mGameCharacteristics . isIteratedGame ) { Set < Move > moves = new HashSet < > ( ) ; for ( ForwardDeadReckonLegalMoveInfo moveInfo : legalMoves ) { moves . add ( moveInfo . move ) ; } if ( ! ( previousChoices . equals ( moves ) ) ) { mGameCharacteristics . isIteratedGame = false ; } } } else { Set < Move > moves = new HashSet < > ( ) ; for ( ForwardDeadReckonLegalMoveInfo moveInfo : legalMoves ) { moves . add ( moveInfo . move ) ; } roleMoves . set ( i , moves ) ; } choosingRoleIndex = i ; Factor turnFactor = null ; if ( mGameCharacteristics . isStrictlyAlternatingPlay ) { int moveParity = turnNum % ( numRoles ) ; if ( ( playerMoveParity [ choosingRoleIndex ] ) == ( - 1 ) ) { playerMoveParity [ choosingRoleIndex ] = moveParity ; } else if ( moveParity != ( playerMoveParity [ choosingRoleIndex ] ) ) { mGameCharacteristics . isStrictlyAlternatingPlay = false ; } } for ( ForwardDeadReckonLegalMoveInfo moveInfo : legalMoves ) { if ( factors != null ) { for ( Factor factor : factors ) { if ( factor . getMoves ( ) . contains ( moveInfo . move ) ) { if ( ( turnFactor != null ) && ( turnFactor != factor ) ) { mGameCharacteristics . moveChoicesFromMultipleFactors = true ; break ; } turnFactor = factor ; } } } if ( allMovesInState . contains ( moveInfo . move ) ) { mGameCharacteristics . isSimultaneousMove = true ; choosingRoleIndex = - 1 ; break ; } allMovesInState . add ( moveInfo . move ) ; } if ( roleWithChoiceSeen ) { mGameCharacteristics . isPseudoSimultaneousMove = true ; choosingRoleIndex = - 1 ; } roleWithChoiceSeen = true ; numBranchesTaken += legalMoves . size ( ) ; numRoleMovesSimulated ++ ; } jointMove [ i ] = legalMoves . get ( r . nextInt ( legalMoves . size ( ) ) ) ; } heuristic . tuningInterimStateSample ( sampleState , choosingRoleIndex ) ; underlyingStateMachine . getNextState ( sampleState , null , jointMove , newState ) ; sampleState . copy ( newState ) ; int currentOurGoal = underlyingStateMachine . getGoal ( sampleState , ourRole ) ; totalGoalSamples ++ ; if ( currentOurGoal != lastOurGoal ) { totalGoalChangeCount ++ ; if ( lastOurGoal > currentOurGoal ) { goalsMonotonic = false ; } lastOurGoal = currentOurGoal ; } } if ( turnNum > maxNumTurns ) { maxNumTurns = turnNum ; } if ( turnNum < minNumTurns ) { assert turnNum > 0 ; minNumTurns = turnNum ; } for ( int i = 0 ; i < ( numRoles ) ; i ++ ) { <START_BUG> roleScores [ i ] = underlyingStateMachine . getGoal ( roleOrdering . roleIndexToRole ( i ) ) ; <END_BUG> } assert underlyingStateMachine . isTerminal ( sampleState ) ; heuristic . tuningTerminalStateSample ( sampleState , roleScores ) ; if ( numRoleMovesSimulated > 0 ) { branchingFactorApproximation += numBranchesTaken // numRoleMovesSimulated ; } numSamples ++ ; } heuristic . tuningComplete ( ) ; Sancho . LOGGER . info ( ( ( "Performed<seq2seq4repair_space>" + numSamples ) + "<seq2seq4repair_space>simulations<seq2seq4repair_space>to<seq2seq4repair_space>calculate<seq2seq4repair_space>heuristics" ) ) ; if ( numSamples < ( Sancho . MIN_PRIMARY_SIMULATION_SAMPLES ) ) { mGameCharacteristics . isIteratedGame = false ; heuristic . pruneAll ( ) ; Sancho . LOGGER . warn ( "Insufficient<seq2seq4repair_space>sampling<seq2seq4repair_space>time<seq2seq4repair_space>to<seq2seq4repair_space>reliably<seq2seq4repair_space>ascertain<seq2seq4repair_space>game<seq2seq4repair_space>characteristics" ) ; } else { mGameCharacteristics . hasAdequateSampling = true ; branchingFactorApproximation //= numSamples ; } if ( mGameCharacteristics . isSimultaneousMove ) { heuristic . pruneAll ( ) ; } if ( ( maxNumTurns != minNumTurns ) || ( maxNumTurns < 5 ) ) { mGameCharacteristics . isIteratedGame = false ; } mGameCharacteristics . setGoalsStability ( goalsStabilityHeuristic . getGoalStability ( ) ) ; if ( ( mGameCharacteristics . isSimultaneousMove ) || ( mGameCharacteristics . isPseudoSimultaneousMove ) ) { roleControlProps = null ; greedyRolloutsDisabled = true ; underlyingStateMachine . enableGreedyRollouts ( false , true ) ; } else { underlyingStateMachine . enableGreedyRollouts ( true , false ) ; if ( ( numRoles ) == 1 ) { roleControlProps = null ; } else { ForwardDeadReckonInternalMachineState [ ] inverseMasks = new ForwardDeadReckonInternalMachineState [ numRoles ] ; for ( int i = 0 ; i < ( numRoles ) ; i ++ ) { inverseMasks [ i ] = new ForwardDeadReckonInternalMachineState ( roleControlMasks [ i ] ) ; inverseMasks [ i ] . invert ( ) ; } for ( int i = 0 ; i < ( numRoles ) ; i ++ ) { for ( int j = 0 ; j < ( numRoles ) ; j ++ ) { if ( j != i ) { roleControlMasks [ i ] . intersect ( inverseMasks [ j ] ) ;

Fix:
roleScores [ i ] = underlyingStateMachine . getGoal ( sampleState , roleOrdering . roleIndexToRole ( i ) ) ;