• 0

How to be a game programmer and developer?


Question

Hello :) .I am new in this forum and i am really interested in programming.I really want to learn to program with Cuda, C++ you know. I want to make my own game engines and 3D games with stunning grafiks. I saw really interesting things in the Nvidia developer zone like Nvidia PhysX SDK, OpenGL, OpenCL, DirectX and many other stuff. I want to learn how to program with them and for what and how can i use it? What i must learn first? From what i must start? What book's i must read of i am new to software and game programming? I am really confused. Thank's :D .

Recommended Posts

  • 0

I probably don't. I got quite lost as that course went on. I understood the theory but was terrible at implementing it. And yes, AI in games often means things that aren't true AI.

That's what i mean :) . Ok so i want to comment something that you sad. You sad that i am ignoring the 3rd one. That's not true. I am searching every day for more information for what i don't know. I think you know perfectly what i don't know that i don't know :) . Then i will be happy if you tell your secret :) .

  • 0

Well... yes, depending on how simple that AI is. As I just illustrated, you can make a very potent Tic-Tac-Toe AI with a few if statements. It doesn't answer unmodified Jeopardy questions in real-time but you still have to try pretty hard to beat it. :p

I usually have nothing but respect for your posts Dr_Asik, but in this case you're wrong, you made a static decision engine. AI is a whole different ballpark mate.

  • 0

I've never read from an authoritative source that learning was an essential component of any AI. According to Wikipedia, as I've previously quoted:

AI textbooks define the field as "the study and design of intelligent agents"[2] where an intelligent agent is a system that perceives its environment and takes actions that maximize its chances of success.[3] http://en.wikipedia.org/wiki/AI

I think my little function with 3 if statements can be defined as

  • "a system that perceives its environment" (it has access to the tic-tac-toe board data)
  • "and takes actions" (it produces moves)
  • "that maximize its chances of success" (it uses rules to play the best possible move).

It is therefore an intelligent agent which the object of AI.

I'm open to different point of views of course but not without argumentation.

  • 0

This is difficult to answer. Many will think that it is AI and many will thing that it isn't AI. And i am not really sure if it is, but the thing that makes it a little intelligent is the random moves.

In the context of a game, any code that defines the behavior of a computer-controlled opponent is considered "AI". Outside of games it requires the ability to learn. Like many words, it has different meanings depending upon context.

  • 0

I've never read from an authoritative source that learning was an essential component of any AI. According to Wikipedia, as I've previously quoted:

AI textbooks define the field as "the study and design of intelligent agents"[2] where an intelligent agent is a system that perceives its environment and takes actions that maximize its chances of success.[3] http://en.wikipedia.org/wiki/AI

I think my little function with 3 if statements can be defined as

  • "a system that perceives its environment" (it has access to the tic-tac-toe board data)
  • "and takes actions" (it produces moves)
  • "that maximize its chances of success" (it uses rules to play the best possible move).

It is therefore an intelligent agent which the object of AI.

I'm open to different point of views of course but not without argumentation.

You are correct. You would call such a form of AI a Reactionary Agent, as opposed to a State Based Agent.

  • 0

That's what i mean. Everyone in this forum things differently for the AI. I think the random moves make it more inteligent. Another part thing that the if statements make is more inteligent. For the source code: For now i will not post it. It's in developing. For that. And it isn't complete. I want to ask something. Is it normal the code of the AI to be aproximately 1500 lines of code? The Tic-tac-Toe without AI is just aproximately 290 lines of code. So it will be aproximately 1790 lines of code when it is complete i think.

  • 0
Is it normal the code of the AI to be aproximately 1500 lines of code? The Tic-tac-Toe without AI is just aproximately 290 lines of code. So it will be aproximately 1790 lines of code when it is complete i think.
That's probably a lot. You probably have a lot of repetition in there, which can be fixed by better design. But without seeing the code, it's impossible to tell what can be improved.
  • 0

After reading the post that he used 1600 lines to write tic-tac-toe with AI I thought I'd see how small mine would come out to in C.

I ended up with about 100 lines of spaghetti code.

And no, I don't use goto in actual programs.

#include <iostream>
using namespace std;

int AskForNumber(char* prompt) {
	cout << prompt;
	int r = 0;
	cin >> r;
	return r;
}

int CheckForEnd(int (*board)[3][3], int cindex, int lmx, int lmy, bool player) {
	for (int x = 0, y = 0; y < 3; y+=((x==2)?1:0),x+=((x==2)?-2:1) ) {
			if ((*board)[x][y] == 2)
				goto notadraw;
	}
	cout << "\nDraw!\n";
	return 3;
notadraw:
	for (int i = 0; i < 3; i++) {
		if ( ( (*board)[i][0] == (*board)[i][1] ) && ((*board)[i][1] == (*board)[i][2]) ) {
			if ( (*board)[i][0] != 2 )
				goto win;
		}
	}
	for (int i = 0; i < 3; i++) {
		if ( ( (*board)[0][i] == (*board)[1][i] ) && ((*board)[1][i] == (*board)[2][i]) ) {
			if ( (*board)[0][i] != 2 )
				goto win;
		}
	}
	if ( ( (*board)[0][0] == (*board)[1][1] ) && ((*board)[1][1] == (*board)[2][2]) && ((*board)[0][0] != 2)) {
			goto win;
	}
	if ( ( (*board)[1][1] == (*board)[0][2] ) && ((*board)[1][1] == (*board)[2][0]) && ((*board)[1][1] != 2)) {
			goto win;
	}
	return 0;
win:
	cout << (player ? "\nPlayer Won!\n" : "\nComputer Won!\n");
	return (player) ? 1 : 2;
}

int main(int argc, char** argv) {
begin:
	char* boardStrings[] = { "O", "X", "#" };
	int playerIndex = AskForNumber("Choose piece:\n0. O\n1. X\n"), computerIndex = ((playerIndex) ? 0 : 1); //should really check for > 1 here
	int board[3][3] = { 2,2,2,2,2,2,2,2,2 };
	while (!CheckForEnd(&board, computerIndex, 0, 0, false)) {
		for (int x = 0, y = 0; y < 3; y+=((x==2)?1:0),x+=((x==2)?-2:1) ) {
			cout << boardStrings[board[x][y]] << ((x == 2) ? "\n" : "");
		}
	penter:
		int x = AskForNumber("\nEnter 0-based destination x coord: "), y = AskForNumber("\nEnter 0-based destination y coord: ");
		if (x > 2 || y > 2 || board[x][y] != 2) {
			cout << "\nInvalid coordinate!\n";
			goto penter;
		}
		board[x][y] = playerIndex;
		if (CheckForEnd(&board, playerIndex, x, y, true))
			break;
		int p = -1, b = -1;
		for (int cplayer = 1; cplayer != -1; cplayer--) {
			int mx = -1, my = -1;
			for (int nx = 0; nx < 3; nx++) {
				int cplayer_pieces = 0;
				for (int ny = 0; ny < 3; ny++) {
					if (board[nx][ny] == cplayer)
						cplayer_pieces++;
					else if (board[nx][ny] != 2) {
						cplayer_pieces = 0;
						break;
					}
					else {
						mx = nx;
						my = ny;
					}
				}
				if (cplayer_pieces == 2 && mx != -1 && my != -1) {
					board[mx][my] = computerIndex;
					x = mx;
					y = my;
				}
			}
		}
		if (board[1][1] == 2) {
			board[1][1] = computerIndex;
			x = 1;
			y = 1;
			goto computerdone;
		}
		for (int x = 0, y = 0; y < 3; y+=((x==2)?1:0),x+=((x==2)?-2:1) ) {
			if (board[x][y] == 2) {
				board[x][y] = computerIndex;
				p = x;
				b = y;
				goto computerdone;
			}
		}
computerdone:
		if (p != -1) {
			x = p;
			y = b;
		}
		if (CheckForEnd(&board, computerIndex, x, y, false))
			break;
	}
	goto begin;
}

  • 0

After reading the post that he used 1600 lines to write tic-tac-toe with AI I thought I'd see how small mine would come out to in C.

I ended up with about 100 lines of spaghetti code.

Your AI is so good, it can actually play twice in one turn :rofl: :

post-138285-0-41486700-1311813002.png

  • 0

Your AI is so good, it can actually play twice in one turn :rofl: :

post-138285-0-41486700-1311813002.png

Heh, never seen that happen before.

Anyway it wouldn't take 1500 lines to fix that bug so my point still stands.

I just forgot a goto inside

if (cplayer_pieces == 2 && mx != -1 && my != -1) {

  • 0

Ok i will post the code. It isn't well programmet at all. What i mean is the code. For the program it works really well, but it isn't complete. This is the code with AI. The code without AI is aproximately 290 lines of code and i like ot, but it can be really better written. The waste of lines of code is because of the anticheating system and the AI.Without them it will be aproximately 100 lines of code.

PS: And sorry for not using an array for the board. When i was writing the core code of the program i don't knowed what's an array.And sorry for the text format. It say's that i can't upload files in this format. The this format is .cpp. So i made it .txt so that i can upload it.

main.txt

  • 0

Ok i will post the code. It isn't well programmet at all. What i mean is the code. For the program it works really well, but it isn't complete. This is the code with AI. The code without AI is aproximately 290 lines of code and i like ot, but it can be really better written. The waste of lines of code is because of the anticheating system and the AI.Without them it will be aproximately 100 lines of code.

PS: And sorry for not using an array for the board. When i was writing the core code of the program i don't knowed what's an array.And sorry for the text format. It say's that i can't upload files in this format. The this format is .cpp. So i made it .txt so that i can upload it.

OH DEAR GOD! MY EYES, THEY BURN!!!

I know you are quite young, and it's a really good effort. But please before jumping ahead too much and corrupting your fresh brain, try advancing in the core development concepts.

Looking at the code you posted, it's very obvious that you just started coding, and you are doing a lot of things wrong (well pretty much everything).

  • 0

Making games takes a lot of work, learn through either making a cirrulum for yourself or taking computer science courses, you will need to learn data structures, databases, algorithms, software development, and software design and architecture. Learn to walk before you run, set smaller goals for yourself, you will need to do well with mathematics and science. You have to make it a process where you can teach yourself these things, and practice practice practice.

  • 0

Can you please stop with these computer courses. I don't have money for that. And i can't go to college or universuty, because i am in Highschool.

PS: And i know the code is horrible. Some advice? I mean what i must do to fix this? Not the code for the Tic-Tac-Toe. I mean my programming style at all?

  • 0

I know you are doing C++, but these should give you some ideas on how to structure a game well.

http://www.phstudios.com/tutorials/xna/Paddles/PaddlesXNATutorial.pdf (very old but basic tutorial)

http://phstudios.com/?q=node/49

Edit: For a console based Tic-Tac-Toe game, I recommend using the MVC approach (model, view, and controller). Here is an example I did on the iPhone (Objective C). I do not expect you to fully understand the coding, but you should be able to see I created several methods to clean the code, and I also cleaned up the checking code (so there is not 1,000 if statements).

(model): https://phstudios.svn.beanstalkapp.com/iphonedevelopment/trunk/C490/Homework%203/TicTacToeModel.m

(view): https://phstudios.svn.beanstalkapp.com/iphonedevelopment/trunk/C490/Homework%203/TicTacToeView.m

(controller): https://phstudios.svn.beanstalkapp.com/iphonedevelopment/trunk/C490/Homework%203/TicTacToeController.m

Again, I do not expect you to fully understand the Objective C code. If you just take a look at the Model - Win function, this technique should clean up your code by a large amount:

	//Check Rows
	for(int i = 0; i < 3; i++)
	{
		s1 = (NSString *)[board objectAtIndex:i * 3];
		s2 = (NSString *)[board objectAtIndex:(i * 3) + 1];
		s3 = (NSString *)[board objectAtIndex:(i * 3 ) + 2];

		if (s1 == s2 && s2 == s3) {
			return YES;
		}
	}

	//Check columns
	for(int i = 0; i < 3; i++)
	{
		s1 = (NSString *)[board objectAtIndex:i];
		s2 = (NSString *)[board objectAtIndex:i+3];
		s3 = (NSString *)[board objectAtIndex:i+6];

		if (s1 == s2 && s2 == s3) {
			return YES;
		}
	}

	//Check Diagonals
	for(int i = 0; i < 3; i = i+2)
	{
		int j = 1;
		if(i == 2)
			j = -2;
		s1 = (NSString *)[board objectAtIndex:(i * 3)];
		s2 = (NSString *)[board objectAtIndex:(i * 3) + (4 / j)];
		s3 = (NSString *)[board objectAtIndex:(i * 3) + (8 / j)];

		if (s1 == s2 && s2 == s3) {
			return YES;
		}

	}

Where board is a string (NSString) array. You can just use a char array in C++:

char board[] = "123x456o789";
   char s1 = board[3];

S1 will be X.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • The problem of course is simply that government does not always know best. My point is that agency is taken away from the EU consumer in these cases. I'm sorry, but I do not believe that governments (politicians) are inherently good, and "looking out for me." Primarily they look to themselves and their own personal desires first, foremost, and always. When the EU or the DOJ fines these companies, claiming to "represent the welfare of the consumer," how much of these billion-dollar judgments are handed to the consumers they claim to represent? Not even a dollar, as I've seen. Yet the EUC lawyers who are paid to sit around and dream up these suits make huge commissions on the fines the EUC adjudicates, which is an ironclad fact I hope everyone is aware of. It's also rank corruption, of course, but that's another topic. Last, when the EU inflicts these judgments, or the DOJ, take your pick, the costs are bundled right along in the cost of the goods and services these companies provide the consumers they are "looking out for." If you are someone who believes his government is his savior then you have my condolences. I think Apple is right here, because the whole scheme of consumer choice is that consumers pick and choose among the products companies offer. Microsoft Windows is more compatible with third party software and hardware than any desktop OS on Earth, which is my sole reason for choosing it. Just because the EUC forces companies do certain things it knows the companies do not want to do, "or else", has no bearing on consumer benefit. This Siri thing is almost idiotic it's so infantile. But this is what the EUC does when the EU in Brussels becomes cash-strapped and needs a big infusion of cash. Some people get upset by "big companies" but it's the opposite when governments dwarf the size and scope of these companies, which is so obvious it hurts.... I mean you can't honestly believe that forcing Apple to do things with Siri it has its own reasons to decline is something that "opens up" Apple, do you? Say it aint' so...
    • Looks like many years since the request was made, a directory tree view finally may be added. https://github.com/files-community/Files/pull/18537
    • There's this from last year https://gist.github.com/threat...364659a8887841aa43deca4efd9 but nothing about a buffer overflow that MS somehow can't code against. No matter what, it makes sense to take a "protected by default" approach.
  • Recent Achievements

    • One Month Later
      sjbousquet earned a badge
      One Month Later
    • Week One Done
      sjbousquet earned a badge
      Week One Done
    • First Post
      DragonOfMercy earned a badge
      First Post
    • First Post
      bella52 earned a badge
      First Post
    • Reacting Well
      Techinmay earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      501
    2. 2
      PsYcHoKiLLa
      212
    3. 3
      +Edouard
      156
    4. 4
      Steven P.
      84
    5. 5
      FloatingFatMan
      72
  • Tell a friend

    Love Neowin? Tell a friend!