コード例 #1
0
        protected override void SwapWithCurrent(uint index, SwapType swapType)
        {
            // If the value being swapped in is one we're inserting, record the index found or assigned
            if (_currentRowAdding >= 0)
            {
                if (swapType == SwapType.Match)
                {
                    _currentAddedArrayIndices[_currentRowAdding] = _assignedIndices[index];
                }
                else
                {
                    _currentAddedArrayIndices[_currentRowAdding] = _uniqueValueCount++;
                }

                _currentRowAdding = -1;
            }

            // If this wasn't a match (key already found), swap in the keys and (new) index
            if (swapType != SwapType.Match)
            {
                // If this is a swap, write all values
                for (int i = 0; i < _keys.Length; ++i)
                {
                    _keys[i].SwapCurrent(index);
                }

                // Swap the assigned index
                int assignedIndexSwap = _assignedIndices[index];
                _assignedIndices[index] = _currentAssignedIndex;
                _currentAssignedIndex   = assignedIndexSwap;
            }
        }
コード例 #2
0
ファイル: Swap.cs プロジェクト: hliang89/Derivatives
        public Swap(double notional, DateTime maturity, DateTime effectiveDate, DateTime settlementDate, DateTime valuationDate, Dictionary<double,double> liborRate, Dictionary<double, double> disc,
            double fixedRate, SwapType swapType)
        {
            CalcPayDates(effectiveDate, maturity, valuationDate);
            this.notional = notional;
            this.maturity = maturity;
            this.effectiveDate = effectiveDate;
            this.settlementDate = settlementDate;
            this.valuationDate = valuationDate;
            this.DiscRates = disc;
            this.floatRates = liborRate;

            this.fixedLeg = new FixedLeg();
            this.floatingLeg = new FloatingLeg();

            //fixed leg
            this.fixedLeg.Notional = notional;
            this.fixedLeg.ValuationDate = valuationDate;
            this.fixedLeg.PayFrequency = 2;
            this.fixedLeg.FixedLegRate = fixedRate;
            this.fixedLeg.MaturityDate = maturity;
            this.fixedLeg.CalcPayFixed();
            this.fixedLeg.EffectiveDate = effectiveDate;

            //floating leg
            this.floatingLeg.EffectiveDate = effectiveDate;
            this.floatingLeg.PayFrequency = 4;
            this.floatingLeg.Notional = notional;
            this.floatingLeg.ValuationDate = valuationDate;
            this.floatingLeg.FloatLegRate = liborRate;

            this.floatingLeg.CalcPayFloat();
            NetPayments();
            CalcDV01();
        }
コード例 #3
0
        protected override void SwapWithCurrent(uint index, SwapType swapType)
        {
            if (swapType == SwapType.Match)
            {
                return;
            }
            if (swapType == SwapType.Insert && _copier != null)
            {
                _currentKey = _copier.Copy(_currentKey);
            }
            if (swapType == SwapType.Insert && _currentIsNull)
            {
                _nullItemIndex = (int)index;
            }

            T   swapKey   = _keys[index];
            int swapValue = _values[index];

            _keys[index]   = _currentKey;
            _values[index] = _currentValue;

            _currentKey    = swapKey;
            _currentValue  = swapValue;
            _currentIsNull = (_nullItemIndex == index);
        }
コード例 #4
0
        public InfoRecord[] GetInfoRecords(ITranslationManager tm)
        {
            const string tg      = "Statistics";
            var          records = new List <InfoRecord>
            {
                new InfoRecord
                {
                    Name  = tm.T(tg, "Type"),
                    Value = InstrType.ToString()
                },
                new InfoRecord
                {
                    Name  = tm.T(tg, "Comment"),
                    Value = Comment
                },
                new InfoRecord
                {
                    Name  = tm.T(tg, "Digits"),
                    Value = Digits.ToString(CultureInfo.InvariantCulture)
                },
                new InfoRecord
                {
                    Name  = tm.T(tg, "Point value"),
                    Value = Point.ToString("0.#####")
                },
                new InfoRecord
                {
                    Name  = tm.T(tg, "Lot size"),
                    Value = LotSize.ToString(CultureInfo.InvariantCulture)
                },
                new InfoRecord
                {
                    Name  = tm.T(tg, "Spread"),
                    Value = Spread.ToString("F2") + " " + tm.T(tg, "points")
                },
                new InfoRecord
                {
                    Name  = tm.T(tg, "Swap long"),
                    Value = SwapLong.ToString("F2") + " " + tm.T(tg, SwapType.ToString().ToLower())
                },
                new InfoRecord
                {
                    Name  = tm.T(tg, "Swap short"),
                    Value = SwapShort.ToString("F2") + " " + tm.T(tg, SwapType.ToString().ToLower())
                },
                new InfoRecord
                {
                    Name  = tm.T(tg, "Commission"),
                    Value = Commission.ToString("F2") + " " + tm.T(tg, CommissionType.ToString().ToLower())
                },
                new InfoRecord
                {
                    Name  = tm.T(tg, "Slippage"),
                    Value = Slippage.ToString("F2") + " " + tm.T(tg, "points")
                }
            };

            return(records.ToArray());
        }
コード例 #5
0
        protected override void SwapWithCurrent(uint index, SwapType swapType)
        {
            T swapKey   = _keys[index];
            U swapValue = _values[index];

            _keys[index]   = _currentKey;
            _values[index] = _currentValue;

            _currentKey   = swapKey;
            _currentValue = swapValue;
        }
コード例 #6
0
ファイル: AnimalSwap.cs プロジェクト: lipemon1/match3game
        /// <summary>
        /// Called to afirm that we are dealing with a drag swap
        /// </summary>
        /// <param name="animalSlot"></param>
        /// <param name="startedPosition"></param>
        private void EnableSwap(AnimalSlot animalSlot, Vector2 startedPosition)
        {
            _curSwapMode = SwapType.Drag;

            if (_animalSlotDragMoving != null)
            {
                return;
            }
            _animalSlotDragMoving = animalSlot;
            _mouseStart           = startedPosition;
        }
コード例 #7
0
 // Executes the swap.
 public void AttempSwap(SwapType type)
 {
     if (type == SwapType.NORMAL && swapAvailable)
     {
         ActivateCover(swapHit, true);
     }
     else if (type == SwapType.JUMP && jumpSwapAvailable)
     {
         ActivateCover(jumpSwapHit, true);
     }
 }
コード例 #8
0
ファイル: GridAnalyzer.cs プロジェクト: GloomyBoy/Solver
        private static List <SwapResult> GetPossibleSwaps(Grid grid, SwapType type)
        {
            List <SwapResult> result = new List <SwapResult>();
            var limW = grid.Width;
            var limH = grid.Height;

            switch (type)
            {
            case SwapType.Right:
                limW--;
                break;

            case SwapType.Down:
                limH--;
                break;
            }

            for (int i = 0; i < limW; i++)
            {
                for (int j = 0; j < limH; j++)
                {
                    var testGrid = grid.Clone();
                    if (testGrid[i, j] == null)
                    {
                        continue;
                    }
                    var pointed    = ActionFactory.GetBehaviour(testGrid[i, j]).Action(type);
                    var collapsing = testGrid.GetCollapsingCells().Union(pointed).ToList();
                    if (collapsing.Any())
                    {
                        SwapResult swap = new SwapResult()
                        {
                            X = i, Y = j, Direction = type
                        };
                        swap.Result = new CollapseResult(grid.Width);
                        while (collapsing.Any())
                        {
                            var newCollapsing = new List <CellItem>(collapsing);
                            foreach (var cellItem in collapsing)
                            {
                                newCollapsing.AddRange(ActionFactory.GetBehaviour(cellItem)
                                                       .Action(SwapType.Kill, newCollapsing));
                            }

                            swap.Result.Append(testGrid.Collapse(newCollapsing, swap.Generated));
                            collapsing     = testGrid.GetCollapsingCells().Distinct().ToList();
                            swap.FinalGrid = testGrid;
                        }
                        result.Add(swap);
                    }
                }
            }
            return(result);
        }
コード例 #9
0
ファイル: ActionFactory.cs プロジェクト: GloomyBoy/Solver
        public override List <CellItem> Action(SwapType action, List <CellItem> processed = null)
        {
            var touch = new List <CellItem>();

            if (processed?.Contains(_item) == true)
            {
                return(touch);
            }
            touch.AddRange(processed ?? new List <CellItem>());
            switch (action)
            {
            case SwapType.Point:
                return(new List <CellItem>());

            case SwapType.Down:
                if (_item.Parent.Height <= _item.Position.Y + 1)
                {
                    throw new MovementException($"Cant move cell {_item} down");
                }
                Swap(_item, _item.Position.X, _item.Position.Y + 1);
                break;

            case SwapType.Up:
                if (_item.Position.Y - 1 < 0)
                {
                    throw new MovementException($"Cant move cell {_item} up");
                }
                Swap(_item, _item.Position.X, _item.Position.Y - 1);
                break;

            case SwapType.Right:
                if (_item.Parent.Width <= _item.Position.X + 1)
                {
                    throw new MovementException($"Cant move cell {_item} right");
                }
                Swap(_item, _item.Position.X + 1, _item.Position.Y);
                break;

            case SwapType.Left:
                if (_item.Position.X - 1 < 0)
                {
                    throw new MovementException($"Cant move cell {_item} left");
                }
                Swap(_item, _item.Position.X - 1, _item.Position.Y);
                break;

            case SwapType.Kill:
                touch.Add(_item);
                break;
            }
            return(touch);
        }
コード例 #10
0
ファイル: AnimalSwap.cs プロジェクト: lipemon1/match3game
        /// <summary>
        /// Event called when user click on some animal, can be a drag or click until this moment
        /// </summary>
        /// <param name="animalSlot"></param>
        public void OnAnimalClickDown(AnimalSlot animalSlot)
        {
            _curSwapMode = SwapType.Click;

            UpdateCurAnimalDirections(animalSlot);

            if (_possibleAnimalSlotMoving != null)
            {
                return;
            }
            _possibleAnimalSlotMoving = animalSlot;
            _possibleMouseStart       = Input.mousePosition;
        }
コード例 #11
0
ファイル: AnimalSwap.cs プロジェクト: lipemon1/match3game
        /// <summary>
        /// Return the vector direction that will be used for swap animals
        /// </summary>
        /// <param name="swapType"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        private Vector2 GetDirectionToSwap(SwapType swapType)
        {
            switch (swapType)
            {
            case SwapType.Drag:
                return((Vector2)Input.mousePosition - _mouseStart);

            case SwapType.Click:
                return(GetRandomDirection());

            default:
                throw new ArgumentOutOfRangeException(nameof(swapType), swapType, null);
            }
        }
コード例 #12
0
ファイル: AnimalSwap.cs プロジェクト: lipemon1/match3game
        /// <summary>
        /// Called when we do a full click, so it is called also when we do a OnPointerUp event
        /// </summary>
        /// <param name="animalSlot"></param>
        public void OnAnimalClick(AnimalSlot animalSlot)
        {
            //Cleaning possible values because we want to clear our mouse
            if (_possibleAnimalSlotMoving != null)
            {
                _possibleAnimalSlotMoving = null;
            }
            _possibleMouseStart = Vector2.zero;

            if (_possibleAnimalSlotMoving == null && _animalSlotDragMoving == null)
            {
                _animalSlotClickMoving = animalSlot;
                _curSwapMode           = SwapType.Click;
                SwapAnimalByClick();
            }
        }
コード例 #13
0
        protected override void SwapWithCurrent(uint index, SwapType swapType)
        {
            // If the keys matched, compare the ranks
            if (swapType == SwapType.Match)
            {
                if (_ranks.BetterThanCurrent(index, _chooseDirection))
                {
                    // If the rank is better or we're swapping with a non-match, write the new rank and row
                    _ranks.SwapCurrent(index);
                    _bestRowIndices.SwapCurrent(index);
                }
            }
            else
            {
                // Otherwise, write all values
                for (int i = 0; i < _keys.Length; ++i)
                {
                    _keys[i].SwapCurrent(index);
                }

                _ranks.SwapCurrent(index);
                _bestRowIndices.SwapCurrent(index);
            }
        }
