• 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.