Click here to Skip to main content
15,915,076 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Calculate checksum using ASLR Pin
Giggsey738-Jun-12 8:34
Giggsey738-Jun-12 8:34 
GeneralRe: Calculate checksum using ASLR Pin
Randor 8-Jun-12 9:48
professional Randor 8-Jun-12 9:48 
GeneralRe: Calculate checksum using ASLR Pin
Giggsey738-Jun-12 18:48
Giggsey738-Jun-12 18:48 
GeneralRe: Calculate checksum using ASLR Pin
Randor 9-Jun-12 4:36
professional Randor 9-Jun-12 4:36 
GeneralRe: Calculate checksum using ASLR Pin
Giggsey739-Jun-12 4:52
Giggsey739-Jun-12 4:52 
GeneralRe: Calculate checksum using ASLR Pin
Randor 9-Jun-12 5:28
professional Randor 9-Jun-12 5:28 
GeneralRe: Calculate checksum using ASLR Pin
Giggsey739-Jun-12 6:51
Giggsey739-Jun-12 6:51 
QuestionRe: Calculate checksum using ASLR Pin
Randor 9-Jun-12 7:04
professional Randor 9-Jun-12 7:04 
QuestionC++ Program without main() Pin
pix_programmer6-Jun-12 22:45
pix_programmer6-Jun-12 22:45 
AnswerRe: C++ Program without main() Pin
Richard MacCutchan6-Jun-12 23:22
mveRichard MacCutchan6-Jun-12 23:22 
GeneralRe: C++ Program without main() Pin
pix_programmer7-Jun-12 0:33
pix_programmer7-Jun-12 0:33 
GeneralRe: C++ Program without main() Pin
Richard MacCutchan7-Jun-12 4:53
mveRichard MacCutchan7-Jun-12 4:53 
AnswerRe: C++ Program without main() Pin
Aescleal7-Jun-12 0:12
Aescleal7-Jun-12 0:12 
GeneralRe: C++ Program without main() Pin
Aescleal13-Jun-12 16:50
Aescleal13-Jun-12 16:50 
QuestionDump analysis Pin
HungryCPPDev6-Jun-12 21:22
HungryCPPDev6-Jun-12 21:22 
AnswerRe: Dump analysis Pin
«_Superman_»6-Jun-12 22:23
professional«_Superman_»6-Jun-12 22:23 
GeneralRe: Dump analysis Pin
HungryCPPDev11-Jun-12 20:23
HungryCPPDev11-Jun-12 20:23 
AnswerRe: Dump analysis Pin
Erudite_Eric6-Jun-12 22:32
Erudite_Eric6-Jun-12 22:32 
QuestionWhat's problem of my code?( create a random maze) Pin
jiuyejii6-Jun-12 0:45
jiuyejii6-Jun-12 0:45 
C++
#include <iostream>
#include <stdlib.h>
#include<ctime>
using namespace std;

void makebg(char**&);

bool Is(int ,int );

void cmaze(int,int);


void count(int,int);

int M=0;
int N=0;
int in=0;
int out=0;
char  **maze; 
int c=0;
int *cti;
int *ctj;
int dir =1;

int main()
{

    cin>>M>>N;
    maze =new char*[M];
    for(int i=0;i<M;i++)
        maze[i]=new char[N];
    cti =new int[M*N];
    ctj =new int[M*N];
    for(int i=0;i<M*N;i++) 
    {
        cti[i]=0;
        ctj[i]=0;
    }

    makebg(maze);

    return 0;
}

void makebg(char **&maze)
{ 
    int   i,j; 


    for(i=0;i <M;i++) 
        for(j=0;j <N;j++) 
            maze[i][j]='#';

    srand((unsigned)time(0));

    in=rand()%(M-2)+1;       // Create entrance or exit 
    maze[in][0]='.';

    out=rand()%(M-2)+1;

         cti[0]=in;
         ctj[0]=1;
    cmaze(in,1);

} 

void cmaze(int i,int j){

    int ran=rand()%4; 


    if((i==out&&j==N-2))      //if then out the recursion
    {
        maze[i][j]='.';
        maze[i][j+1]='.';
    }


    if(maze[out][N-1]=='.')
        return;

    else{

        maze[i][j]='.';

        for (int s=0;s<M;s++)
        {
            for (int t=0;t<N;t++)
                cout<<maze[s][t]<<' ';
            cout<<'\n';
        }
        //system("cls");


        switch(ran)
        {
        case 0:{ //down
                
            if(Is(i+2,j)&&Is(i+1,j-1)&&Is(i+2,j+1)){ //To ensure that the next three sides wall and not backtrack
                i++;
                count(i,j);
                dir=2;
            } 

            else if(i+1==M-1) {               //step return
                c--;
                i=cti[c];
                j=ctj[c];
                cti[c+1]=0;     

                ctj[c+1]=0;

            }
            break;
               }   
        case 1:{ //left
            if(Is(i,j-2)&&Is(i+1,j-1)&&Is(i-1,j-1)){ 
                j--;
                count(i,j);
                dir=3;

            } 

            else if(j-1==0){          
                c--;
                i=cti[c];
                j=ctj[c];
                cti[c+1]=0;

                ctj[c+1]=0;

            }
            break;
               } 
        case 2:{ //up
            if(Is(i-2,j)&&Is(i-1,j-1)&&Is(i-1,j+1)){ 
                i--;
                count(i,j);
                dir=0;

            } 

            else if(i-1==0){             
                c--;
                i=cti[c];
                j=ctj[c];
                cti[c+1]=0;

                ctj[c+1]=0;
            

            }
            break;
               } 
        case 3:{ //right
            if(Is(i,j+2)&&Is(i-1,j+1)&&Is(i+1,j+1)){ 
                j++; 
                count(i,j);
                dir=1;
            }

            else if(j+1==N-1){              
                c--;
                i=cti[c];
                j=ctj[c];
                cti[c+1]=0;

                ctj[c+1]=0;
    
            }
            break;
               } 

        }
        dir=ran;
        cmaze(i,j);

    }

}
void count(int i,int j)
{
    c++;        //       
    cti[c]=i;   //
    ctj[c]=j;   //Record the location

}


bool Is(int i,int j)        
{
    if(i>=0&&i<=M-1&&j>=0&&j<=N-1&&maze[i][j]=='#')
        return true;
    else
        return false;
}



what's the problem of my code?? can't create the maze.
may be problem comes from back to previous step,but how to correct it?
AnswerRe: What's problem of my code?( create a random maze) Pin
Chris Losinger6-Jun-12 1:14
professionalChris Losinger6-Jun-12 1:14 
GeneralRe: What's problem of my code?( create a random maze) Pin
jiuyejii6-Jun-12 1:36
jiuyejii6-Jun-12 1:36 
SuggestionRe: What's problem of my code?( create a random maze) Pin
David Crow6-Jun-12 2:36
David Crow6-Jun-12 2:36 
AnswerRe: What's problem of my code?( create a random maze) Pin
Maximilien6-Jun-12 2:46
Maximilien6-Jun-12 2:46 
AnswerRe: What's problem of my code?( create a random maze) Pin
Aescleal6-Jun-12 6:47
Aescleal6-Jun-12 6:47 
GeneralRe: What's problem of my code?( create a random maze) Pin
Peter_in_27806-Jun-12 17:37
professionalPeter_in_27806-Jun-12 17:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.