Class RandomStrategy
java.lang.Object
be.belegkarnil.game.board.tak.strategy.RandomStrategy
- All Implemented Interfaces:
RoundListener,Strategy,EventListener
This
Strategy represents a strategy that randomly plays.
Pieces are randomly sorted, position are randomly sorted, rotation are randomly sorted.
Then for each combination, if the move is valid (Board.canPlace(Piece, Point)) then play.
Otherwise, ask to replace/swap if the bag if not empty.
In other cases, return the skip action.- Author:
- Belegkarnil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidonRoundBegins(RoundEvent event) Invoked when a round begins.voidonRoundEnds(RoundEvent event) Invoked when a round ends.Override theStrategy.plays(Player, Board, Player)and try to play randomy a valid action.voidThis method is called before a game starts in order to allow the strategy to listen events.voidunregister(Game game) This method is called after a game finishes in order to clear and the strategy stops to listen events.
-
Constructor Details
-
RandomStrategy
public RandomStrategy()Initialize the RandomStrategy (i.e. a random generator)
-
-
Method Details
-
plays
Override theStrategy.plays(Player, Board, Player)and try to play randomy a valid action.- Specified by:
playsin interfaceStrategy- Parameters:
myself- seeStrategy.plays(be.belegkarnil.game.board.tak.Player, be.belegkarnil.game.board.tak.Board, be.belegkarnil.game.board.tak.Player)board- seeStrategy.plays(be.belegkarnil.game.board.tak.Player, be.belegkarnil.game.board.tak.Board, be.belegkarnil.game.board.tak.Player)opponent- seeStrategy.plays(be.belegkarnil.game.board.tak.Player, be.belegkarnil.game.board.tak.Board, be.belegkarnil.game.board.tak.Player)- Returns:
- a valid {Action#Action(Piece, Point, int)}
-
register
Description copied from interface:StrategyThis method is called before a game starts in order to allow the strategy to listen events. (seeGame.addGameListener(GameListener),Game.addMisdesignListener(MisdesignListener),Game.addRoundListener(RoundListener), andGame.addTurnListener(TurnListener)) -
unregister
Description copied from interface:StrategyThis method is called after a game finishes in order to clear and the strategy stops to listen events. (seeGame.removeGameListener(GameListener),Game.removeMisdesignListener(MisdesignListener),Game.removeRoundListener(RoundListener), andGame.removeTurnListener(TurnListener))- Specified by:
unregisterin interfaceStrategy- Parameters:
game- the finished game to stop listening events
-
onRoundBegins
Description copied from interface:RoundListenerInvoked when a round begins.- Specified by:
onRoundBeginsin interfaceRoundListener- Parameters:
event- The event that contains all information about the current round
-
onRoundEnds
Description copied from interface:RoundListenerInvoked when a round ends.- Specified by:
onRoundEndsin interfaceRoundListener- Parameters:
event- The event that contains all information about the current round
-