• 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

    • If you are willing to go to approx $200, then as mentioned in your other thread I think a refurbished Pixel 8 will be a great deal that will last you for years. I recently recommended that to someone at work, he was on a strict £200 budget, which got him an excellent conditioned refurbished Pixel 8 here. He's since told me its the best phone he's ever had and feels its a massive upgrade over his old Samsung A series device. I don't know the sites which deal in refurbished devices in the US, however I’m sure you will have some options like we do here. Failing that Ebay is also quite good in my experience. If you wanted something a bit cheaper, then you could maybe go for an older Pixel 7, these will still get security updates until the end of 2027. Even after that you have good third party OS support from LineageOS. It doesn't have to be a Pixel though, you can buy many older devices for a good deal that would be better than a new $100 phone and flash LineageOS to them: https://wiki.lineageos.org/devices/
    • I don't use one drive, but then I don't use any cloud storage, not even Icloud on my mac. If I did use cloud storage, then I would not use One drive, not because there is anything wrong with it, but because I can use Icloud. The only reason I see to use one drive is if your job requires you to have access to it
    • Not built in, which is not a bad thing. There are ways of adding cloud storage to it, Dropbox is the most well know that also have a client for Linux, but there are others.
    • My advice, dont use teams, use the web version if possible. https://teams.microsoft.com/v2/
  • Recent Achievements

    • Collaborator
      WndSks went up a rank
      Collaborator
    • One Month Later
      Sopa flores earned a badge
      One Month Later
    • First Post
      StaticMatrix earned a badge
      First Post
    • Week One Done
      StaticMatrix earned a badge
      Week One Done
    • Rookie
      lamborghiniv10 went up a rank
      Rookie
  • Popular Contributors

    1. 1
      +primortal
      506
    2. 2
      PsYcHoKiLLa
      209
    3. 3
      +Edouard
      152
    4. 4
      Steven P.
      89
    5. 5
      ATLien_0
      79
  • Tell a friend

    Love Neowin? Tell a friend!