Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void the_big_to_the_first(int &n1, int &n2){
- if(n1<n2){
- int tmp = n1;
- n1 = n2;
- n2 = tmp;
- }
- }
- class HomeArray{
- public:
- int arr[9];
- void set(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9){
- arr[0] = n1;
- arr[1] = n2;
- arr[2] = n3;
- arr[3] = n4;
- arr[4] = n5;
- arr[5] = n6;
- arr[6] = n7;
- arr[7] = n8;
- arr[8] = n9;
- }
- void show(){
- for (int i=0; i<9; i++) cout<<arr[i]<<" ";
- cout<<"\n";
- }
- void show_full(){
- }
- bool is_it_legal(){
- for (int i=0; i<8; i++){
- if(arr[i]==arr[i+1]) return false;
- switch (arr[i]){
- case 0: if(arr[i+1]!=1 && arr[i+1]!=2){ return false;} break;
- case 3: if(arr[i+1]==0){ return false;} break;
- case 4: if(arr[i+1]==0){ return false;} break;
- }
- // עד כאן ווידאנו שיש קווים בצורה של הבית בלבד
- // מכאן מתחילנ בדיקה שאין שני מקלות זהים
- int an1 = arr[i], an2 = arr[i+1];
- the_big_to_the_first(an1, an2);
- // עד כאן המספר הגדול מבניהם נמצא במשתנה 1 והקטן במשתנה 2
- int ab1, ab2;
- for(int j=i+1; j<8; j++){
- ab1 = arr[j], ab2 = arr[j+1];
- the_big_to_the_first(ab1, ab2);
- if(ab1==an1 && ab2==an2) return false;
- }
- // עד כאן הבדיקה
- }
- return true;
- }
- };
- void main(){
- cout<<"\n 0\n * *\n * *\n1*****2\n* *\n* *\n3*****4\n\n\n";
- cout<<"\n 0\n * *\n * *\n1*****2\n** **\n* * * *\n* * *\n* * * *\n** **\n3*****4\n";
- HomeArray HM[200], htmp;
- int ind=0;
- int i1, i2, i3, i4, i5, i6, i7, i8, i9;
- for(i1=0; i1<5; i1++){
- for(i2=0; i2<5; i2++)
- for(i3=0; i3<5; i3++)
- for(i4=0; i4<5; i4++)
- for(i5=0; i5<5; i5++)
- for(i6=0; i6<5; i6++)
- for(i7=0; i7<5; i7++)
- for(i8=0; i8<5; i8++)
- for(i9=0; i9<5; i9++){
- htmp.set(i1, i2, i3, i4, i5, i6, i7, i8, i9);
- if (htmp.is_it_legal() == true){
- HM[ind] = htmp;
- ind ++;
- }
- }
- }
- cout<<"\nThis program checks for all possible solutions to the game.\nFound: "<<ind<<"\n\n";
- for(int i=0; i<ind; i++){
- if(i<9)cout<<" ";
- cout<<i+1<<"@ ";
- HM[i].show();
- }
- cout<<"\n -END-\n\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment