Skip to main content

LudO - The Game


/*
Programmer - Aditya Gupta (Techy15)
Language - C++
Program - LudO - The Game
*/

/* PLANS- Add functionality for name of player */

//IMP NOTE - See all notes, written in this form "//NOTE..."

//NOTE- Mark 'R','G','B','Y' for gotis, ignore doubling for now
//NOTE- Settings will have options: change default game play order(ie RBYG), change/give names to each colour
//NOTE- Add code in case of attacks
//NOTE- Add stops, and ways to show them distinct from others {may require graphics.h}

#include<iostream>

/* #include<fstream>
   To be used in case save & resume to be used*/

#include<cstdio>
#include<cstdlib>
using namespace std;
//Changes on 16th Oct

//Show gotis as R1, R2... and ask user to enter string R1 or whatever


//


// Place within appropriate block ...
    short diethrow(){
    int fl=1; //holds 0 if decnum is 0
    while(fl==0) { char *temp;
        temp=new char; short decnum=0;
    unsigned long location=&temp; //Considering 64-bit system
    decnum=location%6;
    delete temp;
    if(decnum==0) fl=0; }
    return decnum+1;
}

int i=0,j=0;
struct box{
        box *next,*prev;
        char curr, temp;    /* temp stores previous state of that box */
                    //NOTE- Initialise curr with NULL (or equivalent character that works as NULL pointer)
        short flagp, flagu;    /* flagp for 'if any goti present'; flagu is an unified flag */
                    /* Unified Flag for 'kind of use' (flagu) -
                        0 if 'not' usable (greyed out regions)
                        1 if 'normal' block (the usual path)
                        2 if 'locked home' (the place where we need 6 to get out)
                        3 if 'home path' (the goti colour specific path)*/
                    //NOTE- Maybe flagp can be used in case of knowing 'dual/multiple goti presence also'
                    //NOTE- flagr and temp collectively used to display to user who removed whom
        bool flagr;        /*flagr for 'if previous was removed/attacked' ; */   
        box(){ next=prev=NULL; curr=//NOTE- Something that is equivalent to NULL' in pointers
            temp=//null character
            flagr=0; flagp=0;    //NOTE- If locked home position is causing problem this maybe the error, ie. initialising them also with flagp=0
            flagu=1;
            }
        ~box();
    };

struct dice{
        short flag; /*'1' if not 6, '2' to store 2 numbers, '3' to store 3...*/
        short out[10]; /*stores max 10 die throw result*/
                //NOTE- Initialise all elements of out[] with 0
        char user; //either of RGBY
                //NOTE- Add conditions for 3 sixes... eg. if(out[3]!=0) then directly consider out[3] onwards...BUT this will not always be true... think
    };

class game{
    box Board[15][15]; //BOARD WILL BE AN ARRAY OF ALL BOXES
    public:
        ~game();
        game(){
            /*Setting unified flag as 0*/
            for(i=0; i<6; i++)
                for(j=0; j<6; j++) Board[i][j]->flagu=0;
            for(i=0; i>8,i<15; i++)
                for(j=0; j<6; j++) Board[i][j]->flagu=0;
            for(i=0; i<6; i++)
                for(j=0; j>8,j<15; j++) Board[i][j]->flagu=0;
            for(i=0; i>8,i<15; i++)
                for(j=0; j>8,j<15; j++) Board[i][j]->flagu=0;
            for(i=0; i>5,i<9; i++)
                for(j=0; j>5,j<9; j++) Board[i][j]->flagu=0;           

            /*Setting unified flag as 2*/
            for(i=1; i<5; i+=3)
                for(j=1;j<5;j+=3) Bonus[i][j]->flagu=2;
            for(i=10; i<14; i+=3)
                for(j=1; j<5; j+=3) Bonus[i][j]->flagu=2;       
            for(i=1; i<5; i+=2)
                for(j=10;j<14;j+=3) Bonus[i][j]->flagu=2;
            for(i=10; i<14; i++=2)
                for(j=10; j<14; j+=3) Bonus[i][j]->flagu=2;

            /*Setting unified flag as 3*/
           
            }       
};

//PIECES OF GAME... (that have to be arranged later)
1. Way to input: //Check Page 3-bottom and page 4 (for explained)
    Show the results of die throw (ie. basically list all non zero entries in out[])
    And, then list locations of all gotis (of current player), then let the user chose among them
        a. If 'only' out[0]!=0 (ie. all others are zeroes... ie. no six, no attack, no finish), move selected one
        b. In case of multiple non zero entries take two inputs goti number(choice from list) and distance by which it is to be moved then check if sum of any possible permutations of the die results equals the distance input... then move, and then give list again