コード例 #14
0
ファイル: ActionFactory.cs プロジェクト: GloomyBoy/Solver
        public override List <CellItem> Action(SwapType action, List <CellItem> processed = null)
        {
            var touch = new List <CellItem>();

            if (processed?.Contains(_item) == true)
            {
                return(touch);
            }
            touch.AddRange(processed ?? new List <CellItem>());
            switch (action)
            {
            case SwapType.Down:
                if (_item.Parent.Height <= _item.Position.Y + 1)
                {
                    throw new MovementException($"Cant move cell {_item} down");
                }
                Swap(_item, _item.Position.X, _item.Position.Y + 1);
                break;

            case SwapType.Up:
                if (_item.Position.Y - 1 < 0)
                {
                    throw new MovementException($"Cant move cell {_item} up");
                }
                Swap(_item, _item.Position.X, _item.Position.Y - 1);
                break;

            case SwapType.Right:
                if (_item.Parent.Width <= _item.Position.X + 1)
                {
                    throw new MovementException($"Cant move cell {_item} right");
                }
                Swap(_item, _item.Position.X + 1, _item.Position.Y);
                break;

            case SwapType.Left:
                if (_item.Position.X - 1 < 0)
                {
                    throw new MovementException($"Cant move cell {_item} left");
                }
                Swap(_item, _item.Position.X - 1, _item.Position.Y);
                break;

            case SwapType.Point:
            case SwapType.Kill:
                touch.Add(_item);
                for (int i = 0; i < _item.Parent.Width; i++)
                {
                    for (int j = 0; j < _item.Parent.Height; j++)
                    {
                        if (_item.Parent[i, j]?.Tag == _item.Tag)
                        {
                            touch.AddRange(ActionFactory.GetBehaviour(_item.Parent[i, j])
                                           .Action(SwapType.Kill, touch));
                        }
                    }
                }
                break;
            }
            return(touch);
        }
コード例 #15
0
ファイル: ActionFactory.cs プロジェクト: GloomyBoy/Solver
 public override List <CellItem> Action(SwapType action, List <CellItem> processed = null)
 {
     return(processed ?? new List <CellItem>());
 }
コード例 #16
0
 public Swap(SwapType swapType, Position original, Position replacement)
 {
     this.SwapType    = swapType;
     this.Original    = original;
     this.Replacement = replacement;
 }
コード例 #17
0
ファイル: HashCore.cs プロジェクト: sharwell/elfie-arriba
 protected abstract void SwapWithCurrent(uint index, SwapType swapType);
コード例 #18
0
ファイル: IBehaviour.cs プロジェクト: GloomyBoy/Solver
 public abstract List <CellItem> Action(SwapType action, List <CellItem> processed = null);
コード例 #19
0
    public static void DoSwap(string path, SwapType swapType)
    {
        if (path == null)
        {
            throw new ArgumentNullException("path",
                                            "You must supply a path to the file.");
        }
        if (!File.Exists(path))
        {
            throw new FileNotFoundException("File not found.");
        }
        string tempPath = Path.GetTempFileName();

        byte[] buffer    = new byte[4096];
        byte[] swapBytes = new byte[100];
        using (FileStream inputFs = new FileStream(path, FileMode.Open,
                                                   FileAccess.Read))
            using (FileStream outputFs = new FileStream(tempPath,
                                                        FileMode.Open, FileAccess.Write))
            {
                int bytesRead = -1;
                if (swapType == SwapType.FrontToBack)
                {
                    // We want to keep hold of the first 100 bytes of the file
                    // and output them after copying the rest of file
                    inputFs.Read(swapBytes, 0, 100);
                }
                else
                {
                    // Read the last 100 bytes of the file
                    inputFs.Seek(-100, SeekOrigin.End);
                    inputFs.Read(swapBytes, 0, 100);
                    // Output them straight to the output file
                    outputFs.Write(swapBytes, 0, 100);
                    // Reposition to the beginning of the input file
                    inputFs.Seek(0, SeekOrigin.Begin);
                }
                // The number of bytes left to copy is 100 less than the file
                // length
                long bytesRemaining = inputFs.Length - 100;
                // Copy the rest of the bytes
                while (bytesRemaining > 0)
                {
                    bytesRead = inputFs.Read(buffer, 0, buffer.Length);
                    // NB: the number of bytes read could be more than the
                    // number remaining
                    outputFs.Write(buffer, 0,
                                   (int)Math.Min(bytesRead, bytesRemaining));
                    bytesRemaining -= bytesRead;
                }
                // Don't forget to append the start bytes if required
                if (swapType == SwapType.FrontToBack)
                {
                    outputFs.Write(swapBytes, 0, 100);
                }
            }
        // Now swap the files themselves
        File.Delete(path);
        File.Move(tempPath, path);
        // NB: could do File.Replace() if backup is needed
    }