I have a starter code in Java, and just need to complete the following methods. ThreeMusketeers.java move(Agent agent) Gets a valid move from the given agent (Human/Random), adds a copy of the move...


I have a starter code in Java, and just need to complete the following methods.


ThreeMusketeers.java


  move(Agent agent)


Gets a valid move from the given agent (Human/Random), adds a copy of the move using the Move


copy constructor to the moves stack for undoing later, then does the move on the board.


  undoMove()


Removes a move from the top of the moves stack and undoes the move on the board.


Board.java


  getCell(Coordinate coordinate)


Gets the cell on the board at the given coordinate.


  getMusketeerCells():


Gets all the musketeer cells on the board.


  getGuardCells():


Gets all the guard cells on the board.


  move(Move move):


Executes the given valid move on the board.


  undoMove(Move move):


Undo the given move on the board. The given move is a copy of the original move. So the cells in


the copy are not the same as the cells on the board and the copy has the pieces that were originally


in the fromCell and toCell.


  isValidMove(Move move):


Checks if the given move is valid according to the rules of the game. (1) the toCell is next to the


fromCell. (2) the fromCell piece can move onto the toCell piece.


6


  getPossibleCells():


Gets all the cells that have pieces that can be moved this turn. Needs to check if the cell has at least


one possible destination.


  getPossibleDestinations(Cell fromCell):


Gets all the cells that the piece in the given fromCell can move to.


  getPossibleMoves():


Gets all the possible moves that can happen this turn. This function can use the getPossibleCells and


getPossibleDestinations functions to help get the list of possible moves.


  isGameOver():


Checks if the game is over and if it is, sets the winner attribute in the Board class to the winner


Piece Type.


Guard.java


  canMoveOnto(Cell cell):


Returns true if the Guard can move onto the given cell according to the rules of the game, false


otherwise.


Musketeer.java


  canMoveOnto(Cell cell):


Returns true if the Musketeer can move onto the given cell according to the rules of the game, false


otherwise.


HumanAgent.java


  getMove():


Asks the human for a move to be done. This function needs to validate the human input and make


sure the move is valid for the piece type that is moving.


RandomAgent.java


  getMove():


Gets a valid random move that can be done on the board.

Feb 19, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here