// have one legal move, and so calling "getRandomJointMove" with our move
// fixed will always return the joint move consisting of our move and the
// opponent's no-op. In a simultaneous-action game, however, the opponent
// may have many moves, and so we will randomly pick one of our opponent's
// possible actions and assume they do that.
MachineState nextState = theMachine.getNextState(getCurrentState(), theMachine.getRandomJointMove(getCurrentState(), getRole(), moveUnderConsideration));
// Does the move under consideration end the game? If it does, do we win
// or lose? If we lose, don't bother considering it. If we win, then we
// definitely want to take this move. If its goal is better than our current
// best goal, go ahead and tentatively select it
if(theMachine.isTerminal(nextState)) {
if(theMachine.getGoal(nextState, getRole()) == 0) {
continue;
} else if(theMachine.getGoal(nextState, getRole()) == 100) {
selection = moveUnderConsideration;
break;
} else {
if (theMachine.getGoal(nextState, getRole()) > maxGoal)
{
selection = moveUnderConsideration;
maxGoal = theMachine.getGoal(nextState, getRole());
}
continue;
}
}
// Check whether any of the legal joint moves from this state lead to
// a loss for us. Again, this only makes sense in the context of an alternating
// play zero-sum game, in which this is the opponent's move and they are trying
// to make us lose, and so if they are offered any move that will make us lose
// they will take it.
boolean forcedLoss = false;
for(List<Move> jointMove : theMachine.getLegalJointMoves(nextState)) {
MachineState nextNextState = theMachine.getNextState(nextState, jointMove);
if(theMachine.isTerminal(nextNextState)) {
if(theMachine.getGoal(nextNextState, getRole()) == 0) {
forcedLoss = true;
break;
}