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

AP, GP Generator (using Linked List)

//Future advancements-> add save as file, in text or in a database option (for the sequences) //                      add more series to this //Programmer - Aditya Gupta #include<iostream> #include<stdlib.h> #include<math.h> //#include<fstream> //reqd when save support is added to this! using namespace std; struct Node{ int data; Node* next; }; void inline title(void){ system("cls"); cout<<"\tNAMASTE!...\n\nProgram-AP,GP Generator\nPrograammer - MR. ADITYA GUPTA (TEChY 3)\n\n"; } class List{ //NOTE: I HAVE REMOVED ALL COMMENTS, REFER TO THE LINKED LIST TEMPLATE FOR DETAILED COMMENTS             //here only generator specific comments are there, and that too which are not in template Node *top,*rear; public: void Push(int dat); int isempty(); int search(int dat); int noofelements(); void Pop(); //CAUTION- will decrease number of terms by 1 each time it runs, and pushing the last element again will be same

More_Inferences_in_C++(1Aug'19-16thOct'19)

Programmer/Tester- Aditya Gupta (aka Techy3.5 :-) I used g++ to compile these on linux 1. Type casting of floating point numeral to integer (either automatic or by type casting)- Conversion of floating point to integer is by taking the GIF (Greatest Integer Funtion) and NOT ROUNDING OFF Greatest Integer Function(Maths,12th) it gives the integer part when the original number is written as integer+fractional part (where fractional part is less than 1 but positive) 2. NEsted MultiLine Comment [actually wont work as expected?!] if you do this in C++.... /*  blah /*blah blah blah*/ blah*/ the last blah will be visible to the compiler!!! (Inference- Multiline-Comment ends whenever */ is encountered, no matter where!!)NEsted MultiLine Comment 3. Size of various types (of C++) on 'Linux' Mint - (and same as in later versions of windows, and most PCs nowadays) char - 1 int - 4  (and: short - 2, unsigned long - 8) long long - 8 float - 4 double - 8 (and: lo

Decimal to Binary (wo Array) - A DIFFERENT APPROACH (the way i do it)

 /* * Title - Decimal to Binary Converter - My Way  *  * Programmer - Aditya Gupta (@Techy15)  *  * */ /*The more general approach is to take remainders after dividing by 2, but this one is by comparison*/ /*Compiled with g++ on Zorin OS (Linux)*/ #include<iostream> using namespace std; long pow(int a, int power){         if(power==0) return 1;         else if(power==1) return a;         else return a*pow(a,power-1);         } int main(){         int dec,bin=0,wtemp1,wtemp2,i=0;         cin>>dec; wtemp1=wtemp2=dec;         while(wtemp1>0){                         while(wtemp1>=pow(2,i)){                                  i++;                         }                 bin+=pow(10,i-1);                 wtemp1-=pow(2,i-1);                 i=0;            }         cout<<bin;         return 0; } ~