Advertisement
Guest User

AoC day 23

a guest
Dec 24th, 2021
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 50.95 KB | None | 0 0
  1. use core::panicking::panic;
  2. use std::fmt::{Debug, Display, Formatter};
  3. use itertools::Itertools;
  4. use pathfinding::prelude::{dijkstra, astar};
  5. use crate::day23::Amphipods::{Amber, Bronze, Copper, Desert};
  6. use crate::day23::IsOccupied::{No, Yes};
  7.  
  8. #[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
  9. struct Space {
  10.     hallway: [IsOccupied; 11],
  11.     room1: [IsOccupied; 2],
  12.     //0th index is the top of the room
  13.     room2: [IsOccupied; 2],
  14.     room3: [IsOccupied; 2],
  15.     room4: [IsOccupied; 2],
  16. }
  17.  
  18. #[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
  19. struct Space2 {
  20.     hallway: [IsOccupied; 11],
  21.    //0th index is the top of the room
  22.     rooms: [[IsOccupied; 4]; 4],
  23.  
  24. }
  25.  
  26. #[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
  27. enum Amphipods {
  28.     Amber,
  29.     Bronze,
  30.     Copper,
  31.     Desert,
  32. }
  33.  
  34. #[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
  35. enum IsOccupied {
  36.     Yes(Amphipods),
  37.     No,
  38. }
  39.  
  40.  
  41. impl Display for IsOccupied {
  42.     fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
  43.        match self
  44.        {
  45.            Yes(Amber)  => {write!(f, "A")},
  46.            Yes(Bronze) => {write!(f, "B")},
  47.            Yes(Copper) => {write!(f, "C")},
  48.            Yes(Desert) => {write!(f, "D")},
  49.            No          => {write!(f, ".")}
  50.        }
  51.    }
  52. }
  53.  
  54. impl Display for Space{
  55.    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
  56.         let hallway = self.hallway;
  57.         let room1 = self.room1;
  58.         let room2 = self.room2;
  59.         let room3 = self.room3;
  60.         let room4 = self.room4;
  61.         write!(f, "#############\n#{}{}{}{}{}{}{}{}{}{}{}#\n###{}#{}#{}#{}###\n  #{}#{}#{}#{}#\n  #########",
  62.                hallway[0], hallway[0], hallway[0], hallway[0], hallway[0], hallway[0], hallway[0], hallway[0], hallway[0], hallway[0], hallway[0],
  63.             room1[0], room2[0], room3[0], room4[0],
  64.                room1[1], room2[1], room3[1], room4[1],
  65.         )
  66.     }
  67. }
  68.  
  69. const AMBER_MOVE_COST: u16 = 1;
  70. const BRONZE_MOVE_COST: u16 = 10;
  71. const COPPER_MOVE_COST: u16 = 100;
  72. const DESERT_MOVE_COST: u16 = 1000;
  73.  
  74. fn charToAmphipods(c: char) -> IsOccupied
  75. {
  76.     match c {
  77.         'A' => { Yes(Amber) }
  78.         'B' => { Yes(Bronze) }
  79.         'C' => { Yes(Copper) }
  80.         'D' => { Yes(Desert) }
  81.         _ => { panic!() }
  82.     }
  83. }
  84.  
  85.  
  86. pub fn day23_2()
  87. {
  88.     let input = include_str!("../temp23").lines().skip(2)
  89.         .flat_map(|x| x.trim().split('#').filter(|&x| !x.is_empty()).map(|x| x.chars().at_most_one().unwrap().unwrap())).collect_vec();
  90.     let initialState = Space2 {
  91.         hallway: [No, No, No, No, No, No, No, No, No, No, No, ],
  92.         rooms: [[charToAmphipods(input[0]), Yes(Desert), Yes(Desert), charToAmphipods(input[4])],
  93.             [charToAmphipods(input[1]), Yes(Copper), Yes(Bronze), charToAmphipods(input[5])],
  94.             [charToAmphipods(input[2]), Yes(Bronze), Yes(Amber), charToAmphipods(input[6])],
  95.             [charToAmphipods(input[3]), Yes(Amber), Yes(Copper), charToAmphipods(input[7])]],
  96.     };
  97.     let finState = Space2 {
  98.         hallway: [No, No, No, No, No, No, No, No, No, No, No, ],
  99.         rooms: [[Yes(Amber), Yes(Amber), Yes(Amber), Yes(Amber)],
  100.             [Yes(Bronze), Yes(Bronze), Yes(Bronze), Yes(Bronze)],
  101.             [Yes(Copper), Yes(Copper), Yes(Copper), Yes(Copper)],
  102.             [Yes(Desert), Yes(Desert), Yes(Desert), Yes(Desert)]],
  103.     };
  104.     let res = astar(&initialState, |x| {
  105.         let mut ret: Vec<_> = Vec::new();
  106.         for (pos, Thing) in x.hallway.iter().enumerate()
  107.         {
  108.             //IF anything is in the hallway that can move to its final spot
  109.             match Thing {
  110.                 Yes(a) => {
  111.                     let home = amph_to_room_index(a);
  112.                     let room_num = amph_to_room(a);
  113.                     if x.rooms[home][0] == No {
  114.                         let clear = routeIsClear2(x, (0, pos), (room_num, 0));
  115.                         let occupier = Yes(*a);
  116.                         if clear.0 {
  117.                             if x.rooms[home][1] == occupier && x.rooms[home][2] == occupier && x.rooms[home][3] == occupier {
  118.                                 // can move into the top spot
  119.                                 let mut new_space = x.clone();
  120.                                 new_space.hallway[pos] = No;
  121.                                 new_space.rooms[home][0] = occupier;
  122.                                 ret.push((new_space, clear.1 * amph_to_cost(a)));
  123.                             } else if x.rooms[home][1] == No && x.rooms[home][2] == occupier && x.rooms[home][3] == occupier {
  124.                                 //can move into the second spot
  125.                                 let mut new_space = x.clone();
  126.                                 new_space.hallway[pos] = No;
  127.                                 new_space.rooms[home][1] = occupier;
  128.                                 ret.push((new_space, (clear.1 + 1) * amph_to_cost(a)));
  129.                             } else if x.rooms[home][1] == No && x.rooms[home][2] == No && x.rooms[home][3] == occupier {
  130.                                 //can move into the third spot
  131.                                 let mut new_space = x.clone();
  132.                                 new_space.hallway[pos] = No;
  133.                                 new_space.rooms[home][2] = occupier;
  134.                                 ret.push((new_space, (clear.1 + 2) * amph_to_cost(a)));
  135.                             } else if x.rooms[home][1] == No && x.rooms[home][2] == No && x.rooms[home][3] == No {
  136.                                 //can move into the fourth spot
  137.                                 let mut new_space = x.clone();
  138.                                 new_space.hallway[pos] = No;
  139.                                 new_space.rooms[home][3] = occupier;
  140.                                 ret.push((new_space, (clear.1 + 3) * amph_to_cost(a)));
  141.                             }
  142.                         }
  143.                     }
  144.                 }
  145.                 No => {}
  146.             }
  147.         }
  148.         //if anything is in a top row or anything is in an unobstructed bottom row it can move to the hallway if route is clear
  149.         for (roomIndex, room) in x.rooms.iter().enumerate() {
  150.             let belongs_to = Yes(room_index_to_amph(roomIndex));
  151.             //check top row moves
  152.             match room[0] {
  153.                 Yes(a) => {
  154.                     if (room[1] != belongs_to || room[2] != belongs_to || room[3] != belongs_to) || room[0] != belongs_to
  155.                     {
  156.                         for (pos, &thing) in x.hallway.iter().enumerate()
  157.                         {
  158.                             if pos == 2 || pos == 4 || pos == 6 || pos == 8 || thing != No { continue; } //invalid moves, cant move to those positions, cant move if someone is there
  159.                             let clear = routeIsClear2(x, (roomIndex + 1, 0), (0, pos));
  160.                             if clear.0 {
  161.                                 let mut new_space = x.clone();
  162.                                 new_space.hallway[pos] = Yes(a);
  163.                                 new_space.rooms[roomIndex][0] = No;
  164.                                 ret.push((new_space, clear.1 * amph_to_cost(&a)));
  165.                             }
  166.                         }
  167.                     }
  168.                 }
  169.                 No => {}
  170.             }
  171.             //check second row moves
  172.             match room[1] {
  173.                 Yes(a) => {
  174.                     if (room[2] != belongs_to || room[3] != belongs_to) || room[1] != belongs_to
  175.                     {
  176.                         for (pos, &thing) in x.hallway.iter().enumerate()
  177.                         {
  178.                             if pos == 2 || pos == 4 || pos == 6 || pos == 8 || thing != No { continue; } //invalid moves, cant move to those positions, cant move if someone is there
  179.                             let clear = routeIsClear2(x, (roomIndex + 1, 1), (0, pos));
  180.                             if clear.0 {
  181.                                 let mut new_space = x.clone();
  182.                                 new_space.hallway[pos] = Yes(a);
  183.                                 new_space.rooms[roomIndex][1] = No;
  184.                                 ret.push((new_space, clear.1 * amph_to_cost(&a)));
  185.                             }
  186.                         }
  187.                     }
  188.                 }
  189.                 No => {}
  190.             }
  191.             //check third row moves
  192.             match room[2] {
  193.                 Yes(a) => {
  194.                     if (room[3] != belongs_to) || room[2] != belongs_to
  195.                     {
  196.                         for (pos, &thing) in x.hallway.iter().enumerate()
  197.                         {
  198.                             if pos == 2 || pos == 4 || pos == 6 || pos == 8 || thing != No { continue; } //invalid moves, cant move to those positions, cant move if someone is there
  199.                             let clear = routeIsClear2(x, (roomIndex + 1, 1), (0, pos));
  200.                             if clear.0 && room[1] == No {
  201.                                 let mut new_space = x.clone();
  202.                                 new_space.hallway[pos] = Yes(a);
  203.                                 new_space.rooms[roomIndex][2] = No;
  204.                                 ret.push((new_space, (clear.1 + 1) * amph_to_cost(&a)));
  205.                             }
  206.                         }
  207.                     }
  208.                 }
  209.                 No => {}
  210.             }
  211.             //check fourth row moves
  212.             match room[3] {
  213.                 Yes(a) => {
  214.                     if  room[3] != belongs_to
  215.                     {
  216.                         for (pos, &thing) in x.hallway.iter().enumerate()
  217.                         {
  218.                             if pos == 2 || pos == 4 || pos == 6 || pos == 8 || thing != No { continue; } //invalid moves, cant move to those positions, cant move if someone is there
  219.                             let clear = routeIsClear2(x, (roomIndex + 1, 1), (0, pos));
  220.                             if clear.0 && room[1] == No && room[2] == No {
  221.                                 let mut new_space = x.clone();
  222.                                 new_space.hallway[pos] = Yes(a);
  223.                                 new_space.rooms[roomIndex][3] = No;
  224.                                 ret.push((new_space, (clear.1 + 2) * amph_to_cost(&a)));
  225.                             }
  226.                         }
  227.                     }
  228.                 }
  229.                 No => {}
  230.             }
  231.         }
  232.         ret
  233.     }
  234.                     , |x| {
  235.             let mut ret = 0;
  236.             //commented out heuristic because it made runtime go from 150ms to 175ms
  237.             /*//min add all the hallway moves
  238.             for (pos, Thing) in x.hallway.iter().enumerate() {
  239.                 match Thing {
  240.                     Yes(a) => { ret += routeIsClear2(x, (0, pos), (amph_to_room(a), 0)).1 * amph_to_cost(a) }
  241.                     No => {}
  242.                 }
  243.             }
  244.             //cost of moving to the correct room, or into and out of the room if you are stacked badly
  245.             for (roomIndex, room) in x.rooms.iter().enumerate() {
  246.                 let belongs_to = Yes(room_index_to_amph(roomIndex));
  247.                 for (row_idx, &row) in room.iter().enumerate() {
  248.                     let mut is_not_good_below = false;
  249.                     for i in row_idx+1..4 {
  250.                         is_not_good_below |= room[i] != belongs_to;
  251.                     }
  252.                     match row {
  253.                         Yes(a) => {
  254.                             if is_not_good_below || row != belongs_to
  255.                             {
  256.                                 let temp_loc = match roomIndex {
  257.                                     0 => {3},
  258.                                     1 => {if a == Amber { 3 } else { 5 }},
  259.                                     2 => {if a == Desert { 7 } else { 5 }},
  260.                                     3 => {7}
  261.                                     _ => {unreachable!()}
  262.                                 };
  263.                                 let hallwayLoc = (0, temp_loc);
  264.                                 let finishLoc = (amph_to_room(&a), 0);
  265.                                 let spaces_to_move = routeIsClear2(x, (roomIndex + 1, 0), hallwayLoc).1 + routeIsClear2(x, hallwayLoc, finishLoc).1 + row_idx as u16;
  266.                                 ret += (spaces_to_move * amph_to_cost(&a))
  267.  
  268.                             }
  269.                         }
  270.                         No => {}
  271.                     }
  272.                 }
  273.             }*/
  274.             ret
  275.         }, |x| x.eq(&finState)).unwrap();
  276.     println!("ANS {}", res.1);
  277.     return;
  278. }
  279.  
  280. pub fn day23_1A_STAR() {
  281.     let input = include_str!("../temp23").lines().skip(2)
  282.         .flat_map(|x| x.trim().split('#').filter(|&x| !x.is_empty()).map(|x| x.chars().at_most_one().unwrap().unwrap())).collect_vec();
  283.     let initialState = Space {
  284.         hallway: [No, No, No, No, No, No, No, No, No, No, No, ],
  285.         room1: [charToAmphipods(input[0]), charToAmphipods(input[4])],
  286.         room2: [charToAmphipods(input[1]), charToAmphipods(input[5])],
  287.         room3: [charToAmphipods(input[2]), charToAmphipods(input[6])],
  288.         room4: [charToAmphipods(input[3]), charToAmphipods(input[7])],
  289.     };
  290.     //dbg!(initialState);
  291.     let finState = Space {
  292.         hallway: [No, No, No, No, No, No, No, No, No, No, No, ],
  293.         room1: [Yes(Amber), Yes(Amber)],
  294.         room2: [Yes(Bronze), Yes(Bronze)],
  295.         room3: [Yes(Copper), Yes(Copper)],
  296.         room4: [Yes(Desert), Yes(Desert)],
  297.     };
  298.  
  299.     let res = astar(&initialState, |x| {
  300.         let mut ret: Vec<_> = Vec::new();
  301.         //println!("SEARCHING THIS SPACE: ");
  302.         //println!("{}", x);
  303.         //IF anything is in the hallway that can move to its final spot
  304.         for (pos, Thing) in x.hallway.iter().enumerate()
  305.         {
  306.             match Thing {
  307.                 Yes(Amber) => {
  308.                     if x.room1[0] == No {
  309.                         let clear = routeIsClear(x, (0, pos), (1, 0));
  310.                         if clear.0 && x.room1[1] == Yes(Amber)
  311.                         {
  312.                             //can move into top spot
  313.                             let mut new_space = x.clone();
  314.                             new_space.hallway[pos] = No;
  315.                             new_space.room1[0] = Yes(Amber);
  316.                             ret.push((new_space, clear.1 * AMBER_MOVE_COST));
  317.                             //println!("FOUND MOVE TYPE 1: ");
  318.                             //println!("{}", &new_space);
  319.                         } else if x.room1[1] == No && clear.0 {
  320.                             //can move into bottom spot
  321.                             let mut new_space = x.clone();
  322.                             new_space.hallway[pos] = No;
  323.                             new_space.room1[1] = Yes(Amber);
  324.                             ret.push((new_space, (clear.1 + 1) * AMBER_MOVE_COST));
  325.                             //println!("FOUND MOVE TYPE 2: ");
  326.                             //println!("{}", new_space);
  327.                         }
  328.                     }
  329.                 }
  330.                 Yes(Bronze) => {
  331.                     if x.room2[0] == No {
  332.                         let clear = routeIsClear(x, (0, pos), (2, 0));
  333.                         if clear.0 && x.room2[1] == Yes(Bronze)
  334.                         {
  335.                             //can move into top spot
  336.                             let mut new_space = x.clone();
  337.                             new_space.hallway[pos] = No;
  338.                             new_space.room2[0] = Yes(Bronze);
  339.                             ret.push((new_space, clear.1 * BRONZE_MOVE_COST));
  340.                             //println!("FOUND MOVE TYPE 3: ");
  341.                             //println!("{}", new_space);
  342.                         } else if x.room2[1] == No && clear.0 {
  343.                             //can move into bottom spot
  344.                             let mut new_space = x.clone();
  345.                             new_space.hallway[pos] = No;
  346.                             new_space.room2[1] = Yes(Bronze);
  347.                             ret.push((new_space, (clear.1 + 1) * BRONZE_MOVE_COST));
  348.                             //println!("FOUND MOVE TYPE 4: ");
  349.                             //println!("{}", new_space);
  350.                         }
  351.                     }
  352.                 }
  353.                 Yes(Copper) => {
  354.                     if x.room3[0] == No {
  355.                         let clear = routeIsClear(x, (0, pos), (3, 0));
  356.                         if clear.0 && x.room3[1] == Yes(Copper)
  357.                         {
  358.                             //can move into top spot
  359.                             let mut new_space = x.clone();
  360.                             new_space.hallway[pos] = No;
  361.                             new_space.room3[0] = Yes(Copper);
  362.                             ret.push((new_space, clear.1 * COPPER_MOVE_COST));
  363.                             //println!("FOUND MOVE TYPE 5: ");
  364.                             //println!("{}", new_space);
  365.                         } else if x.room3[1] == No && clear.0 {
  366.                             //can move into bottom spot
  367.                             let mut new_space = x.clone();
  368.                             new_space.hallway[pos] = No;
  369.                             new_space.room3[1] = Yes(Copper);
  370.                             ret.push((new_space, (clear.1 + 1) * COPPER_MOVE_COST));
  371.                             //println!("FOUND MOVE TYPE 6: ");
  372.                             //println!("{}", new_space);
  373.                         }
  374.                     }
  375.                 }
  376.                 Yes(Desert) => {
  377.                     if x.room4[0] == No {
  378.                         let clear = routeIsClear(x, (0, pos), (4, 0));
  379.                         if clear.0 && x.room4[1] == Yes(Desert)
  380.                         {
  381.                             //can move into top spot
  382.                             let mut new_space = x.clone();
  383.                             new_space.hallway[pos] = No;
  384.                             new_space.room4[0] = Yes(Desert);
  385.                             ret.push((new_space, clear.1 * DESERT_MOVE_COST));
  386.                             //println!("FOUND MOVE TYPE 7: ");
  387.                             //println!("{}", new_space);
  388.                         } else if x.room4[1] == No && clear.0 {
  389.                             //can move into bottom spot
  390.                             let mut new_space = x.clone();
  391.                             new_space.hallway[pos] = No;
  392.                             new_space.room4[1] = Yes(Desert);
  393.                             ret.push((new_space, (clear.1 + 1) * DESERT_MOVE_COST));
  394.                             //println!("FOUND MOVE TYPE 8: ");
  395.                             //println!("{}", new_space);
  396.                         }
  397.                     }
  398.                 }
  399.                 No => { continue; }
  400.             }
  401.         }
  402.         //if anything is in a top row or anything is in an unobstructed bottom row  it can move to the hallway if route is clear
  403.  
  404.         //check bottom row moves
  405.         match x.room1[1]  {
  406.             Yes(Amber) => {}
  407.             Yes(a) => {
  408.                 for (pos, &thing) in x.hallway.iter().enumerate() {
  409.                     if pos == 2 || pos == 4 || pos == 6 || pos == 8 { continue; }
  410.                     if thing == No {
  411.                         let clear = routeIsClear(x, (1, 1), (0, pos));
  412.                         if clear.0 {
  413.                             let mut new_space = x.clone();
  414.                             new_space.hallway[pos] = Yes(a);
  415.                             new_space.room1[1] = No;
  416.                             ret.push((new_space, clear.1 * amph_to_cost(&a)));
  417.                             //println!("FOUND MOVE TYPE 9: ");
  418.                             //println!("{}", new_space);
  419.                         }
  420.                     }
  421.                 }
  422.             }
  423.             No => {}
  424.         }
  425.         match x.room2[1]  {
  426.             Yes(Bronze) => {}
  427.             Yes(a) => {
  428.                 for (pos, &thing) in x.hallway.iter().enumerate() {
  429.                     if pos == 2 || pos == 4 || pos == 6 || pos == 8 { continue; }
  430.                     if thing == No {
  431.                         let clear = routeIsClear(x, (2, 1), (0, pos));
  432.                         if clear.0 {
  433.                             let mut new_space = x.clone();
  434.                             new_space.hallway[pos] = Yes(a);
  435.                             new_space.room2[1] = No;
  436.                             ret.push((new_space, clear.1 * amph_to_cost(&a)));
  437.                             //println!("FOUND MOVE TYPE 10: ");
  438.                             //println!("{}", new_space);
  439.  
  440.                         }
  441.                     }
  442.                 }
  443.             }
  444.             No => {}
  445.         }
  446.         match x.room3[1]  {
  447.             Yes(Copper) => {}
  448.             Yes(a) => {
  449.                 for (pos, &thing) in x.hallway.iter().enumerate() {
  450.                     if pos == 2 || pos == 4 || pos == 6 || pos == 8 { continue; }
  451.                     if thing == No {
  452.                         let clear = routeIsClear(x, (3, 1), (0, pos));
  453.                         if clear.0 {
  454.                             let mut new_space = x.clone();
  455.                             new_space.hallway[pos] = Yes(a);
  456.                             new_space.room3[1] = No;
  457.                             ret.push((new_space, clear.1 * amph_to_cost(&a)));
  458.                             //println!("FOUND MOVE TYPE 11: ");
  459.                             //println!("{}", new_space);
  460.                         }
  461.                     }
  462.                 }
  463.             }
  464.             No => {}
  465.         }
  466.         match x.room4[1]  {
  467.             Yes(Desert) => {}
  468.             Yes(a) => {
  469.                 for (pos, &thing) in x.hallway.iter().enumerate() {
  470.                     if pos == 2 || pos == 4 || pos == 6 || pos == 8 { continue; }
  471.                     if thing == No {
  472.                         let clear = routeIsClear(x, (4, 1), (0, pos));
  473.                         if clear.0 {
  474.                             let mut new_space = x.clone();
  475.                             new_space.hallway[pos] = Yes(a);
  476.                             new_space.room4[1] = No;
  477.                             ret.push((new_space, clear.1 * amph_to_cost(&a)));
  478.                             //println!("FOUND MOVE TYPE 12: ");
  479.                             //println!("{}", new_space);
  480.                         }
  481.                     }
  482.                 }
  483.             }
  484.             No => {}
  485.         }
  486.         // check top rooms for moves
  487.         match x.room1[0] {
  488.             Yes(a) => {
  489.                 if x.room1[1] != Yes(Amber) || (x.room1[1] == Yes(Amber) && Yes(a) != Yes(Amber))
  490.                 {
  491.                     for (pos, &thing) in x.hallway.iter().enumerate() {
  492.                         if pos == 2 || pos == 4 || pos == 6 || pos == 8 { continue; }
  493.                         if thing == No {
  494.                             let clear = routeIsClear(x, (1, 0), (0, pos));
  495.                             if clear.0 {
  496.                                 let mut new_space = x.clone();
  497.                                 new_space.hallway[pos] = Yes(a);
  498.                                 new_space.room1[0] = No;
  499.                                 ret.push((new_space, clear.1 * amph_to_cost(&a)));
  500.                                 //println!("FOUND MOVE TYPE 13: ");
  501.                                 //println!("{}", new_space);
  502.                             }
  503.                         }
  504.                     }
  505.                 }
  506.             }
  507.             No => {}
  508.         }
  509.         match x.room2[0] {
  510.             Yes(a) => {
  511.                 if x.room2[1] != Yes(Bronze) || (x.room2[1] == Yes(Bronze) && Yes(a) != Yes(Bronze))
  512.                 {
  513.                     for (pos, &thing) in x.hallway.iter().enumerate() {
  514.                         if pos == 2 || pos == 4 || pos == 6 || pos == 8 { continue; }
  515.                         if thing == No {
  516.                             let clear = routeIsClear(x, (2, 0), (0, pos));
  517.                             if clear.0 {
  518.                                 let mut new_space = x.clone();
  519.                                 new_space.hallway[pos] = Yes(a);
  520.                                 new_space.room2[0] = No;
  521.                                 ret.push((new_space, clear.1 * amph_to_cost(&a)));
  522.                                 //println!("FOUND MOVE TYPE 14: ");
  523.                                 //println!("{}", new_space);
  524.                             }
  525.                         }
  526.                     }
  527.                 }
  528.             }
  529.             No => {}
  530.         }
  531.         match x.room3[0] {
  532.             Yes(a) => {
  533.                 if x.room3[1] != Yes(Copper) || (x.room3[1] == Yes(Copper) && Yes(a) != Yes(Copper))
  534.                 {
  535.                     for (pos, &thing) in x.hallway.iter().enumerate() {
  536.                         if pos == 2 || pos == 4 || pos == 6 || pos == 8 { continue; }
  537.                         if thing == No {
  538.                             let clear = routeIsClear(x, (3, 0), (0, pos));
  539.                             if clear.0 {
  540.                                 let mut new_space = x.clone();
  541.                                 new_space.hallway[pos] = Yes(a);
  542.                                 new_space.room3[0] = No;
  543.                                 ret.push((new_space, clear.1 * amph_to_cost(&a)));
  544.                                 //println!("FOUND MOVE TYPE 15: ");
  545.                                 //println!("{}", new_space);
  546.                             }
  547.                         }
  548.                     }
  549.                 }
  550.             }
  551.             No => {}
  552.         }
  553.         match x.room4[0] {
  554.             Yes(a) => {
  555.                 if x.room4[1] != Yes(Desert) || (x.room4[1] == Yes(Desert) && Yes(a) != Yes(Desert))
  556.                 {
  557.                     for (pos, &thing) in x.hallway.iter().enumerate() {
  558.                         if pos == 2 || pos == 4 || pos == 6 || pos == 8 { continue; }
  559.                         if thing == No {
  560.                             let clear = routeIsClear(x, (4, 0), (0, pos));
  561.                             if clear.0 {
  562.                                 let mut new_space = x.clone();
  563.                                 new_space.hallway[pos] = Yes(a);
  564.                                 new_space.room4[0] = No;
  565.                                 ret.push((new_space, clear.1 * amph_to_cost(&a)));
  566.                                 //println!("FOUND MOVE TYPE 16: ");
  567.                                 //println!("{}", new_space);
  568.                             }
  569.                         }
  570.                     }
  571.                 }
  572.             }
  573.             No => {}
  574.         }
  575.         // we don't need room to room movement all has to go through a hallway anyway
  576.  
  577.         ret
  578.     },
  579.                     |x| {
  580.                         let mut ret = 0;
  581.                         //min add all the hallway moves
  582.                         for (pos, Thing) in x.hallway.iter().enumerate() {
  583.                             match Thing {
  584.                                 Yes(a) => {ret += routeIsClear(x, (0, pos), (amph_to_room(a), 0)).1 * amph_to_cost(a)}
  585.                                 No => {}
  586.                             }
  587.                         }
  588.                         //add all the top moves
  589.                         match x.room1[0] {
  590.                             Yes(a) => {
  591.                                 if x.room1[1] != Yes(Amber) || (x.room1[1] == Yes(Amber) && Yes(a) != Yes(Amber))
  592.                                 {
  593.                                     let hallwayLoc = (0,3);
  594.                                     let finishLoc = (amph_to_room(&a), 0);
  595.                                     let spaces_to_move = routeIsClear(x, (1,0), hallwayLoc).1 + routeIsClear(x, hallwayLoc,finishLoc).1;
  596.                                     ret += spaces_to_move * amph_to_cost(&a)
  597.                                 }
  598.                             }
  599.                             No => {}
  600.                         }
  601.                         match x.room2[0] {
  602.                             Yes(a) => {
  603.                                 if x.room2[1] != Yes(Bronze) || (x.room2[1] == Yes(Bronze) && Yes(a) != Yes(Bronze))
  604.                                 {
  605.                                     let hallwayLoc = (0,if a == Amber { 3 } else { 5 } );
  606.                                     let finishLoc = (amph_to_room(&a), 0);
  607.                                     let spaces_to_move = routeIsClear(x, (2,0), hallwayLoc).1 + routeIsClear(x, hallwayLoc,finishLoc).1;
  608.                                     ret += spaces_to_move * amph_to_cost(&a)
  609.                                 }
  610.                             }
  611.                             No => {}
  612.                         }
  613.                         match x.room3[0] {
  614.                             Yes(a) => {
  615.                                 if x.room3[1] != Yes(Copper) || (x.room3[1] == Yes(Copper) && Yes(a) != Yes(Copper))
  616.                                 {
  617.                                     let hallwayLoc = (0,if a == Desert { 7 } else { 5 } );
  618.                                     let finishLoc = (amph_to_room(&a), 0);
  619.                                     let spaces_to_move = routeIsClear(x, (3,0), hallwayLoc).1 + routeIsClear(x, hallwayLoc,finishLoc).1;
  620.                                     ret += spaces_to_move * amph_to_cost(&a)
  621.                                 }
  622.                             }
  623.                             No => {}
  624.                         }
  625.                         match x.room4[0] {
  626.                             Yes(a) => {
  627.                                 if x.room4[1] != Yes(Desert) || (x.room4[1] == Yes(Desert) && Yes(a) != Yes(Desert))
  628.                                 {
  629.                                     let hallwayLoc = (0,7);
  630.                                     let finishLoc = (amph_to_room(&a), 0);
  631.                                     let spaces_to_move = routeIsClear(x, (4,0), hallwayLoc).1 + routeIsClear(x, hallwayLoc,finishLoc).1;
  632.                                     ret += spaces_to_move * amph_to_cost(&a)
  633.                                 }
  634.                             }
  635.                             No => {}
  636.                         }
  637.                         //add all the bottom moves
  638.                         match x.room1[1] {
  639.                             Yes(Amber) => {}
  640.                             Yes(a) => {
  641.                                 let hallwayLoc = (0,3);
  642.                                 let finishLoc = (amph_to_room(&a), 0);
  643.                                 let spaces_to_move = routeIsClear(x, (1,1), hallwayLoc).1 + routeIsClear(x, hallwayLoc,finishLoc).1;
  644.                                 ret += spaces_to_move * amph_to_cost(&a)
  645.                             }
  646.                             No => {}
  647.                         }
  648.                         match x.room2[1] {
  649.                             Yes(Bronze) => {}
  650.                             Yes(a) => {
  651.                                 let hallwayLoc = (0,if a == Amber { 3 } else { 5 } );
  652.                                 let finishLoc = (amph_to_room(&a), 0);
  653.                                 let spaces_to_move = routeIsClear(x, (2,1), hallwayLoc).1 + routeIsClear(x, hallwayLoc,finishLoc).1;
  654.                                 ret += spaces_to_move * amph_to_cost(&a)
  655.                             }
  656.                             No => {}
  657.                         }
  658.                         match x.room3[1] {
  659.                             Yes(Copper) => {}
  660.                             Yes(a) => {
  661.                                 let hallwayLoc = (0,if a == Desert { 7 } else { 5 } );
  662.                                 let finishLoc = (amph_to_room(&a), 0);
  663.                                 let spaces_to_move = routeIsClear(x, (3,1), hallwayLoc).1 + routeIsClear(x, hallwayLoc,finishLoc).1;
  664.                                 ret += spaces_to_move * amph_to_cost(&a)
  665.                             }
  666.                             No => {}
  667.                         }
  668.                         match x.room4[1] {
  669.                             Yes(Desert) => {}
  670.                             Yes(a) => {
  671.                                 let hallwayLoc = (0,3);
  672.                                 let finishLoc = (amph_to_room(&a), 0);
  673.                                 let spaces_to_move = routeIsClear(x, (4,1), hallwayLoc).1 + routeIsClear(x, hallwayLoc,finishLoc).1;
  674.                                 ret += spaces_to_move * amph_to_cost(&a)
  675.                             }
  676.                             No => {}
  677.                         }
  678.                         ret
  679.                     }
  680.                     ,
  681.                     |x| x.eq(&finState)).unwrap();
  682.     println!("ANS {}", res.1);
  683.     return;
  684. }
  685.  
  686.  
  687. fn amph_to_cost(a: &Amphipods) -> u16
  688. {
  689.     match a {
  690.         Amber => {AMBER_MOVE_COST}
  691.         Bronze => {BRONZE_MOVE_COST}
  692.         Copper => {COPPER_MOVE_COST}
  693.         Desert => {DESERT_MOVE_COST}
  694.     }
  695. }
  696.  
  697. fn amph_to_room(a: &Amphipods) -> usize
  698. {
  699.     match a {
  700.         Amber => {1}
  701.         Bronze => {2}
  702.         Copper => {3}
  703.         Desert => {4}
  704.     }
  705. }
  706.  
  707. fn amph_to_room_index(a: &Amphipods) -> usize
  708. {
  709.     match a {
  710.         Amber => {0}
  711.         Bronze => {1}
  712.         Copper => {2}
  713.         Desert => {3}
  714.     }
  715. }
  716.  
  717.  
  718. fn room_index_to_amph(index: usize) -> Amphipods
  719. {
  720.     match index {
  721.         0 => {Amber}
  722.         1 => {Bronze}
  723.         2 => {Copper}
  724.         3 => {Desert}
  725.         _ => {unreachable!()}
  726.     }
  727. }
  728.  
  729. ///will check if route from (start, end) (exclusive on both) so you must check if the end is clear,
  730. /// is clear of obstacles, and the amount of spaces moved
  731. /// start end are room and position where room 0 is the hallway.
  732. /// (0, x) means in hallway (1-4, x) means in rooms
  733. fn routeIsClear(space: &Space, start: (usize, usize), end: (usize, usize)) -> (bool, u16) {
  734.     let mut ret = (false, 0);
  735.     match (start, end) {
  736.         //hallway to rooms
  737.         //start 0,0
  738.         ((0, 0), (1, 0)) => {
  739.             if space.hallway[1] == No
  740.             {
  741.                 ret.0 = true;
  742.             }
  743.             ret.1 = 3;
  744.         }
  745.         ((0, 0), (1, 1)) => {
  746.             if space.hallway[1] == No &&
  747.                 space.room1[0] == No {
  748.                 ret.0 = true
  749.             }
  750.             ret.1 = 4;
  751.         }
  752.         ((0, 0), (2, 0)) => {
  753.             if space.hallway[1] == No && space.hallway[3] == No {
  754.                 ret.0 = true
  755.             }
  756.             ret.1 = 5;
  757.         }
  758.         ((0, 0), (2, 1)) => {
  759.             if space.hallway[1] == No && space.hallway[3] == No
  760.                 && space.room2[1] == No {
  761.                 ret.0 = true
  762.             }
  763.             ret.1 = 6;
  764.         }
  765.         ((0, 0), (3, 0)) => {
  766.             if space.hallway[1] == No && space.hallway[3] == No && space.hallway[5] == No {
  767.                 ret.0 = true
  768.             }
  769.             ret.1 = 7;
  770.         }
  771.         ((0, 0), (3, 1)) => {
  772.             if space.hallway[1] == No && space.hallway[3] == No && space.hallway[5] == No &&
  773.                 space.room3[0] == No {
  774.                 ret.0 = true
  775.             }
  776.             ret.1 = 8;
  777.         }
  778.         ((0, 0), (4, 0)) => {
  779.             if space.hallway[1] == No && space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No {
  780.                 ret.0 = true
  781.             }
  782.             ret.1 = 7;
  783.         }
  784.         ((0, 0), (4, 1)) => {
  785.             if space.hallway[1] == No && space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No &&
  786.                 space.room4[0] == No {
  787.                 ret.0 = true
  788.             }
  789.             ret.1 = 8;
  790.         }
  791.         //start 0,1
  792.         ((0, 1), (1, 0)) => {
  793.             ret = (true, 2)
  794.         }
  795.         ((0, 1), (1, 1)) => {
  796.             if
  797.             space.room1[0] == No {
  798.                 ret.0 = true
  799.             }
  800.             ret.1 = 3;
  801.         }
  802.         ((0, 1), (2, 0)) => {
  803.             if space.hallway[3] == No {
  804.                 ret.0 = true
  805.             }
  806.             ret.1 = 4;
  807.         }
  808.         ((0, 1), (2, 1)) => {
  809.             if space.hallway[3] == No &&
  810.                 space.room2[0] == No {
  811.                 ret.0 = true
  812.             }
  813.             ret.1 = 5;
  814.         }
  815.         ((0, 1), (3, 0)) => {
  816.             if space.hallway[3] == No && space.hallway[5] == No {
  817.                 ret.0 = true
  818.             }
  819.             ret.1 = 6;
  820.         }
  821.         ((0, 1), (3, 1)) => {
  822.             if space.hallway[3] == No && space.hallway[5] == No &&
  823.                 space.room3[0] == No {
  824.                 ret.0 = true
  825.             }
  826.             ret.1 = 7;
  827.         }
  828.         ((0, 1), (4, 0)) => {
  829.             if space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No {
  830.                 ret.0 = true
  831.             }
  832.             ret.1 = 8;
  833.         }
  834.         ((0, 1), (4, 1)) => {
  835.             if space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No &&
  836.                 space.room4[0] == No {
  837.                 ret.0 = true
  838.             }
  839.             ret.1 = 9;
  840.         }
  841.         //start 0,3
  842.         ((0, 3), (1, 0)) => {
  843.             ret = (true, 2)
  844.         }
  845.         ((0, 3), (1, 1)) => {
  846.             if
  847.             space.room1[0] == No {
  848.                 ret.0 = true
  849.             }
  850.             ret.1 = 3;
  851.         }
  852.         ((0, 3), (2, 0)) => {
  853.             ret = (true, 2)
  854.         }
  855.         ((0, 3), (2, 1)) => {
  856.             if
  857.             space.room2[0] == No {
  858.                 ret.0 = true
  859.             }
  860.             ret.1 = 3;
  861.         }
  862.         ((0, 3), (3, 0)) => {
  863.             if space.hallway[5] == No {
  864.                 ret.0 = true
  865.             }
  866.             ret.1 = 4;
  867.         }
  868.         ((0, 3), (3, 1)) => {
  869.             if space.hallway[5] == No &&
  870.                 space.room3[0] == No {
  871.                 ret.0 = true
  872.             }
  873.             ret.1 = 5;
  874.         }
  875.         ((0, 3), (4, 0)) => {
  876.             if space.hallway[5] == No && space.hallway[7] == No {
  877.                 ret.0 = true
  878.             }
  879.             ret.1 = 6;
  880.         }
  881.         ((0, 3), (4, 1)) => {
  882.             if space.hallway[5] == No && space.hallway[7] == No &&
  883.                 space.room4[0] == No {
  884.                 ret.0 = true
  885.             }
  886.             ret.1 = 7;
  887.         }
  888.         //start 0,5
  889.         ((0, 5), (1, 0)) => {
  890.             if space.hallway[3] == No {
  891.                 ret.0 = true
  892.             }
  893.             ret.1 = 4;
  894.         }
  895.         ((0, 5), (1, 1)) => {
  896.             if space.hallway[3] == No &&
  897.                 space.room1[0] == No {
  898.                 ret.0 = true
  899.             }
  900.             ret.1 = 5;
  901.         }
  902.         ((0, 5), (2, 0)) => {
  903.             ret = (true, 2)
  904.         }
  905.         ((0, 5), (2, 1)) => {
  906.             if
  907.             space.room2[0] == No {
  908.                 ret.0 = true
  909.             }
  910.             ret.1 = 3;
  911.         }
  912.         ((0, 5), (3, 0)) => {
  913.             ret = (true, 2)
  914.         }
  915.         ((0, 5), (3, 1)) => {
  916.             if
  917.             space.room3[0] == No {
  918.                 ret.0 = true
  919.             }
  920.             ret.1 = 3;
  921.         }
  922.         ((0, 5), (4, 0)) => {
  923.             if space.hallway[7] == No
  924.             {
  925.                 ret.0 = true
  926.             }
  927.             ret.1 = 4;
  928.         }
  929.         ((0, 5), (4, 1)) => {
  930.             if space.hallway[7] == No &&
  931.                 space.room4[0] == No {
  932.                 ret.0 = true
  933.             }
  934.             ret.1 = 5;
  935.         }
  936.         //start 0,7
  937.         ((0, 7), (1, 0)) => {
  938.             if space.hallway[3] == No && space.hallway[5] == No {
  939.                 ret.0 = true
  940.             }
  941.             ret.1 = 6;
  942.         }
  943.         ((0, 7), (1, 1)) => {
  944.             if space.hallway[3] == No && space.hallway[5] == No &&
  945.                 space.room1[0] == No {
  946.                 ret.0 = true
  947.             }
  948.             ret.1 = 7;
  949.         }
  950.         ((0, 7), (2, 0)) => {
  951.             if space.hallway[5] == No {
  952.                 ret.0 = true
  953.             }
  954.             ret.1 = 4;
  955.         }
  956.         ((0, 7), (2, 1)) => {
  957.             if space.hallway[5] == No &&
  958.                 space.room2[0] == No {
  959.                 ret.0 = true
  960.             }
  961.             ret.1 = 5;
  962.         }
  963.         ((0, 7), (3, 0)) => {
  964.             ret = (true, 2)
  965.         }
  966.         ((0, 7), (3, 1)) => {
  967.             if
  968.             space.room3[0] == No {
  969.                 ret.0 = true
  970.             }
  971.             ret.1 = 3;
  972.         }
  973.         ((0, 7), (4, 0)) => {
  974.             ret = (true, 2)
  975.         }
  976.         ((0, 7), (4, 1)) => {
  977.             if
  978.             space.room4[0] == No {
  979.                 ret.0 = true
  980.             }
  981.             ret.1 = 3;
  982.         }
  983.         //start 0,9
  984.         ((0, 9), (1, 0)) => {
  985.             if space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No
  986.             {
  987.                 ret.0 = true
  988.             }
  989.             ret.1 = 8;
  990.         }
  991.         ((0, 9), (1, 1)) => {
  992.             if space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No &&
  993.                 space.room1[0] == No {
  994.                 ret.0 = true
  995.             }
  996.             ret.1 = 9;
  997.         }
  998.         ((0, 9), (2, 0)) => {
  999.             if space.hallway[5] == No && space.hallway[7] == No
  1000.             {
  1001.                 ret.0 = true
  1002.             }
  1003.             ret.1 = 6;
  1004.         }
  1005.         ((0, 9), (2, 1)) => {
  1006.             if space.hallway[5] == No && space.hallway[7] == No &&
  1007.                 space.room2[0] == No {
  1008.                ret.0 = true
  1009.             }
  1010.             ret.1 = 7;
  1011.         }
  1012.         ((0, 9), (3, 0)) => {
  1013.             if space.hallway[7] == No
  1014.             {
  1015.                 ret.0 = true
  1016.             }
  1017.             ret.1 = 4;
  1018.         }
  1019.         ((0, 9), (3, 1)) => {
  1020.             if space.hallway[7] == No &&
  1021.                 space.room3[0] == No {
  1022.                 ret.0 = true
  1023.             }
  1024.             ret.1 = 5;
  1025.         }
  1026.         ((0, 9), (4, 0)) => {
  1027.             ret = (true, 2)
  1028.         }
  1029.         ((0, 9), (4, 1)) => {
  1030.             if
  1031.             space.room4[0] == No {
  1032.                 ret.0 = true
  1033.             }
  1034.             ret.1 = 3;
  1035.         }
  1036.         ((0, 10), a) => {
  1037.             let start09 = routeIsClear(space, (0, 9), a);
  1038.             ret = (start09.0 && space.hallway[9] == No, start09.1 + 1)
  1039.         }
  1040.         //room to hallway
  1041.         (a, b) => {
  1042.             //dbg!(a, b);
  1043.             ret = routeIsClear(space, b, a);
  1044.         }
  1045.     }
  1046.     ret
  1047. }
  1048.  
  1049. ///will check if route from (start, end) (exclusive on both) so you must check if the end is clear,
  1050. /// is clear of obstacles, and the amount of spaces moved
  1051. /// start end are room and position where room 0 is the hallway.
  1052. /// (0, x) means in hallway (1-4, x) means in rooms
  1053. fn routeIsClear2(space: &Space2, start: (usize, usize), end: (usize, usize)) -> (bool, u16) {
  1054.     let mut ret = (false, 0);
  1055.     //dbg!(start, end);
  1056.     match (start, end) {
  1057.         //hallway to rooms
  1058.         //start 0,0
  1059.         ((0, 0), (1, 0)) => {
  1060.             if space.hallway[1] == No
  1061.             {
  1062.                 ret.0 = true;
  1063.             }
  1064.             ret.1 = 3;
  1065.         }
  1066.         ((0, 0), (1, 1)) => {
  1067.             if space.hallway[1] == No &&
  1068.                 space.rooms[0][0] == No {
  1069.                 ret.0 = true
  1070.             }
  1071.             ret.1 = 4;
  1072.         }
  1073.         ((0, 0), (2, 0)) => {
  1074.             if space.hallway[1] == No && space.hallway[3] == No {
  1075.                 ret.0 = true
  1076.             }
  1077.             ret.1 = 5;
  1078.         }
  1079.         ((0, 0), (2, 1)) => {
  1080.             if space.hallway[1] == No && space.hallway[3] == No
  1081.                 && space.rooms[1][1] == No {
  1082.                 ret.0 = true
  1083.             }
  1084.             ret.1 = 6;
  1085.         }
  1086.         ((0, 0), (3, 0)) => {
  1087.             if space.hallway[1] == No && space.hallway[3] == No && space.hallway[5] == No {
  1088.                 ret.0 = true
  1089.             }
  1090.             ret.1 = 7;
  1091.         }
  1092.         ((0, 0), (3, 1)) => {
  1093.             if space.hallway[1] == No && space.hallway[3] == No && space.hallway[5] == No &&
  1094.                 space.rooms[2][0] == No {
  1095.                 ret.0 = true
  1096.             }
  1097.             ret.1 = 8;
  1098.         }
  1099.         ((0, 0), (4, 0)) => {
  1100.             if space.hallway[1] == No && space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No {
  1101.                 ret.0 = true
  1102.             }
  1103.             ret.1 = 7;
  1104.         }
  1105.         ((0, 0), (4, 1)) => {
  1106.             if space.hallway[1] == No && space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No &&
  1107.                 space.rooms[3][0] == No {
  1108.                 ret.0 = true
  1109.             }
  1110.             ret.1 = 8;
  1111.         }
  1112.         //start 0,1
  1113.         ((0, 1), (1, 0)) => {
  1114.             ret = (true, 2)
  1115.         }
  1116.         ((0, 1), (1, 1)) => {
  1117.             if
  1118.             space.rooms[0][0] == No {
  1119.                 ret.0 = true
  1120.             }
  1121.             ret.1 = 3;
  1122.         }
  1123.         ((0, 1), (2, 0)) => {
  1124.             if space.hallway[3] == No {
  1125.                 ret.0 = true
  1126.             }
  1127.             ret.1 = 4;
  1128.         }
  1129.         ((0, 1), (2, 1)) => {
  1130.             if space.hallway[3] == No &&
  1131.                 space.rooms[1][0] == No {
  1132.                 ret.0 = true
  1133.             }
  1134.             ret.1 = 5;
  1135.         }
  1136.         ((0, 1), (3, 0)) => {
  1137.             if space.hallway[3] == No && space.hallway[5] == No {
  1138.                 ret.0 = true
  1139.             }
  1140.             ret.1 = 6;
  1141.         }
  1142.         ((0, 1), (3, 1)) => {
  1143.             if space.hallway[3] == No && space.hallway[5] == No &&
  1144.                 space.rooms[2][0] == No {
  1145.                 ret.0 = true
  1146.             }
  1147.             ret.1 = 7;
  1148.         }
  1149.         ((0, 1), (4, 0)) => {
  1150.             if space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No {
  1151.                 ret.0 = true
  1152.             }
  1153.             ret.1 = 8;
  1154.         }
  1155.         ((0, 1), (4, 1)) => {
  1156.             if space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No &&
  1157.                 space.rooms[3][0] == No {
  1158.                 ret.0 = true
  1159.             }
  1160.             ret.1 = 9;
  1161.         }
  1162.         //start 0,3
  1163.         ((0, 3), (1, 0)) => {
  1164.             ret = (true, 2)
  1165.         }
  1166.         ((0, 3), (1, 1)) => {
  1167.             if
  1168.             space.rooms[0][0] == No {
  1169.                 ret.0 = true
  1170.             }
  1171.             ret.1 = 3;
  1172.         }
  1173.         ((0, 3), (2, 0)) => {
  1174.             ret = (true, 2)
  1175.         }
  1176.         ((0, 3), (2, 1)) => {
  1177.             if
  1178.             space.rooms[1][0] == No {
  1179.                 ret.0 = true
  1180.             }
  1181.             ret.1 = 3;
  1182.         }
  1183.         ((0, 3), (3, 0)) => {
  1184.             if space.hallway[5] == No {
  1185.                 ret.0 = true
  1186.             }
  1187.             ret.1 = 4;
  1188.         }
  1189.         ((0, 3), (3, 1)) => {
  1190.             if space.hallway[5] == No &&
  1191.                 space.rooms[2][0] == No {
  1192.                 ret.0 = true
  1193.             }
  1194.             ret.1 = 5;
  1195.         }
  1196.         ((0, 3), (4, 0)) => {
  1197.             if space.hallway[5] == No && space.hallway[7] == No {
  1198.                 ret.0 = true
  1199.             }
  1200.             ret.1 = 6;
  1201.         }
  1202.         ((0, 3), (4, 1)) => {
  1203.             if space.hallway[5] == No && space.hallway[7] == No &&
  1204.                 space.rooms[3][0] == No {
  1205.                 ret.0 = true
  1206.             }
  1207.             ret.1 = 7;
  1208.         }
  1209.         //start 0,5
  1210.         ((0, 5), (1, 0)) => {
  1211.             if space.hallway[3] == No {
  1212.                 ret.0 = true
  1213.             }
  1214.             ret.1 = 4;
  1215.         }
  1216.         ((0, 5), (1, 1)) => {
  1217.             if space.hallway[3] == No &&
  1218.                 space.rooms[0][0] == No {
  1219.                 ret.0 = true
  1220.             }
  1221.             ret.1 = 5;
  1222.         }
  1223.         ((0, 5), (2, 0)) => {
  1224.             ret = (true, 2)
  1225.         }
  1226.         ((0, 5), (2, 1)) => {
  1227.             if
  1228.             space.rooms[1][0] == No {
  1229.                 ret.0 = true
  1230.             }
  1231.             ret.1 = 3;
  1232.         }
  1233.         ((0, 5), (3, 0)) => {
  1234.             ret = (true, 2)
  1235.         }
  1236.         ((0, 5), (3, 1)) => {
  1237.             if
  1238.             space.rooms[2][0] == No {
  1239.                 ret.0 = true
  1240.             }
  1241.             ret.1 = 3;
  1242.         }
  1243.         ((0, 5), (4, 0)) => {
  1244.             if space.hallway[7] == No
  1245.             {
  1246.                 ret.0 = true
  1247.             }
  1248.             ret.1 = 4;
  1249.         }
  1250.         ((0, 5), (4, 1)) => {
  1251.             if space.hallway[7] == No &&
  1252.                 space.rooms[3][0] == No {
  1253.                 ret.0 = true
  1254.             }
  1255.             ret.1 = 5;
  1256.         }
  1257.         //start 0,7
  1258.         ((0, 7), (1, 0)) => {
  1259.             if space.hallway[3] == No && space.hallway[5] == No {
  1260.                 ret.0 = true
  1261.             }
  1262.             ret.1 = 6;
  1263.         }
  1264.         ((0, 7), (1, 1)) => {
  1265.             if space.hallway[3] == No && space.hallway[5] == No &&
  1266.                 space.rooms[0][0] == No {
  1267.                 ret.0 = true
  1268.             }
  1269.             ret.1 = 7;
  1270.         }
  1271.         ((0, 7), (2, 0)) => {
  1272.             if space.hallway[5] == No {
  1273.                 ret.0 = true
  1274.             }
  1275.             ret.1 = 4;
  1276.         }
  1277.         ((0, 7), (2, 1)) => {
  1278.             if space.hallway[5] == No &&
  1279.                 space.rooms[1][0] == No {
  1280.                 ret.0 = true
  1281.             }
  1282.             ret.1 = 5;
  1283.         }
  1284.         ((0, 7), (3, 0)) => {
  1285.             ret = (true, 2)
  1286.         }
  1287.         ((0, 7), (3, 1)) => {
  1288.             if
  1289.             space.rooms[2][0] == No {
  1290.                 ret.0 = true
  1291.             }
  1292.             ret.1 = 3;
  1293.         }
  1294.         ((0, 7), (4, 0)) => {
  1295.             ret = (true, 2)
  1296.         }
  1297.         ((0, 7), (4, 1)) => {
  1298.             if
  1299.             space.rooms[3][0] == No {
  1300.                 ret.0 = true
  1301.             }
  1302.             ret.1 = 3;
  1303.         }
  1304.         //start 0,9
  1305.         ((0, 9), (1, 0)) => {
  1306.             if space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No
  1307.             {
  1308.                 ret.0 = true
  1309.             }
  1310.             ret.1 = 8;
  1311.         }
  1312.         ((0, 9), (1, 1)) => {
  1313.             if space.hallway[3] == No && space.hallway[5] == No && space.hallway[7] == No &&
  1314.                 space.rooms[0][0] == No {
  1315.                 ret.0 = true
  1316.             }
  1317.             ret.1 = 9;
  1318.         }
  1319.         ((0, 9), (2, 0)) => {
  1320.             if space.hallway[5] == No && space.hallway[7] == No
  1321.             {
  1322.                 ret.0 = true
  1323.             }
  1324.             ret.1 = 6;
  1325.         }
  1326.         ((0, 9), (2, 1)) => {
  1327.             if space.hallway[5] == No && space.hallway[7] == No &&
  1328.                 space.rooms[1][0] == No {
  1329.                ret.0 = true
  1330.             }
  1331.             ret.1 = 7;
  1332.         }
  1333.         ((0, 9), (3, 0)) => {
  1334.             if space.hallway[7] == No
  1335.             {
  1336.                 ret.0 = true
  1337.             }
  1338.             ret.1 = 4;
  1339.         }
  1340.         ((0, 9), (3, 1)) => {
  1341.             if space.hallway[7] == No &&
  1342.                 space.rooms[2][0] == No {
  1343.                 ret.0 = true
  1344.             }
  1345.             ret.1 = 5;
  1346.         }
  1347.         ((0, 9), (4, 0)) => {
  1348.             ret = (true, 2)
  1349.         }
  1350.         ((0, 9), (4, 1)) => {
  1351.             if
  1352.             space.rooms[3][0] == No {
  1353.                 ret.0 = true
  1354.             }
  1355.             ret.1 = 3;
  1356.         }
  1357.         ((0, 10), a) => {
  1358.             let start09 = routeIsClear2(space, (0, 9), a);
  1359.             ret = (start09.0 && space.hallway[9] == No, start09.1 + 1)
  1360.         }
  1361.         //room to hallway
  1362.         (a, b) => {
  1363.             //dbg!(a, b);
  1364.             ret = routeIsClear2(space, b, a);
  1365.         }
  1366.     }
  1367.     ret
  1368. }
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement