main.rs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. use std::collections::HashMap;
  2. /*
  3. * The basic element is a single Triangle.
  4. * It can be with a wide base (upright) or on its tip:
  5. *
  6. * /\ +--------+
  7. * / \ \ /
  8. * / \ \ /
  9. * / \ \ /
  10. * +--------+ \/
  11. *
  12. * We number its edges accordingly:
  13. * 1
  14. * /\ +--------+
  15. * 3 / \ 2 \ /
  16. * / \ \ /
  17. * / \ 3 \ / 2
  18. * +--------+ \/
  19. * 1
  20. *
  21. */
  22. type Edge = u8;
  23. /* Numbers 1..7 are used to identify a given part */
  24. type PartID = u8;
  25. /* Parts are described by a given upright triangle and a sequence of edges that are extended */
  26. type Part = Vec<Edge>;
  27. /* For example, the brown part (1) could be described by starting at the lower right triangle and
  28. * traversing edges in the following order: 3, 3, 1, 1, 2, 1, 3
  29. * ____
  30. * \ /\
  31. * \/__\
  32. * /\ /\
  33. * /__\/__\ <--
  34. * \ /
  35. * \/
  36. *
  37. *
  38. *
  39. */
  40. fn generate_parts() -> HashMap<PartID, Part> {
  41. HashMap::from([
  42. (1, vec![3, 3, 1, 1, 2, 1, 3]),
  43. (2, vec![2, 1, 2, 2, 1]),
  44. (3, vec![2, 1, 3, 1, 2]),
  45. ])
  46. }
  47. /*
  48. * A map has two sides (left and right) and is not neccesarily convex.
  49. * We specify each side by a list of lines.
  50. * Each line is represented by yet another list of skip entries:
  51. * a two-tuple, where the first number designates the cells that are "skipped" (a.k.a inaccessible)
  52. * and the second number which specifies the number of valid fields.
  53. */
  54. type SkipEntryIO = (u8, u8);
  55. type MapSideIO = Vec<Vec<SkipEntryIO>>;
  56. type MapIO = (MapSideIO, MapSideIO);
  57. /*
  58. * For in-memory representation however, we simply use a two-dimensional array of cells.
  59. * Each cell can be a Barrier (meaning no part may be placed on the cell), Empty (meaning at the
  60. * current time, it is not occupied by a part) or Occupied.
  61. */
  62. enum Cell {
  63. Barrier,
  64. Empty,
  65. Occupied(PartID)
  66. }
  67. /*
  68. * A triangular grid looks like this:
  69. * __ __
  70. * /\ /\ /\
  71. * /__\/__\/__\
  72. * \ /\ /\ /
  73. * \/__\/__\/
  74. * /\ /\ /\
  75. * /__\/__\/__\
  76. *
  77. * We require by definition that the left upper-most triangle is upright.
  78. * A map is then represented by a two-dimensional row-major (meaning the outer array represents the
  79. * different rows) two-dimensional array with a maximum
  80. * size of 16x16.
  81. * Since there are two sides, we store both of them in a tuple.
  82. */
  83. type MapSide = [[Cell; 16]; 16];
  84. type Map = (MapSide, MapSide);
  85. fn main() {
  86. println!("Hello, world!");
  87. }