Example #1
0
        public static Piece ToMaximized(this PieceMinified min)
        {
            var piece = new Piece(min.X, min.Y, min.IsWhite, min.CanGoUp, min.CanGoDown);

            piece.IsQueen        = min.IsQueen;
            piece.IsCaptured     = min.IsCaptured;
            piece.AvailableMoves = min.GetAvailableMoves().Where(x => x.IsNotNull).ToList();
            return(piece);
        }
        public void Minify(IHistoryItem fromMaximizedSource, IBoard board)
        {
            IsPieceChangeType = fromMaximizedSource.IsPieceChangeType;
            From = fromMaximizedSource.Move.From;
            To   = fromMaximizedSource.Move.To;

            if (fromMaximizedSource.Captured != null)
            {
                Captured = ((Piece)fromMaximizedSource.Captured).ToMinified();
            }

            Player = board.Player1 == fromMaximizedSource.Player;
        }
Example #3
0
        public static PieceMinified ToMinified(this Piece from)
        {
            var min = new PieceMinified(
                from.X,
                from.Y,
                from.IsWhite,
                from.CanGoUp,
                from.CanGoDown,
                from.IsQueen);

            min.IsCaptured = from.IsCaptured;

            return(min);
        }
Example #4
0
        internal void RestorePiece(PieceMinified captured, bool player)
        {
            captured.IsCaptured = true;

            if (player)
            {
                Player1PiecesCount++;
                // todo - we know the size of BoardMinified fixed buffers in advance
                for (byte i = 0; i < BufferSize; i++)
                {
                    var piece = (PieceMinified)Player1Pieces[i];
                    if (piece.IsEmpty())
                    {
                        throw new ArgumentException("Couldn't find the required piece");
                    }

                    if (piece.Equals(captured))
                    {
                        SetBoardCell(captured.X, captured.Y, new BoardCell(i, captured.IsWhite));
                        piece.IsCaptured = false;
                        Player1Pieces[i] = piece;
                        break;
                    }
                }
            }
            else
            {
                Player2PiecesCount++;
                // todo - we know the size of BoardMinified fixed buffers in advance
                for (byte i = 0; i < BufferSize; i++)
                {
                    var piece = (PieceMinified)Player2Pieces[i];
                    if (piece.IsEmpty())
                    {
                        throw new ArgumentException("Couldn't find the required piece");
                    }

                    if (piece.Equals(captured))
                    {
                        SetBoardCell(captured.X, captured.Y, new BoardCell(i, captured.IsWhite));
                        piece.IsCaptured = false;
                        Player2Pieces[i] = piece;
                        break;
                    }
                }
            }
        }
Example #5
0
        public void UpdatePieceAvailableMoves(PieceMinified piece, bool player)
        {
            var cell  = GetBoardCell(piece.X, piece.Y);
            var index = cell.GetIndex();

            if (player)
            {
                var target = (PieceMinified)Player1Pieces[index];
                target.UpdateAvailableMoves(piece);
                Player1Pieces[index] = target;
            }
            else
            {
                var target = (PieceMinified)Player2Pieces[index];
                target.UpdateAvailableMoves(piece);
                Player2Pieces[index] = target;
            }
        }