<commit_before>/*
 * Copyright (C) <NAME>. 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 <NAME>
 * @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));
		}
	}

}<commit_msg>support chess960 castling noted as KxR used by chess engines<commit_after>/*
 * Copyright (C) <NAME>. 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 <NAME>
 * @version $Revision: 1.1 $
 */
public abstract class AbstractMoveablePosition extends AbstractMutablePosition
		implements MoveablePosition {

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

	@Override
	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 || isChess960ShortCastle(from, to))) {
			return Move.getShortCastle(getToPlay());
		} else if (piece == Chess.KING && ((to - from) == -2 || isChess960LongCastle(from, to))) {
			return Move.getLongCastle(getToPlay());
		} else {
			return Move.getRegularMove(from, to, !isSquareEmpty(to));
		}
	}

	private boolean isChess960ShortCastle(int from, int to) {
		return getPiece(to) == Chess.ROOK && getColor(to) == getToPlay()
				&& (to - from) > 0;
	}

	private boolean isChess960LongCastle(int from, int to) {
		return getPiece(to) == Chess.ROOK && getColor(to) == getToPlay()
				&& (to - from) < 0;
	}
}
{'fraction_non_alphanumeric': 0.12879387701240433, 'fraction_numerical': 0.015043547110055424, 'mean_word_length': 4.053333333333334, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6341716', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1261, 'n_words': 353}