klaus.chess
Class MoveControl

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

public class MoveControl
extends Object

This class is used to check if a move is legal, if a certain square is controlled by white or black, if a king is in check etc.

Since:
2009-03-13
Author:
Stephan Hillebrand

Constructor Summary
MoveControl()
           
 
Method Summary
static boolean accept(Move move, Position position)
          Check if a move is legal in a given position
private static boolean canDoMove(Move move, Position position)
          Checks whether a move is technically possible (meaning regarding the pieces positions, if the way is free etc, ignoring if pieces are in check etc.
static Point findKing(Position position, boolean white)
          Get the king's current position
static boolean squareInCheck(Position pos, int searchx, int searchy, boolean white)
          Checks if a certain square is in check
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MoveControl

public MoveControl()
Method Detail

accept

public static boolean accept(Move move,
                             Position position)
Check if a move is legal in a given position

Parameters:
move - the move to be checked
position - the position in which the move should be done
Returns:
true if the move was accepted, false if it was rejected

canDoMove

private static boolean canDoMove(Move move,
                                 Position position)
Checks whether a move is technically possible (meaning regarding the pieces positions, if the way is free etc, ignoring if pieces are in check etc.. For checking if a move is completely legal, use accept() instead.

Parameters:
move -
position -
Returns:

findKing

public static Point findKing(Position position,
                             boolean white)
Get the king's current position

Parameters:
position - a position to search
white - true if the white king is to be searched, false if we need the black king's position
Returns:

squareInCheck

public static boolean squareInCheck(Position pos,
                                    int searchx,
                                    int searchy,
                                    boolean white)
Checks if a certain square is in check

Parameters:
pos - the position
searchx - the square that has to be checked (X coordinate)
searchy - the square that has to be checked (Y coordinate)
white - who shall be in check?
Returns:
true if the king is in check, else false