vendredi 24 juin 2016

Counting rooms while knowing where walls are.using C++ builder 6

The txt file which also represents the data I have in an array: 1101 0110 1101 0110 1100 0101 0110 1110 1001 0110 1011 1010 1111 1010 1000 0101 0011 1110 1011 1110 1010 1011 1101 0101 0001 0101 0011 1011 Explanation of the txt: The numbers from the txt file are a 4-bit representation of the walls to a room, with a set bit representing a wall. The wall bits are in clockwise order starting with the most significant bit being the West wall. For example, 1101 represents a room where: The set bit in the most significant position indicates a wall to the West The set bit in the next most significant position indicates a wall to the North The unset bit indicates no wall to the East The set bit in the least significant position indicates a wall to the South Given: The exterior walls of rooms will always have a wall Interior walls will always be expressed in both rooms (in the example since the room at (1, 1) is 1101 it contains a wall to the South, the room at (1, 2) 1110 must contain a wall to the North There will never be more than numeric_limits<int>::max() rooms I was asked to post my code so here it is: I've tried to solve this but I'm getting an EAAccessviolation can someone tell me what I'm doing wrong? int rn=0,z=0, global=0,coord[15],c[411],b1[411]; void peruse ( int i, int j,int* bb) { bool top=false,bottom=false,right=false,left=false; //truth checks if (bb[i*m+j]<1000) left=true; if (bb[i*m+j]<100) top=true; else if (bb[i*m+j]-1000<100) top=true; if (bb[i*m+j]<10) right=true; else if ( (bb[i*m+j]-100<10) || (bb[i*m+j]-1000<10) || (bb[i*m+j]-100<10) ) right=true; if (bb[i*m+j]<1) bottom=true; else if ( (bb[i*m+j]-10<1) || (bb[i*m+j]-100<1) || (bb[i*m+j]-1000<1) ||(bb[i*m+j]-100<1)) bottom=true; //marc if (left) { c[i*m+j]=c[i*m+j]+1000; // EAaccessViolation i dont know why..... peruse(i,j-1,c); } if (top) { c[i*m+j]=c[i*m+j]+100; peruse(i-1,j,c); } if (right) { c[i*m+j]=c[i*m+j]+10; peruse(i,j+1,c); } if (bottom) { c[i*m+j]=c[i*m+j]+1; peruse(i+1,i,c); } if ( !(left) && !(top) && !(right) && !(bottom) ) { bb[411]++; } } void __fastcall TForm1::Button7Click(TObject *Sender) { b1[411]=0; for(int i=0;i<n;i++) for (int j=0;j<m;j++) { b1[i*m+j]=b[i][j]; c[i*m+j]=b[i][j]; } peruse (1,1,b1); ShowMessage("Nr. "+IntToStr(b1[411]) ); } See comments for additional Bounty requirements

Aucun commentaire:

Enregistrer un commentaire