2. RGBY classes:

    class R{
            box *goti1,*goti2,*goti3,*goti4;
            short locknum; /*number of locked beads (used to replace beads in locked home {by default in anti-clockwise})*/
            short disthpath[4], distnextturn[4]; /*both distances excludes current tile; distance from homepath is from last tile before home'path'*/
                                 /*can be used to calculate distance from finish*/

                    //NOTE - SEE PG. 11 & 12-up; For ways to prevent gotis from reprogressing again at normal path instead of home path
            public:
                R(){ goti1=&board[4][4]; goti2=&board[1][4]; goti3=&board[1][1]; goti4=&board[4][1]; locknum=4; }
                ~R(){}
        };
/*
//NOTE- USE THIS in Actual Program (locked beads link to NULL, better and wont cause problems since locknum will be used to show the locked beads)
    class R{
            box *goti1,*goti2,*goti3,*goti4;
            short locknum;
            public:
                class gotiloc{ box *front, *rear;
                        public:
                            gotiloc(){front=rear=NULL; createlist(); }
                            void createlist(); };
                R(){ goti1=NULL; goti2=NULL; goti3=NULL; goti4=NULL; locknum=4; } //QUESTION- NULL is a pointer or a location? ie *ptr=NULL, ptr=&NULL or ptr=NULL??? Which one's correct??
                ~R(){}
void R::gotiloc::createlist()
{
    front=goti1; goti1->prev=front; goti2->prev=goti1; goti3->prev=goti2; goti4->prev=goti3; goti1->next=goti2; goti2->next=goti3; goti3->next=goti4; rear=goti4;
}
        };*/
    class B{
            box *goti1,*goti2,*goti3,*goti4;
            short locknum; /*number of locked beads (used to replace beads in locked home {by default in anti-clockwise})*/
            public:
                B(){ goti1=&board[13][4]; goti2=&board[10][4]; goti3=&board[10][1]; goti4=&board[13][1]; locknum=4; }
                ~B(){}
        };
    class Y{
            box *goti1,*goti2,*goti3,*goti4;
            short locknum; /*number of locked beads (used to replace beads in locked home {by default in anti-clockwise})*/
            public:
                Y(){ goti1=&board[13][13]; goti2=&board[10][13]; goti3=&board[10][10]; goti4=&board[13][10]; locknum=4; }
                ~Y(){}
        };
    class G{
            box *goti1,*goti2,*goti3,*goti4;
            short locknum; /*number of locked beads (used to replace beads in locked home {by default in anti-clockwise})*/
            public:
                G(){ goti1=&board[4][13]; goti2=&board[1][13]; goti3=&board[1][10]; goti4=&board[4][10]; locknum=4; }
                ~G(){}
        };

Comments

Popular posts from this blog

Using 'ls' command as a replacement of 'find'

Advantage over find - Actually not probably in terms of speed, but... only point of this is that it's an observation, but... you can do like 'search only in' */*/*Programs* , /*/*Programs*/* , this may compensate the extra time took by using two commands 1. To search in current folder only (1 level... only this folder, no subfolder)     Type... ls | grep Search_Term 2. To search in current folder only (till level 2... this folder + subfolder)     Type... ls * | grep Search_Term #ls and ls * are NOT same! 3. To search in current folder only (till level 3... this folder + subfolder + subfolder)     Type... ls */* | grep Search_Term 4. To search in current folder only (till level 4... this folder + subfolder + subfolder + subfolder)     Type... ls */*/* | grep Search_Term ... and so on... FORMULA - To search till 'n' level (considering current folder as 1)... go till (n-1) stars If wanting to search whole disk... better type stars, like this... ls * ** *** **** *****

C++ printed a 100MB text file in just 6 seconds inference (Due to file stream not initialized with any file on system)

This was actually acomplished by 'not' intialising the inout file stream with any real file. So, computer may have pointed to some random location, and hence it went on printing for so long! In 6 seconds, it printed a 91.4MB text file In 1 minute (60 seconds), it printed a 848MB text file! [though notepad hang when trying to open these files]

Interesting Inferences about strings in C++ (and related library functions)

1. strlen() FUNCTION OF string.h It stops counting where it finds uninitialised character (ie if Arr[i] is uninitialised, it gives length as i) for eg. char S[10]; S[0]='c'; cout<<strlen(S); //This prints '1' for eg. char S[10]; S[4]='c'; cout<<strlen(S); //This prints '0', even though there is one character NOTE- Though such case may not be ever encountered in actual use but i just found this out experimenting with the code Reason- See the function definition of strlen() in string (or string.h on older ones) header file 2. THE NULL CHARACTER The null character (that terminates strings, ie '\0') has the integer code '0'. (i. cout<<int('\0'); gives 0) '\n' has code 10 ' ' has code 32 txt files terminate with a character with code '-1', but when i tried to print the respective character using cout<<char(-1); it just printed a space!? //I used Dev C++ Ver 5.11