View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Checking my Progress in Game Programming

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

19 replies to this topic

#1Saint Squireen  Members

Posted 31 August 2012 - 02:18 PM

Hello! Today I want to find out if I am ready to start moving along in my learning by showing you guys the coding of my 2 and a half games. Basically my "Question" is, am I ready to move on based on the style of programming in these games? Also, if not, then what kind of tips can you give me to push me in the direction of Industrial Qualified style of game programming? Thanks!

[source lang="cpp"]#include <iostream>#include <cstdlib>#include <ctime>#include <stdio.h>using namespace std;int number,guess=0,maximum=0,choice=0,restart=1,tries=0,gameRun=1,times=0,compare=0,go=0;void personGuess(){ while(restart==1){ tries=0; cout<<"\n\n\n\n\nWhat do you want the maximum number to be?\n"; cin>>maximum; srand(time(0)); number=((rand()%maximum)+1); cout<<"\n\nWhats your Guess?\n"; guess=-1; while(guess!=number){ cin>>guess; tries++; cout<<"\n\n\n\n\n"; cout<<endl<<endl; if(guess>number){cout<<"Too high, try again.\n";} if(guess<number){cout<<"Too low, try again.\n";} } cout<<"You found the random number, "<<number<<"!!! Good job!!\n\nTries: "<<tries<<"\n\n\n\n\nWould you like to try again? 1} Yes 2} No\n\n"; restart=0; while(restart!=1 and restart!=2){ cin>>restart; } cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; }}void compGuess(){ restart=1; while(restart==1){ times=1,compare=0,go=0,tries=0; cout<<"Choose the number that your computer will have to guess.\n\n"; cin>>number; cout<<"\n\n\n"; cout<<"\n\n\n\n\nAlso choose the number that will be the maximum number your computer can pick.\n\n"; cin>>maximum; cout<<"\n\n\n"; srand(time(0)); guess=((rand()%maximum)+1); cout<<guess<<endl; tries++; while(guess!=number){ if(guess>number){ if(times==1){ guess=guess-maximum/4; } if(times==2){ guess=guess-maximum/4/4; } if(times==3){ guess=guess-100; } if(times==4){ guess=guess-50; } if(times==5){ guess=guess-25; } if(times==6){ guess=guess-10; } if(times==7){ guess=guess-5; } if(times==8){ guess--; } compare=1; tries++; cout<<guess<<endl; } if(compare==1 and guess<number and times!=8){ times=times+1; } if(guess<number or go==2){ if(times==1){ guess=guess+maximum/4; } if(times==2){ guess=guess+maximum/4/4; } if(times==3){ guess=guess+100; } if(times==4){ guess=guess+50; } if(times==5){ guess=guess+25; } if(times==6){ guess=guess+10; } if(times==7){ guess=guess+5; } if(times==8){ guess++; } compare=2; tries++; cout<<guess<<endl; } if(compare==2 and guess>number and times!=8){ times=times+1; } } cout<<"\n\n\n\aYour computer found your number, "<<number<<"!!! It found it in "<<tries<<" tries.\n\n\n"; cout<<"Would you like to restart? (1) for Yes and (2) for No."; restart=0; while(restart!=1 and restart!=2){ cin>>restart; } cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; }}int main(){ while(gameRun==1){ choice=0; cout<<"Do you want to try and guess a computer generated number (1),\nor have the computer guess a number of your choice (2)?\n\n"; while(choice!=1 and choice!=2){ cin>>choice; } cout<<"\n\n\n\n\n"; if(choice==1){ personGuess(); } if(choice==2){ compGuess(); } cout<<"Do you want to repick the game type (1),\nor completely quit the game (2)?\n\n"; gameRun=0; while(gameRun!=1 and gameRun!=2){ cin>>gameRun; } cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; } cout<<"Guessing Game script finished.\n\n"; system("pause");}\\\\This line is not part of the code, just me saying there is a total of 149 lines in my Guessing Game Program. \\\\[/source]

[source lang="cpp"]#include <iostream>#include <cstdlib>using namespace std;int n=0,m=0;int main(){ cout << "Choose a number to run the Matrix.\n\n"; n=0;m=0; while(n<100000 or n>999999998){ cin>>n; cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; if(n<100000){cout<<"Number is too small, try again.\n\n\n";} if(n>999999998){cout<<"Number is too big try again.";} if(n>999999999){cout<<"Number is so big you just crashed the Matrix. Just saying.";} } cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMake sure to look for patterns!!! ;D"; while(m!=100000000){m++;} while(1){cout<<n;} cout<<"Matrix program script finished.\n\n"; system("pause");}\\\\This line is not part of the code, just me saying there is a total of 21 lines in my Matrix Program. \\\\[/source]

