• 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

    • Of course the problem was Secure Boot's new certificates. Install media created by the official Media Creation Tool is already signed with a valid certificate from Microsoft, so maybe that certificate isn't "up-to-date" enough for machines with the new ones installed in the UEFI. There's really no other logical explanation.
    • Here is how I fixed Windows 11 not booting after clean installation by Taras Buria Story time. A couple of weeks ago, I experienced a very odd thing with my computers. I was trying to reinstall Windows 11 on my primary device, and everything was going smoothly until the installer performed the first restart. After that, my computer entered the boot disk selection screen instead of continuing the setup process. Huh, that's odd, said I, and selected Windows Boot Manager only to see it fall back into the same screen right away. Then I tried booting from the USB drive with the same result—the PC kept returning to the boot device selection screen, and removing the drive would send my PC to UEFI, again, with no way to launch Windows 11. I fired up my spare laptop, which has been sitting unused for quite a while, to see if I am dealing with a defective USB drive. Nope, Windows 11 installed and started without issues. After trying another drive and checking all the possible settings in UEFI, I decided to try disabling Secure Boot. Lo and behold, Windows 11 started as it should have been in the first place, continued the setup process, and reached the initial setup screen. Victory! After I finished the setup and applied all updates, I re-enabled Secure Boot, and Windows 11 started without issues. Some time later, I tried reinstalling Windows 11 on my laptop only to experience similar issues, with UEFI claiming a Secure Boot violation. I checked whether the drive works on my main PC, and yes, it installed Windows 11 without errors. I scratched my head, went to UEFI, turned off Secure Boot, and installed Windows 11 without issues. After that, I enabled Secure Boot. Note: I used the official Media Creation Tool app for my USB drive. Also, UEFI was properly configured for Windows 11, including no Legacy Mode, a GPT-partitioned drive, and TPM and Secure Boot enabled. From my experience, if you are dealing with similar symptoms, I recommend two things: If you use old Windows 11 install media, create a new one with the latest Windows 11 release, especially if you know your PC already has the latest Secure Boot certificates. If you cannot create a new one, turn off Secure Boot, complete the installation, download all available updates, and then re-enable Secure Boot in UEFI. Note that you need to turn off Secure Boot after installing Windows 11. Otherwise, the installer won't run, claiming a hardware requirements mismatch. I believe the problem hides in Secure Boot certificates that expire this month. Microsoft is currently rolling out new certificates, and maybe a mismatch was causing these issues for both of my systems. I am out of my depth to make a definitive statement; this article is flagged as "Opinion," as I only share my experience and some tips on how to fix the problem. If some of you possess deeper knowledge and understanding of the situation, please share it in the comments. As for everyone else struggling with computers not booting after a clean install, the two steps above should get you out of the pickle.
    • I gave the tool a chance the other day to make a USB. An hour later it was stuck at 0% downloaded. I downloaded the official ISO, downloaded Rufus, and made the USB myself in 15 min.
    • <Moved to software discussion and support> I've got fond memories of Winamp. Changing the skins, the different visualisations etc. But now I just need a simple music player. MSN messenger would be another one, MSN Messenger Plus (I think?) offered so many different plugins. But again, it probably wouldn't work for me these days. And then there is miRC. i think it's still going these days, but lord i had fun with that back in the day. Now it's mostly stuff like Discord, WhatsApp group chats, Signal, Telegram... /me is showing his age...
  • Recent Achievements

    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
    • One Month Later
      agatameier earned a badge
      One Month Later
    • Week One Done
      agatameier earned a badge
      Week One Done
    • Week One Done
      ssd21345 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      518
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      147
    4. 4
      ATLien_0
      94
    5. 5
      Steven P.
      77
  • Tell a friend

    Love Neowin? Tell a friend!