Package sudoku
Class Player
- java.lang.Object
-
- akka.actor.typed.Behavior<T>
-
- akka.actor.typed.ExtensibleBehavior<T>
-
- akka.actor.typed.javadsl.AbstractBehavior<Player.Protocol>
-
- sudoku.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPlayer.AdditionalInfoRequestMsgMessage received from the Table, requesting for additional info about other stakeholder's(s') digit.static classPlayer.BadFinishExceptionCustom exception thrown when Table finishes negotiations with a digit different from what was offered.static classPlayer.BadRejectionExceptionCustom exception thrown when a Player receives RejectOfferMsg with a different digit it offered.static classPlayer.ConsentToStartIterationMsgMessage allowing the agent to start new iteration by sending new offers.static classPlayer.CreateMsgMessage for creating the Player.static classPlayer.DoubleFinishExceptionCustom exception thrown when Player receives NegotiationsFinishedMsg with the same digit from more than one Table.static classPlayer.GrantRewardMsgMessage from the Teacher granting the Player reward (or punishment if negative) for its choices.static classPlayer.IncorrectRegisterExceptionCustom exception thrown when excessive Table is about to be registered to this Playerstatic interfacePlayer.InitialisationProtocolProtocol interface for messages for initialisation strategy.static classPlayer.MemorisedDigitsRequestMsgMessage - request for memorised Digits and Masks for given Table IDs by the Player.static classPlayer.NegotiationsFinishedMsgMessage received when the Table announces finish of the negotiations.static classPlayer.NegotiationsMsgAbstract class for messages received from Table Agent during negotiations.static classPlayer.NegotiationsPositiveMsgMessage received when the Table announces positive result of the negotiations.static interfacePlayer.ProtocolProtocol interface for input messages.static classPlayer.RegisterTableMsgMessage for registering a Table.static classPlayer.RejectOfferMsgMessage received when Player's offer is rejected, requesting for new offer.static classPlayer.ResetMemoryMsgMessage commanding the agent to reset it's memory due to start of new iteration.static classPlayer.ResetMemorySoftlyMsgMessage commanding the agent to reset it's memory softly due to start of new mini-iteration.static classPlayer.WakeUpMsgMessage received from the Table when agent is not responding.-
Nested classes/interfaces inherited from class akka.actor.typed.Behavior
akka.actor.typed.Behavior.BehaviorDecorators<Inner extends Object>, akka.actor.typed.Behavior.BehaviorDecorators$
-
-
Field Summary
Fields Modifier and Type Field Description private PlayerMemory_memoryStructure containing awards and current digit vectorprivate akka.actor.typed.ActorRef<Teacher.Protocol>_parentReference to Player's parent - the Teacherprivate int_playerIdGlobal ID of this Playerprivate AgentMap<akka.actor.typed.ActorRef<Table.Protocol>>_tablesMap from global Table id to internal index and Table reference.
-
Constructor Summary
Constructors Modifier Constructor Description privatePlayer(akka.actor.typed.javadsl.ActorContext<Player.Protocol> context, Player.CreateMsg createMsg)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static akka.actor.typed.Behavior<Player.Protocol>create(Player.CreateMsg createMsg)Public method that calls private constructor.akka.actor.typed.javadsl.Receive<Player.Protocol>createReceive()Main method controlling incoming messages.private akka.actor.typed.Behavior<Player.Protocol>onAdditionalInfoRequest(Player.AdditionalInfoRequestMsg msg)Weighs given offer(s) for given digits.private akka.actor.typed.Behavior<Player.Protocol>onConsentToStartIteration(Player.ConsentToStartIterationMsg msg)Player receives permission to start new iteration.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.private akka.actor.typed.Behavior<Player.Protocol>onMemorisedDigitsRequest(Player.MemorisedDigitsRequestMsg msg)During inspection, replies with all memorised Digits and Masks.private akka.actor.typed.Behavior<Player.Protocol>onNegotiationsFinished(Player.NegotiationsFinishedMsg msg)Action taken when negotiations finished.private akka.actor.typed.Behavior<Player.Protocol>onNegotiationsPositive(Player.NegotiationsPositiveMsg msg)Action taken when Player is informed of positive result of the negotiations.private PlayeronPostStop()Handler of PostStop signal.private akka.actor.typed.Behavior<Player.Protocol>onRegisterTable(Player.RegisterTableMsg msg)Registers new Table to this Player.private akka.actor.typed.Behavior<Player.Protocol>onRejectOffer(Player.RejectOfferMsg msg)Player is informed that theirs offer is rejected.private akka.actor.typed.Behavior<Player.Protocol>onResetMemory(Player.ResetMemoryMsg msg)Player resets it's memory to get ready for new iteration.private akka.actor.typed.Behavior<Player.Protocol>onResetMemorySoftly(Player.ResetMemorySoftlyMsg msg)Player resets it's memory softly to get ready for new mini-iteration.private akka.actor.typed.Behavior<Player.Protocol>onWakeUp(Player.WakeUpMsg msg)Player is being informed that is not enough responsive.private voidsendBestOffer(int tableIndex)Send offer message to a Table.-
Methods inherited from class akka.actor.typed.javadsl.AbstractBehavior
getContext, newReceiveBuilder, receive, receiveSignal
-
-
-
-
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
-
-
Constructor Detail
-
Player
private Player(akka.actor.typed.javadsl.ActorContext<Player.Protocol> context, Player.CreateMsg createMsg)
-
-
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:
createReceivein classakka.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
-
-