core
Class Move
java.lang.Object
core.Move
public class Move
- extends Object
A Move represents a single player's move on a board. It is immutable, and may
mean different things on different boards.
A can either be represented by an ordered pair of Positions or by a pass.
- Specification Fields
-
-
ispass
: boolean // If the move is a pass (OR)
-
fromposition
: Position // Where the move originates
-
toposition
: Position // Where the move ends
- Derived Fields:
boardupdates
: Map // How the move changes a
board
Abstract invariant: either it is a pass or the positions are valid
Move
public Move(Position from,
Position to)
- See Also:
Piece
Move
public Move()
- Construct the pass move.
getFrom
public Position getFrom()
- Returns:
- the Position the move is from
getTo
public Position getTo()
- Returns:
- the Position the move is to
isPass
public boolean isPass()
- Returns:
- whether this is a pass
fromString
public static Move fromString(String s)
- Parameters:
s
- is a String representing an Antichess move
- Returns:
- a Move representing the same set of changes to the GameState g as
the String s. Its toString method will return a String equal to
s.
- Requires:
- s is of the form [position1]-[position2]; that is, two valid
and distinct positions separated by a hyphen. For example,
a3-a8 is a legal argument to this method. Or, s.equals("") for
a pass.
toMap
public Map<Position,Piece> toMap(GameState g)
- Parameters:
g
- is the gamestate to make this move on- Requires:
- g != null and this move is a valid move candidate; the pieces
may move as desired, but for possibly not capturing or entering
into check.
- Returns:
- the Map of updates to g to perform this move.
parseableMove
public static boolean parseableMove(String s)
- Returns:
- true if s is of the form [position1]-[position2]; that is, two
valid and distinct positions separated by a hyphen. For example,
a3-a8 is a valid move String.
toString
public String toString()
- Overrides:
toString
in class Object
- Returns:
- a String representation of this, in the form
[position1]-[position2], where position1 and position2 are the
old and new positions of the moving piece, respectively. In the
case of castling, the King is the "moving" piece. In the case of
en passant, the capturing pawn is the "moving" piece.
equals
public boolean equals(Object o)
- Overrides:
equals
in class Object
- See Also:
Object
hashCode
public int hashCode()
- Overrides:
hashCode
in class Object
- See Also:
Object