[source lang="cpp"]#include <iostream>#include <cstdlib>#include <ctime>#include <stdio.h>using namespace std;int topLeft=0,topCenter=0,topRight=0,middleLeft=0,middleCenter=0,middleRight=0,bottomLeft=0,bottomCenter=0,bottomRight=0,turn=0,restart=1,playerMove=0,compMove=0,playerMoveAccept=0,compMoveAccept=0,win=0,fourCorners=0,care=0,chance=0,difficulty=0,placement=0;void compAI(){ care=1; srand(time(0)); chance=((rand()%10)+1); if(chance>=difficulty){ if(middleCenter==1 and topLeft==0 and topRight==0 and bottomLeft==0 and bottomRight==0){ srand(time(0)); placement=((rand()%4)+1); if(placement==1){topLeft=2;care=0;} if(placement==2){topRight=2;care=0;} if(placement==3){bottomLeft=2;care=0;} if(placement==4){bottomRight=2;care=0;} } if(fourCorners==1 and care==1){ if(topLeft==0 and topRight==2 and bottomLeft==2 and bottomRight==2 and care==1){topLeft=2;care=0;} if(topLeft==2 and topRight==0 and bottomLeft==2 and bottomRight==2 and care==1){topRight==2;care=0;} if(topLeft==2 and topRight==2 and bottomLeft==0 and bottomRight==2 and care==1){bottomLeft=2;care=0;} if(topLeft==2 and topRight==2 and bottomLeft==2 and bottomRight==0 and care==1){bottomRight==2;care=0;} } if(topLeft==2 and topRight==2 and bottomLeft==2 and bottomRight==2 and middleCenter==0 and care==1){middleCenter=2;care=0;} if(topCenter==2 and bottomCenter==2 and middleLeft==2 and middleRight==2 and middleCenter==0 and care==1){middleCenter=2;care=0;} if(topLeft==2 and topCenter==0 and topRight==2 and middleCenter==2 and bottomCenter==2 and care==1){topCenter=2;care=0;} if(bottomLeft==2 and bottomCenter==0 and bottomRight==2 and middleCenter==2 and topCenter==2 and care==1){bottomCenter=0;care=0;} if(topLeft==2 and middleLeft==0 and bottomLeft==2 and middleCenter==2 and middleRight==2 and care==1){middleLeft=2;care=0;} if(topRight==2 and middleRight==0 and bottomRight==2 and middleCenter==2 and middleLeft==2 and care==1){middleRight=2;care=0;} if(topLeft==2 and middleLeft==0 and bottomLeft==2 and care==1){middleLeft=2;care=0;} if(topCenter==2 and middleCenter==0 and bottomCenter==2 and care==1){middleCenter=2;care=0;} if(topRight==2 and middleRight==0 and bottomRight==2 and care==1){middleRight=2;care=0;} if(topLeft==0 and middleLeft==2 and bottomLeft==2 and care==1){topLeft=2;care=0;} if(topCenter==0 and middleCenter==2 and bottomCenter==2 and care==1){topCenter=2;care=0;} if(topRight==0 and middleRight==2 and bottomRight==2 and care==1){topRight=2;care=0;} if(topLeft==2 and middleLeft==2 and bottomLeft==0 and care==1){bottomLeft=2;care=0;} if(topCenter==2 and middleCenter==2 and bottomCenter==0 and care==1){bottomCenter=2;care=0;} if(topRight==2 and middleRight==2 and bottomRight==0 and care==1){bottomRight=2;care=0;} if(topLeft==2 and topCenter==2 and topRight==0 and care==1){topRight=2;care=0;} if(middleLeft==2 and middleCenter==2 and middleRight==0 and care==1){middleRight=2;care=0;} if(bottomLeft==2 and bottomCenter==2 and bottomRight==0 and care==1){bottomRight=2;care=0;} if(topLeft==2 and topCenter==0 and topRight==2 and care==1){topCenter=2;care=0;} if(middleLeft==2 and middleCenter==0 and middleRight==2 and care==1){middleCenter=2;care=0;} if(bottomLeft==2 and bottomCenter==0 and bottomRight==2 and care==1){bottomCenter=2;care=0;} if(topLeft==0 and topCenter==2 and topRight==2 and care==1){topLeft=2;care=0;} if(middleLeft==0 and middleCenter==2 and middleRight==2 and care==1){middleLeft=2;care=0;} if(bottomLeft==0 and bottomCenter==2 and bottomRight==2 and care==1){bottomLeft=2;care=0;} if(topLeft==2 and middleCenter==0 and bottomRight==2 and care==1){middleCenter=2;care=0;} if(topLeft==0 and middleCenter==2 and bottomRight==2 and care==1){topLeft=2;care=0;} if(topLeft==2 and middleCenter==2 and bottomRight==0 and care==1){bottomRight=2;care=0;} if(topRight==2 and middleCenter==0 and bottomLeft==2 and care==1){middleCenter=2;care=0;} if(topRight==0 and middleCenter==2 and bottomLeft==2 and care==1){topRight=2;care=0;} if(topRight==2 and middleCenter==2 and bottomLeft==0 and care==1){bottomLeft=2;care=0;} if(fourCorners==1 and care==1){ if(topLeft==0 and topRight==1 and bottomLeft==1 and bottomRight==1 and care==1){topLeft=2;care=0;} if(topLeft==1 and topRight==0 and bottomLeft==1 and bottomRight==1 and care==1){topRight==2;care=0;} if(topLeft==1 and topRight==1 and bottomLeft==0 and bottomRight==1 and care==1){bottomLeft=2;care=0;} if(topLeft==1 and topRight==1 and bottomLeft==1 and bottomRight==0 and care==1){bottomRight==2;care=0;} } if(topLeft==1 and topRight==1 and bottomLeft==1 and bottomRight==1 and middleCenter==0 and care==1){middleCenter=2;care=0;} if(topCenter==1 and bottomCenter==1 and middleLeft==1 and middleRight==1 and middleCenter==0 and care==1){middleCenter=2;care=0;} if(topLeft==1 and topCenter==0 and topRight==1 and middleCenter==1 and bottomCenter==1 and care==1){topCenter=2;care=0;} if(bottomLeft==1 and bottomCenter==0 and bottomRight==1 and middleCenter==1 and topCenter==1 and care==1){bottomCenter=0;care=0;} if(topLeft==1 and middleLeft==0 and bottomLeft==1 and middleCenter==1 and middleRight==1 and care==1){middleLeft=2;care=0;} if(topRight==1 and middleRight==0 and bottomRight==1 and middleCenter==1 and middleLeft==1 and care==1){middleRight=2;care=0;} if(topLeft==1 and middleLeft==0 and bottomLeft==1 and care==1){middleLeft=2;care=0;} if(topCenter==1 and middleCenter==0 and bottomCenter==1 and care==1){middleCenter=2;care=0;} if(topRight==1 and middleRight==0 and bottomRight==1 and care==1){middleRight=2;care=0;} if(topLeft==0 and middleLeft==1 and bottomLeft==1 and care==1){topLeft=2;care=0;} if(topCenter==0 and middleCenter==1 and bottomCenter==1 and care==1){topCenter=2;care=0;} if(topRight==0 and middleRight==1 and bottomRight==1 and care==1){topRight=2;care=0;} if(topLeft==1 and middleLeft==1 and bottomLeft==0 and care==1){bottomLeft=2;care=0;} if(topCenter==1 and middleCenter==1 and bottomCenter==0 and care==1){bottomCenter=2;care=0;} if(topRight==1 and middleRight==1 and bottomRight==0 and care==1){bottomRight=2;care=0;} if(topLeft==1 and topCenter==1 and topRight==0 and care==1){topRight=2;care=0;} if(middleLeft==1 and middleCenter==1 and middleRight==0 and care==1){middleRight=2;care=0;} if(bottomLeft==1 and bottomCenter==1 and bottomRight==0 and care==1){bottomRight=2;care=0;} if(topLeft==1 and topCenter==0 and topRight==1 and care==1){topCenter=2;care=0;} if(middleLeft==1 and middleCenter==0 and middleRight==1 and care==1){middleCenter=2;care=0;} if(bottomLeft==1 and bottomCenter==0 and bottomRight==1 and care==1){bottomCenter=2;care=0;} if(topLeft==0 and topCenter==1 and topRight==1 and care==1){topLeft=2;care=0;} if(middleLeft==0 and middleCenter==1 and middleRight==1 and care==1){middleLeft=2;care=0;} if(bottomLeft==0 and bottomCenter==1 and bottomRight==1 and care==1){bottomLeft=2;care=0;} if(topLeft==1 and middleCenter==0 and bottomRight==1 and care==1){middleCenter=2;care=0;} if(topLeft==0 and middleCenter==1 and bottomRight==1 and care==1){topLeft=2;care=0;} if(topLeft==1 and middleCenter==1 and bottomRight==0 and care==1){bottomRight=2;care=0;} if(topRight==1 and middleCenter==0 and bottomLeft==1 and care==1){middleCenter=2;care=0;} if(topRight==0 and middleCenter==1 and bottomLeft==1 and care==1){topRight=2;care=0;} if(topRight==1 and middleCenter==1 and bottomLeft==0 and care==1){bottomLeft=2;care=0;} }}void gameDisplay(){ if(topLeft==0){cout<<" ";} if(topLeft==1){cout<<"X";} if(topLeft==2){cout<<"O";} cout<<"|"; if(topCenter==0){cout<<" ";} if(topCenter==1){cout<<"X";} if(topCenter==2){cout<<"O";} cout<<"|"; if(topRight==0){cout<<" ";} if(topRight==1){cout<<"X";} if(topRight==2){cout<<"O";} cout<<endl; cout<<"_____"<<endl; if(middleLeft==0){cout<<" ";} if(middleLeft==1){cout<<"X";} if(middleLeft==2){cout<<"O";} cout<<"|"; if(middleCenter==0){cout<<" ";} if(middleCenter==1){cout<<"X";} if(middleCenter==2){cout<<"O";} cout<<"|"; if(middleRight==0){cout<<" ";} if(middleRight==1){cout<<"X";} if(middleRight==2){cout<<"O";} cout<<endl; cout<<"_____"<<endl; if(bottomLeft==0){cout<<" ";} if(bottomLeft==1){cout<<"X";} if(bottomLeft==2){cout<<"O";} cout<<"|"; if(bottomCenter==0){cout<<" ";} if(bottomCenter==1){cout<<"X";} if(bottomCenter==2){cout<<"O";} cout<<"|"; if(bottomRight==0){cout<<" ";} if(bottomRight==1){cout<<"X";} if(bottomRight==2){cout<<"O";} cout<<endl<<endl<<endl<<endl<<endl;}void playerInput(){ playerMoveAccept=0; while(playerMoveAccept==0){ playerMove=0; while(playerMove!=1 and playerMove!=2 and playerMove!=3 and playerMove!=4 and playerMove!=5 and playerMove!=6 and playerMove!=7 and playerMove!=8 and playerMove!=9 and playerMove!=99){ cin>>playerMove; if(playerMove==1 and topLeft==0){topLeft=1;playerMoveAccept=1;} if(playerMove==1 and topLeft==1 and topLeft==2){playerMove=0;} if(playerMove==2 and topCenter==0){topCenter=1;playerMoveAccept=1;} if(playerMove==2 and topCenter==1 and topCenter==2){playerMove=0;} if(playerMove==3 and topRight==0){topRight=1;playerMoveAccept=1;} if(playerMove==3 and topRight==1 and topRight==2){playerMove=0;} if(playerMove==4 and middleLeft==0){middleLeft=1;playerMoveAccept=1;} if(playerMove==4 and middleLeft==1 and middleLeft==2){playerMove=0;} if(playerMove==5 and middleCenter==0){middleCenter=1;playerMoveAccept=1;} if(playerMove==5 and middleCenter==1 and middleCenter==2){playerMove=0;} if(playerMove==6 and middleRight==0){middleRight=1;playerMoveAccept=1;} if(playerMove==6 and middleRight==1 and middleRight==2){playerMove=0;} if(playerMove==7 and bottomLeft==0){bottomLeft=1;playerMoveAccept=1;} if(playerMove==7 and bottomLeft==1 and bottomLeft==2){playerMove=0;} if(playerMove==8 and bottomCenter==0){bottomCenter=1;playerMoveAccept=1;} if(playerMove==8 and bottomCenter==1 and bottomCenter==2){playerMove=0;} if(playerMove==9 and bottomRight==0){bottomRight=1;playerMoveAccept=1;} if(playerMove==9 and bottomRight==1 and bottomRight==2){playerMove=0;} if(playerMove==99){cout<<"\n\nDo you want to Quit? 1} Yes 2} No\n\n"; while(playerMove!=1 and playerMove!=2){ cin>>playerMove; } if(playerMove==1){playerMove=99;win=8;} if(playerMove==2){playerMove=0;cout<<"\n\n\n\n\n";gameDisplay();} } cout<<"\n\n\n\n\n"; } }}void compInput(){ compAI(); compMoveAccept=0; if(care==1){ while(compMoveAccept==0){ srand(time(0)); compMove=((rand()%9)+1); if(compMove==1 and topLeft==0){topLeft=2;compMoveAccept=1;} if(compMove==1 and topLeft==1 and topLeft==2){compMove=0;} if(compMove==2 and topCenter==0){topCenter=2;compMoveAccept=1;} if(compMove==2 and topCenter==1 and topCenter==2){compMove=0;} if(compMove==3 and topRight==0){topRight=2;compMoveAccept=1;} if(compMove==3 and topRight==1 and topRight==2){compMove=0;} if(compMove==4 and middleLeft==0){middleLeft=2;compMoveAccept=1;} if(compMove==4 and middleLeft==1 and middleLeft==2){compMove=0;} if(compMove==5 and middleCenter==0){middleCenter=2;compMoveAccept=1;} if(compMove==5 and middleCenter==1 and middleCenter==2){compMove=0;} if(compMove==6 and middleRight==0){middleRight=2;compMoveAccept=1;} if(compMove==6 and middleRight==1 and middleRight==2){compMove=0;} if(compMove==7 and bottomLeft==0){bottomLeft=2;compMoveAccept=1;} if(compMove==7 and bottomLeft==1 and bottomLeft==2){compMove=0;} if(compMove==8 and bottomCenter==0){bottomCenter=2;compMoveAccept=1;} if(compMove==8 and bottomCenter==1 and bottomCenter==2){compMove=0;} if(compMove==9 and bottomRight==0){bottomRight=2;compMoveAccept=1;} if(compMove==9 and bottomRight==1 and bottomRight==2){compMove=0;} cout<<"\n\n\n\n\n"; } }}void winCheck(){ if(topLeft==1 and topCenter==1 and topRight==1){win=1;} if(middleLeft==1 and middleCenter==1 and middleRight==1){win=1;} if(bottomLeft==1 and bottomCenter==1 and bottomRight==1){win=1;} if(topLeft==1 and middleLeft==1 and bottomLeft==1){win=1;} if(topCenter==1 and middleCenter==1 and bottomCenter==1){win=1;} if(topRight==1 and middleRight==1 and bottomRight==1){win=1;} if(topLeft==1 and middleCenter==1 and bottomRight==1){win=1;} if(topRight==1 and middleCenter==1 and bottomLeft==1){win=1;} if(topLeft==1 and bottomLeft==1 and topRight==1 and bottomRight==1 and middleCenter==1){win==5;} if(topCenter==1 and bottomCenter==1 and middleLeft==1 and middleRight==1 and middleCenter==1){win=5;} if(topLeft==1 and topCenter==1 and topRight==1 and middleCenter==1 and bottomCenter==1){win=5;} if(bottomLeft==1 and bottomCenter==1 and bottomRight==1 and middleCenter==1 and topCenter==1){win=5;} if(topLeft==1 and middleLeft==1 and bottomLeft==1 and middleCenter==1 and middleRight==1){win=5;} if(middleLeft==1 and middleCenter==1 and middleRight==1 and topRight==1 and bottomRight==1){win=5;} if(fourCorners==1){ if(topLeft==1 and bottomLeft==1 and topRight==1 and bottomRight==1){win=7;} } if(topLeft!=0 and topCenter!=0 and topRight!=0 and middleLeft!=0 and middleCenter!=0 and middleRight!=0 and bottomLeft!=0 and bottomCenter!=0 and bottomRight!=0){win==3;} if(topLeft==2 and topCenter==2 and topRight==2){win=2;} if(middleLeft==2 and middleCenter==2 and middleRight==2){win=2;} if(bottomLeft==2 and bottomCenter==2 and bottomRight==2){win=2;} if(topLeft==2 and middleLeft==2 and bottomLeft==2){win=2;} if(topCenter==2 and middleCenter==2 and bottomCenter==2){win=2;} if(topRight==2 and middleRight==2 and bottomRight==2){win=2;} if(topLeft==2 and middleCenter==2 and bottomRight==2){win=2;} if(topRight==2 and middleCenter==2 and bottomLeft==2){win=2;} if(topLeft==2 and bottomLeft==2 and topRight==2 and bottomRight==2 and middleCenter==2){win=4;} if(topCenter==2 and bottomCenter==2 and middleLeft==2 and middleRight==2 and middleCenter==2){win=4;} if(topLeft==2 and topCenter==2 and topRight==2 and middleCenter==2 and bottomCenter==2){win=4;} if(bottomLeft==2 and bottomCenter==2 and bottomRight==2 and middleCenter==2 and topCenter==2){win=4;} if(topLeft==2 and middleLeft==2 and bottomLeft==2 and middleCenter==2 and middleRight==2){win=4;} if(middleLeft==2 and middleCenter==2 and middleRight==2 and topRight==2 and bottomRight==2){win=4;} if(fourCorners==1){ if(topLeft==2 and bottomLeft==2 and topRight==2 and bottomRight==2){win=6;} }}int main(){ while (restart==1){ cout<<"What Difficulty do you want? 1} Easy 2} Medium 3} Hard\n\n"; difficulty=0; while(difficulty!=1 and difficulty!=2 and difficulty!=3){ cin>>difficulty; } cout<<"\n\n"; if(difficulty==1){ difficulty=7; } if(difficulty==2){ difficulty=6; } if(difficulty==3){ difficulty=0; } cout<<"NOTE: Type 99 on your turn for an option to quit mid-game.\n\n\n\n\n"; cout<<"Do you want to play with the extra 'Four Corners' rule?\n(Press '1' for yes or '2' for no.)\n\n"; fourCorners=0; while(fourCorners!=1 and fourCorners!=2){ cin>>fourCorners; } cout<<endl<<endl<<endl<<endl<<endl; win=0;topLeft=0;topCenter=0;topRight=0;middleLeft=0;middleCenter=0;middleRight=0;bottomLeft=0;bottomCenter=0;bottomRight=0; srand(time(0)); turn=((rand()%2)+1); gameDisplay(); while(win==0){ while (turn==1 and win==0){ cout<<"Your turn!\n\n"; playerInput(); turn=2; gameDisplay(); winCheck(); } while (turn==2 and win==0){ cout<<"Computer's turn!\n\n\n\n\n"; compInput(); turn=1; gameDisplay(); winCheck(); } } if(win==1){ cout<<"Hurrah!! You won against your computer!!!\n\n\n"; } if(win==2){ cout<<"You lost against your own computer!!!\n\n\n"; } if(win==3){ cout<<"Wow! You tied against your computer!!!!\n\n\n"; } if(win==4){ cout<<"What the...... Your computer just owned you!!!!!! Your computer got a double win!!!!!!!!!!\n\n\n"; } if(win==5){ cout<<"Dang! You just double beat your own computer!!! ppppsssshhh So much for Artificial Intelligence hahaha:)\n\n\n"; } if(win==6){ cout<<"Woah!! Your computer used the Four Corners rule against you!!!\n\n\n"; } if(win==7){ cout<<"Woah!! You used the Four Corners rule againt your computer!!!\n\n\n"; } if(win==8){cout<<"You quit the game? Hopefully not because of a bug...;D\n\n\n";} cout<<"Would you like to retart?\n(Press '1' for yes or '2' for no.)\n"; restart=0; while(restart!=1 and restart!=2){cin>>restart;} cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; } cout<<"Tic-Tac-Toe game script finished.\n\n"; system("pause");}\\\\This line is not part of the code, just me saying there is a total of 337 lines in my Tic-Tac-Toe Program. \\\\[/source]

