12 Replies - 1696 Views - Last Post: 10 October 2012 - 09:20 PM Rate Topic: -----

#1 devonrevenge  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 22
  • Joined: 08-October 12

where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 03:25 AM

didnt have enough room there.

this is the challenge, i dont want the answer but i need hints enough to know how to study for it or approach the problem, i know i need an array in a loop to display the board, do i do this by writing lines and endlines or is there some kinda board function?

Make a two player tic tac toe game.

★ Modify the program so that it will announce when a player has won the game (and which player won, x or o)

★★ Modify the program so that it is a one player game against the computer (with the computer making its moves randomly)

★★★★ Modify the program so that anytime the player is about to win (aka, they have 2 of 3 x's in a row, the computer will block w/ an o)

Is This A Good Question/Topic? 0
  • +

Replies To: where t start studying to learn how to go about this practice chalenge

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 03:49 AM

I'd use a 2-dimensional array to store the values (o, x or clear).
char board = [3][3]

Ie: Then just check based on:
The positions of Xs, Os and clears within the array.
Like this:
if (board[3][3] == 'X' && ) \\etc
{
cout << "X wins!"
}

And so on for that. I don't know too much about painting and drawing things, just the logic stuff.

This post has been edited by DimitriV: 09 October 2012 - 03:50 AM

Was This Post Helpful? 1
  • +
  • -

#3 devonrevenge  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 22
  • Joined: 08-October 12

Re: where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 04:16 AM

yeah thats really good, now i have to suss out a board
Was This Post Helpful? 0
  • +
  • -

#4 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 04:22 AM

Does it have to be an image or can it be ASCII?
You could just have it running and clearing the screen:
http://www.cplusplus.../beginner/3304/

This link advises not to use System calls and instead use cout.

Urrgh: how are you going to get it to place the tiles in the right space?

This post has been edited by DimitriV: 09 October 2012 - 04:26 AM

Was This Post Helpful? 1
  • +
  • -

#5 devonrevenge  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 22
  • Joined: 08-October 12

Re: where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 08:11 AM

im trying to make a tic tac toe game work, this is only the beginning but when i test it, no board updaty :(
trying to understand why it wont update the characters in "getboard"
#include <iostream>
#include <string>

using namespace std;

char a,b,c,d,e,f,g,h,i,j;// so these represent the empty spaces in getbrd
char x = 'X';
char o = 'O';// these are what i want to replace the empty spaces with                  
string name;
string name2;
char brdlog [3] [3];// im not using this yet
void getbrdstart ();//this is just the display to start with
void getbrd ();
int input;
void plyr1 ();//the function that usees a switch statment to replace spaces in                 \\getbrd


int main ()

{
getbrdstart ();

cout << "TIC TAC TOE BY DEVONREVENGE\n"<<endl;

cout << "player 1 enter your name..."<<endl;
cin >> name;
cout << "player 2 enter your name..."<<endl;
cin >>name2;
plyr1 ();
getbrd ();



return 0;
}

void getbrd ()
{
cout << a << "|" << b << "|" << c<<endl;
cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << d<<"|"<<e<<"|"<< f <<endl;
  cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << g<<"|"<<h<<"|"<< i <<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"<< endl;

}

void getbrdstart ()
{
cout << "1" << "|" << "2" << "|" << "3"<<endl;
cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << "4"<<"|"<<"5"<<"|"<< "6" <<endl;
  cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << "7"<<"|"<<"8"<<"|"<< "9\n \n" <<endl;
}


void plyr1 ()
{
cout << name << "input number to place your O"<<endl;
cin >> input;
switch (input)
{
case '1':
a=o;
break;
case '2':
b=o;
break;
case '3':
c=o;
break;
case '4':
d=o;
break;
case '5':
e=o;
break;
case '6':
f=o;
break;
case '7':
g=o;
break;
case '8':
h=o;
break;
case '9':
i=o;
break;
}
}



wait this is the wrong place i will put it somwhere else in the main help bit

This post has been edited by devonrevenge: 09 October 2012 - 08:19 AM
Reason for edit:: Fixed Code tags.

Was This Post Helpful? 0
  • +
  • -

#6 devonrevenge  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 22
  • Joined: 08-October 12

Re: where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 08:34 AM

ahh wait they closed it, the admin way too keen they love to give me bad reputation points to encourage me

no ones gonna bloody see it here too and now i cant talk about it to anyone else theyve kind of made my subject taboo :plain:

This post has been edited by devonrevenge: 09 October 2012 - 08:41 AM

Was This Post Helpful? -2
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9195
  • View blog
  • Posts: 34,526
  • Joined: 12-June 08

Re: where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 09:17 AM

Quote

no ones gonna bloody see it here too and now i cant talk about it to anyone else theyve kind of made my subject taboo :plain:

No, we just do not need to have 2 -> n possible threads about the same topic of yours.
Was This Post Helpful? 0
  • +
  • -

#8 jimblumberg  Icon User is offline

  • member icon


Reputation: 4068
  • View blog
  • Posts: 12,549
  • Joined: 25-December 09

Re: where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 09:18 AM

You don't need multiple topics open for the same problem. So I closed the second topic. You have this one open use it.

People will respond when and if they so desire. You can really help yourself to get more help by finding an indentation style you like and use it consistently, using meaningful variable names, avoiding global variables.


Jim

This post has been edited by jimblumberg: 09 October 2012 - 09:18 AM
Reason for edit:: Added Missing link.

Was This Post Helpful? 2
  • +
  • -

#9 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3570
  • View blog
  • Posts: 11,104
  • Joined: 05-May 12

Re: where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 09:55 AM

I have to agree with Jim. I usually skip questions with badly formatted code and come back to them only on the third or fourth pass because it takes 3 to 4 times more time and energy to read badly formatted code than it is to read code with poor variable and function names.

Anyway, you are inputting an integer input, yet in your switch statement you are comparing against characters.
Was This Post Helpful? 0
  • +
  • -

#10 devonrevenge  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 22
  • Joined: 08-October 12

Re: where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 10:08 AM

indentation style will be a lot of help thank you for suggesting mr bloomburg
Was This Post Helpful? 0
  • +
  • -

#11 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3570
  • View blog
  • Posts: 11,104
  • Joined: 05-May 12

Re: where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 11:15 AM

View PostDimitriV, on 09 October 2012 - 03:49 AM, said:

I'd use a 2-dimensional array to store the values (o, x or clear).
char board = [3][3]

Ie: Then just check based on:
The positions of Xs, Os and clears within the array.
Like this:
if (board[3][3] == 'X' && ) \\etc
{
cout << "X wins!"
}

And so on for that. I don't know too much about painting and drawing things, just the logic stuff.


Beware: The code above overruns the buffer because C/C++ arrays are zero based.
Was This Post Helpful? 1
  • +
  • -

#12 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5305
  • View blog
  • Posts: 27,198
  • Joined: 10-May 07

Re: where t start studying to learn how to go about this practice chalenge

Posted 09 October 2012 - 11:27 AM

View Postdevonrevenge, on 09 October 2012 - 11:34 AM, said:

ahh wait they closed it, the admin way too keen they love to give me bad reputation points to encourage me

Pm sent.
Was This Post Helpful? 1
  • +
  • -

#13 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: where t start studying to learn how to go about this practice chalenge

Posted 10 October 2012 - 09:20 PM

Now, looking at the code, I find that after you enter the player names, the control goes to the plyr1 function. In this function you are expecting the player to provide an input in the form of numbers and the player enters numbers from 1 to 9. Here what I feel is that instead of a character initialization,you could probably use a character array and assign the values according to the indexes of the arrays.

For eg.


char tictac[]={'_','_','_','_','_','_','_','_','_'}/*I am not sure if this can be done but you can try it*/
.
.
.
switch(input)
{
case 1: tictac[0]=o;
break;
case 2: tictac[1]=o;
.
.
.
.
case 9: tictac[8]=o;
}



And remember to change the variable values to array values in your getbrd function.
Hope the idea I have provided helps you. :)

regards,
Raghav

This post has been edited by raghav.naganathan: 10 October 2012 - 09:22 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1