Class PlayerNode.Remote

java.lang.Object
org.xxdc.oss.example.PlayerNode.Remote
All Implemented Interfaces:
AutoCloseable, ToIntFunction<GameState>, PlayerNode
Enclosing interface:
PlayerNode

public static final class PlayerNode.Remote extends Object implements PlayerNode, AutoCloseable
Represents a remote player node that communicates with a client over a transport server. The remote player node sends the current game state to the client and receives the player's next move. The remote player node is responsible for validating the received move and applying it to the game board. The remote player node must be closed when the game is finished to release the transport server resources.
  • Constructor Details

    • Remote

      public Remote(String playerMarker, TransportServer transport)
      Constructs a new Remote PlayerNode instance that communicates with a client over the provided TransportServer.
      Parameters:
      playerMarker - the marker to identify this player
      transport - the TransportServer to use for communication with the client
      Throws:
      IllegalArgumentException - if the provided TransportServer is null
  • Method Details

    • applyAsInt

      public int applyAsInt(GameState state)
      Gets the player's next move to apply to the given game board.
      Specified by:
      applyAsInt in interface PlayerNode
      Specified by:
      applyAsInt in interface ToIntFunction<GameState>
      Parameters:
      state - the current state of the game
      Returns:
      the location on the game board where the move was made
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • playerMarker

      public String playerMarker()
      Description copied from interface: PlayerNode
      Gets the player's marker: a string representation of the player's identity. Returns the marker (e.g. "X" or "O") used by this player.
      Specified by:
      playerMarker in interface PlayerNode
      Returns:
      the player's marker
    • toString

      public String toString()
      Overrides:
      toString in class Object