// функция поиска возможных ходов public List <Move> FindMoves() { List <Move> moves = new List <Move>(); if (!FieldAssistant.main.gameObject.activeSelf) { return(moves); } if (LevelProfile.main == null) { return(moves); } Solution solution; int potential; Side[] asixes = new Side[2] { Side.Right, Side.Top }; foreach (Side asix in asixes) { foreach (Slot slot in Slot.all.Values) { if (slot[asix] == null) { continue; } if (slot.block != null || slot[asix].block != null) { continue; } if (slot.chip == null || slot[asix].chip == null) { continue; } if (slot.chip.id == slot[asix].chip.id) { continue; } Move move = new Move(); move.from = slot.coord; move.to = slot[asix].coord; AnalizSwap(move); Dictionary <Slot, Solution> solutions = new Dictionary <Slot, Solution>(); Slot[] cslots = new Slot[2] { slot, slot[asix] }; foreach (Slot cslot in cslots) { solutions.Add(cslot, null); potential = 0; solution = MatchAnaliz(cslot); if (solution != null) { solutions[cslot] = solution; potential = solution.potential; } solution = MatchSquareAnaliz(cslot); if (solution != null && potential < solution.potential) { solutions[cslot] = solution; potential = solution.potential; } move.potencial += potential; } if (solutions[cslots[0]] != null && solutions[cslots[1]] != null) { move.solution = solutions[cslots[0]].potential > solutions[cslots[1]].potential ? solutions[cslots[0]] : solutions[cslots[1]]; } else { move.solution = solutions[cslots[0]] != null ? solutions[cslots[0]] : solutions[cslots[1]]; } AnalizSwap(move); if (Mix.ContainsThisMix(slot.chip.chipType, slot[asix].chip.chipType)) { move.potencial += 100; } if (move.potencial > 0) { moves.Add(move); } } } return(moves); }
public List <Move> FindMoves() { List <Move> moves = new List <Move>(); if (!FieldAssistant.Instance.gameObject.activeSelf) { return(moves); } if (LevelProfile.CurrentLevelProfile == null) { return(moves); } int x; int y; int width = LevelProfile.CurrentLevelProfile.Width; int height = LevelProfile.CurrentLevelProfile.Height; Move move; Solution solution; int potential; SlotForCard slot; string chipTypeA = ""; string chipTypeB = ""; // horizontal for (x = 0; x < width - 1; x++) { for (y = 0; y < height; y++) { if (!FieldAssistant.Instance.field.slots[x, y]) { continue; } if (!FieldAssistant.Instance.field.slots[x + 1, y]) { continue; } if (FieldAssistant.Instance.field.blocks[x, y] > 0) { continue; } if (FieldAssistant.Instance.field.blocks[x + 1, y] > 0) { continue; } if (FieldAssistant.Instance.field.chips[x, y] == FieldAssistant.Instance.field.chips[x + 1, y]) { continue; } if (FieldAssistant.Instance.field.chips[x, y] == -1 && FieldAssistant.Instance.field.chips[x + 1, y] == -1) { continue; } if (FieldAssistant.Instance.field.wallsV[x, y]) { continue; } move = new Move(); move.fromX = x; move.fromY = y; move.toX = x + 1; move.toY = y; AnalizSwap(move); Solution solutionA = null; Solution solutionB = null; slot = SlotManager.Instance.FindSlot(move.fromX, move.fromY).GetComponent <SlotForCard>(); chipTypeA = slot.card == null ? "SimpleChip" : slot.card.chipType; potential = 0; solution = slot.MatchAnaliz(); if (solution != null) { solutionA = solution; potential = solution.potential; } // solution = slot.MatchSquareAnaliz(); // if (solution != null && potential < solution.potential) { // solutionA = solution; // potential = solution.potential; // } move.potencial += potential; slot = SlotManager.Instance.FindSlot(move.toX, move.toY).GetComponent <SlotForCard>(); chipTypeB = slot.card == null ? "SimpleChip" : slot.card.chipType; potential = 0; solution = slot.MatchAnaliz(); if (solution != null) { solutionB = solution; potential = solution.potential; } // solution = slot.MatchSquareAnaliz(); // if (solution != null && potential < solution.potential) { // solutionB = solution; // potential = solution.potential; // } move.potencial += potential; if (solutionA != null && solutionB != null) { move.solution = solutionA.potential >= solutionB.potential ? solutionA : solutionB; } else { move.solution = solutionA != null ? solutionA : solutionB; } AnalizSwap(move); if (Mix.ContainsThisMix(chipTypeA, chipTypeB)) { move.potencial += 100; } if (move.potencial > 0 || (chipTypeA != "SimpleChip" && chipTypeB != "SimpleChip")) { moves.Add(move); } } } // vertical for (x = 0; x < width; x++) { for (y = 0; y < height - 1; y++) { if (!FieldAssistant.Instance.field.slots[x, y]) { continue; } if (!FieldAssistant.Instance.field.slots[x, y + 1]) { continue; } if (FieldAssistant.Instance.field.blocks[x, y] > 0) { continue; } if (FieldAssistant.Instance.field.blocks[x, y + 1] > 0) { continue; } if (FieldAssistant.Instance.field.chips[x, y] == FieldAssistant.Instance.field.chips[x, y + 1]) { continue; } if (FieldAssistant.Instance.field.chips[x, y] == -1 && FieldAssistant.Instance.field.chips[x, y + 1] == -1) { continue; } if (FieldAssistant.Instance.field.wallsH[x, y]) { continue; } move = new Move(); move.fromX = x; move.fromY = y; move.toX = x; move.toY = y + 1; AnalizSwap(move); Solution solutionA = null; Solution solutionB = null; slot = SlotManager.Instance.FindSlot(move.fromX, move.fromY).GetComponent <SlotForCard>(); chipTypeA = slot.card == null ? "SimpleChip" : slot.card.chipType; potential = 0; solution = slot.MatchAnaliz(); if (solution != null) { solutionA = solution; potential = solution.potential; } // solution = slot.MatchSquareAnaliz(); // if (solution != null && potential < solution.potential) { // solutionA = solution; // potential = solution.potential; // } move.potencial += potential; slot = SlotManager.Instance.FindSlot(move.toX, move.toY).GetComponent <SlotForCard>(); chipTypeB = slot.card == null ? "SimpleChip" : slot.card.chipType; potential = 0; solution = slot.MatchAnaliz(); if (solution != null) { solutionB = solution; potential = solution.potential; } // solution = slot.MatchSquareAnaliz(); // if (solution != null && potential < solution.potential) { // solutionB = solution; // potential = solution.potential; // } move.potencial += potential; if (solutionA != null && solutionB != null) { move.solution = solutionA.potential >= solutionB.potential ? solutionA : solutionB; } else { move.solution = solutionA != null ? solutionA : solutionB; } AnalizSwap(move); if (Mix.ContainsThisMix(chipTypeA, chipTypeB)) { move.potencial += 100; } if (move.potencial > 0 || (chipTypeA != "SimpleChip" && chipTypeB != "SimpleChip")) { moves.Add(move); } } } return(moves); }