klaus.chess
Class Move

java.lang.Object
  extended by klaus.chess.Move

public class Move
extends Object

Represents a half-move

Since:
2009-03-13
Author:
Stephan Hillebrand

Field Summary
private  boolean check
           
private  boolean checkmate
           
private  boolean ep
           
private  int fromX
          The original X coordinate
private  int fromY
          The original Y coordinate
private static char[] lines
           
private  boolean longCastling
           
private  Position newPosition
           
static Move NO_NEW_MOVE
           
private  char piece
           
private  char promotion
           
private static char[] rows
           
private  boolean shortCastling
           
private  boolean stalemate
           
private  boolean take
           
private  int toX
          The new X coordinate
private  int toY
          The new Y coordinate
 
Constructor Summary
Move(int fromX, int fromY, int toX, int toY)
          Creates a new move
Move(int fromX, int fromY, int toX, int toY, char promotion)
          Creates a new move with pawn promotion
Move(String engineMove, Position position)
          Creates a move from an engine's string
 
Method Summary
 Position applyMoveTo(Position pos)
          This applies this move to a position and returns a new position with the given move done.
 boolean equals(Object obj)
           
 int getFromX()
           
 int getFromY()
           
 String getNotation(Position oldPosition)
           
 char getPromotion()
           
 int getToX()
           
 int getToY()
           
 int hashCode()
           
 void setFromX(int fromX)
           
 void setFromY(int fromY)
           
 void setPromotion(char promotion)
           
 void setToX(int toX)
           
 void setToY(int toY)
           
private  char toLocalizedPiece(char c)
           
 String toXEngString()
          Generate a description string for WinBoard/XBoard connections
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_NEW_MOVE

public static final Move NO_NEW_MOVE

fromX

private int fromX
The original X coordinate


fromY

private int fromY
The original Y coordinate


toX

private int toX
The new X coordinate


toY

private int toY
The new Y coordinate


promotion

private char promotion

lines

private static final char[] lines

rows

private static final char[] rows

newPosition

private Position newPosition

piece

private char piece

check

private boolean check

checkmate

private boolean checkmate

stalemate

private boolean stalemate

take

private boolean take

ep

private boolean ep

longCastling

private boolean longCastling

shortCastling

private boolean shortCastling
Constructor Detail

Move

public Move(int fromX,
            int fromY,
            int toX,
            int toY)
Creates a new move

Parameters:
fromX - the original location's X coordinate
fromY - the original location's Y coordinate
toX - the new X coordinate
toY - the new Y coordinate

Move

public Move(int fromX,
            int fromY,
            int toX,
            int toY,
            char promotion)
Creates a new move with pawn promotion

Parameters:
fromX - the original location's X coordinate
fromY - the original location's Y coordinate
toX - the new X coordinate
toY - the new Y coordinate
promotion - the piece to which the pawn is promoted. ' ' will not do any promotion. Possibilities are QqRrNnBb or a blank. Upper /lower case is ignored.

Move

public Move(String engineMove,
            Position position)
Creates a move from an engine's string

Parameters:
engineMove - the string sent by the engine. On WinBoard/XBoard and UCI this has the format e2e4 etc.
position - the old position, necessary e. g. for castling
Method Detail

getFromX

public int getFromX()

getFromY

public int getFromY()

getToX

public int getToX()

getToY

public int getToY()

setFromX

public void setFromX(int fromX)

setFromY

public void setFromY(int fromY)

setToX

public void setToX(int toX)

setToY

public void setToY(int toY)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

applyMoveTo

public Position applyMoveTo(Position pos)
This applies this move to a position and returns a new position with the given move done. The original position is not touched. This method can also (but does not necessarily) check if the move is legal. If this will be done can be set using the check variable. Note that the move is not given as an argument! This is an instance method of Move.

Parameters:
pos - the original position
Returns:
a clone of the original position with the move done.

getNotation

public String getNotation(Position oldPosition)

toLocalizedPiece

private char toLocalizedPiece(char c)

toXEngString

public String toXEngString()
Generate a description string for WinBoard/XBoard connections

Returns:
a String like e2e4 for communication with WinBoard / XBoard engines

getPromotion

public char getPromotion()

setPromotion

public void setPromotion(char promotion)