Learning to Code Game Enemy AI in C++ from Scratch or in Assembly?

In summary, the OP is looking for resources on learning to code Game Enemy AI in C++ from scratch. He recommends books, tutorials, CD-ROMs, and videos. He also recommends learning Unity first because it supports many platforms and already has a large audience of players.
  • #1
DeVaughn_B970
7
1
Hello,

To keep my questions straightforward they are below.

How do I learn how to code Game Enemy AI in C++ from scratch and what are the top resources you recommend(Books, Tutorials, CD-Roms, Videos)?

How do I learn how to code Game Enemy AI in Assembly Langauge from scratch and what are the top resources you recommend(Books, Tutorials, CD-Roms, Videos)?(If Possible)

If you can provide solid answers to these questions asap that would be very helpful looking for resources on concrete coding Game AI from the ground up.
 
Technology news on Phys.org
  • #2
Welcome to PF.

Why do you need to do this ASAP? What's the rush?

What experience do you have in writing software? What have you written in C++ and assembly so far? What platform are you targeting?
 
  • #3
Why I need to do this asap:
Its the only part of my game I don't got a plan to cover so its become my second priority in development for me as I plan on releasing my game commercially.

What experience do I have writing software? Almost 15 years

What have I written in C++ and Assembly?
At this point for C++ Games, Game Engines, Basic Frameworks shell, Algorithms, Graphics Programming(DirectX, OpenGL).

For Assembly language most recently controls for a game engine using C++ inline Assembly which is slightly different than regular Assembly Language.

The platform I am targeting is PC most likely on Steam.
 
  • Informative
Likes berkeman
  • #5
OK, so you are not looking for the code to Game Enemy AI (propernoun, and what you wrote) but instead for an enemy AI (common noun) for a game. Got it.

Honestly, I suspect that this is very game-dependent. Tic-tac-toe is simple enough that a game is just a set of nested IF statements. Chess is complex enough that people are still working on improving machine play. Wordle's opponent has only one play (Hangman is the same way), Portal, despite having an antagonist, doesn't really have an opponent, others play every turn, etc.
 
  • #6
Vanadium 50 said:
OK, so you are not looking for the code to Game Enemy AI (propernoun, and what you wrote) but instead for an enemy AI (common noun) for a game. Got it.
Wait, what? Oh no, all that wasted and confusing Google searching stuff. The proper noun version has some pretty strange websites, BTW...
 
  • #7
Basically, you need to use some established C++ Machine Learning libraries as mentioned in this article:

https://www.geeksforgeeks.org/machine-learning-in-c/

such as Boost and ML Pack.

No game developer would build custom AI code nowadays when there are math libraries for doing matrix operations, graphics, and database work. In addition, you might want to avail yourself of Nvidia graphics cards for AI calculations.

Simple strategy games might use custom code but a game like World of Warcraft would likely use Unity as a basis with all its embedded tools and support.

https://unity.com/

One nice feature of Unity is that it supports many gaming platforms already making any game on it immediately have a larger audience of players in exchange for gaming royalties for using Unity as the engine.
 
  • #8
Game AI has little, if anything, to do with machine learning.
 
  • Like
Likes Tom.G and Vanadium 50
  • #9
Game "AI" is more a marketing term than anything having to do with actual AI. (Although many, many years ago I wrote a Tic-Tac-Tor program that actually did learn from its losses - it refused to play a losing move twice)
 
  • #10
  • #11
One of my early forays into game AI was an intelligent Othello game where I collected stats on cells that tended to be a part of winning gameplay. The stats directed the computer player on the selection of the next move.

There were 60 squares and a maximum of 60 moves which I mapped to an 8x8 array record in a random file of 60 records. At move #7, I would retrieve the 8x8 stat matrix stored in record #7 and use the stats to order the moves and select the one with the highest score.

This was in 1980, on a Honeywell 6000, using TSS Fortran. It didn't occur to me to write an article for Byte magazine at the time. Six months later, someone did, and I missed an opportunity. Their game used hard-coded rule-based move selection, ie corner squares were the most desirable, followed by edge squares, and then the innermost squares (ones bordering the 4 center squares ...

The squares bordering the outer edge were the worst since your opponent could easily flip them to their advantage.

https://www.wikihow.com/Play-Othello

aid2600041-v4-728px-Play-Othello-Step-13.jpg.webp
 
  • #12
anorlunda said:
Your extensive experience history makes that question hard to understand. Surely, by now you can teach yourself how to code any game. So maybe I don't understand the point of your question.

Maybe you can start here: Learn To Create Enemy AI Systems With A Few Lines Of Code In Unity Game Engine
That's not the point I can code the game coding AI for it is a completely different story and is usually its own piece that works with the game also unity isn't going to work here so no unity
 
  • Skeptical
Likes Vanadium 50 and berkeman
  • #13
