public static List <List <IRuntimeJewel> > FindMatchesBuffer(IRuntimeJewel[,] jewelMap) { int width = jewelMap.GetLength(0); int height = jewelMap.GetLength(1); List <IRuntimeJewel> buffer = new List <IRuntimeJewel>(); List <List <IRuntimeJewel> > toRemoveBuff = new List <List <IRuntimeJewel> >(); // Look at all the rows and remove gems that are in the buffer more than 3 for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { EvaluateBuffer(buffer, toRemoveBuff, jewelMap[x, y]); } EvaluateBuffer(buffer, toRemoveBuff, null); buffer.Clear(); } // Look at all the columns and remove gems that are in the buffer more than 3 for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { EvaluateBuffer(buffer, toRemoveBuff, jewelMap[x, y]); } EvaluateBuffer(buffer, toRemoveBuff, null); buffer.Clear(); } return(toRemoveBuff); }
public static int WillCauseMatchCount(IRuntimeJewel[,] jewels, IRuntimeJewel swap1, IRuntimeJewel swap2, List <JewelID> prefJewels = null) { jewels[(int)swap1.Pos.x, (int)swap1.Pos.y] = swap2; jewels[(int)swap2.Pos.x, (int)swap2.Pos.y] = swap1; int MatchCount = 0; List <IRuntimeJewel> foundMatches = FindMatchesUtil.FindMatches(jewels); if (prefJewels != null) { List <JewelID> matchesPref = new List <JewelID>(); foreach (IRuntimeJewel jwl in foundMatches) { if (prefJewels.Contains(jwl.Data.JewelID) && !matchesPref.Contains(jwl.Data.JewelID)) { matchesPref.Add(jwl.Data.JewelID); } } MatchCount = foundMatches.Count + matchesPref.Count; } else { MatchCount = foundMatches.Count; } jewels[(int)swap1.Pos.x, (int)swap1.Pos.y] = swap1; jewels[(int)swap2.Pos.x, (int)swap2.Pos.y] = swap2; return(MatchCount); }
public override void OnEnterState() { // Look through all jewels IRuntimeJewel[,] jewels = board.GetBoardData().GetMap(); // Right here is where I need to look through all the jewels and see if two jewels are clicked List <IRuntimeJewel> jewelsClicked = new List <IRuntimeJewel>(); for (int x = 0; x < jewels.GetLength(0); x++) { for (int y = 0; y < jewels.GetLength(1); y++) { if (jewels[x, y].IsSelected) { jewelsClicked.Add(jewels[x, y]); } } } if (jewelsClicked.Count <= 1) { // Clean Board state GameEvents.Instance.Notify <ICleanBoard>(i => i.OnBoardCleanCheck()); } else if (jewelsClicked.Count == 2 && FindMatchesUtil.WillCauseMatch(jewels, jewelsClicked[0], jewelsClicked[1])) { // If the two jewels will cause a match, swap the jewels, then swap to evaluate board state GameEvents.Instance.Notify <ISwapBoard>(i => i.OnBoardSwapCheck()); } else { // Remove all selected board state GameEvents.Instance.Notify <IRemoveSelectedBoard>(i => i.OnBoardRemoveSelectedCheck()); } }
//private List<IRuntimeJewel> toRemoveBuff = new List<IRuntimeJewel>(); public override void OnEnterState() { //Logger.Log<EvaluateBoardState>("OnEnterState"); base.OnEnterState(); // Bring in board data IRuntimeJewel[,] jewelMap = board.GetBoardData().GetMap(); if (FindMatchesUtil.FindBestMatches(jewelMap).Count == 0) { OnResetState(); return; } List <List <IRuntimeJewel> > toRemoveBuffs = FindMatchesUtil.FindMatchesBuffer(jewelMap); foreach (var toRemoveBuff in toRemoveBuffs) { if (toRemoveBuff.Count > 3) { OnBonus(toRemoveBuff.Select((jewel) => { return(jewel.Data.JewelID); }).ToList()); } foreach (var jewel in toRemoveBuff) { OnRemove(jewel); } } if (toRemoveBuffs.Count > 0 || FindMatchesUtil.ContainsNullJewel(board.GetBoardData().GetMap())) { OnCascadeState(); } else { OnCleanBoardState(); } }
public static bool WillCauseMatch(IRuntimeJewel[,] jewels, IRuntimeJewel swap1, IRuntimeJewel swap2) { jewels[(int)swap1.Pos.x, (int)swap1.Pos.y] = swap2; jewels[(int)swap2.Pos.x, (int)swap2.Pos.y] = swap1; bool foundMatches = FindMatchesUtil.FindMatches(jewels).Count > 0; jewels[(int)swap1.Pos.x, (int)swap1.Pos.y] = swap1; jewels[(int)swap2.Pos.x, (int)swap2.Pos.y] = swap2; return(foundMatches); }
public Vector2 OffsetJewelByPosition(Vector2 pos) { IRuntimeJewel[,] jewelMap = GameData.Instance.RuntimeGame.GameBoard.GetBoardData().GetMap(); int width = jewelMap.GetLength(0); int height = jewelMap.GetLength(1); Vector2 middle = new Vector2((int)width / 2, (int)height / 2); return(new Vector2(pos.x - middle.x, pos.y - middle.y)); }
public void OnUnselectAll() { IRuntimeJewel[,] jewels = GameBoard.GetBoardData().GetMap(); for (int x = 0; x < jewels.GetLength(0); x++) { for (int y = 0; y < jewels.GetLength(1); y++) { jewels[x, y].DoUnselect(); } } }
private IRuntimeJewel FindNextJewel(IRuntimeJewel[,] jewelMap, Vector2 currentPos) { int height = jewelMap.GetLength(1); int row = (int)currentPos.y; while (row < height - 1 && jewelMap[(int)currentPos.x, row] == null) { row++; } return(jewelMap[(int)currentPos.x, row]); }
public override void OnEnterState() { base.OnEnterState(); //Debug.Log("CascadeBoardState"); List <JewelData> jewels = JewelDatabase.Instance.GetFullList(); List <IRuntimeJewel> readyJewels = new List <IRuntimeJewel>(); IRuntimeJewel[,] jewelMap = board.GetBoardData().GetMap(); int width = jewelMap.GetLength(0); int height = jewelMap.GetLength(1); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Vector2 pos = new Vector2(x, y); IRuntimeJewel jewel = FindNextJewel(jewelMap, pos); GameObject UIJewel = jewel == null ? null : GameObject.Find(jewel.JewelID); if (jewel == null || UIJewel == null) { jewel = new RuntimeJewel(jewels[Random.Range(0, jewels.Count)], pos, "Jewel_" + Count++); } else { // Rotate gem's position jewel.RotatePos(pos); // Remove old jewel position from buffer jewelMap[(int)jewel.LastPos.x, (int)jewel.LastPos.y] = null; } // Place Jewel On Board SetJewelData(jewel, pos); // Update UI readyJewels.Add(jewel); // Update temp buffer jewelMap[x, y] = jewel; } } //board.GetBoardData().PrettyJewelMap(); // Update UI foreach (IRuntimeJewel jwl in readyJewels) { OnCascadeJewel(jwl); } }
public override bool Execute(IRuntimeJewel TriggerJewel) { Debug.Log("Execute Destroy Effect!"); // Destroy between MinAmt and MaxAmt of random Jewel // -1 values in MinAmt or MaxAmt will destroy all of type Jewel // Get gameboard IRuntimeJewel[,] board = GameData.Instance.RuntimeGame.GameBoard.GetBoardData().GetMap(); // Find all jewels of type List <IRuntimeJewel> matching = new List <IRuntimeJewel>(); int width = board.GetLength(0); int height = board.GetLength(1); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (board[x, y].Data.JewelID == Jewel || Jewel == JewelID.any) { matching.Add(board[x, y]); } } } // Pick out the right jewels in range // -1 values in MinAmt or MaxAmt will destroy all of type Jewel if (MinAmt != -1 && MaxAmt != -1) { int amt = Random.Range(MinAmt, MaxAmt); ListExtensions.Shuffle(matching); matching = matching.Take(amt).ToList(); } // Destroy jewels in list foreach (IRuntimeJewel jwl in matching) { //GameData.Instance.RuntimeGame.GameBoard.GetBoardData().SetJewel(null, jwl.Pos); GameEvents.Instance.Notify <IRemoveJewel>(i => i.OnRemoveJewel(jwl)); } // Notify Evaluate //GameEvents.Instance.Notify<ICascadeBoard>(i => i.OnBoardCascadeCheck()); return(true); }
public override bool Execute(IRuntimeJewel TriggerJewel) { Debug.Log("Execute Pop Effect!"); if (TriggerJewel.Data.JewelID != Jewel) { return(false); } // Find all jewels of type List <IRuntimeJewel> matching = new List <IRuntimeJewel>(); // Make sure the jewel clicked is the correct jewel for the effect // Pop in a radius between min and max int radius = Random.Range(MinAmt, MaxAmt); // Get gameboard IRuntimeJewel[,] board = GameData.Instance.RuntimeGame.GameBoard.GetBoardData().GetMap(); int width = board.GetLength(0); int height = board.GetLength(1); for (int x = (int)TriggerJewel.Pos.x - radius; x <= (int)TriggerJewel.Pos.x + radius; x++) { for (int y = (int)TriggerJewel.Pos.y - radius; y <= (int)TriggerJewel.Pos.y + radius; y++) { if (x >= 0 && x < width && y >= 0 && y < height) { matching.Add(board[x, y]); } } } // Destroy jewels in list foreach (IRuntimeJewel jwl in matching) { //GameData.Instance.RuntimeGame.GameBoard.GetBoardData().SetJewel(null, jwl.Pos); GameEvents.Instance.Notify <IRemoveJewel>(i => i.OnRemoveJewel(jwl)); } return(true); }
public override void OnEnterState() { // Look through all jewels IRuntimeJewel[,] jewelMap = board.GetBoardData().GetMap(); List <SwapChoices> matchesBuff = FindMatchesUtil.FindBestMatches(jewelMap); if (matchesBuff.Count == 0) { int width = jewelMap.GetLength(0); int height = jewelMap.GetLength(1); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { OnRemove(jewelMap[x, y]); } } } Notify(); }
public static bool ContainsNullJewel(IRuntimeJewel[,] jewelMap) { int width = jewelMap.GetLength(0); int height = jewelMap.GetLength(1); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (jewelMap[x, y] == null) { return(true); } //GameObject UIJewel = GameObject.Find(jewelMap[x, y].JewelID); //if (UIJewel == null) // return true; //Debug.Log(jewelMap[x, y].JewelID + ": " + x.ToString() + "|" + y.ToString() + " : " + jewelMap[x, y].Pos.ToString()); } } return(false); }
public override List <IRuntimeJewel> GetAbilityJewel(PlayerSeat seat, IRuntimeAbility ability) { List <IRuntimeJewel> abilityJewels = new List <IRuntimeJewel>(); IRuntimeJewel[,] jwlMap = game.GameBoard.GetBoardData().GetMap(); int width = jwlMap.GetLength(0); int height = jwlMap.GetLength(1); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (jwlMap[x, y].Data.JewelID == ability.Ability.AfterEffect.Jewel || ability.Ability.AfterEffect.Jewel == JewelID.any) { abilityJewels.Add(jwlMap[x, y]); } } } return(abilityJewels); }
public override void OnEnterState() { // Look through all jewels IRuntimeJewel[,] jewels = board.GetBoardData().GetMap(); // Right here is where I need to look through all the jewels and see if two jewels are clicked List <IRuntimeJewel> jewelsClicked = new List <IRuntimeJewel>(); for (int x = 0; x < jewels.GetLength(0); x++) { for (int y = 0; y < jewels.GetLength(1); y++) { if (jewels[x, y].IsSelected) { jewels[x, y].DoUnselect(); } } } OnEvaluateBoardState(); }
public static List <SwapChoices> FindBestMatches(IRuntimeJewel[,] jewelMap, List <JewelID> prefJewels = null) { int width = jewelMap.GetLength(0); int height = jewelMap.GetLength(1); List <SwapChoices> options = new List <SwapChoices>(); // Look at all the rows and remove gems that are in the buffer more than 3 for (int y = 0; y < height; y++) { for (int x = 0; x < width - 1; x++) { IRuntimeJewel j1 = jewelMap[x, y]; IRuntimeJewel j2 = jewelMap[x + 1, y]; int matchcount = WillCauseMatchCount(jewelMap, j1, j2, prefJewels); if (matchcount > 0) { options.Add(new SwapChoices(j1, j2, matchcount)); } } } // Look at all the columns and remove gems that are in the buffer more than 3 for (int x = 0; x < width; x++) { for (int y = 0; y < height - 1; y++) { IRuntimeJewel j1 = jewelMap[x, y]; IRuntimeJewel j2 = jewelMap[x, y + 1]; int matchcount = WillCauseMatchCount(jewelMap, j1, j2, prefJewels); if (matchcount > 0) { options.Add(new SwapChoices(j1, j2, matchcount)); } } } return(options); }
public void OnJewelPosition(IRuntimeJewel Jewel, Vector3 from, Vector3 to) { /* * Here is where we need to query the board map holder and make sure that * this gem is the gem that is supposed to be in the position */ if (jewel.JewelID == Jewel.JewelID) { IRuntimeJewel[,] board = GameData.Instance.RuntimeGame.GameBoard.GetBoardData().GetMap(); IRuntimeJewel boardJewel = board[(int)jewel.Pos.x, (int)jewel.Pos.y]; if (boardJewel.JewelID == jewel.JewelID) { // The board and the cascader are in sync, move jewel to correct position parent.MonoBehavior.StartCoroutine(CascadeJewelFromPosition(from, to)); } else { // The board and the cascader are out of sync, and this jewel should have been deleted parent.OnRemove(jewel); } } }
public override bool Execute(IRuntimeJewel TriggerJewel) { // Get gameboard IRuntimeJewel[,] board = GameData.Instance.RuntimeGame.GameBoard.GetBoardData().GetMap(); // Find all jewels of type List <IRuntimeJewel> matching = new List <IRuntimeJewel>(); int width = board.GetLength(0); int height = board.GetLength(1); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (board[x, y].Data.JewelID == Jewel || Jewel == JewelID.any) { matching.Add(board[x, y]); } } } // Pick out the right jewels in range // -1 values in MinAmt or MaxAmt will destroy all of type Jewel if (MinAmt != -1 && MaxAmt != -1) { int amt = Random.Range(MinAmt, MaxAmt); ListExtensions.Shuffle(matching); matching = matching.Take(amt).ToList(); } // Destroy jewels in list foreach (IRuntimeJewel jwl in matching) { GameEvents.Instance.Notify <ITransformJewel>(i => i.OnTransformJewel(jwl, TransformJewel)); } return(true); }
public override void OnEnterState() { // Look through all jewels IRuntimeJewel[,] jewels = board.GetBoardData().GetMap(); // Right here is where I need to look through all the jewels and see if two jewels are clicked List <IRuntimeJewel> jewelsClicked = new List <IRuntimeJewel>(); for (int x = 0; x < jewels.GetLength(0); x++) { for (int y = 0; y < jewels.GetLength(1); y++) { if (jewels[x, y].IsSelected) { jewelsClicked.Add(jewels[x, y]); } } } if (jewelsClicked.Count == 2) { Vector2 pos1 = jewelsClicked[0].Pos; Vector2 pos2 = jewelsClicked[1].Pos; jewelsClicked[0].RotatePos(pos2); jewelsClicked[1].RotatePos(pos1); SetJewelData(jewelsClicked[0], jewelsClicked[0].Pos); SetJewelData(jewelsClicked[1], jewelsClicked[1].Pos); MarkPlayerSwap(); OnSwapJewel(jewelsClicked[0], jewelsClicked[1]); } //OnSwapFinished(); }