Exemple #1
0
        /// Find which way to go from the ghost's next cell (in the direction of travel)
        /// to the target cell.
        public Directions GetWhichWayToGo(CellIndex targetCell)
        {
            Tile currentTile = _ghost.Tile;

            CellIndex cellPosition = currentTile.Index;

            if (cellPosition == _lastDecisionMadeAt)
            {
                return(Directions.None);
            }

            Tile nextTile = currentTile.NextTileWrapped(_ghost.Direction.Next);

            // the tile might not be in bounds, e.g. the ghost could be at the bottom of the maze facing
            // up when a power pill is eaten, this will mean the next direction is down (directions are reversed)
            // which will mean the next cell is 1 below the bottom of the maze.
            if (!nextTile.Index.IsInBounds)
            {
                return(_ghost.Direction.Current);
            }

            Directions decision = calculateWhichWayToGo(nextTile, targetCell);

            _lastDecisionMadeAt = cellPosition;

            return(decision);
        }
        /// <summary>
        /// Masks the specified puzzle board.
        /// </summary>
        /// <param name="cells">Puzzle to mask.</param>
        internal void MaskBoard(CellClass[,] cells)
        {
            List <CellClass> list          = TransferToList(cells);             // Transfer the 2D array to a list.
            Int32            mask          = 81 - GetMaskedValue(_level);       // Get the number of cells to mask based on the difficulty level.
            SolveGame        cSolve        = new SolveGame();                   // Instantiate a the game solver class
            Int32            numIterations = 0;                                 // Initialize the iteration counter

            NotGood = false;                                                    // Clear the flag.
            do
            {
                CellIndex index1 = FindRandomCell(list);                        // Find a random cell
                CellIndex index2 = GetMirror(index1);                           // Get a mirror cell on the vertical axis
                SetCellState(cells, index1, index2, CellStateEnum.Blank);       // Mask the cells
                if (cSolve.SolvePuzzle(cells))                                  // Try to sell the puzzle
                {
                    mask         -= RemoveCells(list);                          // Solvable, remove the masked cells from the list
                    numIterations = 0;                                          // Zero out the interation counter
                }
                else
                {                                                               // Not solvable
                    SetCellState(cells, index1, index2, CellStateEnum.Answer);  // Restore the cell states
                    numIterations++;                                            // Increment the interation counter
                    if (numIterations > _cMaxInterations)                       // Did we exceed the maximum iterations?
                    {
                        NotGood = true;                                         // Yes, raise the flag
                        break;                                                  // Exit out of the loop
                    }
                }
            } while (mask > 0);                                                 // Keep loop until there are no more cells to mask
        }
 public void AddCellPosition(CellIndex from, Vector3 fromPoint)
 {
     if (!positions.ContainsKey(from))
     {
         positions[from] = fromPoint;
     }
 }
 public void Connect(CellIndex from, CellIndex to, Vector3 fromPosition, Vector3 toPosition)
 {
     AddAdjacency(from, to);
     AddAdjacency(to, from);
     AddCellPosition(from, fromPosition);
     AddCellPosition(to, toPosition);
 }
        private List <CellIndex> InnerSphereIndices(Vector3 position, float range)
        {
            var hPos         = new Vector2(position.x, position.z);
            var rectMinIndex = IndexFromPosition(hPos - Vector2.one * range);
            var rectMaxIndex = IndexFromPosition(hPos + Vector2.one * range);
            var list         = new List <CellIndex>();

            for (var x = rectMinIndex.x; x < rectMaxIndex.x; x++)
            {
                if (x < 0 || separation <= x)
                {
                    continue;
                }
                for (var y = rectMinIndex.y; y < rectMaxIndex.y; y++)
                {
                    if (y < 0 || separation <= y)
                    {
                        continue;
                    }
                    var index     = new CellIndex(x, y);
                    var cellPos   = CenterPos3D(index);
                    var direction = cellPos - position;
                    if (direction.magnitude <= range)
                    {
                        list.Add(index);
                    }
                }
            }
            return(list);
        }
Exemple #6
0
        /// <summary>
        /// Gets a cell selection from A1 reference
        /// </summary>
        /// <param name="cells">The cells collection</param>
        /// <param name="cellRangeRef">An A1 reference designating a rectangular area, e.g. "A1:B5"</param>
        /// <returns>A cell selection matching the referenced area</returns>
        public static CellSelection GetCellSelection(this Cells cells, string cellRangeRef)
        {
            var cellNames = cellRangeRef.Split(':');
            int row;
            int column;
            CellRange cellRange;

            if (cellNames.Length == 1)
            {
                NameConverter.ConvertCellNameToIndex(cellRangeRef, out row, out column);
                CellIndex index = new CellIndex(row, column);
                cellRange = new CellRange(index, index);
            }
            else
            {
                int row1 = 0;
                int column1 = 0;
                bool isRowAbsolute;
                bool isColumnAbsolute;
                bool isRowAbsolute1;
                bool isColumnAbsolute1;

                NameConverter.ConvertCellNameToIndex(cellNames[0], out isRowAbsolute, out row, out isColumnAbsolute, out column);
                NameConverter.ConvertCellNameToIndex(cellNames[1], out isRowAbsolute1, out row1, out isColumnAbsolute1, out column1);

                cellRange = new CellRange(new CellIndex(row, column), new CellIndex(row1, column1));
            }

            return cells[cellRange];
        }
