Class JesonMor
- All Implemented Interfaces:
java.lang.Cloneable
public class JesonMor extends Game
Game, implementing the game logic of JesonMor game.
Student needs to implement methods in this class to make the game work.
Hint: make good use of methods predefined in Game to get various information to facilitate your work.
Several sample tests are provided to test your implementation of each method in the test directory. Please make make sure all tests pass before submitting the assignment.
-
Field Summary
Fields inherited from class castle.comp3021.assignment.protocol.Game
board, configuration, currentPlayer, numMoves -
Constructor Summary
Constructors Constructor Description JesonMor(Configuration configuration) -
Method Summary
Modifier and Type Method Description @NotNull Move[]getAvailableMoves(Player player)Get all available moves of one player.PlayergetWinner(Player lastPlayer, Piece lastPiece, Move lastMove)Get the winner of the game.voidmovePiece(@NotNull Move move)Make a move.Playerstart()Start the game Players will take turns according to the order inConfiguration.getPlayers()to make a move until a player wins.voidupdateScore(Player player, Piece piece, Move move)Update the score of a player according to thePieceand corresponding move made by him just now.Methods inherited from class castle.comp3021.assignment.protocol.Game
clone, getCentralPlace, getConfiguration, getCurrentPlayer, getNumMoves, getPiece, getPiece, getPlayers, refreshOutput
-
Constructor Details
-
Method Details
-
start
Start the game Players will take turns according to the order inConfiguration.getPlayers()to make a move until a player wins.In the implementation, student should implement the loop letting two players take turns to move pieces. The order of the players should be consistent to the order in
Configuration.getPlayers().Player.nextMove(Game, Move[])should be used to retrieve the player's choice of his next move. After each move,Game.refreshOutput()should be called to refresh the gameboard printed in the console.When a winner appears, set the local variable
winnerso that this method can return the winner. -
getWinner
Get the winner of the game. If there is no winner yet, return null; This method will be called every time after a player makes a move and afterupdateScore(Player, Piece, Move)is called, in order to check whether anyPlayerwins. If this method returns a player (the winner), then the game will exit with the winner. If this method returns null, next player will be asked to make a move. -
updateScore
Update the score of a player according to thePieceand corresponding move made by him just now. This method will be called every time after a player makes a move, in order to update the corresponding score of this player.The score of a player is the cumulative score of each move he makes. The score of each move is calculated with the Manhattan distance between the source and destination
Place.Student can use
Player.getScore()to get the current score of a player before updating.Player.setScore(int)can be used to update the score of a player.Attention: Student should make NO assumption that the
Moveis valid.- Specified by:
updateScorein classGame- Parameters:
player- the player who just makes a movepiece- the piece that is just movedmove- the move that is just made
-
movePiece
Make a move. This method performs moving aPiecefrom source to destinationPlaceaccordingMoveobject. Note that after the move, there will be noPiecein sourcePlace.Positions of all
Pieces on the gameboard are stored inGame.boardfield as a 2-dimension array ofPieceobjects. The x and y coordinate of aPlaceon the gameboard are used as index inGame.board. E.g.board[place.x()][place.y()]. If onePlacedoes not have a piece on it, it will be null inboard[place.x()][place.y()]. Student may modify elements inGame.boardto implement moving aPiece. TheMoveobject can be considered valid on present gameboard. -
getAvailableMoves
Get all available moves of one player. This method is called when it is thePlayer's turn to make a move. It will iterate allPieces belonging to thePlayeron board and obtain available moves of each of thePieces through methodPiece.getAvailableMoves(Game, Place)of eachPiece.Attention: Student should make sure all
Moves returned are valid.- Specified by:
getAvailableMovesin classGame- Parameters:
player- the player whose available moves to get- Returns:
- an array of available moves
-