protected void AddToImmediateSpawnList(TileColorType dropTileColor)
    {
        TileSpawnRule tileSpawnRule = new TileSpawnRule();

        tileSpawnRule.numberOfExecutions = 1;
        tileSpawnRule.ownerList          = immediateSpawnList;

        RuleEntry ruleEntry = tileSpawnRule.ruleEntries[0];

        ruleEntry.RuleTileType   = typeof(DropTile);
        ruleEntry.ColorSelection = ColorSelectionMethod.ColorBased;
        ruleEntry.RuleTileColor  = dropTileColor;
        ruleEntry.randomColor    = false;

        immediateSpawnList.Add(tileSpawnRule);

//		Debug.LogError("[AddToImmediateSpawnList()]");
    }
示例#2
0
        private static RuleEntry RandomPossiblyResolvableEntry(string keyword, Dictionary <string, string> constants, List <string> extraTags, List <string> resolvedTags)
        {
            List <RuleEntry> list = rules.TryGetValue(keyword);

            if (list == null)
            {
                return(null);
            }
            float maxPriority = float.MinValue;

            for (int i = 0; i < list.Count; i++)
            {
                RuleEntry ruleEntry = list[i];
                if (!ruleEntry.knownUnresolvable && ruleEntry.ValidateConstantConstraints(constants) && ruleEntry.ValidateRequiredTag(extraTags, resolvedTags) && ruleEntry.SelectionWeight != 0f)
                {
                    maxPriority = Mathf.Max(maxPriority, ruleEntry.Priority);
                }
            }
            return(list.RandomElementByWeightWithFallback((RuleEntry rule) => (rule.knownUnresolvable || !rule.ValidateConstantConstraints(constants) || !rule.ValidateRequiredTag(extraTags, resolvedTags) || rule.Priority != maxPriority) ? 0f : rule.SelectionWeight));
        }
示例#3
0
    public override bool Equals(object obj)
    {
        if (obj == null)
        {
            return(false);
        }

        RuleEntry entryParam = null;

        if (obj is RuleEntry)
        {
            entryParam = obj as RuleEntry;
            if (entryParam.RuleTileType == this.RuleTileType)
            {
                if (entryParam.RuleTileColor == this.RuleTileColor || entryParam.randomColor || this.randomColor)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
示例#4
0
        private static bool TryResolveRecursive(RuleEntry entry, int depth, Dictionary <string, string> constants, out string output, bool log)
        {
            if (log)
            {
                logSb.AppendLine();
                logSb.Append(depth.ToStringCached() + " ");
                for (int i = 0; i < depth; i++)
                {
                    logSb.Append("   ");
                }
                logSb.Append(entry + " ");
            }
            loopCount++;
            if (loopCount > 1000)
            {
                Log.Error("Hit loops limit resolving grammar.");
                output = "HIT_LOOPS_LIMIT";
                if (log)
                {
                    logSb.Append("UNRESOLVABLE: Hit loops limit");
                }
                return(false);
            }
            if (depth > 50)
            {
                Log.Error("Grammar recurred too deep while resolving keyword (>" + 50 + " deep)");
                output = "DEPTH_LIMIT_REACHED";
                if (log)
                {
                    logSb.Append("UNRESOLVABLE: Depth limit reached");
                }
                return(false);
            }
            string text = entry.rule.Generate();
            bool   flag = false;
            int    num  = -1;

            for (int j = 0; j < text.Length; j++)
            {
                char c = text[j];
                if (c == '[')
                {
                    num = j;
                }
                if (c == ']')
                {
                    if (num == -1)
                    {
                        Log.Error("Could not resolve rule " + text + ": mismatched brackets.");
                        output = "MISMATCHED_BRACKETS";
                        if (log)
                        {
                            logSb.Append("UNRESOLVABLE: Mismatched brackets");
                        }
                        flag = true;
                    }
                    else
                    {
                        string text2 = text.Substring(num + 1, j - num - 1);
                        while (true)
                        {
                            RuleEntry ruleEntry = RandomPossiblyResolvableEntry(text2, constants);
                            if (ruleEntry == null)
                            {
                                entry.MarkKnownUnresolvable();
                                output = "CANNOT_RESOLVE_SUBSYMBOL:" + text2;
                                if (log)
                                {
                                    logSb.Append("UNRESOLVABLE: Cannot resolve subsymbol '" + text2 + "'");
                                }
                                flag = true;
                                break;
                            }
                            ruleEntry.uses++;
                            if (TryResolveRecursive(ruleEntry, depth + 1, constants, out string output2, log))
                            {
                                text = text.Substring(0, num) + output2 + text.Substring(j + 1);
                                j    = num;
                                break;
                            }
                            ruleEntry.MarkKnownUnresolvable();
                        }
                    }
                }
            }
            output = text;
            return(!flag);
        }
 public void SetUp()
 {
     _testEntity    = new RuleEntry();
     _privateObject = new PrivateObject(_testEntity);
 }
示例#6
0
        private static bool TryResolveRecursive(RuleEntry entry, int depth, Dictionary <string, string> constants, out string output, bool log, List <string> extraTags, List <string> resolvedTags)
        {
            string text = "";

            for (int i = 0; i < depth; i++)
            {
                text += "  ";
            }

            if (log && depth > 0)
            {
                GrammarResolver.logSbTrace.AppendLine();
                GrammarResolver.logSbTrace.Append(depth.ToStringCached().PadRight(3));
                GrammarResolver.logSbTrace.Append(text + entry);
            }

            text += "     ";
            GrammarResolver.loopCount++;
            if (GrammarResolver.loopCount > 1000)
            {
                Log.Error("Hit loops limit resolving grammar.");
                output = "HIT_LOOPS_LIMIT";
                if (log)
                {
                    GrammarResolver.logSbTrace.Append("\n" + text + "UNRESOLVABLE: Hit loops limit");
                }

                return(false);
            }

            if (depth > 50)
            {
                Log.Error("Grammar recurred too deep while resolving keyword (>" + 50 + " deep)");
                output = "DEPTH_LIMIT_REACHED";
                if (log)
                {
                    GrammarResolver.logSbTrace.Append("\n" + text + "UNRESOLVABLE: Depth limit reached");
                }

                return(false);
            }

            string text2 = entry.rule.Generate();
            bool   flag  = false;
            int    num   = -1;

            for (int j = 0; j < text2.Length; j++)
            {
                char num2 = text2[j];
                if (num2 == '[')
                {
                    num = j;
                }

                if (num2 != ']')
                {
                    continue;
                }

                if (num == -1)
                {
                    Log.Error("Could not resolve rule because of mismatched brackets: " + text2);
                    output = "MISMATCHED_BRACKETS";
                    if (log)
                    {
                        GrammarResolver.logSbTrace.Append("\n" + text + "UNRESOLVABLE: Mismatched brackets");
                    }

                    flag = true;
                    continue;
                }

                string text3 = text2.Substring(num + 1, j - num - 1);
                while (true)
                {
                    RuleEntry ruleEntry = RandomPossiblyResolvableEntry(text3, constants, extraTags, resolvedTags);
                    if (ruleEntry == null)
                    {
                        entry.MarkKnownUnresolvable();
                        output = "CANNOT_RESOLVE_SUBSYMBOL:" + text3;
                        if (log)
                        {
                            GrammarResolver.logSbTrace.Append("\n" + text + text3 + " → UNRESOLVABLE");
                        }

                        flag = true;
                        break;
                    }

                    ruleEntry.uses++;
                    List <string> list = resolvedTags.ToList();
                    if (TryResolveRecursive(ruleEntry, depth + 1, constants, out string output2, log, extraTags, list))
                    {
                        text2 = text2.Substring(0, num) + output2 + text2.Substring(j + 1);
                        j     = num;
                        resolvedTags.Clear();
                        resolvedTags.AddRange(list);
                        if (!ruleEntry.rule.tag.NullOrEmpty() && !resolvedTags.Contains(ruleEntry.rule.tag))
                        {
                            resolvedTags.Add(ruleEntry.rule.tag);
                        }

                        break;
                    }

                    ruleEntry.MarkKnownUnresolvable();
                }
            }

            output = text2;
            return(!flag);
        }
	/// <summary>
	/// Spawns the new tile.
	/// </summary>
	/// <param name='targetPiece'>
	/// Target piece.
	/// </param>
	public Match3Tile SpawnNewTile(bool isBoardSetup = false)
	{
		Match3Tile tileResult = null;
		
		// Early out if rule
		if(ruleEntries == null || ruleEntries.Count == 0)
		{
			return tileResult;
		}

		if (numberOfExecutions == 0)
		{
			EndSpawnRule();
			return tileResult;
		}
		
		//Select random rule entry and acquire its info
		spawnedEntry = ruleEntries[Random.Range(0, ruleEntries.Count)];
		spawnedType = spawnedEntry.RuleTileType;
		spawnedColor = spawnedEntry.RuleTileColor;
		
		if(ownerList != null && ownerList.Count > 0)
		{
			numberOfExecutions--;
		}

//		bool offBoard = false;
//
//		if(ownerList != null)
//		{
//			if (ownerList.Count == 0)
//			{
//				offBoard = false;
//			}
//			else
//			{
//				offBoard = true;
//				numberOfExecutions--;
//			}
//		}

		//Spawn tile as described by the spawn rule
//		Debug.LogWarning("[SpawnRule] Spawning [" + spawnedType.ToString() + "] [" + spawnedColor.ToString() + "] [offboard:" + offBoard + "]");
		
		if (typeof(BombTile) == spawnedType)
		{
			BombTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, TileColorType.None, isBoardSetup) as BombTile;
//			BombTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, TileColorType.None, offBoard, isBoardSetup) as BombTile;
			spawnedTile.TileColor = spawnedColor;
			spawnedTile.UpdateMaterial();
			tileResult = spawnedTile;
		}
		else if (typeof(DirectionalDestroyTile).IsAssignableFrom(spawnedType))
		{
			DirectionalDestroyTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, TileColorType.None, isBoardSetup) as DirectionalDestroyTile;
//			DirectionalDestroyTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, TileColorType.None, offBoard, isBoardSetup) as DirectionalDestroyTile;
			spawnedTile.TileColor = spawnedColor;
			spawnedTile.UpdateMaterial();
			tileResult = spawnedTile;
		}
		else
		{
//			tileResult = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, spawnedColor, offBoard, isBoardSetup);
			tileResult = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, spawnedColor, isBoardSetup);
		}
		
		if (tileResult != null) {
			tileResult.IsTileIgnoredByAntiMatchSystems = isTileIgnoredByAntiMatchSystems;
		}
		
		return tileResult;
	}
    /// <summary>
    /// Spawns the new tile.
    /// </summary>
    /// <param name='targetPiece'>
    /// Target piece.
    /// </param>
    public Match3Tile SpawnNewTile(bool isBoardSetup = false)
    {
        Match3Tile tileResult = null;

        // Early out if rule
        if (ruleEntries == null || ruleEntries.Count == 0)
        {
            return(tileResult);
        }

        if (numberOfExecutions == 0)
        {
            EndSpawnRule();
            return(tileResult);
        }

        //Select random rule entry and acquire its info
        spawnedEntry = ruleEntries[Random.Range(0, ruleEntries.Count)];
        spawnedType  = spawnedEntry.RuleTileType;
        spawnedColor = spawnedEntry.RuleTileColor;

        if (ownerList != null && ownerList.Count > 0)
        {
            numberOfExecutions--;
        }

//		bool offBoard = false;
//
//		if(ownerList != null)
//		{
//			if (ownerList.Count == 0)
//			{
//				offBoard = false;
//			}
//			else
//			{
//				offBoard = true;
//				numberOfExecutions--;
//			}
//		}

        //Spawn tile as described by the spawn rule
//		Debug.LogWarning("[SpawnRule] Spawning [" + spawnedType.ToString() + "] [" + spawnedColor.ToString() + "] [offboard:" + offBoard + "]");

        if (typeof(BombTile) == spawnedType)
        {
            BombTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, TileColorType.None, isBoardSetup) as BombTile;
//			BombTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, TileColorType.None, offBoard, isBoardSetup) as BombTile;
            spawnedTile.TileColor = spawnedColor;
            spawnedTile.UpdateMaterial();
            tileResult = spawnedTile;
        }
        else if (typeof(DirectionalDestroyTile).IsAssignableFrom(spawnedType))
        {
            DirectionalDestroyTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, TileColorType.None, isBoardSetup) as DirectionalDestroyTile;
//			DirectionalDestroyTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, TileColorType.None, offBoard, isBoardSetup) as DirectionalDestroyTile;
            spawnedTile.TileColor = spawnedColor;
            spawnedTile.UpdateMaterial();
            tileResult = spawnedTile;
        }
        else
        {
//			tileResult = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, spawnedColor, offBoard, isBoardSetup);
            tileResult = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, spawnedColor, isBoardSetup);
        }

        if (tileResult != null)
        {
            tileResult.IsTileIgnoredByAntiMatchSystems = isTileIgnoredByAntiMatchSystems;
        }

        return(tileResult);
    }