<commit_before>﻿using System.Linq;
using CAESAR.Chess.Core;
using CAESAR.Chess.Positions;

namespace CAESAR.Chess.Games.Statuses.Updaters
{
    /// <summary>
    ///     Updates the <seealso cref="IGame.Status" /> and <seealso cref="IGame.StatusReason" /> of an
    ///     <seealso cref="IGame" />, when the move just played is illegal.
    /// </summary>
    public class IllegalMoveUpdater : IStatusUpdater
    {
        /// <summary>
        ///     Updates the <seealso cref="IGame.Status" /> and <seealso cref="IGame.StatusReason" /> of an
        ///     <seealso cref="IGame" />, when the move just played is illegal.
        /// </summary>
        /// <param name="game">The <seealso cref="IGame" /> for which the status is to be updated.</param>
        public void UpdateStatus(IGame game)
        {
            // If less than 2 moves played
            if (game.Moves.Count <= 2)
                return;

            var lastPosition = game.Moves.Last().Position;
            var currentPosition = game.Position;

            // If check was ignored, illegal move
            var sideThatJustPlayed = lastPosition.SideToMove;
            var checkedNow = currentPosition.IsInCheck(sideThatJustPlayed);
            if (checkedNow)
            {
                game.Status = game.Position.SideToMove == Side.White ? Status.WhiteWon : Status.BlackWon;
                game.StatusReason = StatusReason.IllegalMove;
            }
        }
    }
}<commit_msg>Fixes king capture and incorrect number of kings on board<commit_after>﻿using System.Linq;
using CAESAR.Chess.Core;
using CAESAR.Chess.Pieces;
using CAESAR.Chess.Positions;

namespace CAESAR.Chess.Games.Statuses.Updaters
{
    /// <summary>
    ///     Updates the <seealso cref="IGame.Status" /> and <seealso cref="IGame.StatusReason" /> of an
    ///     <seealso cref="IGame" />, when the move just played is illegal.
    /// </summary>
    public class IllegalMoveUpdater : IStatusUpdater
    {
        /// <summary>
        ///     Updates the <seealso cref="IGame.Status" /> and <seealso cref="IGame.StatusReason" /> of an
        ///     <seealso cref="IGame" />, when the move just played is illegal.
        /// </summary>
        /// <param name="game">The <seealso cref="IGame" /> for which the status is to be updated.</param>
        public void UpdateStatus(IGame game)
        {
            var currentPosition = game.Position;

            // If the number of kings is incorrect
            if (game.Position.Board.Squares.Count(x => x.HasPiece && x.Piece.PieceType == PieceType.King) != 2)
            {
                game.Status = currentPosition.SideToMove == Side.White ? Status.WhiteWon : Status.BlackWon;
                game.StatusReason = StatusReason.IllegalMove;
            }

            // If less than 2 moves played
            if (game.Moves.Count <= 2)
                return;

            var lastPosition = game.Moves.Last().Position;
            var sideThatJustPlayed = lastPosition.SideToMove;

            // If check was ignored, illegal move
            var checkedNow = currentPosition.IsInCheck(sideThatJustPlayed);
            if (checkedNow)
            {
                game.Status = currentPosition.SideToMove == Side.White ? Status.WhiteWon : Status.BlackWon;
                game.StatusReason = StatusReason.IllegalMove;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.11358244365361803, 'fraction_numerical': 0.0014827995255041518, 'mean_word_length': 1.9849557522123893, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 30, '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': '7588807', 'n_tokens_mistral': 969, 'n_tokens_neox': 953, 'n_words': 241}