MANY people argue that C++ is good for nothing...

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

MANY people argue that C++ is good for nothing...

Post by Falco Girgis »

This is a VERY popular arguement among programmers nowadays...
C++ is useless. It is too high level to do what C and Assembly can, and it is too low level to effectively do what Java can...
How would you respond to this?
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

First off, let me tell you why C++ was created. A while back, the most popular language out there was c. Every company, university, everyone used it. Then, one fateful day *cough* Object Oriented programming was invented. People saw this as the future of programming. But one little problem was in the way... no one in thier right mind was going to reprogram everything in some new language, no matter how good it was. So, the c masters sat down and eventualy developed C++. Giving people the ability to compile their old c programs and the new C++ programs together. C++ had more power, it was faster, and it had the one thing that was taking the world by storm, OO Technology. SO, the people who tell you C++ sucks, are the ones who spent thier long hard time developing in c.

I hope you enjoyed my somewhat exaggerated story, but it is true!
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

Java is extremely slow and pathetic, and as for it being higher-level than C, it was made from C. And try to learn assembly -- C++ compilers optimize the code in assembly probably better than you could write it in assembly yourself.

http://en.wikipedia.org/wiki/C_Plus_Plu ... of_C.2B.2B
Peridox

Post by Peridox »

Try making a Tic Tac Toe game with no instructions what so ever in C++. its hard as fucking shit. I learned that last year.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

By the way, I just made all that stuff about C++ up. I really don't care much why it's here... just that it is.

Oh and Peridox, I feel your pain, I thought "Hey, I can make a simple lil' tic tac toe program in no time"..... 3 days later "the heck is WRONG with this stupid thing!!!!!!!!" 5 days later....... well, lets just say I had to replace my keyboard...
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Peridox

Post by Peridox »

I got everything to work within the first day....except for the Count....which I spent a week on for a fecking Final.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

OMFG!!111one

JS Lemming, by reading his previous posts, your first impression is that Peridox is a dumbass (sorry peri, it comes naturally :wink: J/K). In reality, he's got some mad skillz. Maybe almost as mad as me! :D

Anyway, I'm going to introduce MarauderIIC, and he DOES have exremely mad C++ skills. Any questions and you should ask either of them.

I just can't believe peridox knows C++ O_o
... and from what I conclude, he really kicks ass :shock:
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

...Wouldn't you just use a 3x3 array? And then there are only... one two three four five six seven eight.. eight different checks to make for whether or not someone wins. Which you can narrow by checking where they placed their last piece (IE, bottom left would have left column right column diagonal checks). But that'd require more effort. (1:29 AM now)

Crappy code just seeing how fast I can write it.

Code: Select all



//Open-source tic-tac-toe by Alex Wilson (MechMarauderIIC@hotmail.com)
//Feel free to distribute and modify without giving any credit to me at all whatsoever.
//Dedicated to JSLemming's keyboard ;)

#include <iostream>
#include <ctype.h>
#include <string>

char board[3][3] = {
					'n', 'n', 'n',
					'n', 'n', 'n',
					'n', 'n', 'n'
					};
void displayBoard();
bool doChecks(char checking);

using namespace std;
int main() {
 
	string userInput = " ";
	int player = 1;
	int x, y = -1;
	cout << "please note that the coordinates are zero based." << endl;
	displayBoard();
	do {
		cout << "player: " << player << ": x-coordinate? ";
		getline(cin, userInput);

		if (!(isdigit(userInput[0]))) {
			continue;
		}
		x = atoi(userInput.c_str());
		cout << endl << "player: " << player << ": y-coordinate? ";
		getline(cin, userInput);
		if (!(isdigit(userInput[0]))) {
			cout << "not a digit" << endl;
			x = y = -1;
			continue;
		}
		y = atoi(userInput.c_str());
		if (y < 0 || x < 0 || y > 2 || x > 2) {
			cout << "invalid" << endl;
			x = y = -1;
			continue;
		}
		if (board[x][y] != 'n') {
			cout << "spot taken" << endl;
			x = y = -1;
			continue;
		}
		if (player == 1) {
			board[x][y] = 'x';
		} else if (player == 2) {
			board[x][y] = 'o';
		}
		displayBoard();
		if (player == 1) {
			if (doChecks('x')) {
				cout << "p1 == WINNER!!!" << endl;
				break;
			}
			player = 2;
		} else {
			if (doChecks('o')) {
				cout << "p2 == WINNER!!" << endl;
				break;
			}
			player = 1;
		}
	} while (userInput[0] != 'q');
	cout << "done - hit enter to quit" << endl;
	getline(cin, userInput);
	return 0;
}

void displayBoard() {
	cout << endl << endl << endl << endl;
	cout << " 012" << endl;
	for (unsigned int ycount = 0;ycount < 3;ycount++) {
		cout << ycount;
		for (unsigned int xcount = 0;xcount < 3;xcount++) {
			cout << board[xcount][ycount];
		}
		cout << endl;
	}
}

