/// <summary>
		///   Constructor
		/// </summary>
		/// <param name="caption">
		/// The caption, only used for IRoot that might want to summarize results
		/// </param>
		/// <param name="view">
		/// The view to display
		/// </param>
		/// <param name="transparent">
		/// If this is set, then the view is responsible for painting the entire area,
		/// otherwise the default cell paint code will be used.
		/// </param>
		public UIViewElement(string caption, UIView view, bool transparent) : base(caption)
		{
			//Value = view.ToString();
			ContentView = view;
			Flags = transparent ? CellFlags.Transparent : 0;
			DataContext = null;
		}
 /// <summary>
 ///   Constructor
 /// </summary>
 /// <param name="caption">
 /// The caption, only used for RootElements that might want to summarize results
 /// </param>
 /// <param name="view">
 /// The view to display
 /// </param>
 /// <param name="transparent">
 /// If this is set, then the view is responsible for painting the entire area,
 /// otherwise the default cell paint code will be used.
 /// </param>
 public UIViewElement(string caption, UIView view, bool transparent)
     : base(caption)
 {
     this.View  = view;
     this.Flags = transparent ? CellFlags.Transparent : 0;
     key        = new NSString("UIViewElement" + count++);
 }
Beispiel #3
0
 /// <summary>
 ///   Constructor
 /// </summary>
 /// <param name="caption">
 /// The caption, only used for IRoot that might want to summarize results
 /// </param>
 /// <param name="view">
 /// The view to display
 /// </param>
 /// <param name="transparent">
 /// If this is set, then the view is responsible for painting the entire area,
 /// otherwise the default cell paint code will be used.
 /// </param>
 public UIViewElement(string caption, UIView view, bool transparent) : base(caption)
 {
     //Value = view.ToString();
     ContentView = view;
     Flags       = transparent ? CellFlags.Transparent : 0;
     DataContext = null;
 }
Beispiel #4
0
 public void SetFlag(CellFlags Flag, bool Value)
 {
     if (Value)
         Flags |= Flag;
     else
         Flags &= ~Flag;
 }
Beispiel #5
0
    public static float GetCellValue(CellFlags mapFlags)
    {
        var adjValue = -0.2f;

        if (mapFlags.CHasFlag(CellFlags.Wall))
        {
            adjValue = 0;
        }
        else if (mapFlags.CHasFlag(CellFlags.GemPellet))
        {
            adjValue = 10;
        }
        else if (mapFlags.CHasFlag(CellFlags.HadPellet))
        {
            adjValue = 2;
        }
        else if (!mapFlags.CHasFlag(CellFlags.Seen))
        {
            adjValue = 1;
        }
        else if (mapFlags.CHasFlag(CellFlags.EnemyPac))
        {
            adjValue = -5;
        }
        else if (mapFlags.CHasFlag(CellFlags.MyPac))
        {
            adjValue = -2;
        }
        else
        {
            return(-0.2f);
        }

        return(adjValue);
    }
		/// <summary>
		///   Constructor
		/// </summary>
		/// <param name="caption">
		/// The caption, only used for RootElements that might want to summarize results
		/// </param>
		/// <param name="view">
		/// The view to display
		/// </param>
		/// <param name="transparent">
		/// If this is set, then the view is responsible for painting the entire area,
		/// otherwise the default cell paint code will be used.
		/// </param>
		public UIViewElement(string caption, UIView view, bool transparent)
			: base(caption)
		{
			this.View = view;
			this.Flags = transparent ? CellFlags.Transparent : 0;
			key = new NSString("UIViewElement" + count++);
		}
Beispiel #7
0
 public virtual void RefreshCoordinates()
 {
     PlacedPosition = Pivot + PosOffset;
     if (SubCellFlags != SubCellFlags.Free)
     {
         CellBlocking = CellUtils.Combine(SubCellFlags, CellBlocking, transform);
     }
 }
Beispiel #8
0
 public Breadcrump(Point pos, int hops, float hScore, float gScore = 0, CellFlags flags = default)
 {
     Pos    = pos;
     HScore = hScore;
     GScore = gScore;
     Hops   = (byte)hops;
     Flags  = flags;
 }
Beispiel #9
0
 public void RecomputeBlocking()
 {
     Blocking = CellFlags.Free;
     foreach (var placeable in this)
     {
         Blocking |= placeable.CellBlocking;
     }
 }
Beispiel #10
0
    public static Point?FindNearest(this GameField gameField, Point pos, CellFlags flags, int minPath = 1)
    {
        var openList = new List <Point> {
            pos
        };
        var nextOpenList = new List <Point>();

        var rowLen     = gameField.Width;
        var colLen     = gameField.Height;
        var closedList = GetClosedList(gameField);

        var iterations = 1;

        for (var i = 0;; i++)
        {
            if (i == openList.Count)
            {
                if (nextOpenList.Count == 0)
                {
                    return(null);
                }
                ++iterations;
                var sw = openList;
                openList     = nextOpenList;
                nextOpenList = sw;
                nextOpenList.Clear();
                i = 0;
            }

            var src = openList[i];

            for (int j = 0; j < 4; j++)
            {
                var adj = new Point(src.X + ColNum[j], src.Y + RowNum[j]);
                Warp(ref adj, rowLen, colLen);
                if (!IsValid(adj, rowLen, colLen))
                {
                    continue;
                }
                if (closedList[adj.ToIdx(rowLen)])
                {
                    continue;
                }
                if (!gameField.CanTraverse(adj))
                {
                    continue;
                }

                if (iterations >= minPath && gameField.GetFlags(adj).CHasFlag(flags))
                {
                    return(adj);
                }

                closedList[adj.ToIdx(rowLen)] = true;
                nextOpenList.Add(adj);
            }
        }
    }
Beispiel #11
0
    public CellData(System.IO.BinaryReader reader)
    {
        flags = (CellFlags)reader.ReadInt32();

        var x = reader.ReadInt32();
        var y = reader.ReadInt32();

        coordinates = new Vector2Int(x, y);
    }
Beispiel #12
0
 public Placeable GetFirst(ref Cell cell, CellFlags flags)
 {
     foreach (var p in cell)
     {
         if ((p.CellBlocking & flags) != 0)
         {
             return(p);
         }
     }
     return(null);
 }
Beispiel #13
0
        internal void SetFlagValue(int Row, int Col, bool value, CellFlags cellFlags)
        {
            CellFlags currentValue = (CellFlags)GetValue(Row, Col);

            if (value)
            {
                SetValue(Row, Col, (byte)(currentValue | cellFlags)); // add the CellFlag bit
            }
            else
            {
                SetValue(Row, Col, (byte)(currentValue & ~cellFlags)); // remove the CellFlag bit
            }
        }
Beispiel #14
0
        private void TestFreeSand(int cellz)
        {
            CellFlags sandFlags = CellUtils.Combine(SubCellFlags.Sand, cellz);
            var       sandCombo = GetFirst(ref cells[cellPos], sandFlags) as SandCombiner;

            if (sandCombo && !sandCombo.Collapsing)
            {
                if (ShouldSandCollapse(cellz, sandCombo))
                {
                    sandCombo.Collapse();
                }
            }
        }
Beispiel #15
0
        public void Add(Placeable p, Ksids ksids)
        {
            int size = listInfo.Size;

            if (size == 0)
            {
                first         = p;
                listInfo.Size = 1;
                Blocking      = p.CellBlocking;
            }
            else
            {
                if (p == first)
                {
                    Debug.LogError("Duplikujes pridavani " + p.name);
                    return;
                }
                if (size == 1)
                {
                    var arr = CellList.ReserveData(2, out listInfo, out int offset);
                    arr[offset] = p;
                    Blocking    = first.CellBlocking | p.CellBlocking;
                    TriggerAddTest(p, first, ksids);
                }
                else if (size == CellListInfo.SizeMask)
                {
                    // Throw Helper
                    throw new InvalidOperationException("Prekrocena maximalni kapacita bunky");
                }
                else
                {
                    CellList.IncSize(ref listInfo, size + 1);
                    var arr = CellList.GetData(listInfo, out int offset);
                    size--;
                    arr[offset + size] = p;
                    Blocking           = first.CellBlocking | p.CellBlocking;
                    TriggerAddTest(p, first, ksids);

                    for (int f = offset; f < offset + size; f++)
                    {
                        Blocking |= arr[f].CellBlocking;
                        TriggerAddTest(p, arr[f], ksids);
                        if (arr[f] == p)
                        {
                            Debug.LogError("Duplikujes pridavani !" + p.name);
                        }
                    }
                }
            }
        }
Beispiel #16
0
 bool SetFilledCell(int x, int y, int n, CellFlags fx)
 {
     if (flags[x, y] == CellFlags.Fixed && fx != CellFlags.Fixed)
     {
         // Don't play into fixed cell
         return(values[x, y] == n);
     }
     flags[x, y] = fx;
     if (values[x, y] != n)
     {
         // Change clue, reset solver
         values[x, y] = n;
         ResetSolver();
     }
     return(true);
 }
