Beispiel #1
0
        /// <summary>
        /// Get possible points
        /// </summary>
        /// <param name="chessBoard">chessboard</param>
        /// <returns>list of points</returns>
        public virtual List <Point> GetPossibleMoves(ChessBoard chessBoard)
        {
            var possibleMoves = new List <Point>();

            foreach (var currentPossibles in PossiblePoints)
            {
                foreach (var currentPoint in currentPossibles)
                {
                    var tempPoint = currentPoint + this.Position;
                    if (Point.IsValid(tempPoint))
                    {
                        if (chessBoard.GetFigureByPercolate(f => f.Position == tempPoint) == null)
                        {
                            possibleMoves.Add(tempPoint);
                        }
                        else
                        {
                            var figure = chessBoard.GetFigureByPercolate(f => f.Position == tempPoint);
                            if (figure.Color != this.Color)
                            {
                                possibleMoves.Add(tempPoint);
                            }
                            break;
                        }
                    }
                }
            }
            return(possibleMoves);
        }
Beispiel #2
0
 public static Vector Subtract(this Point point, Point other)
 {
     Contract.Requires(point.IsValid());
     Contract.Requires(other.IsValid());
     Contract.Ensures(Contract.Result <Vector>().IsValid());
     return(new Vector(point.X - other.X, point.Y - other.Y));
 }
Beispiel #3
0
 protected void AddIfMoveIsPossible(int[,] chessBoard, List <Point> list, Point point)
 {
     if (point.IsValid(_chessBoardSize) && chessBoard[point.X, point.Y] == _unvisitedField)
     {
         list.Add(point);
     }
 }
Beispiel #4
0
        /// <param name="angleRadians">The angle, in radians, from 3-o'clock going counter-clockwise.</param>
        public static void DrawLine(this DrawingContext drawingContext, Pen pen, Point startPoint, double angleRadians, double length)
        {
            Util.RequireNotNull(drawingContext, "drawingContext");
              Util.RequireArgument(startPoint.IsValid(), "startPoint");
              Util.RequireNotNull(pen, "Pen");

              drawingContext.DrawLine(pen, startPoint, startPoint + GeoHelper.GetVectorFromAngle(angleRadians, length));
        }
Beispiel #5
0
        /// <param name="angleRadians">The angle, in radians, from 3-o'clock going counter-clockwise.</param>
        public static void DrawLine(this DrawingContext drawingContext, Pen pen, Point startPoint, double angleRadians, double length)
        {
            Contract.Requires <ArgumentNullException>(drawingContext != null);
            Contract.Requires <ArgumentException>(startPoint.IsValid());
            Contract.Requires <ArgumentNullException>(pen != null);

            drawingContext.DrawLine(pen, startPoint, startPoint + GeoHelper.GetVectorFromAngle(angleRadians, length));
        }
Beispiel #6
0
        public Line(Point p1, Point p2)
        {
            Contract.Requires(p1.IsValid());
            Contract.Requires(p2.IsValid());

            m_p1 = p1;
            m_p2 = p2;
        }
Beispiel #7
0
 protected override Point OnOriginalPosition(TVertex v, Point p)
 {
     if (AlsoRandomValidPosition)
     {
         return(new Point(Randomizer.Next(0, 2000), Randomizer.Next(0, 2000)));
     }
     return(p.IsValid() ? p : new Point(Randomizer.Next(0, 2000), Randomizer.Next(0, 2000)));
 }
Beispiel #8
0
        /// <param name="angleRadians">The angle, in radians, from 3-o'clock going counter-clockwise.</param>
        public static void DrawLine(this DrawingContext drawingContext, Pen pen, Point startPoint, double angleRadians, double length)
        {
            Contract.Requires<ArgumentNullException>(drawingContext != null);
            Contract.Requires<ArgumentException>(startPoint.IsValid());
            Contract.Requires<ArgumentNullException>(pen != null);

            drawingContext.DrawLine(pen, startPoint, startPoint + GeoHelper.GetVectorFromAngle(angleRadians, length));
        }
Beispiel #9
0
        protected override Point OnOriginalPosition(YodiiGraphVertex v, Point p)
        {
            // Keep existing positions
            if (p.IsValid())
            {
                return(p);
            }

            Point newPoint = new Point(0, 0);

            if (VertexPositions == null)
            {
                return(newPoint);
            }
            if (v.IsService)
            {
                if (v.LabServiceInfo.ServiceInfo.Generalization != null)
                {
                    // Find & get point of generalization
                    var generalizationQuery = VertexPositions.Where(kvp => kvp.Key.IsService && kvp.Key.LabServiceInfo.ServiceInfo == v.LabServiceInfo.ServiceInfo.Generalization);

                    if (generalizationQuery.Count() > 0)
                    {
                        Point generalizationPoint = generalizationQuery.First().Value;
                        if (generalizationPoint.IsValid())
                        {
                            newPoint.X = generalizationPoint.X;
                            newPoint.Y = generalizationPoint.Y + VERTICAL_MARGIN_SIZE;
                        }
                    }
                }
            }
            else if (v.IsPlugin)
            {
                if (v.LabPluginInfo.PluginInfo.Service != null)
                {
                    // Find & get point of service
                    var serviceQuery = VertexPositions.Where(kvp => kvp.Key.IsService && kvp.Key.LabServiceInfo.ServiceInfo == v.LabPluginInfo.PluginInfo.Service);

                    if (serviceQuery.Count() > 0)
                    {
                        Point generalizationPoint = serviceQuery.First().Value;
                        if (generalizationPoint.IsValid())
                        {
                            newPoint.X = generalizationPoint.X;
                            newPoint.Y = generalizationPoint.Y + VERTICAL_MARGIN_SIZE;
                        }
                    }
                }
            }

            return(newPoint);
        }
Beispiel #10
0
        public static double AngleRad(Point point1, Point point2, Point point3)
        {
            Debug.Assert(point1.IsValid());
            Debug.Assert(point2.IsValid());
            Debug.Assert(point3.IsValid());

            var rad = AngleRad(point2.Subtract(point1), point2.Subtract(point3));

            var rad2 = AngleRad(point2.Subtract(point1), (point2.Subtract(point3)).RightAngle());

            if (rad2 < (Math.PI / 2))
            {
                return(rad);
            }
            return((Math.PI * 2) - rad);
        }
Beispiel #11
0
        public bool Animate(
            Point currentValue, Vector currentVelocity, Point targetValue,
            double attractionFator, double dampening,
            double terminalVelocity, double minValueDelta, double minVelocityDelta,
            out Point newValue, out Vector newVelocity)
        {
            Debug.Assert(currentValue.IsValid());
            Debug.Assert(currentVelocity.IsValid());
            Debug.Assert(targetValue.IsValid());

            Debug.Assert(dampening.IsValid());
            Debug.Assert(dampening > 0 && dampening < 1);

            Debug.Assert(attractionFator.IsValid());
            Debug.Assert(attractionFator > 0);

            Debug.Assert(terminalVelocity > 0);

            Debug.Assert(minValueDelta > 0);
            Debug.Assert(minVelocityDelta > 0);

            Vector diff = targetValue.Subtract(currentValue);

            if (diff.Length > minValueDelta || currentVelocity.Length > minVelocityDelta)
            {
                newVelocity  = currentVelocity * (1 - dampening);
                newVelocity += diff * attractionFator;
                if (currentVelocity.Length > terminalVelocity)
                {
                    newVelocity *= terminalVelocity / currentVelocity.Length;
                }

                newValue = currentValue + newVelocity;

                return(true);
            }
            else
            {
                newValue    = targetValue;
                newVelocity = new Vector();
                return(false);
            }
        }
Beispiel #12
0
        public static double AngleRad(Point point1, Point point2, Point point3)
        {
            Debug.Assert(point1.IsValid());
            Debug.Assert(point2.IsValid());
            Debug.Assert(point3.IsValid());

            double rad = AngleRad(point2.Subtract(point1), point2.Subtract(point3));

            double rad2 = AngleRad(point2.Subtract(point1), (point2.Subtract(point3)).RightAngle());

            if (rad2 < (Math.PI / 2))
            {
                return rad;
            }
            else
            {
                return (Math.PI * 2) - rad;
            }
        }
Beispiel #13
0
        /// <summary>
        /// Standart possible points for figure
        /// </summary>
        /// <returns>list of points</returns>
        private List <Point> GetPossiblePoints(ChessBoard chessBoard)
        {
            var possiblePoints = new List <Point>();
            var possibleMoves  = new List <Point>();

            //standart possible points
            if (identifier == PawnIdentifier.Top)
            {
                possiblePoints.Add(PossiblePoints[0][0]);
                //boost points
                if (this.Position.X == 1)
                {
                    possiblePoints.Add(PossiblePoints[2][0]);
                }
            }
            else
            {
                possiblePoints.Add(PossiblePoints[1][0]);
                //bost points
                if (this.Position.X == 6)
                {
                    possiblePoints.Add(PossiblePoints[3][0]);
                }
            }

            foreach (var currentPossible in possiblePoints)
            {
                var tempPoint = this.Position + currentPossible;
                if (Point.IsValid(tempPoint) &&
                    chessBoard.GetFigureByPercolate(f => f.Position == tempPoint) == null)
                {
                    possibleMoves.Add(tempPoint);
                }
                else
                {
                    break;
                }
            }

            return(possibleMoves);
        }
Beispiel #14
0
        // constructor
        public ChessJumperBase(int chessBoardSize, Point startField)
        {
            if (chessBoardSize < 4 || !startField.IsValid(chessBoardSize))
            {
                throw new Exception("Bad chess board size or start field");
            }

            _startField = startField;

            _chessBoardSize = chessBoardSize;
            _chessBoard     = new int[chessBoardSize, chessBoardSize];

            for (int i = 0; i < chessBoardSize; i++)
            {
                for (int j = 0; j < chessBoardSize; j++)
                {
                    _chessBoard[i, j] = _unvisitedField;
                }
            }

            _stopwatch = new Stopwatch();
        }
Beispiel #15
0
        /// <summary>
        /// Standart possible points for figure
        /// </summary>
        /// <returns>list of points</returns>
        public List <Point> GetPossiblePoints(ChessBoard chessBoard)
        {
            var possibleMoves = new List <Point>();

            for (int i = 0; i < PossiblePoints.Count; i++)
            {
                var currentPossibles = PossiblePoints[i];
                for (int j = 0; j < currentPossibles.Count; j++)
                {
                    var tempPoint     = Position + PossiblePoints[i][j];
                    var figureToCheck = chessBoard.GetFigureByPercolate(f => f.Position == tempPoint);
                    if (figureToCheck != null && figureToCheck?.Color == this.Color)
                    {
                        continue;
                    }
                    if (Point.IsValid(tempPoint))
                    {
                        possibleMoves.Add(tempPoint);
                    }
                }
            }
            return(possibleMoves);
        }
Beispiel #16
0
 public static Vector Subtract(this Point point, Point other)
 {
     Contract.Requires(point.IsValid());
     Contract.Requires(other.IsValid());
     Contract.Ensures(Contract.Result<Vector>().IsValid());
     return new Vector(point.X - other.X, point.Y - other.Y);
 }
Beispiel #17
0
        public static bool Animate(
            Point currentValue, Vector currentVelocity, Point targetValue,
            double attractionFator, double dampening,
            double terminalVelocity, double minValueDelta, double minVelocityDelta,
            out Point newValue, out Vector newVelocity)
        {
            Debug.Assert(currentValue.IsValid());
            Debug.Assert(currentVelocity.IsValid());
            Debug.Assert(targetValue.IsValid());

            Debug.Assert(dampening.IsValid());
            Debug.Assert(dampening > 0 && dampening < 1);

            Debug.Assert(attractionFator.IsValid());
            Debug.Assert(attractionFator > 0);

            Debug.Assert(terminalVelocity > 0);

            Debug.Assert(minValueDelta > 0);
            Debug.Assert(minVelocityDelta > 0);

            Vector diff = targetValue.Subtract(currentValue);

            if (diff.Length > minValueDelta || currentVelocity.Length > minVelocityDelta)
            {
                newVelocity = currentVelocity * (1 - dampening);
                newVelocity += diff * attractionFator;
                if (currentVelocity.Length > terminalVelocity)
                {
                    newVelocity *= terminalVelocity / currentVelocity.Length;
                }

                newValue = currentValue + newVelocity;

                return true;
            }
            else
            {
                newValue = targetValue;
                newVelocity = new Vector();
                return false;
            }
        }
Beispiel #18
0
      /// <summary/>
      protected override Point GetCurrentValueCore(Point baseFromValue, Point baseToValue, AnimationClock animationClock) {
         var progress = animationClock.CurrentProgress;
         if (!progress.HasValue || Interpolator == null) {
            return base.GetCurrentValueCore(baseFromValue, baseToValue, animationClock);
         }

         var fromValue = new Point();
         var toValue = new Point();
         var offset = new Vector();
         var isValid = true;

         if (From.HasValue) {
            fromValue = From.Value;
            if (To.HasValue) {
               // from ... to 
               toValue = To.Value;
               if (IsAdditive) {
                  offset = (Vector)baseFromValue;
                  isValid = offset.IsValid();
               }
            } else if (By.HasValue) {
               // from ... from+by
               toValue = fromValue + (Vector)By.Value;
               if (IsAdditive) {
                  offset = (Vector)baseFromValue;
                  isValid = offset.IsValid();
               }
            } else {
               // from ... base
               toValue = baseToValue;
               isValid = toValue.IsValid();
            }
         } else if (To.HasValue) {
            // base ... to
            fromValue = baseFromValue;
            toValue = To.Value;
            isValid = fromValue.IsValid();
         } else if (By.HasValue) {
            // base ... base+by
            toValue = By.Value;
            offset = (Vector)baseFromValue;
            isValid = offset.IsValid();
         } else {
            // base ... base
            fromValue = baseFromValue;
            toValue = baseToValue;
            isValid = fromValue.IsValid() && toValue.IsValid();
         }
         if (!isValid) {
            throw new InvalidOperationException("GetCurrentValueCore");
         }

         if (IsCumulative) {
            var iteration = animationClock.CurrentIteration;
            if (iteration.HasValue && iteration.Value > 1) {
               offset += (toValue - fromValue) * (iteration.Value - 1);
            }
         }

         var interpolator = Interpolator ?? Interpolators.Linear;
         return fromValue + (toValue - fromValue) * interpolator(progress.Value, 0.0, 1.0) + offset;
      }
 protected virtual Point OnOriginalPosition(TVertex v, Point p)
 {
     return(p.IsValid() ? p : new Point(_random.Next(0, 2000), _random.Next(0, 2000)));
 }