예제 #1
0
파일: King.cs 프로젝트: aydoganf/chess-api
        public override bool TryMove(Location target, Table table, out IStone willEated)
        {
            willEated = null;

            if (CheckMove(target, table) == false)
            {
                return(false);
            }

            var span = target - Location;

            // yatay - dikey hareket
            if (span.XDiff == 0 || span.YDiff == 0)
            {
                if (MovementRules.HorizontalOrVerticalCheck(Location, target, table) == false)
                {
                    return(false);
                }
            }

            // çapraz
            else
            {
                if (MovementRules.DiagonalCheck(Location, target, table) == false)
                {
                    return(false);
                }
            }

            willEated = table.Stones.GetFromLocation(target);
            return(true);
        }
예제 #2
0
        public override bool TryMove(Location target, Table table, out IStone willEated)
        {
            willEated = default;
            if (CheckMove(target, table) == false)
            {
                return(false);
            }

            if (MovementRules.HorizontalOrVerticalCheck(Location, target, table) == false)
            {
                return(false);
            }

            willEated = table.Stones.GetFromLocation(target);
            return(true);
        }
예제 #3
0
        public override bool TryMove(Location target, Table table, out IStone willEated)
        {
            willEated = default;
            if (CheckMove(target, table) == false)
            {
                return(false);
            }

            var targetLocationStone = table.Stones.GetFromLocation(target);
            var span = target - Location;

            // çapraz gidiş
            if (span.XDiff == span.YDiff)
            {
                var result = MovementRules.DiagonalCheck(Location, target, table);
                if (result == false)
                {
                    return(result);
                }

                if (targetLocationStone != null)
                {
                    willEated = targetLocationStone;
                }
            }

            // yatay || dikey gidiş
            if (span.XDiff == 0 || span.YDiff == 0)
            {
                var result = MovementRules.HorizontalOrVerticalCheck(Location, target, table);
                if (result == false)
                {
                    return(result);
                }

                if (targetLocationStone != null)
                {
                    willEated = targetLocationStone;
                }
            }

            return(true);
        }