Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 What's Wrong????????
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
A.J




PostPosted: Sun Mar 09, 2008 11:37 pm   Post subject: What's Wrong????????

code:

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
    bool dp[30][30][30][30];
    bool win;
    for (int a=0;a<=30;a++)
    {
        for (int b=0;b<=30;b++)
         {
             for (int c=0;c<=30;c++)
             {
                 for (int d=0;d<=30;d++)
                 {
                     win=false;
                     if (a>0 && b>0 && c>0 && d>0)
                     {
                         if (dp[a-1][b-1][c-1][d-1]==false && win==false)
                         {
                             dp[a][b][c][d]=true;
                             win=true;
                         }
                     }
                     if (a>1 && b>0 && d>1)
                     {
                         if (dp[a-2][b-1][c][d-2]==false && win==false)
                         {
                             dp[a][b][c][d]=true;
                             win=true;
                         }
                     }
                     if (c>1 && d>0)
                     {
                         if (dp[a][b][c-2][d-1]==false && win==false)
                         {
                             dp[a][b][c][d]=true;
                             win=true;
                         }
                     }
                     if (b>2)
                     {
                         if (dp[a][b-3][c][d]==false && win==false)
                         {
                             dp[a][b][c][d]=true;
                             win=true;
                         }
                     }
                     if (a>0 && d>0)
                     {
                         if (dp[a-1][b][c][d-1]==false && win==false)
                         {
                             dp[a][b][c][d]=true;
                             win=true;
                         }
                     }
                     if (win==false)
                     {
                         dp[a][b][c][d]=false;
                     }
                 }
             }
         }
    }
    ifstream fin("s5.txt");
    int testcases;
    fin>>testcases;
    for (int i=1;i<=testcases;i++)
    {
        int A,B,C,D;
        fin>>A>>B>>C>>D;
        if (dp[A][B][C][D]=true)
        {
            cout<<"Patrick"<<endl;
        }
        else
        {
            cout<<"Roland"<<endl;
        }
    }
        return 0;
}


This is the code I have of Q5 CCC.
It just doesn't run (nothing happens!).
WHAT IS WRONG?????????????????????????? Burn (It crashes after the for loops)
Sponsor
Sponsor
Sponsor
sponsor
Saad




PostPosted: Sun Mar 09, 2008 11:48 pm   Post subject: RE:What\'s Wrong????????

Your specifying an array of 30 elements, which gives you a range from 0-29, however your trying to access the 31'st element which is which is at index 30, and as a result your trying to access unassigned memory
A.J




PostPosted: Mon Mar 10, 2008 11:41 am   Post subject: Re: What's Wrong????????

thx saad.
A.J




PostPosted: Mon Mar 10, 2008 8:19 pm   Post subject: Re: What's Wrong????????

what's wrong with this
code:

class PuzzleState
{
public:
        typedef enum
        {
                TL_SPACE,
                TL_1,
                TL_2,
                TL_3,
                TL_4,
                TL_5,
                TL_6,
                TL_7,
                TL_8

        } TILE;

It is a part of my code.
It says "fsa.h:79: error: expected primary-expression before ']' token"
What does that mean?
Saad




PostPosted: Mon Mar 10, 2008 8:29 pm   Post subject: RE:What\'s Wrong????????

Is this the whole definition of the PuzzleState class? if so that class is in-complete.
Else please post the whole PuzzleState class.
A.J




PostPosted: Mon Mar 10, 2008 10:28 pm   Post subject: Re: What's Wrong????????

I'll post the full class (it's kinda big!?!?!)
code:

class PuzzleState
{
public:
        typedef enum
        {
                TL_SPACE,
                TL_1,
                TL_2,
                TL_3,
                TL_4,
                TL_5,
                TL_6,
                TL_7,
                TL_8

        } TILE;

        // data

        static TILE g_goal[ BOARD_WIDTH*BOARD_HEIGHT];
        static TILE g_start[ BOARD_WIDTH*BOARD_HEIGHT];

        // the tile data for the 8-puzzle
        TILE tiles[ BOARD_WIDTH*BOARD_HEIGHT ];

        // member functions

        PuzzleState() {
                                                memcpy( tiles, g_goal, sizeof( TILE ) * BOARD_WIDTH * BOARD_HEIGHT );
                                        }

        PuzzleState( TILE *param_tiles )
                                        {
                                                memcpy( tiles, param_tiles, sizeof( TILE ) * BOARD_WIDTH * BOARD_HEIGHT );
                                        }

        float GoalDistanceEstimate( PuzzleState &nodeGoal );
        bool IsGoal( PuzzleState &nodeGoal );
        bool GetSuccessors( AStarSearch<PuzzleState> *astarsearch, PuzzleState *parent_node );
        float GetCost( PuzzleState &successor );
        bool IsSameState( PuzzleState &rhs );

        void PrintNodeInfo();

private:
        // User stuff - Just add what you need to help you write the above functions...

        void GetSpacePosition( PuzzleState *pn, int *rx, int *ry );
        bool LegalMove( TILE *StartTiles, TILE *TargetTiles, int spx, int spy, int tx, int ty );
        int GetMap( int x, int y, TILE *tiles );




};
md




PostPosted: Mon Mar 10, 2008 11:15 pm   Post subject: RE:What\'s Wrong????????

So... your copying code from http://code.google.com/p/a-star-algorithm-implementation/source/diff?r=2&format=side&path=/trunk/8puzzle.cpp and it doesn't work... and you want us to help?

Sorry, methinks if your gonna do shady things like that then your on your own.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: