|
|
|
||||
|
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() |
|
|||||||
| Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
|
Thread Tools |
|
|
#1 |
|
Guest
Posts: n/a
|
basic C++ question:
So I have this 2 dimensional Array (3X3)
and I want to make it so "if there is an "X" in slot 2-2, return a "YES" tried doing if ( board[2][2] hahahaha 'X' ) { cout << "Yes"; } else { cout << "No"; } and I keep on getting "No"s at every turn can anybody help me out on this one? what I am actually trying to do, is that it's a TIC TAC TOE game, and I need to stop the program once someone wins... help me out yooo!!! 178340550 |
|
|
|
#2 |
|
Confirmed User
Join Date: Oct 2002
Location: Ottawa
Posts: 4,179
|
ah shit.. haven't done any C++ in over 10years
damn.. now I wanna know too and I know it's a fuckin simple thing |
|
|
|
|
|
#3 |
|
Confirmed User
Join Date: Apr 2004
Location: NEW YORK CITY
Posts: 2,274
|
post the code somewhere where it wont go hahahaha
__________________
Make Real Green with ORGANIC SEO | Blog post exchange | Non-index page trades | A-B C-D Trades [icq: 194-215-962] [mail: [email protected]] |
|
|
|
|
|
#4 | |
|
Guest
Posts: n/a
|
Quote:
|
|
|
|
|
#5 | |
|
Confirmed User
Industry Role:
Join Date: Jan 2004
Location: Nor'easterland
Posts: 1,914
|
Quote:
Try this: Code:
if(board[1][1]hahahaha'X') { // Is there an X in the middle square?
cout << "Yes";
} else {
cout << "No";
}
|
|
|
|
|
|
|
#6 |
|
Confirmed User
Industry Role:
Join Date: Jan 2004
Location: Nor'easterland
Posts: 1,914
|
A 'win' state checker:
Code:
char *checkwin(char board[2][2]) // Prototype might be a bit off, adjust accordingly ;)
{
// Check horizontal
for(int y=0;y<3;y++) {
int xs, os;
for(int x=0;x<3;x++) {
xs += (board[x][y] = = 'X');
os += (board[x][y] = = 'O');
}
}
if(xs= =3) return("X Wins");
if(os= =3) return("O Wins");
// Check vertical
for(int x=0;x<3;x++) {
int xs, os;
for(int y=0;y<3;y++) {
xs += (board[x][y] = = 'X');
os += (board[x][y] = = 'O');
}
}
if(xs= =3) return("X Wins");
if(os= =3) return("O Wins");
// Check left-right diag
for(int a=0,xs=0,os=0;a<3;a++) {
xs += (board[a][a] = = 'X');
os += (board[a][a] = = 'O');
}
if(xs= =3) return("X Wins");
if(os= =3) return("O Wins");
// Check right-left diag
for(int a=0,xs=0,os=0;a<3;a++) {
xs += (board[a][2-a] = = 'X');
os += (board[a][2-a] = = 'O');
}
if(xs= =3) return("X Wins");
if(os= =3) return("O Wins");
// No winnar.
return;
}
![]() |
|
|
|
|
|
#7 | |
|
Ryde or Die
Industry Role:
Join Date: Dec 2002
Location: California-Shanghai
Posts: 19,568
|
Quote:
Doing a assignment for cs class? |
|
|
|
|
|
|
#8 |
|
Confirmed User
Join Date: Dec 2003
Location: Toronto
Posts: 562
|
use the min max algo, i coded a tic tac toe game for school a couple years ago using this algo, and it was undefeatable..
http://personal.vsnl.com/erwin/tictactoe.htm
__________________
icq: 375956791 |
|
|
|
|
|
#9 |
|
Join Date: Nov 2002
Posts: 2,174
|
array element numbering starts with 0 not 1
__________________
|
|
|
|
|
|
#10 |
|
Confirmed User
Join Date: Feb 2003
Location: Mostly the couch
Posts: 331
|
Nerds
just kidding ![]() |
|
|
|
|
|
#11 |
|
Confirmed User
Join Date: Jul 2001
Location: Teh Interweb
Posts: 2,439
|
Nerds
![]() |
|
|
|
|
|
#12 |
|
Guest
Posts: n/a
|
got it! thanx guys
now another question, how do I reset an array? make it all empty again? |
|
|
|
#13 |
|
ICQ: 197-556-237
Join Date: Jun 2003
Location: BRASIL !!!
Posts: 57,559
|
Damn! I used to know C++, now I don't remember shit!
__________________
I'm just a newbie. |
|
|
|
|
|
#14 | |
|
Confirmed User
Industry Role:
Join Date: Jan 2004
Location: Nor'easterland
Posts: 1,914
|
Quote:
Code:
memset((void *)array_ptr, number_of_elements * sizeof(array_type), 0); Code:
array_ptr = (array_type *)calloc(number_of_elements, sizeof(array_type)); HTH. HAND. PS - If you malloc()'d the array originally, make sure you free() it before doing a new malloc(), otherwise you'll leak ram. ![]() |
|
|
|
|
|
|
#15 |
|
Guest
Posts: n/a
|
everything works!!! thanx alot for your help guys
|
|