Feel free to plug this into any compiler/debugger and check to see how it runs and plays.

P.S.~ I'm pretty sure you know which one of these games is the "Half Game"

~Saint Squireen

#2Saint Squireen  Members

Posted 31 August 2012 - 02:21 PM

~Saint Squireen

#3Dunge  Members

Posted 31 August 2012 - 03:51 PM

First of all, this is mostly basic C, not C++. You don't have any classes and use global variable. Learning object-oriented development would be the next logical step in your training. You do use std (cin and cout) but that's about it. Try using containers like list, map and vectors.
Your tictactoe source use a whole lot of "if" lines. I didn't analyse it, but I'm pretty sure it could be resumed to a clearer algorithm taking much less lines of code using mathematics and logic instead of handling every possible possibilities individually.
Also, I know it was not a need in these games, but you only used variables of type int. Always try to select the best type who use the less memory for the data you handle. Instead of validating maximum using a made-up value (99999999), try using constant that means something like INT_MAX available in <limits.h>

Also, what do you mean by "move on"? You always improve while programming, it never stop. If you mean learn new things, only you can answer that. Do you understand the code you wrote? If so, go ahead because it can only help learning new ways of thinking and doing that same thing in a more efficient manner.

Edited by Dunge, 31 August 2012 - 04:06 PM.

