Example #1
0
        private Dictionary <PointInt, double> _getMoveRanks(double[,] map, KeyValuePair <WaterDrop, PointInt> drop)
        {
            var currentDropPosition = drop.Value;
            var dropObj             = drop.Key;
            var moveRanks           = new Dictionary <PointInt, double>();

            foreach (var targetCell in _neighborsGetter(currentDropPosition))
            {
                if (!IsInMap(map, targetCell))
                {
                    continue;
                }
                var heightDiff = GetHeight(map, currentDropPosition) - GetHeight(map, targetCell);
                if (heightDiff < 0)
                {
                    continue;
                }
                if (dropObj.Speed.Length > 0)
                {
                    var targetSpeed = VectorExtension.CreateFromTwoPoints(currentDropPosition, targetCell);
                    var angle       = dropObj.Speed.GetAngleWith(targetSpeed);
                    var factor      = 0.5 * Math.Abs(angle);
                    moveRanks[targetCell] = heightDiff / factor;
                }
                else
                {
                    var factor = Math.PI / 3; //TODO
                    moveRanks[targetCell] = heightDiff / factor;
                }
            }

            return(moveRanks);
        }
Example #2
0
        private static Vector CalculateSpeed(double[,] map, KeyValuePair <WaterDrop, PointInt> drop, KeyValuePair <PointInt, double> targetCell)
        {
            var scalarSpeed     = GetHeight(map, drop.Value) - GetHeight(map, targetCell.Key);
            var unitVectorSpeed = VectorExtension.CreateFromTwoPoints(drop.Value, targetCell.Key);
            var speed           = scalarSpeed * unitVectorSpeed;

            return(speed + drop.Key.Speed);
        }