Exemple #7
0
        public void GetHyperlinks()
        {
            #region radspreadsheet-features-hyperlink_4
            CellIndex a1Index   = new CellIndex(0, 0);
            CellIndex b3Index   = new CellIndex(2, 1);
            CellRange a1b3Range = new CellRange(a1Index, b3Index);
            #endregion

            SpreadsheetHyperlink spreadsheetHyperlink;

            //Get all hyperlinks which ranges are contained in the A1:B3 cell range:
            #region radspreadsheet-features-hyperlink_5
            IEnumerable <SpreadsheetHyperlink> containingHyperlinks = worksheet.Hyperlinks.GetContainingHyperlinks(a1b3Range);
            #endregion

            //Get all hyperlinks which ranges intersect with in the A1:B3 cell range:
            #region radspreadsheet-features-hyperlink_6
            IEnumerable <SpreadsheetHyperlink> intersectingHyperlinks = worksheet.Hyperlinks.GetIntersectingHyperlinks(a1b3Range);
            #endregion

            //Get the last added hyperlink that intersects with the A1:B3 cell range:
            #region radspreadsheet-features-hyperlink_7
            bool canGetHyperlink = worksheet.Hyperlinks.TryGetHyperlink(a1Index, out spreadsheetHyperlink);
            #endregion

            //Get the hyperlink which range matches A1:B3 cell range:
            #region radspreadsheet-features-hyperlink_8
            bool canGetHyperlinkExact = worksheet.Hyperlinks.TryGetHyperlinkExact(a1b3Range, out spreadsheetHyperlink);
            #endregion
        }
Exemple #8
0
    public bool PlaceObject(Vector2 position)
    {
        if (currentObject == null)
        {
            return(false);
        }

        CellIndex tile = levelScript.Grid.GetCellIndex(currentObject.transform.position);

        if (levelScript.Grid.CellIsEmpty(tile))
        {
            if (currentObject.IsType <Wall>())
            {
                wallPlacer.PlaceWall((Wall)currentObject);
            }
            else
            {
                levelScript.Grid.AddObjectToCell(currentObject, currentObject.transform.position);
            }

            currentObject = null;
            return(true);
        }
        else
        {
            Debug.Log("Cannot place there!");
            return(false);
        }
    }
Exemple #9
0
 public void AssignValue(CellIndex index, int value)
 {
     ParentCellIndex   = index;
     number            = value;
     valueDisplay.text = number.ToString();
     SetPosToParentCell();
 }
Exemple #10
0
 public void Shift(CellIndex delta)
 {
     for (var i = 0; i < ShiftableItems.Count; i++)
     {
         ShiftableItems[i].Shift(delta.ToVector3() * CellSize);
     }
 }
Exemple #11
0
        Directions pickShortest(Tile ghostTile, CellIndex targetCell, List <Directions> choices)
        {
            if (choices.Count == 0)
            {
                throw new InvalidOperationException("No choices to pick from!");
            }

            _distanceAndDirections.Clear();

            Tile targetTile = Tile.FromIndex(targetCell);

            Vector2 centerOfTarget = targetTile.CenterPos;

            foreach (var direction in choices)
            {
                var nextTileInThatDirection = ghostTile.NextTile(direction);

                var distance = Extensions.DistanceBetween(
                    nextTileInThatDirection.CenterPos,
                    centerOfTarget);

                _distanceAndDirections.Add(new DistanceAndDirection(distance, direction));
            }

            _distanceAndDirections.Sort(_distanceAndDirectionComparer);

            return(_distanceAndDirections[0].Direction);
        }
Exemple #12
0
        public virtual async ValueTask <MovementResult> Update(CanvasTimingInformation context)
        {
            var tile = Ghost.Tile;

            // if a ghost is near the center of a cell, then get the 'next cell' and
            // store where to go from there

            if (tile.IsInCenter)
            {
                CellIndex targetCell = await _getTargetCellPoint();

                TargetCell = targetCell;

                Directions direction = _intersectionLogic.GetWhichWayToGo(targetCell);

                if (direction != Directions.None)
                {
                    setDirection(direction);
                }
            }

            Ghost.MoveForwards();

            return(MovementResult.NotFinished);
        }
        void Start()
        {
            SelectableEventHelper helper = gameObject.AddComponent <SelectableEventHelper>();

            helper.name       = CellIndex.ToString();
            helper.OnClicked += HandlePointerClick;
        }
