/** * Execute an action on this FSM, the action acts like a transition and will change its status. * * @param action the action to execute * @return a pair of public and private messages containing the result of the action */ public ResultMsgPair executeAction(Action action) { if (state.isActionValid(action, game)) { // The next state of this FSM, if null the status should not change // (this keeps the FSM much more simple!) TurnState nextState = state.executeAction(action, game); if (nextState != null) { setState(nextState); } // Get the ResultMsgPair subsequently yo the execution of the action // (must be called only after execution!) return action.getResult(); } else { // The action is NOT valid, inform the client and don't broadcast // any message. We inform that the problem is with the game rules // (invalid sequence of actions or action parameters not allowed). return new ResultMsgPair(new InvalidRequestMsg("Request against game rules" + "."), null); } }