private MatchPiece GetPieceByDirection(MatchPiece piece, SwapDirection direction) { var c = piece.column + (direction == SwapDirection.LEFT ? (-1) : direction == SwapDirection.RIGHT ? 1 : 0); var r = piece.row + (direction == SwapDirection.DOWN ? (-1) : direction == SwapDirection.UP ? 1 : 0); return(board[c][r]); }
public void SwapPieces(MatchPiece piece, SwapDirection direction, bool checkMatches = true) { currentPiece = piece; currentDirection = direction; bool validMove = CheckForValidMove(piece, direction); if (!validMove) { if (!dragMode) { piece.gameObject.transform.DOShakePosition(0.5f, 0.3f); } return; } canMove = false; MatchPiece otherPiece = GetPieceByDirection(piece, direction); var piecePosition = piece.transform.position; var otherPiecePosition = otherPiece.transform.position; piece.ChangeSortingLayer("ballFront"); otherPiece.ChangeSortingLayer("ballBack"); DOTween.Sequence() .Append(piece.transform.DOMove(otherPiecePosition, timeToSwap)) .Join(otherPiece.transform.DOMove(piecePosition, timeToSwap)) .SetEase(Ease.OutCirc) .OnComplete(() => { SwapPieces(piece, otherPiece, checkMatches); }); }
private bool CheckForValidMove(MatchPiece piece, SwapDirection direction) { return(!(direction == SwapDirection.LEFT && piece.column == 0 || direction == SwapDirection.RIGHT && piece.column == columns - 1 || direction == SwapDirection.UP && piece.row == rows - 1 || direction == SwapDirection.DOWN && piece.row == 0)); }
public CreditDefaultSwap(SwapLeg premiumLeg, CdsProtectionLeg protectionLeg, SwapDirection swapDirection, string tenor = null, int premiumLegIntegrationIntervals = 60) { PremiumLeg = premiumLeg; ProtectionLeg = protectionLeg; SwapDirection = swapDirection; Tenor = tenor ?? new Term(UnderlyingMaturityDate - StartDate, Period.Day).ToString(); PremiumLegIntegrationIntervals = premiumLegIntegrationIntervals; }
/// <summary> /// Rotates a tile group /// </summary> IEnumerator RotateTileGroup(SwipeDirection _swipeDirection) { _gameState = GameState.rotating; SwapDirection _swapDirection = CalculateRotateDirection(_swipeDirection); print("Rotating..."); //Rotating 120 degrees, 3 times if no matches found for (int i = 0; i < 3; i++) { tileGroup.SetParent(tileGroupCenterObj); float elapsedTime = 0; Quaternion currentRotation = tileGroupCenterObj.transform.rotation; Quaternion targetRotation = currentRotation; //Clockwise or anti-clockwise rotation targetRotation *= Quaternion.Euler(Vector3.forward * 120 * (int)_swapDirection); //Slerp rotation to have a smooth movement effect while (elapsedTime < Values.GroupRotationTime) { elapsedTime += Time.deltaTime; tileGroupCenterObj.transform.rotation = Quaternion.Slerp(currentRotation, targetRotation, elapsedTime / Values.GroupRotationTime); yield return(null); } tileGroupCenterObj.transform.rotation = targetRotation; //Actual swapping of the tiles on the grid matrix tileGroup.SwapTiles(gridTiles, _swapDirection); tileGroup.RemoveParent(); TileMatches groupMatches = gridTiles.CheckTileForMaches(tileGroup); print("Checking group match..."); StartCoroutine(DisableMatchedTiles(groupMatches)); yield return(new WaitForSeconds(Values.RotationDelay)); } _gameState = GameState.idle; }
/* * Rotates the party moving the foward most unit * to the back. * * amount : int (default 1) * The amount of times to move the front most * unit to the back. */ public void Rotate(SwapDirection dir) { Character c; int index; if (dir == SwapDirection.Left) { c = characterList[0]; characterList.RemoveAt(0); characterList.Add(c); } else if (dir == SwapDirection.Right) { c = characterList[2]; characterList.RemoveAt(2); characterList.Insert(0, c); } }
private SwapDirection OppositeDirection(SwapDirection dir) { switch (dir) { case SwapDirection.DOWN: return(SwapDirection.UP); case SwapDirection.UP: return(SwapDirection.DOWN); case SwapDirection.LEFT: return(SwapDirection.RIGHT); case SwapDirection.RIGHT: return(SwapDirection.LEFT); } return(SwapDirection.NULL); }
public void SwapTiles(TileMatrix allTiles, SwapDirection _swapDirection) { int tempRow2 = tiles[2].row; int tempColumn2 = tiles[2].column; int tempRow1 = tiles[1].row; int tempColumn1 = tiles[1].column; int tempRow0 = tiles[0].row; int tempColumn0 = tiles[0].column; if (_swapDirection == SwapDirection.clockwise) { tiles[2].row = tempRow1; tiles[2].column = tempColumn1; tiles[1].row = tempRow0; tiles[1].column = tempColumn0; tiles[0].row = tempRow2; tiles[0].column = tempColumn2; allTiles[tempRow1, tempColumn1] = tiles[2].gameObject; allTiles[tempRow0, tempColumn0] = tiles[1].gameObject; allTiles[tempRow2, tempColumn2] = tiles[0].gameObject; } else { tiles[2].row = tempRow0; tiles[2].column = tempColumn0; tiles[1].row = tempRow2; tiles[1].column = tempColumn2; tiles[0].row = tempRow1; tiles[0].column = tempColumn1; allTiles[tempRow0, tempColumn0] = tiles[2].gameObject; allTiles[tempRow2, tempColumn2] = tiles[1].gameObject; allTiles[tempRow1, tempColumn1] = tiles[0].gameObject; } }
public InterestRateSwap( SwapLeg fixedLeg, SwapLeg floatingLeg, SwapDirection swapDirection, string tenor = null) { FixedLeg = fixedLeg; FloatingLeg = floatingLeg; if (FixedLeg.StartDate != FloatingLeg.StartDate || FixedLeg.UnderlyingMaturityDate != FloatingLeg.UnderlyingMaturityDate || !FixedLeg.Notional.AlmostEqual(-FloatingLeg.Notional) || FixedLeg.NotionalExchange != FloatingLeg.NotionalExchange) { throw new PricingBaseException("Interest rate swap fixed leg and floating leg mismatches"); } SwapDirection = swapDirection; Tenor = tenor ?? string.Format("{0}{1}", (int)(UnderlyingMaturityDate - StartDate), "D"); }
private void CheckDrag(Vector2 position) { if (!mIsDragging || !MatchManager.instance.canMove) { return; } position = Camera.main.ScreenToWorldPoint(position); var x = transform.position.x; var y = transform.position.y; var bSize = MatchManager.instance.dragThreshold; var diffX = Mathf.Abs(x - position.x); var diffY = Mathf.Abs(y - position.y); var right = position.x > x + bSize; var left = position.x < x - bSize; var up = position.y > y + bSize; var down = position.y < y - bSize; if (up && (right || left)) { up = diffY >= diffX; if (up) { right = left = false; } } if (down && (right || left)) { down = diffY >= diffX; if (down) { right = left = false; } } SwapDirection dir = SwapDirection.NULL; if (up) { dir = SwapDirection.UP; } if (down) { dir = SwapDirection.DOWN; } if (left) { dir = SwapDirection.LEFT; } if (right) { dir = SwapDirection.RIGHT; } if (dir != SwapDirection.NULL) { MatchManager.instance.SwapPieces(this, dir); } }
public static double Sign(this SwapDirection swapDirection) { return(swapDirection == SwapDirection.Payer ? -1 : 1); }
public Cashflow[] GetCashflows(IMarketCondition market, bool netted = true) { return(PremiumLeg.GetCashflows(market, netted) .Select(x => new Cashflow(x.AccrualStartDate, x.AccrualEndDate, x.PaymentDate, x.PaymentAmount * SwapDirection.Sign(), x.PaymentCurrency, x.CashflowType, x.IsFixed, market.GetDf(x.PaymentDate), x.CalculationDetails)) .ToArray()); }