public List <Combine> FindBonusCombine(FieldBoard field) { List <Combine> combines = new List <Combine>(); foreach (var typePattern in bonusCombinesPatterns) { foreach (var pattern in typePattern.matrices) { var rightBottomPosPattern = GetMaxPosition(pattern.matrix.ToArray()) + Vector2Int.one; var segments = SplitFieldSegments(field, rightBottomPosPattern); foreach (var segment in segments) { var matrix = ConvertCombine(segment); var compare = SimplifyArray(matrix); var types = new List <ItemsTypes>(); ItemTemplate[] foundItems; if (!IsCombineFound(compare.matrix.ToArray(), pattern.matrix.ToArray(), typePattern, ref types, out foundItems)) { continue; } else { combines.Add(segment); return(combines); } // if(GetBonusCombine(segment)!= ItemsTypes.NONE) // combines.Add(segment); } } } return(combines); }
/// <summary> /// Split field to appropriate rect fragments /// </summary> /// <param name="field"></param> /// <param name="rightBottomPosPattern"></param> /// <returns></returns> private static List <Combine> SplitFieldSegments(FieldBoard field, Vector2Int rightBottomPosPattern) { List <Combine> segments = new List <Combine>(); for (var row = 0; row < field.fieldData.maxRows; row++) { for (var col = 0; col < field.fieldData.maxCols; col++) { var items = field .GetFieldSeqment(new RectInt(col, row, col + rightBottomPosPattern.x, row + rightBottomPosPattern.y)) .WhereNotNull().Select(i => i.Item).WhereNotNull().ToList(); var splitByColors = items.GroupBy(i => i.color); foreach (var color in splitByColors) { var combine = new Combine { items = color.ToList(), color = color.Key }; segments.Add(combine); } col += rightBottomPosPattern.x; } row += rightBottomPosPattern.y; } return(segments); }
public OutlineBorder(int maxRows, int maxCols, FieldBoard fieldBoard) { this.maxRows = maxRows; this.maxCols = maxCols; _fieldBoard = fieldBoard; GenerateOutline(); }
private Square GetSquare(int col, int row, bool safe = false) { if (!field) { field = LevelManager.THIS.field; } return(field.GetSquare(col, row)); }
public List <Combine> GetCombines(FieldBoard field, out List <Combine> allFoundCombines, ItemsTypes _prioritiseItem = ItemsTypes.NONE) { prioritiseItem = _prioritiseItem; maxCols = field.fieldData.maxCols; maxRows = field.fieldData.maxRows; //combines.Clear(); match3Combines.Clear(); tempCombinesPredict.Clear(); dic.Clear(); var color = -1; var combine = new Combine(); vChecking = false; //Horrizontal searching for (var row = 0; row < maxRows; row++) { color = -1; for (var col = 0; col < maxCols; col++) { var square = field.GetSquare(col, row); if (IsSquareNotNull(square)) { CheckMatches(square.Item, color, ref combine); color = square.Item.color; } } } vChecking = true; //Vertical searching for (var col = 0; col < maxCols; col++) { color = -1; for (var row = 0; row < maxRows; row++) { var square = field.GetSquare(col, row); if (IsSquareNotNull(square) && !square.Item.falling && !square.Item.destroying) { // if(match3Combines.Any(i=>i.items.Any(x=>x ==square.item))) continue; CheckMatches(square.Item, color, ref combine); color = square.Item.color; } } } allFoundCombines = match3Combines; // Debug.Log (" test combines detected " + tempCombines.Count); return(CheckCombines(dic, match3Combines)); }
private static List <Item> PridictCombines(FieldBoard field, bool right, ItemsTypes itemType) { var combineManager = LevelManager.THIS.CombineManager; for (var i = 0; i < field.squaresArray.Count(); i++) { var item = field.squaresArray[i].Item; Item item1 = null; if (right) { item1 = (item?.square?.GetNeighborRight())?.Item; } else { item1 = (item?.square?.GetNeighborBottom())?.Item; } if (item1 != null && !item.destroying && !item1.destroying) { var color = item.color; var color1 = item1.color; item.color = color1; item1.color = color; var combines = combineManager.GetCombines(field, itemType); item.color = color; item1.color = color1; var combine = combines.Find(x => GetConditionByType(x, itemType)); if (combine != null) { if (item.color == combine.color) { AI.THIS.TipItem = item; AI.THIS.vDirection = (item1.transform.position - item.transform.position).normalized; } else { AI.THIS.TipItem = item1; AI.THIS.vDirection = (item.transform.position - item1.transform.position).normalized; } combine.items.Add(item); combine.items.Add(item1); return(combine.items); } } } return(new List <Item>()); }
public List <List <Item> > GetCombinedItems(FieldBoard field, bool setNextItemType = false) { var combinedItems = new List <List <Item> >(); var combines = GetCombines(field); foreach (var cmb in combines) { if (cmb.nextType != ItemsTypes.NONE) { var item = cmb.items[Random.Range(0, cmb.items.Count)]; var draggedItem = LevelManager.THIS.lastDraggedItem; if (draggedItem) { if (draggedItem.color != item.color) { draggedItem = LevelManager.THIS.lastSwitchedItem; } //check the dragged item found in this combine or not and change this type if (cmb.items.IndexOf(draggedItem) >= 0) { item = draggedItem; } } if (setNextItemType) { item.NextType = cmb.nextType; } } if (cmb.items != null && cmb.items.Count > 0) { combinedItems.Add(cmb.items); } } return(combinedItems); }
public List <Combine> GetCombines(FieldBoard field, ItemsTypes _prioritiseItem = ItemsTypes.NONE) { List <Combine> allFoundCombines; return(GetCombines(field, out allFoundCombines, _prioritiseItem)); }
public List <Combine> FindBonusCombines(FieldBoard field) { return(bonusItemCombiner.FindBonusCombine(field)); }