Skip to content
Settlers Journal
Go back

Simplifying the FSM by Removing Glides and Adopting ActionEnum.NOOP

Edit page

TLDR

Refactoring the design of the Finite State Machine to remove Glides and StateBase. “Free Transitions” can be simply represented by an updated Transition class that can leverage ActionEnum.NOOP.

Notes and brainstorming of new design structure.

alt text

Defining the ActionEnum with delegator / strategy pattern.

public enum ActionEnum {
  CREATE_GAME(new CreateGameAction()),
  JOIN_GAME(new JoinLobbyAction()),
  SKIP(new SkipAction()),
  ROLL(new RollAction()),
  PLACE_SETTLEMENT(new PlaceSettlementAction()),
  PLACE_ROAD(new PlaceRoadAction()),
  BARTER_OFFER(new BarterOfferAction()),
  BARTER_ANSWER(new BarterAnswerAction()),
  PLACE_ROBBER(new PlaceRobberAction()),
  PLAY_DEV_CARD(new PlayDevCardAction()),
  NOOP(new NoopAction());

  private final IAction actionStrategy;

  ActionEnum(IAction actionStrategy) {
    this.actionStrategy = actionStrategy;
  }

  .
  .
  .
}

Main work

Challenges

Learnings


Edit page
Share this post on:

Previous Post
Implementing the New FSM Transition Design with Regression Testing
Next Post
Printing the FSM Definition at Startup and Discovering a Design Code Smell