Exemple #14
0
    public CellIndex GetIndexFromPos(Vector2 pos)
    {
        var       convPos = pos - firstCellPos;
        CellIndex index   = (Mathf.RoundToInt(convPos.x / cellSize.x), Mathf.RoundToInt(convPos.y / cellSize.y));

        return(index);
    }
Exemple #15
0
        public void AddSubColumn(string parentColumnName, string subColumnName, int rowIndex, int subColWidth)
        {
            var allotedCellsInCol = 0;
            var colIndex          = 0;

            foreach (var kvp in columns)
            {
                if (kvp.Key == parentColumnName)
                {
                    break;
                }
                colIndex += kvp.Value;
            }

            while (WorkSheet.Cells[rowIndex, colIndex + allotedCellsInCol].GetValue().Value.ValueType != CellValueType.Empty)
            {
                allotedCellsInCol++;
            }

            var startCell = new CellIndex(rowIndex, colIndex + allotedCellsInCol);
            var endCell   = new CellIndex(rowIndex, startCell.ColumnIndex + subColWidth - 1);

            WorkSheet.Cells[startCell, endCell].Merge();
            this.WorkSheet.Cells[startCell, endCell].SetValue(subColumnName);
        }
        public override void UpdateUIOverride(WorksheetUIUpdateContextBase updateContext)
        {
            this.Clear();

            WorksheetUIUpdateContext worksheetUIUpdateContext = updateContext as WorksheetUIUpdateContext;

            if (worksheetUIUpdateContext == null || !worksheetUIUpdateContext.WorksheetEditor.Selection.IsCellSelection)
            {
                return;
            }

            SheetViewport viewport = updateContext.SheetViewport;

            for (int paneIndex = 0; paneIndex < viewport.ViewportPanesCount; paneIndex++)
            {
                var       pane         = viewport.ViewportPanes[paneIndex];
                CellRange visibleRange = pane.VisibleRange;

                for (int i = visibleRange.FromIndex.RowIndex; i <= visibleRange.ToIndex.RowIndex; i++)
                {
                    CellIndex cellIndex = new CellIndex(i, Constants.ButtonColumnIndex);
                    if (this.Worksheet.UsedCellRange.Contains(cellIndex))
                    {
                        RadButton button = this.GetElementFromPool <RadButton>(pane.ViewportPaneType);
                        button.Content = "Show age";
                        button.Click  += this.Button_Click;
                        button.Tag     = cellIndex;

                        this.CalculateCellEditorSize(button, updateContext.GetVisibleCellBox(cellIndex));
                    }
                }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            CellIndex  cellIndex = (sender as Button).Tag as CellIndex;
            ICellValue cellValue = this.Owner.Worksheet.Cells[cellIndex].GetValue().Value;

            MessageBox.Show("Age: " + cellValue.RawValue);
        }
Exemple #18
0
    private void UpdateWall(CellIndex tile)
    {
        Wall wall = floor.GetWallFromCell(tile);

        bool northWall = floor.CellHasWall(new CellIndex(tile.Row + 1, tile.Col));
        bool southWall = floor.CellHasWall(new CellIndex(tile.Row - 1, tile.Col));
        bool eastWall  = floor.CellHasWall(new CellIndex(tile.Row, tile.Col + 1));
        bool westWall  = floor.CellHasWall(new CellIndex(tile.Row, tile.Col - 1));

        int numConnections = 0;

        if (northWall)
        {
            numConnections++;
        }
        if (southWall)
        {
            numConnections++;
        }
        if (eastWall)
        {
            numConnections++;
        }
        if (westWall)
        {
            numConnections++;
        }

        CreateWall(wall, numConnections, northWall, southWall, eastWall, westWall);
        floor.RemoveObjectFromCell(wall, tile);
        Destroy(wall.gameObject);
    }
Exemple #19
0
        public double GetAmount(int row, int column)
        {
            CellIndex     cellIndex = new CellIndex(row, column);
            CellSelection selection = sheet.Cells[cellIndex];
            ICellValue    cellValue = selection.GetValue().Value;

            // in case of DBNULL the cell contains a text with content 'NULL'
            // return '0'
            if (cellValue.ValueType == CellValueType.Text)
            {
                if (cellValue.RawValue == "NULL")
                {
                    return(0);
                }
                // An Exception will be thrown
            }

            if (cellValue.ValueType == CellValueType.Empty)
            {
                return(0);
            }
            if (cellValue.ValueType != CellValueType.Number)
            {
                throw new Exception("Value is not a number");
            }
            return(double.Parse(cellValue.RawValue));
        }
Exemple #20
0
    void IDragHandler.OnDrag(PointerEventData eventData)
    {
        if (!mIsDragging)
        {
            return;
        }

        var     gameCam    = GameCamera.instance;
        Vector2 pos        = gameCam.camera2D.unityCamera.ScreenToWorldPoint(eventData.position);
        var     curCellPos = GameMapController.instance.mapData.GetCellIndex(pos);

        if (mPrevCellPos != curCellPos)
        {
            if (HUD.instance.blockMatterExpandPanel.block == block)
            {
                HUD.instance.blockMatterExpandPanel.isMoveMode = true;
            }

            var       cellSize  = GameData.instance.blockSize;
            CellIndex deltaCell = new CellIndex(curCellPos.row - mPrevCellPos.row, curCellPos.col - mPrevCellPos.col);

            block.EditMove(new Vector2(deltaCell.col * cellSize.x, deltaCell.row * cellSize.y));

            mPrevCellPos = curCellPos;
        }
    }
Exemple #21
0
        /// <summary>
        /// Takes the cell.
        /// </summary>
        /// <returns>
        /// <c>true</c>, if cell was taken, <c>false</c> otherwise.
        /// </returns>
        /// <param name='cellCoords'>
        /// Cell coords.
        /// </param>
        /// <param name='player'>
        /// Player.
        /// </param>
        public bool TakeCell(string cellCoords, int player = 0, bool takeOver = false)
        {
            if (cellCoords.Length < 2 || cellCoords.Length > 3)
            {
                return(false);
            }

            try {
                var row = cellCoords.Substring(0, 1).ToUpper().ElementAt(0) - 'A' + 1;
                var col = Convert.ToInt32(cellCoords.Substring(1)) - 1;

                var  cells         = Cells.Skip(row * DIMENSION).Take(DIMENSION);
                var  playableCells = cells.Where(c => c.Playable).ToArray();
                Cell cell          = playableCells.ElementAt(col);

                if (cell.Player != 0 && !takeOver)
                {
                    return(false);
                }

                cell.Player = player;
                Latest      = new CellIndex {
                    Cell  = cell,
                    Index = row * 11 + (10 - playableCells.Length + col),
                    Score = Algorithms.Evaluation(this, cell, player, null)
                };

                return(true);
            } catch (Exception) {
                Console.WriteLine("Error... YAY");
                return(false);
            }
        }
 private Vector2 CenterPos(CellIndex index)
 {
     return(new Vector2(
                index.x * cellSize + cellSizeHalf,
                index.y * cellSize + cellSizeHalf)
            + rect.min);
 }
 private Vector2 MinimumPos(CellIndex index)
 {
     return(new Vector2(
                index.x * cellSize,
                index.y * cellSize)
            + rect.min);
 }
Exemple #24
0
        public DateTime GetDate(int row, int column)
        {
            int           serialDate = 0;
            CellIndex     cellIndex  = new CellIndex(row, column);
            CellSelection selection  = sheet.Cells[cellIndex];
            ICellValue    cellValue  = selection.GetValue().Value;

            if (cellValue.ValueType == CellValueType.Empty)
            {
                return(new DateTime(2000, 1, 1));
            }
            if (cellValue.ValueType != CellValueType.Number)
            {
                // try datetime.tryparse
                string[] formats = { "dd.MM.yyyy" };
                DateTime d       = DateTime.Now;
                if (DateTime.TryParseExact(cellValue.RawValue, formats,
                                           System.Globalization.CultureInfo.CreateSpecificCulture("de-De"), System.Globalization.DateTimeStyles.None, out d))
                {
                    return(d);
                }

                throw new Exception("Value is not a date");
            }
            if (int.TryParse(cellValue.RawValue, out serialDate))
            {
                return(FromExcelSerialDate((int)serialDate));
            }
            return(DateTime.MinValue);
        }
Exemple #25
0
    private void UpdateDimensions(CellIndex minCell, CellIndex maxCell)
    {
        var mapData = GameMapController.instance.mapData;

        var cellSize = GameData.instance.blockSize;

        CellIndex newCellSize = new CellIndex(maxCell.row - minCell.row + 1, maxCell.col - minCell.col + 1);

        Vector2 min = mapData.GetPositionFromCell(minCell);
        Vector2 max = mapData.GetPositionFromCell(maxCell); max += cellSize;

        Vector2 center = Vector2.Lerp(min, max, 0.5f);

        bool sizeChanged = mCellSize != newCellSize;
        bool posChanged  = (Vector2)transform.position != center;

        if (sizeChanged)
        {
            mCellSize = newCellSize;

            ApplyCurrentCellSize();
        }

        if (posChanged)
        {
            transform.position = center;
        }

        if (sizeChanged || posChanged)
        {
            UpdatePlacementValid();

            DimensionChanged();
        }
    }
Exemple #26
0
    public List <int> GetCurrentNumbersFromSquare(CellIndex cellIndex)
    {
        int xSquareIndex = (cellIndex.x - (cellIndex.x % 3)) / 3;
        int ySquareIndex = (cellIndex.y - (cellIndex.y % 3)) / 3;

        int minXIndex = xSquareIndex * 3;
        int maxXIndex = minXIndex + 3;
        int minYIndex = ySquareIndex * 3;
        int maxYIndex = minYIndex + 3;

        List <int> numbersInSquare = new List <int>();

        for (int y = minYIndex; y < maxYIndex; y++)
        {
            for (int x = minXIndex; x < maxXIndex; x++)
            {
                int currentCellValue = sudokuLayout[x, y];
                if (currentCellValue != 0)
                {
                    numbersInSquare.Add(currentCellValue);
                }
            }
        }

        return(numbersInSquare);
    }
Exemple #27
0
        private static string TranslateUnknown(System.Data.DataTable table, string range)
        {
            if (Regex.IsMatch(range, @"^[a-zA-Z]{0,3}[0-9]+:[a-zA-Z]{0,3}\?$"))
            {
                return(range.Replace("?", table.Rows.Count.ToString()));
            }

            if (Regex.IsMatch(range, @"^[a-zA-Z]{0,3}[0-9]+:\?[0-9]+$"))
            {
                var cells = range.Split(':');

                var from = CellIndex.Translate(cells[0], Offset.ZeroBased);
                var to   = CellIndex.Translate((table.Columns.Count - 1, from.Row), Offset.ZeroBased);

                return($"{cells[0]}:{to}");
            }

            if (Regex.IsMatch(range, @"^[a-zA-Z]{0,3}[0-9]+:\?\?$"))
            {
                var cells = range.Split(':');

                var to = CellIndex.Translate((table.Columns.Count, table.Rows.Count));

                return($"{cells[0]}:{to}");
            }

            return(range);
        }
Exemple #28
0
    /// <summary>
    /// Called by <see cref="GameStats"/>. Don't call it yourself
    /// as the game coordinates other things.
    /// </summary>
    /// <param name="point"></param>
    /// <returns></returns>
    public async ValueTask PillEaten(CellIndex point)
    {
        await _ghostHouseDoor.PillEaten();

        await IncreaseScoreBy(Points.From(10));

        _levelStats.PillEaten(point);
    }
 private void SetCellValue(string value, CellIndex cellIndex, string fontFamilyName, bool isItalic, bool isBold)
 {
     CellSelection cell = this.Worksheet.Cells[cellIndex];
     cell.SetValue(value);
     cell.SetFontFamily(new ThemableFontFamily(fontFamilyName));
     cell.SetIsItalic(isItalic);
     cell.SetIsBold(isBold);
 }
Exemple #30
0
 public void HighlightCurrentCell(CellIndex currentCellIndex)
 {
     foreach (SudokuTile tile in allTiles)
     {
         tile.Unhighlight();
     }
     allTiles[currentCellIndex.x, currentCellIndex.y].Highlight();
 }
Exemple #31
0
    public void SetAIMove()
    {
        CellIndex bestMove = tt.FindNextMove();

        tt.SetMove(bestMove.Row, bestMove.Col, true);
        //mCells[bestMove.Row * 3 + bestMove.Col].Activate(true);
        StartCoroutine(Coroutine_OnMakeMove(0.2f, bestMove.Row, bestMove.Col, true));
    }
Exemple #32
0
 public void ShowCell(CellIndex index)
 {
     if (index.Row < 0 || index.Col < 0 || index.Row >= GridProperties.ROOM_ROWS || index.Col >= GridProperties.ROOM_COLS)
     {
         return;
     }
     cells[index.Row, index.Col].Show();
 }
Exemple #33
0
 public void Replace(CellIndex from, CellIndex to)
 {
     to.BoundToGrid(gridSize, gridSize);
     if (cells[to.col, to.raw].MergeContentWith(cells[from.col, from.raw]))
     {
         emptyCells.Remove(to);
     }
 }
        private ICell CellAt(CellIndex index)
        {
            if (!_cells.ContainsKey(index))
                return new EmptyCell();

            if (_cells[index] == 0)
                return new DeadCell(index);

            return new AliveCell(index);
        }
        public void NewGeneration()
        {
            var liveCell = new CellIndex(1, 1);
            const Int32 size = 3;
            var generation = Generation.New(size, liveCell);

            for (var x = 0; x < size; x++)
                for (var y = 0; y < size; y++)
                    if (x != liveCell.X && y != liveCell.Y)
                        Assert.IsType<DeadCell>(generation.CellAt(x, y));
        }
        private static Generation New(Int32 size, ISet<CellIndex> liveCells)
        {
            var cells = new Dictionary<CellIndex, Int32>();

            for (var x = 0; x < size; x++)
                for (var y = 0; y < size; y++)
                {
                    var index = new CellIndex(x, y);
                    cells.Add(index, liveCells.Contains(index) ? 1 : 0);
                }

            return new Generation(cells);
        }
Exemple #37
0
    public virtual void Awake()
    {
        if (UniverseEvents == null)
        {
            UniverseEvents = new List<UniverseEvent>();
        }

        Shiftable = GetComponent<Shiftable>();
        Shiftable.OnShift += Shiftable_OnShift;

        _triggerRadiusSquared = TriggerRadius*TriggerRadius;
        _trackerRadiusSquared = TrackerRadius*TrackerRadius;

        UniverseEvents.Add(this);

        _cellRadius = Mathf.CeilToInt(TriggerRadius/Universe.Current.CellSize);
        _universeCellIndex = Universe.Current.ViewPort.Shiftable.UniverseCellIndex;
    }
Exemple #38
0
    public void Translate(Vector3 translation)
    {
        var destination = (CellLocalPosition + translation);
        cellDelta = CellIndexDeltaFromPosition(destination);

        if (!cellDelta.IsZero())
        {
            UniverseCellIndex += cellDelta;
            if (OnCellIndexChange != null)
            {
                OnCellIndexChange(this, cellDelta);
            }
            CellLocalPosition -= cellDelta.ToVector3() * Universe.Current.CellSize;
        }

        CellLocalPosition += translation;
        transform.position += translation;
    }
Exemple #39
0
 private bool InRange(Shiftable sender)
 {
     _universeCellIndex = Universe.Current.ViewPort.Shiftable.UniverseCellIndex;
     var dX = sender.UniverseCellIndex.X - _universeCellIndex.X;
     if (dX >= -_cellRadius && dX <= _cellRadius)
     {
         var dY = sender.UniverseCellIndex.Y - _universeCellIndex.Y;
         if (dY >= -_cellRadius && dY <= _cellRadius)
         {
             var dZ = sender.UniverseCellIndex.Z - _universeCellIndex.Z;
             if (dZ >= -_cellRadius && dZ <= _cellRadius)
             {
                 return true;
             }
         }
     }
     return false;
 }
    private int[] GetEdgeDistances(bool[,] occupied, CellIndex startIndex, Transform objTransform)
    {
        var dirDistances = new[] { 0, 0, 0, 0 };
        var fromIndex = new CellIndex(startIndex.X, startIndex.Y);
        var stepDir = DirectionToIndex(objTransform.forward);

        // Forward
        while (ShapeGenerator.IsInBounds(occupied, fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y) && occupied[fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y])
        {
            dirDistances[0]++;
            fromIndex.X += stepDir.X;
            fromIndex.Y += stepDir.Y;
        }

        // Left
        stepDir = DirectionToIndex(-objTransform.right);
        fromIndex = new CellIndex(startIndex.X, startIndex.Y);
        while (ShapeGenerator.IsInBounds(occupied, fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y) && occupied[fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y])
        {
            dirDistances[1]++;
            fromIndex.X += stepDir.X;
            fromIndex.Y += stepDir.Y;
        }

        // Backwards
        stepDir = DirectionToIndex(-objTransform.forward);
        fromIndex = new CellIndex(startIndex.X, startIndex.Y);
        while (ShapeGenerator.IsInBounds(occupied, fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y) && occupied[fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y])
        {
            dirDistances[2]++;
            fromIndex.X += stepDir.X;
            fromIndex.Y += stepDir.Y;
        }

        // Right
        stepDir = DirectionToIndex(objTransform.right);
        fromIndex = new CellIndex(startIndex.X, startIndex.Y);
        while (ShapeGenerator.IsInBounds(occupied, fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y) && occupied[fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y])
        {
            dirDistances[3]++;
            fromIndex.X += stepDir.X;
            fromIndex.Y += stepDir.Y;
        }

        return dirDistances;
    }
Exemple #41
0
 public Vector3 GetAbsoluteUniversePosition(UniversePosition universePosition)
 {
     _cell = universePosition.CellIndex;
     return _cell.ToVector3() * CellSize + universePosition.CellLocalPosition;
 }
Exemple #42
0
 private void Shiftable_OnCellIndexChange(Shiftable sender, CellIndex delta)
 {
     Shift(delta);
 }
Exemple #43
0
 private Vector3 GetWorldPosition(CellIndex cellIndex, Vector3 positionInCell)
 {
     _cell = cellIndex - ViewPort.Shiftable.UniverseCellIndex;
     return _cell.ToVector3() * CellSize + positionInCell;
 }
Exemple #44
0
 private Vector3 CellLocalPositionFromWorldPosition(Vector3 worldPosition)
 {
     _cell = CellIndexFromWorldPosition(worldPosition);
     return worldPosition - _cell.ToVector3() * CellSize + ViewPort.Shiftable.UniverseCellIndex.ToVector3() * CellSize;
 }
Exemple #45
0
 public void WarpTo(UniversePosition universePosition)
 {
     _cell = universePosition.CellIndex - ViewPort.Shiftable.UniverseCellIndex;
     ViewPort.Shiftable.SetShiftPosition(universePosition);
     Shift(_cell);
 }
        private void PrepareInvoiceDocument(Worksheet worksheet, int itemsCount)
        {
            int lastItemIndexRow = IndexRowItemStart + itemsCount;

            CellIndex firstUsedCellIndex = new CellIndex(0, 0);
            CellIndex lastUsedCellIndex = new CellIndex(lastItemIndexRow + 1, IndexColumnSubTotal);
            CellBorder border = new CellBorder(CellBorderStyle.DashDot, InvoiceBackground);
            worksheet.Cells[firstUsedCellIndex, lastUsedCellIndex].SetBorders(new CellBorders(border, border, border, border, null, null, null, null));

            worksheet.Cells[firstUsedCellIndex].SetValue("INVOICE");
            worksheet.Cells[firstUsedCellIndex].SetFontSize(20);
            worksheet.Cells[firstUsedCellIndex].SetHorizontalAlignment(RadHorizontalAlignment.Center);
            worksheet.Cells[0, 0, 0, IndexColumnSubTotal].MergeAcross();

            worksheet.Columns[IndexColumnUnitPrice].SetWidth(new ColumnWidth(120, true));
            worksheet.Columns[IndexColumnSubTotal].SetWidth(new ColumnWidth(120, true));

            worksheet.Cells[IndexRowItemStart, 0, lastItemIndexRow, IndexColumnQuantity - 1].MergeAcross();
            worksheet.Cells[IndexRowItemStart, 0].SetValue("Item");
            worksheet.Cells[IndexRowItemStart, IndexColumnQuantity].SetValue("QTY");
            worksheet.Cells[IndexRowItemStart, IndexColumnUnitPrice].SetValue("Unit Price");
            worksheet.Cells[IndexRowItemStart, IndexColumnSubTotal].SetValue("SubTotal");

            worksheet.Cells[IndexRowItemStart, 0, IndexRowItemStart, IndexColumnSubTotal].SetFill
                (new GradientFill(GradientType.Horizontal, InvoiceBackground, InvoiceBackground));
            worksheet.Cells[IndexRowItemStart, 0, IndexRowItemStart, IndexColumnSubTotal].SetForeColor(InvoiceHeaderForeground);
            worksheet.Cells[IndexRowItemStart, IndexColumnUnitPrice, lastItemIndexRow, IndexColumnSubTotal].SetFormat(
                new CellValueFormat(EnUSCultureAccountFormatString));

            worksheet.Cells[lastItemIndexRow + 1, 6].SetValue("TOTAL: ");
            worksheet.Cells[lastItemIndexRow + 1, 7].SetFormat(new CellValueFormat(EnUSCultureAccountFormatString));

            string subTotalColumnCellRange = NameConverter.ConvertCellRangeToName(
                new CellIndex(IndexRowItemStart + 1, IndexColumnSubTotal),
                new CellIndex(lastItemIndexRow, IndexColumnSubTotal));

            worksheet.Cells[lastItemIndexRow + 1, IndexColumnSubTotal].SetValue(string.Format("=SUM({0})", subTotalColumnCellRange));

            worksheet.Cells[lastItemIndexRow + 1, IndexColumnUnitPrice, lastItemIndexRow + 1, IndexColumnSubTotal].SetFontSize(20);
        }
    private Vector3 GetBestDirection(bool[,] occupied, CellIndex startIndex, Transform objTransform)
    {
        /*
        var dirDistances = new[] {0, 0, 0, 0};
        var fromIndex = new CellIndex(startIndex.X, startIndex.Y);
        var stepDir = DirectionToIndex(objTransform.forward);

        // Forward
        while (ShapeGenerator.IsInBounds(occupied, fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y) && occupied[fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y])
        {
            dirDistances[0]++;
            fromIndex.X += stepDir.X;
            fromIndex.Y += stepDir.Y;
        }

        // Left
        stepDir = DirectionToIndex(-objTransform.right);
        fromIndex = new CellIndex(startIndex.X, startIndex.Y);
        while (ShapeGenerator.IsInBounds(occupied, fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y) && occupied[fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y])
        {
            dirDistances[1]++;
            fromIndex.X += stepDir.X;
            fromIndex.Y += stepDir.Y;
        }

        // Backwards
        stepDir = DirectionToIndex(-objTransform.forward);
        fromIndex = new CellIndex(startIndex.X, startIndex.Y);
        while (ShapeGenerator.IsInBounds(occupied, fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y) && occupied[fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y])
        {
            dirDistances[2]++;
            fromIndex.X += stepDir.X;
            fromIndex.Y += stepDir.Y;
        }

        // Right
        stepDir = DirectionToIndex(objTransform.right);
        fromIndex = new CellIndex(startIndex.X, startIndex.Y);
        while (ShapeGenerator.IsInBounds(occupied, fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y) && occupied[fromIndex.X + stepDir.X, fromIndex.Y + stepDir.Y])
        {
            dirDistances[3]++;
            fromIndex.X += stepDir.X;
            fromIndex.Y += stepDir.Y;
        }
        */

        var dirDistances = GetEdgeDistances(occupied, startIndex, objTransform);

        var largestDistance = -1;
        var largestDistanceIndex = -1;
        for (var j = 0; j < dirDistances.Length; j++)
        {
            if (dirDistances[j] > largestDistance)
            {
                largestDistance = dirDistances[j];
                largestDistanceIndex = j;
            }
        }
        /*
        Debug.Log(objTransform.name);
        Debug.LogFormat("FORWARD (0): {0}", dirDistances[0]);
        Debug.LogFormat("LEFT (1): {0}", dirDistances[1]);
        Debug.LogFormat("BACKWARD (2): {0}", dirDistances[2]);
        Debug.LogFormat("RIGHT (3): {0}", dirDistances[3]);
        Debug.LogFormat("CHOSEN INDEX: {0}", largestDistanceIndex);
        */
        var direction = new Vector3();
        switch (largestDistanceIndex)
        {
            case 0:
                direction = objTransform.forward;
                break;
            case 1:
                direction = -objTransform.right;
                break;
            case 2:
                direction= -objTransform.forward;
                break;
            case 3:
                direction = objTransform.right;
                break;
        }
        return direction;
    }
Exemple #48
0
 public void Set(CellIndex cellIndex, Vector3 localPosition)
 {
     CellIndex = cellIndex;
     CellLocalPosition = localPosition;
 }
Exemple #49
0
 public UniversePosition(CellIndex cellIndex, Vector3 localPosition)
 {
     Set(cellIndex, localPosition);
 }
Exemple #50
0
 public bool InPlayerActiveCells(CellIndex checkCell)
 {
     var playerCellIndex = _playVehicleInstance.Shiftable.UniverseCellIndex;
     for (var x = -1; x < 2; x++)
     {
         for (var y = -1; y < 2; y++)
         {
             for (var z = -1; z < 2; z++)
             {
                 if (checkCell.IsEqualTo(playerCellIndex + new CellIndex(x, y, z)))
                     return true;
             }
         }
     }
     return false;
 }
Exemple #51
0
        /// <summary>
        /// Takes the cell.
        /// </summary>
        /// <returns>
        /// <c>true</c>, if cell was taken, <c>false</c> otherwise.
        /// </returns>
        /// <param name='cellCoords'>
        /// Cell coords.
        /// </param>
        /// <param name='player'>
        /// Player.
        /// </param>
        public bool TakeCell(string cellCoords, int player = 0, bool takeOver = false)
        {
            if (cellCoords.Length < 2 || cellCoords.Length > 3)
                return false;

            try {
                var row = cellCoords.Substring (0, 1).ToUpper ().ElementAt (0) - 'A' + 1;
                var col = Convert.ToInt32 (cellCoords.Substring (1)) -1;

                var cells = Cells.Skip(row * DIMENSION).Take(DIMENSION);
                var playableCells = cells.Where(c => c.Playable).ToArray();
                Cell cell = playableCells.ElementAt(col);

                if(cell.Player != 0 && !takeOver) return false;

                cell.Player = player;
                Latest = new CellIndex {
                    Cell = cell,
                    Index = row*11 + (10 - playableCells.Length + col),
                    Score = Algorithms.Evaluation(this, cell, player, null)
                };

                return true;
            } catch (Exception) {
                Console.WriteLine("Error... YAY");
                return false;
            }
        }
Exemple #52
0
 public bool IsEqualTo(CellIndex other)
 {
     return X == other.X && Y == other.Y && Z == other.Z;
 }
 private Vector3 GetCellPosition(CellIndex index)
 {
     return new Vector3(index.X*3f, 0f, index.Y*3f);
 }
 public bool Equals(CellIndex index)
 {
     return X == index.X && Y == index.Y;
 }
Exemple #55
0
 public void SetShiftPosition(UniversePosition position)
 {
     UniverseCellIndex = position.CellIndex;
     CellLocalPosition = position.CellLocalPosition;
 }
 public static int DistanceSquared(CellIndex a, CellIndex b)
 {
     var dX = a.X - b.X;
     var dY = a.Y - b.Y;
     return dX*dX + dY*dY;
 }