< Summary

Information
Class: Rudim.Common.Move
Assembly: Rudim
File(s): /home/runner/work/rudim/rudim/Rudim/Common/Move.cs
Line coverage
81%
Covered lines: 26
Uncovered lines: 6
Coverable lines: 32
Total lines: 91
Line coverage: 81.2%
Branch coverage
66%
Covered branches: 12
Total branches: 18
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Source()100%11100%
get_Target()100%11100%
get_Type()100%11100%
get_Score()100%11100%
.cctor()100%11100%
IsCapture()100%11100%
GetPromotionChar()100%11100%
IsPromotion()100%22100%
IsCastle()100%11100%
ParseLongAlgebraic(...)100%22100%
ParsePromotionType(...)25%16850%
ParseFromString(...)100%11100%
Equals(...)100%210%
Equals(...)100%66100%
GetHashCode()100%210%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%

File(s)

/home/runner/work/rudim/rudim/Rudim/Common/Move.cs

#LineLine coverage
 1using Rudim.Board;
 2using System;
 3using System.Collections.Generic;
 4
 5namespace Rudim.Common
 6{
 622942197    public class Move(Square source, Square target, MoveType type) : IEquatable<Move>
 8    {
 2019772569        public Square Source { get; init; } = source;
 16544863510        public Square Target { get; init; } = target;
 17974590811        public MoveType Type { get; init; } = type;
 43773050612        public int Score { get; set; }
 13
 114        public static readonly Move NoMove = new(Square.NoSquare, Square.NoSquare, MoveTypes.Quiet);
 15
 16        public bool IsCapture()
 17        {
 7258843418            return Type.IsCapture;
 19        }
 20
 21        public string GetPromotionChar()
 22        {
 10423            return Type.PromotionChar;
 24        }
 25
 26        public bool IsPromotion()
 27        {
 1100163028            return Type.Value >= MoveTypes.KnightPromotion.Value && Type.Value <= MoveTypes.QueenPromotionCapture.Value;
 29        }
 30
 31        public bool IsCastle()
 32        {
 1100163033            return Type == MoveTypes.Castle;
 34        }
 35
 36        public static Move ParseLongAlgebraic(string moveString)
 37        {
 28438            Square from = ParseFromString(moveString.Substring(0, 2));
 28439            Square to = ParseFromString(moveString.Substring(2, 2));
 28440            MoveType moveType = moveString.Length == 5 ? ParsePromotionType(moveString[4]) : MoveTypes.Quiet;
 41
 28442            return new Move(from, to, moveType);
 43        }
 44
 45        private static MoveType ParsePromotionType(char piece)
 46        {
 147            return Char.ToLower(piece) switch
 148            {
 149                'q' => MoveTypes.QueenPromotion,
 050                'r' => MoveTypes.RookPromotion,
 051                'b' => MoveTypes.BishopPromotion,
 052                'n' => MoveTypes.KnightPromotion,
 053                _ => throw new InvalidOperationException(),
 154            };
 55        }
 56
 57        private static Square ParseFromString(string squareString)
 58        {
 56859            _ = Enum.TryParse(squareString, out Square square);
 56860            return square;
 61        }
 62
 63        public override bool Equals(object obj)
 64        {
 065            return Equals(obj as Move);
 66        }
 67
 68        public bool Equals(Move other)
 69        {
 2526534970            return other != null &&
 2526534971                   Source == other.Source &&
 2526534972                   Target == other.Target &&
 2526534973                   EqualityComparer<MoveType>.Default.Equals(Type, other.Type);
 74        }
 75
 76        public override int GetHashCode()
 77        {
 078            return HashCode.Combine(Source, Target, Type);
 79        }
 80
 81        public static bool operator ==(Move left, Move right)
 82        {
 13564232483            return EqualityComparer<Move>.Default.Equals(left, right);
 84        }
 85
 86        public static bool operator !=(Move left, Move right)
 87        {
 2526535688            return !(left == right);
 89        }
 90    }
 91}