/ #mechanics 

Turn Based: Static Order

Turn-based means that players take turns acting instead of all acting at once. Static order means that the turn order is fixed, not dynamic.

This is the classic turn-based mechanic used in most board games. Often described as I-go-you-go, which is accurate for two player games. For games with more than two players this turn system can become very unfair towards the players that go last.

Examples:

  • Chess:
    • White plays first, then Black, then White again - this order never changes.
  • Heroes of Might & Magic:
    • Blue plays, then Red, then Green, then Yellow, then repeat.
    • The only possible change is to skip players that have been eliminated.

ECS Design

Components

Player

  • name: String
  • color: Color
  • order: Integer

Active

Marker component indicating that a Player is the active player.

EndTurn

Marker component indicating that the Active Player is ending their turn.

Entities

One entity per player with a single Player component.

Systems

Turn System

The turn system should be implemented aprroximately as follows (Python pseudo-code, very naive implementation):

active_players = world.get_entities_with_components(Player, Active)
if len(active_players) == 0:
  players = world.get_entities_with_component(Player)
  players.sort(key=order)
  
  send_event("start_round") 

  world.add_component(players[0], Active)
  send_event("start_turn", player) 
else:
  active_player = active_players[0]

  if active_player.has_component(EndTurn):
    world.remove_component(active_player, Active)
    world.remove_component(active_player, EndTurn)
    send_event("end_turn", active_player)

    players = world.get_entities_with_component(Player)
    players.sort(key=order)
    for player in players:
      if player.player.order > active_player.player.order:
        world.add_component(player, Active)
        send_event("start_turn", player) 
        return
    
    send_event("end_round")

Notes:

  • To skip an eliminated player, simply delete their Player entity.
  • The events indicate places where other systems may need to do stuff related to turns.
Author

Matt Van Der Westhuizen

Back-end service developer at Ubisoft Blue Byte by day - wannabe game designer & developer by night.