Vanadium 50 said:
Game "AI" is more a marketing term than anything having to do with actual AI. (Although many, many years ago I wrote a Tic-Tac-Tor program that actually did learn from its losses - it refused to play a losing move twice)
I know that code was probably written years ago but what was the logic or sample behind that code as I got logic (Not translated into code yet) for AI that makes decisions based on the notion that the player has lost or died a series of times.
 
  • #14
pasmith said:
Game AI has little, if anything, to do with machine learning.

I neither like or dislike this video what I don't like is the concept of calling AI for enemies NPC(Non Playable Characters for those who don't know) behavior as essentially the characters using the AI is essentially playing unless its an actual NPC designed to be in the game but won't engage with the player to attack.

Some of the AI concepts covered are good points:

Pattern AI follows a series of commands regardless of player action
(This isn't what I'm looking for based on game type 2D 3rd Person shooter)

Intuitive AI follows a decision tree that acts based on the player's actions
(This is closer to what I'm looking for)

Last sometimes less complex AI is useful sometimes more complex AI is useful especially if there are many enemy types (like rpgs)What I am looking for is something inbetween as I want Intuitive AI that decides reactively but I also want the enemies to learn from losses, observe the players actions and tendencies, and strategize based on the weapons, position, and resources.

So after this video let me rephrase my question. (Check my next post)
 
  • #15
So to fully explain what I'm looking for here is the following:

Intuitive AI: This would follow a decision tree for the enemy to react according to the player (2D 3rd Person shooter specific) if you find resources (video, books, cd-rom's) on this it would be helpful.

Learning AI: I want the enemies to learn from its losses and strategize based on position, resources, and weapons based on the enemy type. If you find resources (video, books, cd-rom on this it would be helpful).

Observant AI: I want the enemies to observe how the player is playing the game and by chance react differently when an enemy type has lost an ally to be more aggressive or passive when the enemy realizes they are succeeding. Some enemy types are supposed to obverse the player before they are even created on the screen (I have some logic for this already I got no idea how to code it though). If you find resources (video, books, cd-rom's) on this it would be helpful.

If you find coding resources they need to be C++ or Assembly Langauge specific as I'm attempting to hard code this Unreal and Unity is off the table here and can be left in another thread.
 
  • #16
jedishrfu said:
Basically, you need to use some established C++ Machine Learning libraries as mentioned in this article:

https://www.geeksforgeeks.org/machine-learning-in-c/

such as Boost and ML Pack.

No game developer would build custom AI code nowadays when there are math libraries for doing matrix operations, graphics, and database work. In addition, you might want to avail yourself of Nvidia graphics cards for AI calculations.

Simple strategy games might use custom code but a game like World of Warcraft would likely use Unity as a basis with all its embedded tools and support.

https://unity.com/

One nice feature of Unity is that it supports many gaming platforms already making any game on it immediately have a larger audience of players in exchange for gaming royalties for using Unity as the engine.
I already download the C++ Boost Pack I could look up the C++ Boost for using AI for ML using cmake doesn't always provide consistent results as I have recently used Cmake before.
 
  • #17
This isn't a sorting algorithm, with code that can easily be borrowed. This sounds like a multiyear research project.

Can you name, say, five games that do everything you want?
 

FAQ: Learning to Code Game Enemy AI in C++ from Scratch or in Assembly?

1. How difficult is it to learn to code game enemy AI in C++ or Assembly?

Learning to code game enemy AI can be challenging, especially if you are new to programming. It requires a strong understanding of C++ or Assembly language, as well as knowledge of game development concepts and algorithms. However, with dedication and practice, it is definitely achievable.

2. What skills do I need to have before learning to code game enemy AI?

To successfully code game enemy AI in C++ or Assembly, you should have a good grasp of programming fundamentals, such as variables, loops, and functions. It is also helpful to have some knowledge of game development principles and algorithms, as well as experience with C++ or Assembly language.

3. Do I need to have prior experience in game development to learn to code game enemy AI?

While prior experience in game development can be helpful, it is not a requirement to learn to code game enemy AI in C++ or Assembly. With a strong understanding of programming fundamentals and a willingness to learn, anyone can learn to code game enemy AI.

4. How long does it typically take to learn to code game enemy AI?

The amount of time it takes to learn to code game enemy AI in C++ or Assembly can vary depending on your previous experience and dedication. It may take a few months to grasp the basics and several years to become proficient in advanced techniques. However, with consistent practice and determination, you can make progress at your own pace.

5. Are there any resources available to help me learn to code game enemy AI in C++ or Assembly?

Yes, there are plenty of resources available to help you learn to code game enemy AI in C++ or Assembly. These include online tutorials, books, forums, and coding communities where you can ask for help and advice. It is also helpful to practice by coding your own projects and studying existing game AI code.

Back
Top