#4Saint Squireen  Members

Posted 31 August 2012 - 05:53 PM

I understand everything I wrote and yes i did mean lern new things. Thanks for the insight I really needed it!

~Saint Squireen

#5L. Spiro  Members

Posted 31 August 2012 - 06:57 PM

I don’t really get the point of this question.
What is the alternative to “moving on”? To not change how you write code? To not grow, learn, and develop your skills, but instead to just stay where you are?
Why would you even ask this?

I would say you have no choice but to “move on” because staying where you are would not be a good thing.
The code is convoluted and lacks comments. It is a mess.

As mentioned, you need to represent the logic of the game as mathematical algorithms, not if’s to represent every possible state of the game.
An alternative to that is to use data structures that can be processed by “mini-engines”.

Next, where is the whitespace?
Have you ever heard the term, “Wall of Text”? It appears on forums when people write long diatribes without breaking things into paragraphs.
Whitespace in code exists for a reason—it helps people break the text into readable segments.
Here are 2 examples of different styles that people might use:
number = ((rand() % maximum) + 1);
number = ((rand()%maximum)+1);
While no one can agree on what the best style is, everyone can agree that the worst style is to use no whitespace at all. It is not a disease. Stop avoiding it.

Then you need comments. This is one of the biggest differences between a pro and a beginner, yet is the easiest thing to get right.

Then there is your use of globals. As mentioned above, this is C++. You don’t have a single local variable. Where did you learn to code like this? Are you coming from another language? I have never seen this before.
If you have any intentions of getting anywhere with programming, this is the most critical thing to unlearn. There is virtually no need for globals ever in any code, though how pedantic you go with this concept is up to you. Some people refuse to use any globals of any kind for any reason, while some use them just sparingly for what they consider to be exceptional cases.
But your use of globals is simply criminal.

Creating algorithms to express your logic takes time to learn.
Adding whitespace and comments, and using locals instead of globals do not. These are over-the-night things you can do to improve the quality of your code, so there is no excuse not be be incorporating these things into the code that you will be writing starting from tomorrow.

Moving on is your only choice. And always will be.

L. Spiro

#6lride  Members

Posted 31 August 2012 - 07:42 PM

Why are you seeding rand multiple times?
In the first code, you are calling srand in a loop and in the third one, you are calling srand twice.
And there is something wrong with your excessive use of if statements.
Even such heavy if statements were necessary, you should always comment the code so that you don't have to waste time figuring out what you intended in your code.
An invisible text.

#7EngineProgrammer  Members

Posted 31 August 2012 - 08:38 PM

Don't be so hard on him.

Saint Squireen, What is your goal?
What would you like to program? I assume games? Do you want to work in a game company?

