• 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

Oh you are right. I remember. Then why board[8]=value works?

I could repeat what I said in my last two posts, but what didn't you understand about these? board[8]=value worked by chance, on your machine, at the time you tested; it might stop working or do anything at any time. It's undefined behavior.
  • 0

I could repeat what I said in my last two posts, but what didn't you understand about these? board[8]=value worked by chance, on your machine, at the time you tested; it might stop working or do anything at any time. It's undefined behavior.

Ok. Then can you advice me how to make the AI? And are you are professional programmer?

  • 0

Oh you are right. I remember. Then why board[8]=value works?

I don't know how to code the AI for this Tic-Tac-Toe. Some advice?

For now, you should just make this a two-player game. AI can be added later after you have made a working board, working input, working move validation, and working victory detection. After you have all that you can add an AI player much more easily.

  • 0

What programmer are you? Do you program game engines or anything with games or you make GUI applications? And what are you developing if it isn't a secret? And the problem programming the AI is the code itself. How to do it? Can it be like the code for checking when and who will win?

  • 0

I used to write inventory control and sales software for manufacturers. Now I'm busy writing a touchscreen music player using the Windows Presentation Foundation/C#...

I think Dr_Asik writes the code that falsely tells you that your bank account is overdrawn. *evil grin*

  • 0

What programmer are you? Do you program game engines or anything with games or you make GUI applications? And what are you developing if it isn't a secret?

I worked in telecom, game programming and now I'm developing UI for flight simulators. In C#. :heart:
And the problem programming the AI is the code itself. How to do it? Can it be like the code for checking when and who will win?
Not sure what you mean. You should have a function that says if a particular move is valid, so you can validate the AI moves:

bool IsAValidMove(int x, int y) // where x, y are the coordinates of the move

Then your AI could be as dumb as trying random moves until it stumbles unto a valid one. See rand for generating random numbers. I'm sure you can figure out better strategies, that's the fun of it.

I think Dr_Asik writes the code that falsely tells you that your bank account is overdrawn. *evil grin*
Indeed, plus I added a backdoor so the penalties don't actually apply when it's me.
Ou you are colleagues.
Afaik, no. :shiftyninja:
  • 0

A question. You saw the AI of the old Tic-Tac-Toe that was 1000 lines of code just the AI? How to make it different? I mean the code was:

if (board[0]=='X'&&board[1]=='X'&&board[2]==' ')

board[2]='O'//To block the enemy attack to stop the winning of the enemy

And this code was repeated many times. How can i fix this?

  • 0

Ou you are colleagues. Cool :) . Can you answer how to make the AI code itself? I mean will it be like the code for checking when and who wins? And what do you thing for my new Tic-Tac-Toe code?

No, I believe we've only met here on Neowin... I was just being mean about the bank account code. :)

  • 0

I'll assume you're using a two-dimensional array, because it's much easier to code the AI with that.

So you have this:

char board[3][3] = 
	{
		{ ' ', ' ', ' ' },
		{ ' ', ' ', ' ' },
		{ ' ', ' ', ' ' }
	};

Then the player and the computer each use a certain character:

char playerChar = 'X';
char aiChar = 'O';

So now, all we have to do is count the Xs and Os on each row. If we find a row with two Xs and no O, then we should find the empty square on that row and play there.

void PlayAiMove()
{
	for (int y = 0; y < 3; ++y) // for each row
	{
		int numPlayerMoves = 0;
		int numAiMoves = 0;
		for (int x = 0; x < 3; ++x) // for each square in that row
		{
			if (board[y][x] == playerChar)
			{
				++numPlayerMoves; // count the number of times the player played in that row
			}
			else if (board[y][x] == aiChar)
			{
				++numAiMoves; // count the number of times the AI played in that row
			}
		}
		// If the player played twice and the AI didn't
		if (numPlayerMoves == 2 && numAiMoves == 0)
		{
			// then find the empty square on that row and play there
			for (int x = 0; x < 3; ++x)
			{
				if (board[y][x] == ' ')
				{
					board[y][x] = aiChar;
					return;
				}
			}
		}
	}
}

Then you'd have similar code to check for columns as well. A tricky question would be how to avoid repeating much of this code to check for columns, but I'll let you think about it a bit first.

  • 0

An empty IF just to get to the opposite result is a bad bad bad practise!

Yes i know. The problem is that it don't works in the normal way. What i mean is when i remove the else and making the == to != don't works. I don't know why. It return every time true. Something is wrong, but why?

  • 0

I'll assume you're using a two-dimensional array, because it's much easier to code the AI with that.

So you have this:

char board[3][3] = 
	{
		{ ' ', ' ', ' ' },
		{ ' ', ' ', ' ' },
		{ ' ', ' ', ' ' }
	};

Then the player and the computer each use a certain character:

char playerChar = 'X';
char aiChar = 'O';

So now, all we have to do is count the Xs and Os on each row. If we find a row with two Xs and no O, then we should find the empty square on that row and play there.

void PlayAiMove()
{
	for (int y = 0; y < 3; ++y) // for each row
	{
		int numPlayerMoves = 0;
		int numAiMoves = 0;
		for (int x = 0; x < 3; ++x) // for each square in that row
		{
			if (board[y][x] == playerChar)
			{
				++numPlayerMoves; // count the number of times the player played in that row
			}
			else if (board[y][x] == aiChar)
			{
				++numAiMoves; // count the number of times the AI played in that row
			}
		}
		// If the player played twice and the AI didn't
		if (numPlayerMoves == 2 && numAiMoves == 0)
		{
			// then find the empty square on that row and play there
			for (int x = 0; x < 3; ++x)
			{
				if (board[y][x] == ' ')
				{
					board[y][x] = aiChar;
					return;
				}
			}
		}
	}
}

Then you'd have similar code to check for columns as well. A tricky question would be how to avoid repeating much of this code to check for columns, but I'll let you think about it a bit first.

Ou this is really complicated. I think i understand the code, but it's really complicated. but really good written. Then i will make my program with a 2D array, but not now. I must go to sleep. When i am ready with it i will post the code.

PS: Can the AI be created with a 1D array? I don't thing it will be created in this way, but this is the best way with the 2D array AI i thing.

  • 0
PS: Can the AI be created with a 1D array? I don't thing it will be created in this way, but this is the best way with the 2D array AI i thing.
You can do it with a 1D array, but when you try to go row-by-row and column-by-column to check for wins, it's not as intuitive. A 2D array gives you rows and columns already, whereas you have to calculate them with the 1D array, e.g.

board[3 * rowIndex + columnIndex ] = value;

instead of

board[rowIndex][columnIndex ] = value;

  • 0

Yes i know. The problem is that it don't works in the normal way. What i mean is when i remove the else and making the == to != don't works. I don't know why. It return every time true. Something is wrong, but why?

It could be you're comparing equality between a char and a number. '1' is never equal to 1. One is a character and one is an integer.

You could use

isdigit(input)

to test and make sure the entry is a number, then cast it to a character.

  • 0

No the problem is that the condition doesn't make sense.

Let's make this more simple:

if (myChar != '1' || myChar != '2')
{
    // code
}
else
{
    // unreachable code
}

The condition says: myChar is not '1' OR it's not '2'. So let's see the different possibilities:

myChar is 0. It is not '1', therefore the condition is true.

myChar is 1. It is '1', but it is not '2', therefore the condition is true.

myChar is 2. It is not '1', therefore the condition is true.

myChar is 3. It is not '1', therefore the condition is true.

etc.

Therefore the condition is always true, and the "else" is unreachable.

In boolean algebra, this is equivalent to:

if (!(myChar == '1' && myChar == '2'))
{
}

where the error is much more obvious. myChar cannot be both 1 and 2 simultaneously.

  • 0

No the problem is that the condition doesn't make sense.

Let's make this more simple:

if (myChar != '1' || myChar != '2')
{
    // code
}
else
{
    // unreachable code
}

The condition says: myChar is not '1' OR it's not '2'. So let's see the different possibilities:

myChar is 0. It is not '1', therefore the condition is true.

myChar is 1. It is '1', but it is not '2', therefore the condition is true.

myChar is 2. It is not '1', therefore the condition is true.

myChar is 3. It is not '1', therefore the condition is true.

etc.

Therefore the condition is always true, and the "else" is unreachable.

In boolean algebra, this is equivalent to:

if (!(myChar == '1' && myChar == '2'))
{
}

where the error is much more obvious. myChar cannot be both 1 and 2 simultaneously.

I think you are not right, but when i am looking in your answer i see some mistaces. I am not sure if they are, but i think the second and thirth case must return false, because it must be not 1 or 2. In the second case it is 1 and because i must be not one it will return false. In the thirth case it is 2 and it will return false, because it must be not 1 or 2.

  • 0

I think you are not right, but when i am looking in your answer i see some mistaces. I am not sure if they are, but i think the second and thirth case must return false, because it must be not 1 or 2. In the second case it is 1 and because i must be not one it will return false. In the thirth case it is 2 and it will return false, because it must be not 1 or 2.

Nope, he's right, the if clause will always equal true because its an OR.

if (myChar != '1' || myChar != '2')

{

// code

}

else

{

// unreachable code

}

myChar is 1:

(myChar != '1') => false

(myChar != '2') => true

false OR true => true

myChar is 2:

(myChar != '1') => true

(myChar != '2') => false

true OR false => true

myChar is 3:

(myChar != '1') => true

(myChar != '2') => true

true OR true => true

For that if clause to produce a false output, you need a variable that's equal to 1 and 2 at that same time, which is not possible.

And that's why most people in this thread were focusing on improving core skills, not just programming but also elementary things like logical equations.

  • 0

I think you are not right, but when i am looking in your answer i see some mistaces. I am not sure if they are, but i think the second and thirth case must return false, because it must be not 1 or 2. In the second case it is 1 and because i must be not one it will return false. In the thirth case it is 2 and it will return false, because it must be not 1 or 2.

He's right. Your if statement will always be true because it's impossible for a number to be two different numbers at the same time. The only way your if statement would be false is if the laws of physics suddenly changed or a number was given that was out of range (a number other than 1 through 8).

Your if is checking to see if myChar is a 1 or a 2 or a 3 or a 4 or a 5 or a 6 or a 7 or an 8. Any one of those will make the if statement true.

  • 0

For now, you should just make this a two-player game. AI can be added later after you have made a working board, working input, working move validation, and working victory detection. After you have all that you can add an AI player much more easily.

The Tic-Tac-Toe is already ready.

He's right. Your if statement will always be true because it's impossible for a number to be two different numbers at the same time. The only way your if statement would be false is if the laws of physics suddenly changed or a number was given that was out of range (a number other than 1 through 8).

Your if is checking to see if myChar is a 1 or a 2 or a 3 or a 4 or a 5 or a 6 or a 7 or an 8. Any one of those will make the if statement true.

No, it must check if it's not 1, 2................ And for that it must return false every time of it is a 1, 2.................., but it don't works with the !=. I don't now why.

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

    • No registered users viewing this page.
  • Posts

    • I agree when are you going to read this (really poor BTW) article? Here is a better article so you actually know what is going on and answers questions you had in other comments --> https://arstechnica.com/gadgets/2026/05/speed-boosting-low-latency-profile-is-one-of-the-improvements-coming-to-windows-11/ It is unclear if one will be able to disable the new profile at this point but I am not seeing any reason why one would.
    • 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.
  • Recent Achievements

    • One Month Later
      Jamswaz earned a badge
      One Month Later
    • Week One Done
      Jamswaz earned a badge
      Week One Done
    • 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
  • 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!