bool doChecks(char checking) {
	//cheap cruddy checks
	int soFar = 0;
	unsigned int xcheck, ycheck;

	//vert checks
	for (xcheck = 0;xcheck < 3;xcheck++) {
		for (ycheck = 0;ycheck < 3;ycheck++) {
			if (board[xcheck][ycheck] != checking) {
				soFar = 0;
				break;
			}
			soFar++;
			if (soFar == 3)
				return true;
		}
		soFar = 0;
	}

	//horiz checks
	for (ycheck = 0;ycheck < 3;ycheck++) {
		for (xcheck = 0;xcheck < 3;xcheck++) {
			if (board[xcheck][ycheck] != checking) {
				soFar = 0;
				break;
			}
			soFar++;
			if (soFar == 3)
				return true;
		}
		soFar = 0;
	}

	//diagonal check
	if (board[1][1] != checking)
		return false;
	if ((board[0][0] == checking && board[2][2] == checking) ||
		(board[0][2] == checking && board[2][0] == checking))
	{
		return true;
	}
	return false;
}
it is now 1:49 AM checking to see if it compiles :)
1:53 am - it does after a few parentheses but doesn't work yet ;)
1:55 am - runs. testing to see if it works
1:57 am - doh, has x and y coords flipped.
1:59 am - fixed the x and y coords flipped (was in display)
2:01 am - fixed the display (again ;) ) - counter doesn't work right yet
2:05 am - okay, i think it works 100%. time for the "extensive playtesting" phase.
2:19 am - fixed p2 winning (was checking for 'y' instead of 'o'. yay for mornings :P) - tested and vert wins on a couple places each and both diagonal wins. Pretty sure it all works. Oh. And made it use tabs instead of spaces, since I originally wrote it on the forum :)

Sorry. Just wanted to see if I could do it (quickly). Hadn't written a tic-tac-toe program yet :D

So 20 mins for original code layout. Then 30 minutes of fixing/code-pretty. ;) Total time: ~45 minutes if we allow for me replacing spaces with tabs and doing little things like making it quit when you win and outputting the x-y coordinates. ... yay.

(2:21-2:29 AM - made it prettier. no coding changes, just spaces, a few comments, broke the diagonalchecking line and put {}'s in, etc. edited this post a lot, talked to people, blah blah.
2:30 am- dedicated it to jslemming's keyboard
times are in EST)

Oh, and no I didn't have any instructions. Just thought about how it would work, and how people check to see if they win. Yay, I proved to myself that I can do it. So happy :))

3:25 am : hunted some crap about input. found a new function, std::getline(). then found out why it did not work correctly. fixed the problem. this now uses c++ strings for input. so much better! (read: don't have to check to see if the user wrote more than a character array can handle, don't have to trap the overflow, etc, etc. yes!! learned something new!! funny how www.cppreference.com doesn't list the std::string::getline() function, or i would have learned about it sooner)

IMPORTANT REFERENCE FOR YOU (if you use msvc++ anyway): http://support.microsoft.com/default.as ... US;q240015
(and in general: http://www.bgsu.edu/departments/compsci ... tring.html )
Peridox

Post by Peridox »

I hadn't figured out how to do arrays at that time. thereforth, I ended up with many more lines of code than what you did. And I got pissed off at the count part of the program, for about a week, until I got it to work. Also, I would've used more lines up had I not used the Parse method, which for some reason I like a shitload more than giving each variable their own independant names.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Hey MarauderIIC, Thanks for the dedication.... If only my old keyboard could just type the coords. :mrgreen:

When I tried to make mine, I began with the 2D array also but had a hard time checking it for winning moves.... ha, I had made it look nice though.... the board and pieces where colored (was still a console box) and the board looked like a telephone pad thing... so you only had to type 1 number instead of coords..... o well.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

Well, if you can't think of how to program something, think of how you would do it.
For example, I thought of that by going, "Hmm.. I'd probably look at the top row and if there was an X then I'd go down... and if there were 3 then there would be a winner..." So I programmed it so it goes down one column at a time... but yeah. If you knew that method by now, yay, others can learn. If you didn't, well, you don't have to tell anyone ;)

P.S : Please do not take that as a difinitive sample of my coding, because it is messy and not object-oriented at all :P
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

I've learned how to program what I can By random books, we don't have technology at our learning barns so the peeps there think Apple Computers are Gods..... They don't realize its just the oppisite. Anyway, the books never really tell you how to program, but I'm starting to realize.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

Online tutorials are your friend. That's how I learned (and why there are a few noticable holes in my style and knowledge). Try www.about.com and www.programmersheaven.com -- esp. the C++ message board there -- but only if you get stuck. Learn more by solving it yourself. There's a nice reference at www.cppreference.com and their FAQ has some links to tutorials too I think. Might make a sticky in here for people to post programming resources?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Phelios
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 3
Joined: Sat Jul 24, 2004 2:46 am
Contact:

Post by Phelios »

You say that you should try and do the stuff yourself before checking those sites and whatnot...any sites to actually help me start? I'd figure stuff out myself if I had any clue where to begin. I'm a beginner (but you know that, mar)

By the way, I'm a real life friend of mar's. I expect that I'll be hanging around these boards and attempting to extract knowledge from your posts :)

<--- is interested in programming.

On second thought, I'm not a beginner. I'm 5 steps below beginner. :spin:

Well, any sites for beginners would be good, and thank you. wow...4 in the morning...i should go to bed....
You know, I tried to sign my name here and now I have permanent marker on my computer screen!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

Hiya, welcome to these boards. I'm afraid that I couldn't learn from the internet. Everything I learn is generally from books as I don't do well with simple examples.

If you still want to try to learn from the internet, I can't help you. :(
I learned from books so I don't really know any good sites.

I buy books and lots and lots of them!
Post Reply