Advertisement
Faschz

Mario Party 1 - Pipe Maze Simulator

Sep 3rd, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. #define MAZE_HEIGHT 14
  6. #define PLAYER 1
  7.  
  8. using namespace std;
  9.  
  10. bool check(long long);
  11. int solve(long long);
  12. void print(long long);
  13.  
  14. int main(){
  15.     //A maze can be thought of as a 14-digit number in base 5
  16.     //Each digit represents a layer in the pipe maze
  17.     //0 means no pipes in that layer
  18.     //1, 2, or 3 means 1 pipe in that layer either left, middle, or right respectively
  19.     //4 means 2 pipes in that layer, on the left and right
  20.    
  21.     long long maze = 0;
  22.     long long max = pow(5, MAZE_HEIGHT);
  23.    
  24.     long long sum = 0;
  25.     long long solution[] = {0, 0, 0, 0};
  26.     while(maze < max){
  27.         if(check(maze)){
  28.             sum++;
  29.             solution[solve(maze) - 1]++;
  30.             //print(maze);
  31.         }
  32.         maze++;
  33.     }
  34.    
  35.     cout << "Found: " << sum << endl;
  36.     cout << "1: " << solution[0] << endl;
  37.     cout << "2: " << solution[1] << endl;
  38.     cout << "3: " << solution[2] << endl;
  39.     cout << "4: " << solution[3] << endl;
  40.    
  41.     //system("PAUSE");
  42.     return 0;
  43. }
  44.  
  45. bool check(long long maze){
  46.     int pipes = 0;
  47.    
  48.     //Check for a valid number of pipes
  49.     while(maze > 0){
  50.         int layer = maze%5;
  51.        
  52.         if(layer == 4){ //Left and Right pipes
  53.             pipes += 2;
  54.         }
  55.         else if(layer > 0){ //Left, Right, or Middle pipes
  56.             pipes++;
  57.         }
  58.        
  59.         //Remove the layer
  60.         maze = maze/5;
  61.     }
  62.    
  63.     if(pipes == 12){
  64.         return true;
  65.     }
  66.     else{
  67.         return false;
  68.     }
  69. }
  70.  
  71. int solve(long long maze){
  72.     //Starting location
  73.     int location = PLAYER;
  74.    
  75.     while(maze > 0){
  76.         int layer = maze%5;
  77.         switch(location){
  78.             case 1: if(layer == 1 | layer == 4){
  79.                         location = 2;
  80.                     }
  81.                     break;
  82.  
  83.             case 2: if(layer == 1 | layer == 4){
  84.                         location = 1;
  85.                     }
  86.                     else if(layer == 2){
  87.                         location = 3;
  88.                     }
  89.                     break;
  90.                    
  91.             case 3: if(layer == 2){
  92.                         location = 2;
  93.                     }
  94.                     else if(layer == 3 | layer == 4){
  95.                         location = 4;
  96.                     }
  97.                     break;
  98.                    
  99.             case 4: if(layer == 3 | layer == 4){
  100.                         location = 3;
  101.                     }
  102.                     break;
  103.         }
  104.         maze = maze/5;
  105.     }
  106.     return location;
  107. }
  108.  
  109. void print(long long maze){
  110.     while(maze > 0){
  111.         int layer = maze%5;
  112.         switch(layer){
  113.             case 0: cout << "| | | |" << endl;
  114.                     break;
  115.                    
  116.             case 1: cout << "|-| | |" << endl;
  117.                     break;
  118.                    
  119.             case 2: cout << "| |-| |" << endl;
  120.                     break;
  121.                    
  122.             case 3: cout << "| | |-|" << endl;
  123.                     break;
  124.                    
  125.             case 4: cout << "|-| |-|" << endl;
  126.                     break;
  127.         }
  128.         maze = maze/5;
  129.     }
  130.     cout << endl;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement