///<summary> /// Same as GameTileSameColorArranger, just different comparisons /// The problem here is that, if there is a case for 7-7-7-7, it's included /// but 7-7-7 7 is not, it cannot find subgroups, so FindAll does not find every possibilty under this GroupMethod ///</summary> protected GameTileGroup GroupMethod(GameTile p_selectedTile, GameTileGroup p_gameTileGroup) { GameTileGroup result = new GameTileGroup(); result.AddGameTile(p_selectedTile); for (int i = p_gameTileGroup.GameTiles.IndexOf(p_selectedTile); i < p_gameTileGroup.GameTileCount; i++) { if (p_gameTileGroup[i].CompareNumber(p_selectedTile)) { bool sameColorExists = false; for (int j = 0; j < result.GameTileCount; j++) { if (result[j].CompareColor(p_gameTileGroup[i])) { sameColorExists = true; } } if (!sameColorExists) { p_selectedTile = p_gameTileGroup[i]; result.AddGameTile(p_selectedTile); } } } return(result); }
///<summary> /// This shouldn't be here but yeah, sorts the array by score. ///</summary> protected GameTileGroup[] SortByScore(GameTileGroup[] p_possibilities) { GameTileGroup swapTemp = null; int highestScore = -1; int highestIndex = -1; for (int i = 0; i < p_possibilities.Length; i++) { highestIndex = i; highestScore = -1; for (int j = i; j < p_possibilities.Length; j++) { if (p_possibilities[j].GameTileCount > highestScore) { highestScore = p_possibilities[j].GameTileCount; highestIndex = j; } } swapTemp = p_possibilities[i]; p_possibilities[i] = p_possibilities[highestIndex]; p_possibilities[highestIndex] = swapTemp; } return(p_possibilities); }
///<summary> /// Arrangement algorithm sorts it's Groups and adds them one by one to the Arrangement. /// In here they either go into ArrangedGroups or RemainderGroup ///</summary> public void AddGroup(GameTileGroup p_gameTileGroup) { if (p_gameTileGroup.GameTileCount < 3) { RemainderGroup.AddGroup(p_gameTileGroup); return; } ArrangedGroups.Add(p_gameTileGroup); }
///<summary> /// The warning inside is for Debugging purposes, /// that should never be called, if so the Sorting algorithm messed up ///</summary> public void AddGroup(GameTileGroup p_gameTileGroup) { if (HasDuplicateGroup(p_gameTileGroup)) { Debug.LogWarning("Adding group with same tile"); } GameTiles.AddRange(p_gameTileGroup.GameTiles); }
///<summary> /// Used during sorting algorithms, for collision control ///</summary> public bool HasDuplicateGroup(GameTileGroup p_gameTileGroup) { for (int i = 0; i < p_gameTileGroup.GameTileCount; i++) { if (HasDuplicate(p_gameTileGroup[i])) { return(true); } } return(false); }
///<summary> /// Somewhere between FindAll nd FindFeasibles, some GameTile's are lost depending on GameTileGroup that ha our 14 original tiles. /// This only happens for SmartSort, this function adds the lost Tiles which will be added as remainder to the arrengement. ///</summary> private void FindMissings(GameTileGroup p_everyTile, GameTileArrangement[] p_arrangements) { for (int i = 0; i < p_arrangements.Length; i++) { for (int j = 0; j < p_everyTile.GameTileCount; j++) { if (!p_arrangements[i].HasDuplicateTile(p_everyTile[j])) { p_arrangements[i].AddTile(p_everyTile[j]); } } } }
protected override GameTileGroup[] FindAll(GameTileGroup p_copiedGroup) { List <GameTileGroup> result = new List <GameTileGroup>(); p_copiedGroup.SortByNumber(); for (int i = 0; i < p_copiedGroup.GameTileCount; i++) { result.Add(GroupMethod(p_copiedGroup[i], p_copiedGroup)); } return(result.ToArray()); }
public bool RemoveGroup(GameTileGroup p_gameTileGroup) { bool result = true; for (int i = 0; i < p_gameTileGroup.GameTileCount; i++) { result = RemoveTile(p_gameTileGroup[i]); if (!result) { Debug.LogWarning("Trying to remove a wrong tile"); return(result); } } return(result); }
///<summary> /// Modular code ///</summary> public bool HasDuplicateTileGroup(GameTileGroup p_gameTileGroup) { for (int i = 0; i < ArrangedGroups.Count; i++) { if (ArrangedGroups[i].HasDuplicateGroup(p_gameTileGroup)) { return(true); } } if (RemainderGroup != null && RemainderGroup.HasDuplicateGroup(p_gameTileGroup)) { return(true); } return(false); }
///<summary> /// Grouping method that works on o(n^2) since GameTileGroup is iterated for every GameTile inside the group ///</summary> protected GameTileGroup GroupMethod(GameTile p_selectedTile, GameTileGroup p_gameTileGroup) { GameTileGroup result = new GameTileGroup(); result.AddGameTile(p_selectedTile); for (int i = 0; i < p_gameTileGroup.GameTileCount; i++) { if (p_gameTileGroup[i].CompareColor(p_selectedTile) && p_gameTileGroup[i].IsNextOf(p_selectedTile)) { p_selectedTile = p_gameTileGroup[i]; result.AddGameTile(p_selectedTile); i = -1; } } return(result); }
///<summary> /// No matter the algorithm, the GameTileGroup is treated with same sequence. /// Some of the methods inside are implemented seperately. ///</summary> public GameTileGroup[] Arrange(GameTileGroup p_originalGroup) { List <GameTileGroup> result = new List <GameTileGroup>(); GameTileGroup copiedGroup = new GameTileGroup(p_originalGroup); if (copiedGroup.ContainsOkey(_okeyTile)) { OkeyTreatment(copiedGroup); } GameTileGroup[] everyPossibility = FindAll(copiedGroup); GameTileArrangement[] feasbileArrangements = FindFeasibles(everyPossibility); // Couldn't find the bug, brute fix incoming FindMissings(p_originalGroup, feasbileArrangements); int bestArrangementScore = int.MaxValue; int bestArrangementIndex = 0; for (int i = 0; i < feasbileArrangements.Length; i++) { if (feasbileArrangements[i].Score < bestArrangementScore) { bestArrangementScore = feasbileArrangements[i].Score; bestArrangementIndex = i; } } List <GameTileGroup> arrangementResult = new List <GameTileGroup>(); arrangementResult.AddRange(feasbileArrangements[bestArrangementIndex].ArrangedGroups); arrangementResult.Add(feasbileArrangements[bestArrangementIndex].RemainderGroup); result.AddRange(everyPossibility); return(arrangementResult.ToArray()); }
public GameTileGroup(GameTileGroup p_gameTileGroup) : this(p_gameTileGroup.GameTiles.ToArray()) { }
///<summary> /// Unfinished code ///</summary> protected virtual void OkeyTreatment(GameTileGroup p_copiedGroup) { }
///<summary> /// This is the function that findsevery possible grouping that is possible with given GameTileGroup /// GameTileSmartArranger, GameTileSameNumberArrnger and GameTileSameColorArranger implement this in their own way/ ///</summary> protected abstract GameTileGroup[] FindAll(GameTileGroup p_copiedGroup);
public GameTileHand(GameTileGroup p_gameTileGroup) : this() { EveryTile = p_gameTileGroup; }
public GameTileArrangement() { ArrangedGroups = new List <GameTileGroup>(); RemainderGroup = new GameTileGroup(); }
public PlayerHand(GameTileGroup p_gameTileGroup) : this() { EveryTile = p_gameTileGroup; }
///<summary> /// Unfinished code, i was thinking of removing OkeyTile first, /// find every possibilty, add OkeyTile to a single possiblity and try to generate ne Groups later to be generated as arrrangements ///</summary> protected override void OkeyTreatment(GameTileGroup p_copiedGroup) { p_copiedGroup.RemoveTile(_okeyTile); }