private void processMove(GreedyMoveScope moveScope) {
   Score score =
       moveScope
           .getGreedyFitStepScope()
           .getGreedyFitSolverPhaseScope()
           .calculateScoreFromWorkingMemory();
   if (assertMoveScoreIsUncorrupted) {
     moveScope.getGreedyFitStepScope().getGreedyFitSolverPhaseScope().assertWorkingScore(score);
   }
   moveScope.setScore(score);
   forager.addMove(moveScope);
 }
 private void doMove(GreedyMoveScope moveScope) {
   WorkingMemory workingMemory = moveScope.getWorkingMemory();
   Move move = moveScope.getMove();
   Move undoMove = move.createUndoMove(workingMemory);
   moveScope.setUndoMove(undoMove);
   move.doMove(workingMemory);
   processMove(moveScope);
   undoMove.doMove(workingMemory);
   if (assertUndoMoveIsUncorrupted) {
     GreedyFitSolverPhaseScope greedyFitSolverPhaseScope =
         moveScope.getGreedyFitStepScope().getGreedyFitSolverPhaseScope();
     Score undoScore = greedyFitSolverPhaseScope.calculateScoreFromWorkingMemory();
     Score lastCompletedStepScore =
         greedyFitSolverPhaseScope.getLastCompletedStepScope().getScore();
     if (!undoScore.equals(lastCompletedStepScore)) {
       // First assert that are probably no corrupted score rules.
       greedyFitSolverPhaseScope
           .getSolverScope()
           .getSolutionDirector()
           .assertWorkingScore(undoScore);
       throw new IllegalStateException(
           "The moveClass ("
               + move.getClass()
               + ")'s move ("
               + move
               + ") probably has a corrupted undoMove ("
               + undoMove
               + ")."
               + " Or maybe there are corrupted score rules.\n"
               + "Check the Move.createUndoMove(...) method of that Move class"
               + " and enable EnvironmentMode TRACE to fail-faster on corrupted score rules.\n"
               + "Score corruption: the lastCompletedStepScore ("
               + lastCompletedStepScore
               + ") is not the undoScore ("
               + undoScore
               + ").");
     }
   }
   logger.trace(
       "        Move score ({}) for move ({}).",
       new Object[] {moveScope.getScore(), moveScope.getMove()});
 }
 public void decideNextStep(GreedyFitStepScope stepScope) {
   Object planningEntity = stepScope.getPlanningEntity();
   Iterator<Move> moveIterator = planningVariableWalker.moveIterator(planningEntity);
   while (moveIterator.hasNext()) {
     Move move = moveIterator.next();
     GreedyMoveScope moveScope = new GreedyMoveScope(stepScope);
     moveScope.setMove(move);
     doMove(moveScope);
     if (forager.isQuitEarly()) {
       break;
     }
   }
   GreedyMoveScope pickedMoveScope = forager.pickMove(stepScope);
   if (pickedMoveScope != null) {
     Move step = pickedMoveScope.getMove();
     stepScope.setStep(step);
     if (logger.isDebugEnabled()) {
       stepScope.setStepString(step.toString());
     }
     stepScope.setUndoStep(pickedMoveScope.getUndoMove());
     stepScope.setScore(pickedMoveScope.getScore());
   }
 }