I'm not trying to be rude but I'll give you an honest answer:

Am I ready to move on based on the style of programming in these games?

Answer: No, you are not ready to move on with that style of programming. It is bad coding.

What kind of tips can you give me to push me in the direction of Industrial Qualified style of game programming

The tips I can give is: Write neat. Use classes, tons of methods, etc.
Also learn the theory about everything.

Could you explain me, in a neat/technical sentence, how a pointer works?
Could you explain me what the difference is between a local, global, member variable? Also in in neat sentence.

These things you are supposed to know as programmer. Knowing what you are writing.

I've found this pdf yesteday, I recommend you to have a look at this:
http://www.angelfire...lusin21days.pdf

~EngineProgrammer

#8Bacterius  Members

Posted 31 August 2012 - 09:37 PM

The last block of code makes my eyes bleed, but let's all be honest - most of us also started like this, hardcoding every possible state with a bunch of if/then's. Then we noticed/got told that these states could be logically grouped into categories, and eventually you end up with beautiful code with only a couple conditionals per line and no more than two nested loops, all isolated in a single flexible method that you can put into a code library for easy reuse in your other projects.

However, it takes time, experience, and practice to discover, identify, and make use of these patterns, so the only advice I could give you is, pick one your more harder games, and try and rewrite it more elegantly. You'll instinctively know when you're doing it right: good code should be beautiful to read.

----------

If you would like more specific feedback, look at your "guess the number" game. First, lay off the \n's! If you really need formatting, try and group these into some form of constant. And instead of the fifteen or so newlines at the end of the PersonGuess() method, why not just erase the console screen to start over? That would make more sense in my opinion, it would be more intuitive. That's just a detail though, console formatting is always a bit of a pain using only standard output.

Secondly, your "computer AI" for this game is... defective. The (provably) fastest way for the computer to guess the number is by binary search, which can be concisely implemented in about ten lines of code. I don't C++ so I don't know the exact syntax, but the pseudocode goes like this:

1. Let Lo = 0, Hi = maxNumber. (Lo and Hi are variables)
2. Repeat forever steps 3 to 6.
... 3. Let computerGuess = (Lo + Hi) / 2
... 4. If actualGuess = computerGuess, the computer wins, break out of the loop.
... 5. If actualGuess < computerGuess, then let Hi = computerGuess - 1 and go to step 3.
... 6. If actualGuess > computerGuess, then let Lo = computerGuess, and go to step 3.

This is called binary search and the computer will guess your number in about log2(n) steps on average, where n is the maximum number he can guess. So for n = 100, it'll take the computer about 6-7 steps. For n = 1 million, it'll take it roughly 20 guesses. No need for some strange series of conditions (which, by the way, appear to be a hardcoded form of binary search...)

Unless, of course, you were trying to model a "bad AI" which made bad guesses, but even then you could've just used a variation of the binary search which wouldn't use the midpoint of Lo and Hi at each guess, but a random guess within the search interval for instance, which can end up being faster or slower (but on average the same speed). This way the computer will appear to actually "guess" instead of making mechanical choices. If that makes sense.

----------

Now, this might seem harsh, but you need to learn to code elegantly before moving on to more complex stuff, because, well, it's pretty simple why: you won't be able to get away with your current method in more complex games. You will simply have too many conditions and variables to keep track of. So, no, you are not ready to move on, you need to step back and improve your coding skills. All three games you have attached to this topic are in dire need of rewriting, and you would benefit immensely from doing just that. Though don't hesitate to create new topics if you need specific coding advice while doing this, I'm sure many people would be happy to guide you.

Also, reflect on this quote, which I find to be extremely true to programming in general:

Perfection is achieved, not when there is nothing left to add, but when there is nothing left to take away.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

#9LarsDC  Members

Posted 01 September 2012 - 04:15 PM

Could you explain me, in a neat/technical sentence, how a pointer works?
Could you explain me what the difference is between a local, global, member variable? Also in in neat sentence.

I'm not him but I couldn't resist this little challenge. Always fun to see if I've listened closely enough during my school lessons.
Actually created a user here on the awesome GD.net to post this

Pointer: A pointer work in the way that it gives you direct access to the memorybank/memoryspace in which a variable is stored on your computer. Meaning the chunk of memory that is reserved for this variable. Meaning if you forget to *pointer=0 before reassigned it another value you will create memory leaks as the memorybank is still "locked".

Variables:
Local - Local variables are variables accessible by all functions within the class where it is created.
Example:
int main{
int a;
}
//Destroyed when the block/function/class ends

Member - Member variables are only accessible within the scope where they are created meaning inside a function for instance
Example:
int main{
void randomName(){
int a;
}
}
//Destroyed when the block/function ends

Global - Global variables are accessible from everywhere in your program, hence the name global.
Example:

int a;
int main(){
}
//Destroyed when the program terminates

Wow that was more than a sentence, sorry.

Of course I would appriciate it a lot if you would confirm if I have indeed been listening or need to redo my last semester ;)

You are of course welcome to PM me the answer as to not spoil it completely.

And sorry for hijacking/butting in on the post

Edited by LarsDC, 01 September 2012 - 04:16 PM.

#10L. Spiro  Members

Posted 02 September 2012 - 07:44 AM

Your response to pointers is wrong in concept.
Your response to members is wrong entirely.

As for pointers, you gave basically a textbook definition of how they are used, but not really what they are. They are nothing but integers whose values can be interpreted as an address. Their sizes change between platforms but to keep things simple we should assume Windows x86 (32-bit pointers).
0x00000100 can’t be a pointer but 0x00400000 is. It is simply a value that points to valid memory. Though some values that are meant to be pointers could point to invalid memory if your program has errors.

Members are “attributes” of classes. You posted an example in which a function was declared inside another function. This is entirely illegal.
For this, you need to redo some of your learning.

L. Spiro

Edited by L. Spiro, 02 September 2012 - 07:44 AM.

#11LarsDC  Members

Posted 02 September 2012 - 08:58 AM

Thanks for the response

I had a feeling a month of c++ wouldn't get it in place so it's nice to get some feedback. At least I know I need to practice some more and read a bit more also.
I did know that if you cout a pointer you'll get the memory address and not the variable value itself hence them always being integers, if that is what you meant.

Still much appreciate the response.

Regarding the member variable.

I think I kinda switched around local and member didn't I?

Local being class visible and member being function specific.

Again much appreciated!

Edited by LarsDC, 02 September 2012 - 09:12 AM.

#12EngineProgrammer  Members

Posted 02 September 2012 - 02:26 PM

Your response to pointers is wrong in concept.
Your response to members is wrong entirely.

As for pointers, you gave basically a textbook definition of how they are used, but not really what they are. They are nothing but integers whose values can be interpreted as an address. Their sizes change between platforms but to keep things simple we should assume Windows x86 (32-bit pointers).
0x00000100 can’t be a pointer but 0x00400000 is. It is simply a value that points to valid memory. Though some values that are meant to be pointers could point to invalid memory if your program has errors.

Members are “attributes” of classes. You posted an example in which a function was declared inside another function. This is entirely illegal.
For this, you need to redo some of your learning.

L. Spiro

Looks like someone was before me But I don't mind at all, you've explained it 10x better than I would've done!
I was going to say: "Pointers are addresses. Nothing more nothing less. They only "point to" an object which is allocated on the heap(or on the stack, depending where/how you have allocated your object. But most likely it will be on the heap).
But indeed you need to be careful using pointers.

Assume this code:
int main()
{
Object* pObject1 = new Object();
Object* pObject2 = pObject1;

delete pObject1;

pObject2->ShootBlast();
}

If you don't know what this code will do, too bad I won't tell it!
Write it in C++ and use break points to look what each step will do.
if you like this kind of thinking-work of this code, send a PM because I have tons of these thinking-codes.

LarcDC, you bad bad boy! My question wasn't meant as a challenge.

~EngineProgrammer

#13Saint Squireen  Members

Posted 02 September 2012 - 02:48 PM

Engine Programmer,

My goal is to learn how to program, with the ultimate goal of learning how to program games. As you can see these are the very, VERY first games I have ever created and you can probly tell this too, I am practically teaching myself with the help of a book or two. Do any of you guys know the TI-84 Plus Silver Edition Graphing Calculator? I first learned how to program on that when I was getting tired of doing the Quadratic Formula over and over again. I then got interested in writing code and then into coding games and then into trying to program on the computer. I then got to the point where the books were going to slow, so I went ahead and started to implement what I had learned so far into these "Games". Putting up the source code for these games was a very good decision by me because of all of these tips I have recieved. I just wanted to say thanks so much, and if you guys have anything else you want me to know or clean up, then please put it all out here:)
Thanks again!!!,
Saint Squireen

~Saint Squireen

#14EngineProgrammer  Members

Posted 02 September 2012 - 04:31 PM

Well, if you follow the pdf I've linked to you in my first comment I'm sure you will be a much better programmer soon!

I still remember my first piece of code. I only knew what data members, bitmaps and methods were.
I wrote 1000lines of code for a simple sprite of Warcraft2-Tidens of darkness that could move around the map and plays a random sound when you select it.
And 4 months later I looked again to that code and I really wanted to laugh at myself of being so bad. But when I compared with the progress I've made I was really glad.
The pdf shows you all basics of C++ and you can learn it in 1 month.(but go over it slowly, so take 2 months)

Also I remember I've followed some tutorials on websites to program in C++:
Console Applications: http://xoax.net/cpp/...nsole/index.php
Win32: http://xoax.net/cpp/...win32/index.php

And yes I sure want to tell you something more so you won't make the mistake I did. Listen and follow the advice of good programmers.
I learned Winsock(networking stuff) and I've been told to learn Raknet(better networking stuff) but didn't listened. And on the finals I didn't have a networking system in my game(wasn't really needed but I was going for the extra points). All because I 'was' stubborn.
I'm not saying you need to listen to me, I'm far away of being a good programmer. L. spiro is a great programmer, I've looked at some of his comments and I noticed allot of details he can tell on a single topic.

~EngineProgrammer

#15Servant of the Lord  Members

Posted 02 September 2012 - 04:52 PM

Several tips and one criticism:
1) Don't be afraid to use whitespace. It makes the code easier to read. Easier to read is better than not easy to read.
2) Don't cram multiple things onto one line 'just because'.

For example, this:
int topLeft=0,topCenter=0,topRight=0,middleLeft=0,middleCenter=0,middleRight=0,bottomLeft=0,bottomCenter=0,bottomRight=0,turn=0,restart=1,playerMove=0,compMove=0,playerMoveAccept=0,compMoveAccept=0,win=0,fourCorners=0,care=0,chance=0,difficulty=0,placement=0;

Should be:
int topLeft = 0, topCenter = 0, topRight = 0;
int middleLeft = 0, middleCenter = 0, middleRight = 0;
int bottomLeft = 0, bottomCenter = 0, bottomRight = 0;
int turn = 0;
int restart = 1; //What is restart? It either isn't named very descriptively, or else should be a boolean.
int playerMove = 0, compMove = 0; //Maybe these should be bools also?
int playerMoveAccept = 0, compMoveAccept = 0;
int win = 0; //Bool?
int fourCorners=0;
int care = 0; //Needs more discriptive name, and also should be a bool.
int chance = 0, difficulty = 0, placement = 0;

Use constants or enums wherever applicable. Avoid as many magic numbers as you can.

Declare any variables as close to the first use as reasonable. Definitely declare them in the proper scope. Don't make them all globals. Some globals are okay though.

Learn if else() and else and use them where appropriate.

You're doing good, so keep at it! All of the above is just tips to improve and get better. There's still a ways to go, but you're just starting out so that's to be expected.

Now for the one real criticism:

What in the world is this?
if(middleCenter==1 and topLeft==0 and topRight==0 and bottomLeft==0 and bottomRight==0)
{
//...
}

'and' is not a C++ keyword. If you have a macro named 'and' that is defined as '&&', get rid of it!

(*tongue-in-cheek anger*)

Edited by Servant of the Lord, 02 September 2012 - 04:53 PM.

It's perfectly fine to abbreviate my username to 'Servant' or 'SotL' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames -

#16Trienco  Members

Posted 03 September 2012 - 10:27 PM

'and' is not a C++ keyword. If you have a macro named 'and' that is defined as '&&', get rid of it!

Actually it is and it is the same as &&. However, absolutely nobody uses it to the point where I didn't even know about it after almost 10 years of C++. Maybe it's because && is easier to type or simply because it sticks out a lot better than 'and'. Basically, use && and || instead of 'and' and 'or', unless you are extremely paranoid of accidentally using & and | instead.
f@dzhttp://festini.device-zero.de

#17Servant of the Lord  Members

Posted 04 September 2012 - 10:23 AM

Oh wow, I never knew that. I've never seen them used in C++, and most C++ operator lists don't even mention them (but it does here).

Because of their very uncommon use (in C++), I would still recommend getting rid of them and use the more commonly recognized symbols.

Edited by Servant of the Lord, 04 September 2012 - 10:26 AM.

It's perfectly fine to abbreviate my username to 'Servant' or 'SotL' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames -

#18CC Ricers  Members

Posted 04 September 2012 - 11:54 AM

I've seen "and" sparingly used in some old PHP code, but I also have never seen it being used in any recent examples. Whoever or whatever sources you've used to learn the C++ language must have some interesting but outdated approaches.

2) Don't cram multiple things onto one line 'just because'.

Following this advice is not only to make code easier to read, but also to make it far easier to debug.

If you get a syntax error in runtime, or logical error causing a crash and the debugger points to line XX being the problem line, it's gonna be harder to know exactly what in that line made it crash if you had multiple statements going on.

New game in progress: Project SeedWorld

My development blog: Electronic Meteor

#19L. Spiro  Members

Posted 05 September 2012 - 06:34 AM

“and” and “or” are very rare and I have never seem them in practice, but at least they are documented.
Here is a snippet of code that may look entirely alien to most of you.

int iBlah<:100:>;
if ( bBleegers and bBloopers )
for ( int i = sizeof( iBlah ) / sizeof( iBlah<:0:> ); i--; ) <% iBlah<:i:> = i; %>


I wrote this on paper for my coworkers today and asked, “What language is this?”.
All of them are very experienced and none of them were able to answer correctly.

It’s plain C/C++. Actually “and” is not a C keyword, but the rest of it will compile in any C compiler (assuming you have declared bBleegers and bBloopers).
Try it for yourself.

C/C++:
<% = {
%> = }
<: = [
:> = ]

C++ Only:
and = &&
or = ||

These tokens were created because 20 years ago not all keyboards had &, |, {, }, [, and ] characters. So these are all exact drop-in replacements.

Again, I have never seen any of these in actual use and there seems not to be any documentation of it anywhere.
The only reason I know about them is because I wrote a C compiler a long time ago.
The lexer grammar for ANSI C can be found here:
http://www.lysator.l...-grammar-l.html

All that being said, I have to honestly question how the original poster knew about “and” and especially why he or she is actually using it.
It does not appear in tutorials or books. How could a beginner possibly not know about and use &&? Any learning resource you ever find will be using only &&, so I have to ask, where on earth did you learn C++? Even if you come from a scripting background you would have had to look at some tutorial or learning source on C++ somewhere, and there is no chance it would have been using &&…

L. Spiro

Edited by L. Spiro, 05 September 2012 - 06:38 AM.

#20Servant of the Lord  Members

Posted 05 September 2012 - 07:45 AM

I'm familiar with ternary (though I don't have them memorized).

As to where he learned it, I don't think it's that hard to accidentally learn if you're coming from a different language that uses AND and OR.

For example:

I've seen "and" sparingly used in some old PHP code, but I also have never seen it being used in any recent examples.

When I read that I smiled to myself half-embarrassed, because over the past 30 days I've had to learn PHP for getting my game's website up and running... and I was using 'and' and 'or' the entire time. Only once CC Ricers indicated it was outdated and unused, did I realize that PHP even had && and ||.

'course now I''ve switched to && and || in PHP, since that's what I'm more familiar with from C++ anyway. Plus I like that && and || are so tall and distinguishable from other letters, that they act as visual separators between variable names. (run and gun) vs (run && gun)
It's perfectly fine to abbreviate my username to 'Servant' or 'SotL' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames -

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.