• 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

    • I disagree; they come off very "bitchy" and "whiny". Make a great product and combine that with a great price (free) and people will come over to your side. Or build it and they will come as they say. Constantly trying to get attention by complaining all the time, will turn people off to your product.
    • It use to be a nightmare, with LibreOffice supporting a newer draft ODF standard by default, and Microsoft Office supporting the older non-draft standard. Now that they both support the same version of ODF, they should be interoperable.
    • Brave Browser 1.91.171 by Razvan Serea Brave Browser is a lightning-fast, secure web browser that stands out from the competition with its focus on privacy, security, and speed. With features like HTTPS Everywhere and built-in tracker blocking, Brave keeps your online activities safe from prying eyes. Brave is one of the safest browsers on the market today. It blocks third-party data storage. It protects from browser fingerprinting. And it does all this by default. Speed - Brave is built on Chromium, the same technology that powers Google Chrome, and is optimized for speed, providing a fast and responsive browsing experience. Brave Browser also features Brave Rewards, a system that rewards users with Basic Attention Tokens (BAT) for viewing opt-in ads. This innovative system provides an alternative revenue model for content creators and a way to support the Brave community. SlimBrave Neo takes all the good things about Brave and makes them even better by keeping everything clean, light, and privacy-focused. It removes the extra clutter, turns off features you might not need, and cuts down on anything that could slow you down or collect unnecessary data. Because it relies on simple settings and policies instead of modifying the browser itself, you still get full Brave compatibility—just in a smoother, lighter, and more privacy-friendly package. Brave Browser 1.91.171 changelog: General Fixed Cardano not being disabled on upgrade to Brave Origin. Upgraded Chromium to 149.0.7827.103. Origin Removed “Survey Panelist” setting from brave://settings/privacy. Fixed P3A and usage ping under brave://settings/privacy being displayed on first launch on Linux. Upgraded Chromium to 149.0.7827.103. Download: Brave Browser 64-bit | 1.2 MB (Freeware) Download: Brave Browser 32-bit View: Brave Homepage | Offline Installers | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Hi. As the title suggests, I can't access the forum on my phone. I'm using Edge on Android and when I try to navigate to the forum I get a "we value your privacy" popup and none of the buttons are clickable. It effectively stonewalls me from reading any forum content.
    • Honestly you're not wrong about AdGuard. Neowin frequently has lifetime license discounts for them and that's how I got my cheap family license a few years ago to run it on all my devices.
  • Recent Achievements

    • Rookie
      Marzoid went up a rank
      Rookie
    • Community Regular
      coch went up a rank
      Community Regular
    • One Year In
      slackerzz earned a badge
      One Year In
    • One Year In
      highriskpaym earned a badge
      One Year In
    • One Month Later
      highriskpaym earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      519
    2. 2
      PsYcHoKiLLa
      190
    3. 3
      +Edouard
      156
    4. 4
      Steven P.
      84
    5. 5
      ATLien_0
      75
  • Tell a friend

    Love Neowin? Tell a friend!