• 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

    • Any so called performance increase will be in milliseconds, which nobody will actually notice in real world usage.
    • All it does is use the CPU more efficiently during boot to speed up boot times. That's it. Yawn....
    • It's not a one or the other kind of thing. Software should run efficiently, and the operating system should appropriately manage the CPU clocks. You could have the best most optimized software on earth, and it will still run faster if the CPU does a better job of boosting as needed. All this is doing is pre-boosting the CPU based on user actions, instead of waiting for the normal detection mechanism to kick in. If the OS knows it is about to need more CPU, why shouldn't it use that knowledge? It's the same idea of downshifting before passing someone, instead of just burying your foot into the peddle and waiting for the transmission to figure out what you want to do.
    • Audacity 3.7.8 by Razvan Serea Audacity is a free, open source digital audio editor and recording application. Edit your sounds using cut, copy, and paste features (with unlimited undo functionality), mix tracks, or apply effects to your recordings. The program also has a built-in amplitude-envelope editor, a customizable spectrogram mode, and a frequency-analysis window for audio-analysis applications. Built-in effects include bass boost, wah wah, and noise removal, and the program also supports VST plug-in effects. You can use Audacity to: Record live audio. Record computer playback on any Windows Vista or later machine. Convert tapes and records into digital recordings or CDs. Edit WAV, AIFF, FLAC, MP2, MP3 or Ogg Vorbis sound files. AC3, M4A/M4R (AAC), WMA and other formats supported using optional libraries. Cut, copy, splice or mix sounds together. Numerous effects including change the speed or pitch of a recording. Write your own plug-in effects with Nyquist. And more! See the complete list of features. Audacity 3.7.8 changelog: #10688 Fixed an exception thrown when pasting into a newly-created track (Thanks, David Bailes (@DavidBailes)!) #10870, #10884, #10775, #10629 Fixed tone generation, waveform-scale setting, SetClip Name parameter, and clip-boundary command names for scripting and macros (Thank you, David Bailes (@DavidBailes)!) #11106 Fixed the loading of presets for the Distortion effect (A million thanks, David Bailes (@DavidBailes)!) #10947 Fixed paste into an empty audio track not preserving the source sample rate (Thanks, Juan Gabriel Colonna (@juancolonna)!) #10776 Allowed AltGr modifier in label and clip name editing (Thanks, Davide Peressoni (@DPDmancul)!) #9938 Added options to choose where silence is truncated (start/middle/end) (Thanks, Noah Rosenfield (@nosenfield)!) #9935 Added Podcast 2.0 chapters JSON export for label tracks (Thanks, Noah Rosenfield (@nosenfield)!) #10103 Improve UI on HiDPI displays on Linux/wxGTK (Thanks, Ivan A. Melnikov (@iv-m)!) #10099 Fixed MixerBoard Mute and Solo button display (Thanks, Ivan A. Melnikov (@iv-m)!) #10681 Fixed multichannel FLAC import #10999 Fixed envelope being broken after joining clips Download: Audacity 64-bit | Standalone ~20.0 MB (Open Source) Download: Audacity 32-bit | Standalone Download: Audacity ARM64 | Standalone View: Audacity Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • There really isn't anything magical about the low latency profile, other OS's do this as well. All they're doing is using your CPUs boost clock options in a more smarter way.
  • Recent Achievements

    • One Month Later
      highriskpaym earned a badge
      One Month Later
    • Week One Done
      highriskpaym earned a badge
      Week One Done
    • One Year In
      highriskpaym earned a badge
      One Year In
    • Week One Done
      FBSPL earned a badge
      Week One Done
    • One Year In
      Jim Dugan earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      497
    2. 2
      PsYcHoKiLLa
      198
    3. 3
      +Edouard
      155
    4. 4
      Steven P.
      84
    5. 5
      ATLien_0
      71
  • Tell a friend

    Love Neowin? Tell a friend!