Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <cmath>
  5. using namespace std;
  6.  
  7. #define bitColor 10
  8. #define size 16
  9. // 2^4=16, 2^5 = 32,
  10.  
  11. struct pala
  12. {
  13.     int colors[4];
  14. };
  15.  
  16. vector<pala> palat;
  17.  
  18. // xx00000001 xx00000010 xx00000100, xx = rotate
  19. void set_piece(vector<bool> &taulu, int index, const int input)
  20. {
  21.     index*=bitColor;
  22.     for(int i = bitColor-2 - 1; i >= 0; --i)
  23.     {
  24.         if(input & (1 << i))
  25.             taulu[2+index++]=1;
  26.         else
  27.             taulu[2+index++]=0;
  28.     }
  29. }
  30. int read_piece(vector<bool> &taulu, int index)
  31. {
  32.     index*=bitColor;
  33.     int number = 0;
  34.     for(int i = 2; i<bitColor; ++i)
  35.         number=(number<<1)|taulu[index+i];
  36.     return number;
  37. }
  38. void set_rotate(vector<bool> &taulu, int index, const int input)
  39. {
  40.     index*=bitColor;
  41.     taulu[index]=taulu[index+1]=0;
  42.     if (input == 1) taulu[index+1]=1;
  43.     else if (input == 2) taulu[index]=1;
  44.     else if (input == 3) taulu[index]=taulu[index+1]=1;
  45. }
  46. int read_rotate(vector<bool> &taulu, int index)
  47. {
  48.     index*=bitColor;
  49.     return (taulu[index]<<1)|taulu[index+1];
  50.     return taulu[index]*2+taulu[index+1];
  51. }
  52.  
  53. enum {UP,RIGHT,DOWN,LEFT};
  54. int read_piece_color(int index, int angle, int direction)
  55. {
  56.     return palat[index].colors[(angle+direction)%4];
  57. }
  58.  
  59. bool fitpiece(vector<bool> &taulu, int index)
  60. {
  61.     const int y = index/size;
  62.     const int x = index%size;
  63.     const int piece = read_piece(taulu,index);
  64.     const int pieceR = read_rotate(taulu,index);
  65.  
  66.     if (x==0 && read_piece_color(index,pieceR,LEFT) != 0) return false;
  67.     if (y==0 && read_piece_color(index,pieceR,UP) != 0) return false;
  68.     if (x==size-1 && read_piece_color(index,pieceR,RIGHT) != 0) return false;
  69.     if (y==size-1 && read_piece_color(index,pieceR,DOWN) != 0) return false;
  70.  
  71.     //vasen
  72.     if (x>0 && read_piece_color(index,pieceR,LEFT)
  73.         != read_piece_color(read_piece(taulu,index-1),read_rotate(taulu,index-1),RIGHT))
  74.         return false;
  75.     // oikea
  76.     if (x<size-1 && read_piece_color(index,pieceR,RIGHT)
  77.         != read_piece_color(read_piece(taulu,index+1),read_rotate(taulu,index+1),LEFT))
  78.         return false;
  79.     // ylös
  80.     if (y>0 && read_piece_color(index,pieceR,UP)
  81.         != read_piece_color(read_piece(taulu,index-size),read_rotate(taulu,index-size),DOWN))
  82.         return false;
  83.     // alas
  84.     if (y<size-1 && read_piece_color(index,pieceR,DOWN)
  85.         != read_piece_color(read_piece(taulu,index+size),read_rotate(taulu,index+size),UP))
  86.         return false;
  87.  
  88.     return true;
  89. }
  90.  
  91. void show(vector<bool> &taulu)
  92. {
  93.     char output[size*3][size*3];
  94.     for (int y=0; y<size*3; y++)
  95.         for (int x=0; x<size*3; x++)
  96.             output[y][x]=' ';
  97.  
  98.     for (int y=0; y<size; y++)
  99.     {
  100.         for (int x=0; x<size; x++)
  101.         {
  102.             const int piece = read_piece(taulu,y*size+x);
  103.             const int angle = read_rotate(taulu,y*size+x);
  104.             output[y*3][x*3+1]  ='A'+ read_piece_color(piece,angle,UP);
  105.             output[y*3+1][x*3+2]='A'+ read_piece_color(piece,angle,RIGHT);
  106.             output[y*3+2][x*3+1]='A'+ read_piece_color(piece,angle,DOWN);
  107.             output[y*3+1][x*3]  ='A'+ read_piece_color(piece,angle,LEFT);
  108.         }
  109.     }
  110.     for (int y=0; y<size*3; y++)
  111.     {
  112.         for (int x=0; x<size*3; x++)
  113.             cout << (char)output[y][x];
  114.         cout << endl;
  115.     }
  116. }
  117.  
  118. int rekursio(vector<bool> &taulu, int loc)
  119. {
  120.  
  121. }
  122.  
  123.  
  124. int main()
  125. {
  126.     vector<bool> pala_id(bitColor*256);
  127.     //set_piece(pala_id,0,255); set_rotate(pala_id,0,3); set_piece(pala_id,0,255);
  128.  
  129.  
  130.     int lkm=0, color=0;
  131.     ifstream lue("eternity.in");
  132.     lue >> lkm;
  133.     for (int i=0; i<lkm*lkm; i++)
  134.     {
  135.         int a, b, c, d;
  136.         lue >> a >> b >> c >> d;
  137.         pala p={{a,b,c,d}};
  138.         palat.push_back(p);
  139.     }
  140.  
  141.     for (int i=0; i<256-1; i++)
  142.         set_piece(pala_id,i+1,i);
  143.     set_piece(pala_id,0,0);
  144.  
  145.     show(pala_id);cout << endl;
  146.  
  147.     for (int y=0; y<size; y++)
  148.     for (int x=0; x<size; x++)
  149.         if (!fitpiece(pala_id,y*size+x))
  150.             set_piece(pala_id,y*size+x,0);
  151.     show(pala_id);
  152.  
  153.     //cout << (char)('A'+read_piece_color(0,0,0)) << endl; set_rotate(pala_id,0,1); cout << endl;show(pala_id);cout << (char)('A'+read_piece_color(0,0,0)) << endl;
  154.  
  155.  
  156.     cout << read_piece(pala_id,0) << endl;
  157.     cout << read_rotate(pala_id,0) << endl;
  158.  
  159.     for (int i=0; i<50; i++)
  160.         cout << pala_id[i];
  161.         cout << endl;
  162.  
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement