GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — chess-java/Move.java at main · lindazeng979/chess-java Expand file tree/ Copy pathMove.javaMore file actions 65 lines (56 loc) · 1.88 KB / Copy pathMove.javaFile metadata and controls65 lines (56 loc) · 1.88 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 // Represents a single move, in which a piece moves to a destination location. // Since a move can be undone, also keeps track of the source location and any captured victim. public class Move { private Piece piece; //the piece being moved private Location source; //the location being moved from private Location destination; //the location being moved to private Piece victim; //any captured piece at the destination //Constructs a new move for moving the given piece to the given destination. public Move(Piece piece, Location destination) { this.piece = piece; this.source = piece.getLocation(); this.destination = destination; this.victim = piece.getBoard().get(destination); if (source.equals(destination)) throw new IllegalArgumentException("Both source and dest are " + source); } //Returns the piece being moved public Piece getPiece() { return piece; } //Returns the location being moved from public Location getSource() { return source; } //Returns the location being moved to public Location getDestination() { return destination; } //Returns the piece being captured at the destination, if any public Piece getVictim() { return victim; } //Returns a string description of the move public String toString() { return piece + " from " + source + " to " + destination + " containing " + victim; } //Returns true if this move is equivalent to the given one. public boolean equals(Object x) { Move other = (Move)x; return piece == other.getPiece() && source.equals(other.getSource()) && destination.equals(other.getDestination()) && victim == other.getVictim(); } //Returns a hash code for this move, such that equivalent moves have the same hash code. public int hashCode() { return piece.hashCode() + source.hashCode() + destination.hashCode(); } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |