Package sudoku

Class Player


  • public class Player
    extends akka.actor.typed.javadsl.AbstractBehavior<Player.Protocol>
    Playing agent, who actually learns to solve Sudoku. A child of the Teacher agent.
    • Field Detail

      • _playerId

        private final int _playerId
        Global ID of this Player
      • _memory

        private final PlayerMemory _memory
        Structure containing awards and current digit vector
      • _tables

        private final AgentMap<akka.actor.typed.ActorRef<Table.Protocol>> _tables
        Map from global Table id to internal index and Table reference. Data structure for storing Tables - agents registered to this Player.
      • _parent

        private final akka.actor.typed.ActorRef<Teacher.Protocol> _parent
        Reference to Player's parent - the Teacher
    • Method Detail

      • create

        public static akka.actor.typed.Behavior<Player.Protocol> create​(Player.CreateMsg createMsg)
        Public method that calls private constructor. Existence required by Akka.
        Parameters:
        createMsg - message initialising the start of the agent
        Returns:
        wrapped Behavior
      • createReceive

        public akka.actor.typed.javadsl.Receive<Player.Protocol> createReceive()
        Main method controlling incoming messages. Existence required by Akka.
        Specified by:
        createReceive in class akka.actor.typed.javadsl.AbstractBehavior<Player.Protocol>
        Returns:
        wrapped Behavior
      • onRegisterTable

        private akka.actor.typed.Behavior<Player.Protocol> onRegisterTable​(Player.RegisterTableMsg msg)
        Registers new Table to this Player. It is expected that a table position is already registered and it is replaced with the new ActorRef. When a excessive Table is about to be registered, IncorrectRegisterException is thrown. Also it assigns a piece of Sudoku for given Table's Position to the Player's memory (_memory.setField(...)). Replies with RegisteredMsg.
        Parameters:
        msg - message for registering new Table
        Returns:
        wrapped Behavior
      • onMemorisedDigitsRequest

        private akka.actor.typed.Behavior<Player.Protocol> onMemorisedDigitsRequest​(Player.MemorisedDigitsRequestMsg msg)
        During inspection, replies with all memorised Digits and Masks. Replies with MemorisedDigitsMsg.
        Parameters:
        msg - inspection request
        Returns:
        wrapped Behavior
      • onAdditionalInfoRequest

        private akka.actor.typed.Behavior<Player.Protocol> onAdditionalInfoRequest​(Player.AdditionalInfoRequestMsg msg)
        Weighs given offer(s) for given digits. During negotiations, Player will be asked for weighing other Players' offers. This is the action for that. Replies the Table with AdditionalInfoMsg.
        Parameters:
        msg - request for additional info
        Returns:
        wrapped Behavior
      • sendBestOffer

        private void sendBestOffer​(int tableIndex)
        Send offer message to a Table. Method tries to choose the best offer possible (with the highest weight) for this specific Table.
        Parameters:
        tableIndex - internal index of Table, to which the message is going to be sent
      • onRejectOffer

        private akka.actor.typed.Behavior<Player.Protocol> onRejectOffer​(Player.RejectOfferMsg msg)
        Player is informed that theirs offer is rejected. Replies the Table with OfferMsg.
        Parameters:
        msg - rejecting message
        Returns:
        wrapped Behavior
      • onNegotiationsPositive

        private akka.actor.typed.Behavior<Player.Protocol> onNegotiationsPositive​(Player.NegotiationsPositiveMsg msg)
        Action taken when Player is informed of positive result of the negotiations. Replies the Table with AcceptNegotiationsResultsMsg.
        Parameters:
        msg - positive result of negotiations in a message
        Returns:
        wrapped Behavior
      • onNegotiationsFinished

        private akka.actor.typed.Behavior<Player.Protocol> onNegotiationsFinished​(Player.NegotiationsFinishedMsg msg)
        Action taken when negotiations finished. May send WithdrawOfferMsg to other Tables.
        Parameters:
        msg - message announcing final finish of the negotiations
        Returns:
        wrapped Behavior
      • onResetMemory

        private akka.actor.typed.Behavior<Player.Protocol> onResetMemory​(Player.ResetMemoryMsg msg)
        Player resets it's memory to get ready for new iteration.
        Parameters:
        msg - message from the Teacher
        Returns:
        wrapped Behavior
      • onResetMemorySoftly

        private akka.actor.typed.Behavior<Player.Protocol> onResetMemorySoftly​(Player.ResetMemorySoftlyMsg msg)
        Player resets it's memory softly to get ready for new mini-iteration.
        Parameters:
        msg - message from the Teacher
        Returns:
        wrapped Behavior
      • onConsentToStartIteration

        private akka.actor.typed.Behavior<Player.Protocol> onConsentToStartIteration​(Player.ConsentToStartIterationMsg msg)
        Player receives permission to start new iteration. It chooses the best offers it can make and sends them to appropriate tables.
        Parameters:
        msg - permission from the Teacher
        Returns:
        wrapped Behavior
      • onGrantReward

        private akka.actor.typed.Behavior<Player.Protocol> onGrantReward​(Player.GrantRewardMsg msg)
        Player receives reward or punishment from the Teacher for its choices during the last iteration. Reward has an impact on Player's future choices.
        Parameters:
        msg - reward from the Teacher
        Returns:
        wrapped Behavior
      • onWakeUp

        private akka.actor.typed.Behavior<Player.Protocol> onWakeUp​(Player.WakeUpMsg msg)
        Player is being informed that is not enough responsive.
        Parameters:
        msg - message from the Table
        Returns:
        wrapped Behavior
      • onPostStop

        private Player onPostStop()
        Handler of PostStop signal. Expected after stopping Player agent.
        Returns:
        wrapped Behavior