Guest User

Level Data

a guest
May 7th, 2026
261
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. using System.Collections.Generic;
  2.  
  3. [System.Serializable]
  4. public class LevelData
  5. {
  6. public int GridXSize;
  7. public int GridYSize;
  8. public List<ArrowData> Arrows = new List<ArrowData>();
  9.  
  10. public bool CanSolveLevel()
  11. {
  12. if (Arrows.Count == 0) return true;
  13.  
  14. int totalCells = GridXSize * GridYSize;
  15. int[] board = new int[totalCells];
  16. System.Array.Fill(board, -1);
  17.  
  18. for (int i = 0; i < Arrows.Count; i++)
  19. {
  20. foreach (int idx in Arrows[i].Indices)
  21. board[idx] = i;
  22. }
  23.  
  24. bool[] removed = new bool[Arrows.Count];
  25. int removedCount = 0;
  26. bool changed;
  27.  
  28. do
  29. {
  30. changed = false;
  31. for (int i = 0; i < Arrows.Count; i++)
  32. {
  33. if (removed[i]) continue;
  34.  
  35. if (CanExit(Arrows[i], board))
  36. {
  37. foreach (int idx in Arrows[i].Indices)
  38. board[idx] = -1;
  39.  
  40. removed[i] = true;
  41. removedCount++;
  42. changed = true;
  43. }
  44. }
  45. } while (changed);
  46.  
  47. return removedCount == Arrows.Count;
  48. }
  49.  
  50. private bool CanExit(ArrowData arrow, int[] board)
  51. {
  52. int headIdx = arrow.Indices[0];
  53. int neckIdx = arrow.Indices[1];
  54.  
  55. int hx = headIdx % GridXSize;
  56. int hy = headIdx / GridXSize;
  57. int nx = neckIdx % GridXSize;
  58. int ny = neckIdx / GridXSize;
  59.  
  60. int dx = hx - nx;
  61. int dy = hy - ny;
  62.  
  63. int cx = hx + dx;
  64. int cy = hy + dy;
  65.  
  66. while (cx >= 0 && cx < GridXSize && cy >= 0 && cy < GridYSize)
  67. {
  68. int checkIdx = cy * GridXSize + cx;
  69. if (board[checkIdx] != -1) return false;
  70. cx += dx;
  71. cy += dy;
  72. }
  73.  
  74. return true;
  75. }
  76. }
  77.  
  78. [System.Serializable]
  79. public class ArrowData
  80. {
  81. public List<int> Indices = new();
  82. public int ColorIndex = 0;
  83. }
Advertisement
Comments
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment