Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <cmath>
- using namespace std;
- #define bitColor 10
- #define size 16
- // 2^4=16, 2^5 = 32,
- struct pala
- {
- int colors[4];
- };
- vector<pala> palat;
- // xx00000001 xx00000010 xx00000100, xx = rotate
- void set_piece(vector<bool> &taulu, int index, const int input)
- {
- index*=bitColor;
- for(int i = bitColor-2 - 1; i >= 0; --i)
- {
- if(input & (1 << i))
- taulu[2+index++]=1;
- else
- taulu[2+index++]=0;
- }
- }
- int read_piece(vector<bool> &taulu, int index)
- {
- index*=bitColor;
- int number = 0;
- for(int i = 2; i<bitColor; ++i)
- number=(number<<1)|taulu[index+i];
- return number;
- }
- void set_rotate(vector<bool> &taulu, int index, const int input)
- {
- index*=bitColor;
- taulu[index]=taulu[index+1]=0;
- if (input == 1) taulu[index+1]=1;
- else if (input == 2) taulu[index]=1;
- else if (input == 3) taulu[index]=taulu[index+1]=1;
- }
- int read_rotate(vector<bool> &taulu, int index)
- {
- index*=bitColor;
- return (taulu[index]<<1)|taulu[index+1];
- return taulu[index]*2+taulu[index+1];
- }
- enum {UP,RIGHT,DOWN,LEFT};
- int read_piece_color(int index, int angle, int direction)
- {
- return palat[index].colors[(angle+direction)%4];
- }
- bool fitpiece(vector<bool> &taulu, int index)
- {
- const int y = index/size;
- const int x = index%size;
- const int piece = read_piece(taulu,index);
- const int pieceR = read_rotate(taulu,index);
- if (x==0 && read_piece_color(index,pieceR,LEFT) != 0) return false;
- if (y==0 && read_piece_color(index,pieceR,UP) != 0) return false;
- if (x==size-1 && read_piece_color(index,pieceR,RIGHT) != 0) return false;
- if (y==size-1 && read_piece_color(index,pieceR,DOWN) != 0) return false;
- //vasen
- if (x>0 && read_piece_color(index,pieceR,LEFT)
- != read_piece_color(read_piece(taulu,index-1),read_rotate(taulu,index-1),RIGHT))
- return false;
- // oikea
- if (x<size-1 && read_piece_color(index,pieceR,RIGHT)
- != read_piece_color(read_piece(taulu,index+1),read_rotate(taulu,index+1),LEFT))
- return false;
- // ylös
- if (y>0 && read_piece_color(index,pieceR,UP)
- != read_piece_color(read_piece(taulu,index-size),read_rotate(taulu,index-size),DOWN))
- return false;
- // alas
- if (y<size-1 && read_piece_color(index,pieceR,DOWN)
- != read_piece_color(read_piece(taulu,index+size),read_rotate(taulu,index+size),UP))
- return false;
- return true;
- }
- void show(vector<bool> &taulu)
- {
- char output[size*3][size*3];
- for (int y=0; y<size*3; y++)
- for (int x=0; x<size*3; x++)
- output[y][x]=' ';
- for (int y=0; y<size; y++)
- {
- for (int x=0; x<size; x++)
- {
- const int piece = read_piece(taulu,y*size+x);
- const int angle = read_rotate(taulu,y*size+x);
- output[y*3][x*3+1] ='A'+ read_piece_color(piece,angle,UP);
- output[y*3+1][x*3+2]='A'+ read_piece_color(piece,angle,RIGHT);
- output[y*3+2][x*3+1]='A'+ read_piece_color(piece,angle,DOWN);
- output[y*3+1][x*3] ='A'+ read_piece_color(piece,angle,LEFT);
- }
- }
- for (int y=0; y<size*3; y++)
- {
- for (int x=0; x<size*3; x++)
- cout << (char)output[y][x];
- cout << endl;
- }
- }
- int rekursio(vector<bool> &taulu, int loc)
- {
- }
- int main()
- {
- vector<bool> pala_id(bitColor*256);
- //set_piece(pala_id,0,255); set_rotate(pala_id,0,3); set_piece(pala_id,0,255);
- int lkm=0, color=0;
- ifstream lue("eternity.in");
- lue >> lkm;
- for (int i=0; i<lkm*lkm; i++)
- {
- int a, b, c, d;
- lue >> a >> b >> c >> d;
- pala p={{a,b,c,d}};
- palat.push_back(p);
- }
- for (int i=0; i<256-1; i++)
- set_piece(pala_id,i+1,i);
- set_piece(pala_id,0,0);
- show(pala_id);cout << endl;
- for (int y=0; y<size; y++)
- for (int x=0; x<size; x++)
- if (!fitpiece(pala_id,y*size+x))
- set_piece(pala_id,y*size+x,0);
- show(pala_id);
- //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;
- cout << read_piece(pala_id,0) << endl;
- cout << read_rotate(pala_id,0) << endl;
- for (int i=0; i<50; i++)
- cout << pala_id[i];
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement