1 / 8

Chess

Chess. Responsibilities . Collaborators. ChessRules ChessPlayer (2) ChessDisplayer. ChessRules. Play the game: Initialize the Board Set CurrentPlayer to Player(White) and NextPlayer to Player(Black) while (game is not over) { Get the Move from CurrentPlayer Display the Move

zeno
Télécharger la présentation

Chess

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chess Responsibilities Collaborators ChessRules ChessPlayer(2) ChessDisplayer ChessRules • Play the game: • Initialize the Board • Set CurrentPlayer to Player(White) and NextPlayer to Player(Black) • while (game is not over) { • Get the Move from CurrentPlayer • Display the Move • Update Board to reflect the Move • Display the updated Board • Reverse Current and Next Players } • Display the game result • Construct most of the objects? ChessPlayer ChessRules ChessDisplayer

  2. ChessRules Responsibilities Collaborators ChessBoard ChessPiece ChessMove • Initialize the ChessBoard • Construct ChessPiece’sand put them on it • Return whether or not the game is over • When the game is over, return the result • Returns whether a given Move is valid • Update the Board to reflect a given Move

  3. ChessPlayer Responsibilities Collaborators ChessAI ChessMove ChessRules • Get a Suggested Move • From the human user, or • From an AI player (future expansion) • Choose (return) a Legal Move • Get a Suggested Move • See if it is legal • If not, repeat

  4. ChessDisplayerextends JComponent Responsibilities Collaborators ChessBoard ChessPiece ChessRules? To know what, if anything, to highlight • Display the ChessBoard • Display a given ChessMove • Display the game result

  5. ChessBoard Responsibilities Collaborators Coordinate ChessPiece • Return (get) the ChessPieceat a given Coordinate • Set the given ChessPieceat a given coordinate • Maintains the ChessPiecesin an 8x8 array

  6. ChessPiecehas subclasses for each type of chess piece (King, Bishop, etc) Responsibilities Collaborators Coordinate Color Graphics2D • Draw itself on a given Graphics2D object • Be constructed at a given Coordinate with a given color • Set its location to a given Coordinate • Return the set of valid moves for this piece in isolation • Has a Coordinate (where the Piece is located) and a Color (white or black)

  7. Coordinate Responsibilities Collaborators • Get the row of this Coordinate • Get the column of this Coordinate • Set the row and column of this Coordinate • A Coordinate is a pair of integers

  8. ChessMove Responsibilities Collaborators Coordinate • Get the beginning Coordinate of this ChessMove • Get the ending Coordinate of this ChessMove • Set the beginning and ending Coordinates of this ChessMove • A ChessMoveis a pair of Coordinates

More Related