<commit_before>package javalabra.chess.core.impl.state;

import java.util.Collection;

import javalabra.chess.core.GameContext;
import javalabra.chess.core.MoveDirector;
import javalabra.chess.core.impl.GameEventEmitter;
import javalabra.chess.core.impl.GameState;
import javalabra.chess.domain.Color;
import javalabra.chess.domain.Move;
import javalabra.chess.domain.Piece;
import javalabra.chess.domain.Square;

public class SelectPieceState extends AbstractGameState {

	private final Color color;

	public SelectPieceState(final Color color) {
		this.color = color;
	}

	@Override
	protected GameState handle(final Square square, final MoveDirector director, final GameContext context, final GameEventEmitter em) {
		final Piece piece = square.getPiece();

		if (null == piece || color != piece.getColor()) {
			return this;
		}

		final Collection<Move> moves = piece.getLegalMoves(director, context);

		if (moves.isEmpty()) {
			return this;
		}

		em.trigger(piece.getColor(), square, moves);

		return new SelectMoveState(piece, moves);
	}

}<commit_msg>allow to select piece with no legal moves<commit_after>package javalabra.chess.core.impl.state;

import java.util.Collection;

import javalabra.chess.core.GameContext;
import javalabra.chess.core.MoveDirector;
import javalabra.chess.core.impl.GameEventEmitter;
import javalabra.chess.core.impl.GameState;
import javalabra.chess.domain.Color;
import javalabra.chess.domain.Move;
import javalabra.chess.domain.Piece;
import javalabra.chess.domain.Square;

public class SelectPieceState extends AbstractGameState {

	private final Color color;

	public SelectPieceState(final Color color) {
		this.color = color;
	}

	@Override
	protected GameState handle(final Square square, final MoveDirector director, final GameContext context, final GameEventEmitter em) {
		final Piece piece = square.getPiece();

		if (null == piece || color != piece.getColor()) {
			return this;
		}

		final Collection<Move> moves = piece.getLegalMoves(director, context);

		em.trigger(piece.getColor(), square, moves);

		return new SelectMoveState(piece, moves);
	}

}
{'fraction_non_alphanumeric': 0.1015180265654649, 'fraction_numerical': 0.0, 'mean_word_length': 5.221238938053097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7489952', 'n_tokens_mistral': 715, 'n_tokens_neox': 672, 'n_words': 157}