/*
 * Copyright (C) Bernhard Seybold. All rights reserved.
 *
 * This software is published under the terms of the LGPL Software License,
 * a copy of which has been included with this distribution in the LICENSE.txt
 * file.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 *
 * $Id: AbstractMoveablePosition.java,v 1.1 2002/12/08 13:27:34 BerniMan Exp $
 */

package chesspresso.position;

import chesspresso.Chess;
import chesspresso.move.IllegalMoveException;
import chesspresso.move.Move;

/**
 * 
 * @author Bernhard Seybold
 * @version $Revision: 1.1 $
 */
public abstract class AbstractMoveablePosition extends AbstractMutablePosition
		implements MoveablePosition {

	public void doMove(Move move) throws IllegalMoveException {
		doMove(move.getShortMoveDesc());
	}

	public short getMove(int from, int to, int promoPiece) {
		if (getColor(from) != getToPlay())
			return Move.ILLEGAL_MOVE; // =====>
		int piece = getPiece(from);
		if (piece == Chess.PAWN) {
			if (Chess.sqiToCol(from) != Chess.sqiToCol(to)
					&& getPiece(to) == Chess.NO_PIECE) {
				return Move.getEPMove(from, to);
			} else {
				return Move.getPawnMove(from, to,
						Chess.sqiToCol(from) != Chess.sqiToCol(to), promoPiece);
			}
		} else if (piece == Chess.KING && (to - from) == 2) {
			return Move.getShortCastle(getToPlay());
		} else if (piece == Chess.KING && (to - from) == -2) {
			return Move.getLongCastle(getToPlay());
		} else {
			return Move.getRegularMove(from, to, !isSquareEmpty(to));
		}
	}

}
@@ -682,17 +682,16 @@
 %0A/**%0D%0A *
- 
 %0D%0A * @au
@@ -859,24 +859,36 @@
 sition %7B%0D%0A%0D%0A
+%09@Override%0D%0A
 %09public void
@@ -979,16 +979,28 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09@Override%0D%0A
 %09public 
@@ -1471,32 +1471,33 @@
 = Chess.KING && 
+(
 (to - from) == 2
@@ -1496,16 +1496,52 @@
 om) == 2
+ %7C%7C isChess960ShortCastle(from, to))
 ) %7B%0D%0A%09%09%09
@@ -1618,16 +1618,17 @@
 KING && 
+(
 (to - fr
@@ -1636,16 +1636,51 @@
 m) == -2
+ %7C%7C isChess960LongCastle(from, to))
 ) %7B%0D%0A%09%09%09
@@ -1805,9 +1805,324 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09private boolean isChess960ShortCastle(int from, int to) %7B%0D%0A%09%09return getPiece(to) == Chess.ROOK && getColor(to) == getToPlay()%0D%0A%09%09%09%09&& (to - from) %3E 0;%0D%0A%09%7D%0D%0A%0D%0A%09private boolean isChess960LongCastle(int from, int to) %7B%0D%0A%09%09return getPiece(to) == Chess.ROOK && getColor(to) == getToPlay()%0D%0A%09%09%09%09&& (to - from) %3C 0;%0D%0A%09%7D%0D%0A
 %7D

support chess960 castling noted as KxR used by chess engines