Beispiel #17
0
 public void ClearEntries()
 {
     for (int x = 0; x < Cells; ++x)
     {
         for (int y = 0; y < Cells; ++y)
         {
             CellFlags cf = FlagAt(x, y);
             if (cf == CellFlags.Play || cf == CellFlags.Solved)
             {
                 flags[x, y]  = CellFlags.Free;
                 values[x, y] = -1;
             }
         }
     }
     ResetSolver();
 }
Beispiel #18
0
        bool AddClue(int x, int y, int n, CellFlags fx)
        {
            SudokuCandidate sc = (SudokuCandidate)solver.GetCandidate(x, y, n);

            if (solver.TrySelectCandidate(sc))
            {
                // Add clue
                flags[x, y]  = fx;
                values[x, y] = n;
                Updated();
                return(true);
            }
            else
            {
                // Clue cannot be added
                return(false);
            }
        }
Beispiel #19
0
        /// <summary>
        /// 対象の種族を指定した座標に生成する.引数に応じて役職をつける
        /// </summary>
        /// <param name="tribe"></param>
        /// <param name="spawnPosition"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        Cell GenerateTribe(string tribe, Vector3 spawnPosition, CellFlags flag = CellFlags.None)
        {
            var prefab = Resources.Load <GameObject>("Cells/Cell");
            var go     = Instantiate(prefab, spawnPosition, Quaternion.identity);
            var cell   = go.GetComponent <Cell>();

            cell.Tribe = masterData.Tribes.First(t => t.Name.Equals(tribe));

            ReplaceMesh(go, cell.Tribe);

            cell.ASource        = go.AddComponent <AudioSource>();
            cell.ASource.volume = .1f;
            //cell.transform.localScale *= 3;

            switch (flag)
            {
            case CellFlags.None:
                break;

            case CellFlags.IsGrounded:
                break;

            case CellFlags.IsLeader:
                cell.IsLeader = true;
                break;

            case CellFlags.IsPlayer:
                cell.IsPlayer = true;
                cell.IsLeader = true;
                break;

            case CellFlags.IsBoss:
                cell.IsBoss = true;
                break;

            default:
                break;
            }
            return(cell);
        }
Beispiel #20
0
        private void LeavingCheck(Placeable p, Vector2 posOld, Vector2 pos2Old)
        {
            CellFlags sandFilter = CellFlags.Free;

            if (p.CellBlocking.IsPartBlock0())
            {
                sandFilter = CellFlags.Cell0Sand;
            }
            if (p.CellBlocking.IsPartBlock1())
            {
                sandFilter |= CellFlags.Cell1Sand;
            }

            if (sandFilter == CellFlags.Free)
            {
                return;
            }

            #region Coords Prep CopyPaste
            float boundaryX = 0.20f * CellSize2dInv.x;
            var   posFlOld  = Vector2Int.FloorToInt(posOld - new Vector2(boundaryX, 0));
            var   pos2ClOld = Vector2Int.CeilToInt(pos2Old + new Vector2(boundaryX, 0.20f * CellSize2dInv.y));
            posFlOld  = Vector2Int.Max(Vector2Int.zero, posFlOld);
            pos2ClOld = Vector2Int.Min(mapSize, pos2ClOld);
            int cellPosY = posFlOld.y * sizex;
            #endregion

            for (int y = posFlOld.y; y < pos2ClOld.y; y++, cellPosY += sizex)
            {
                for (int x = posFlOld.x; x < pos2ClOld.x; x++)
                {
                    var foundSand = cells[cellPosY + x].Blocking & sandFilter;
                    if (foundSand != 0)
                    {
                        AddCellStateTest(new Vector2Int(x, y), (CellStateCahnge)foundSand);
                    }
                }
            }
        }
Beispiel #21
0
        public bool SetCell(int x, int y, int n, PlayModes playMode)
        {
            if (playMode == PlayModes.EditBox)
            {
                return(false);
            }
            if (playMode == PlayModes.Pencil)
            {
                return(PencilCell(x, y, n));
            }

            CellFlags fx = playMode == PlayModes.EditCell ? CellFlags.Fixed : CellFlags.Play;

            if (flags[x, y] == CellFlags.Free)
            {
                return(SetFreeCell(x, y, n, fx));
            }
            else
            {
                return(SetFilledCell(x, y, n, fx));
            }
        }
Beispiel #22
0
 bool SetFreeCell(int x, int y, int n, CellFlags fx)
 {
     // Agree with any existing known for that cell
     foreach (Candidate k in solver.SelectedCandidates)
     {
         SudokuCandidate sc = (SudokuCandidate)k;
         if (x == sc.x && y == sc.y)
         {
             if (n == sc.n)
             {
                 flags[x, y]  = fx;
                 values[x, y] = n;
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     return(AddClue(x, y, n, fx));
 }
Beispiel #23
0
 public bool HasFlag(CellFlags Flag)
 {
     return Flags.HasFlag(Flag);
 }
Beispiel #24
0
 public bool TestFlags(CellFlags flags)
 {
     return (this.flags & (byte)flags) != 0;
 }
Beispiel #25
0
 public void SetFlags(CellFlags flags)
 {
     this.flags |= (byte)flags;
 }
Beispiel #26
0
 public void ClearFlags(CellFlags flags)
 {
     this.flags &= (byte)~((byte)flags);
 }
Beispiel #27
0
 public static bool HasSubFlag(this CellFlags flags, SubCellFlags flag, int cellz) => ((int)flags & ((int)flag << (Cell0Shift << cellz))) != 0;
Beispiel #28
0
 public void ResetFlag(CellFlags flag)
 {
     Flags &= ~flag;
 }
Beispiel #29
0
 public static bool IsPartBlock1(this CellFlags flags) => (flags & CellFlags.Cell1Part) != 0;
Beispiel #30
0
 public static CellFlags Combine(SubCellFlags subCellFlags, CellFlags flags, Transform transform) => Combine(subCellFlags, flags, transform.position.z);
Beispiel #31
0
        public static CellFlags Combine(SubCellFlags subCellFlags, CellFlags flags, float z)
        {
            var shift = z < 0.25f ? Cell0Shift : Cell1Shift;

            return((CellFlags)(((int)subCellFlags << shift) | (byte)flags));
        }
Beispiel #32
0
        public static unsafe SubCellFlags Cell1(this CellFlags flags)
        {
            byte *pi = (byte *)&flags;

            return((SubCellFlags)pi[2]);
        }
		/// <summary>
		///  Constructor
		/// </summary>
		/// <param name="caption">
		/// The caption, only used for IRoot that might want to summarize results
		/// </param>
		/// <param name="view">
		/// The view to display
		/// </param>
		/// <param name="transparent">
		/// If this is set, then the view is responsible for painting the entire area,
		/// otherwise the default cell paint code will be used.
		/// </param>
		public UIViewElement(string caption, UIView view, bool transparent) : base(caption)
		{
			ElementView = view;
			Flags = transparent ? CellFlags.Transparent : 0;
		}
Beispiel #34
0
 public bool HasFlag(CellFlags f)
 {
     return(f >= 0 && (Flags & f) == f || f < 0 && (Flags & f) == Flags);
 }
Beispiel #35
0
 public void SetFlag(CellFlags flag)
 {
     Flags |= flag;
 }
Beispiel #36
0
 public static bool IsPartBlock(this CellFlags flags, int cellz) => flags.HasSubFlag(SubCellFlags.Part, cellz);
Beispiel #37
0
 public static bool IsDoubleCell(this CellFlags flags) => (flags & CellFlags.AllPartCells) == CellFlags.AllPartCells;
		/// <summary>
		///   Constructor
		/// </summary>
		/// <param name="caption">
		/// The caption, only used for RootElements that might want to summarize results
		/// </param>
		/// <param name="view">
		/// The view to display
		/// </param>
		/// <param name="transparent">
		/// If this is set, then the view is responsible for painting the entire area,
		/// otherwise the default cell paint code will be used.
		/// </param>
		public UIViewElement (string caption, UIView view, bool transparent, UIEdgeInsets insets) : base (caption) 
		{
			this.insets = insets;
			var oframe = view.Frame;
			var frame = oframe;
			frame.Width += insets.Left + insets.Right;
			frame.Height += insets.Top + insets.Bottom;

			ContainerView = new UIView (frame);
			if ((Flags & CellFlags.Transparent) != 0)
				ContainerView.BackgroundColor = UIColor.Clear;

			if (insets.Left != 0 || insets.Top != 0)
				view.Frame = new RectangleF (insets.Left + frame.X, insets.Top + frame.Y, frame.Width, frame.Height);

			ContainerView.AddSubview (view);
			this.View = view;
			this.Flags = transparent ? CellFlags.Transparent : 0;
			key = new NSString ("UIViewElement" + count++);
		}
Beispiel #39
0
 /// <summary>
 ///   Constructor
 /// </summary>
 /// <param name="caption">
 /// The caption, only used for IRoot that might want to summarize results
 /// </param>
 /// <param name="view">
 /// The view to display
 /// </param>
 /// <param name="transparent">
 /// If this is set, then the view is responsible for painting the entire area,
 /// otherwise the default cell paint code will be used.
 /// </param>
 public UIViewElement(string caption, UIView view, bool transparent) : base(caption)
 {
     Value = view;
     Flags = transparent ? CellFlags.Transparent : 0;
 }