Advertisement
Guest User

AoC DAy 23

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