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

AI Thread Summary
The discussion focuses on learning to code game enemy AI in C++ and Assembly, with an emphasis on finding specific resources for development. The original poster has significant experience in software development and seeks guidance on creating intuitive, learning, and observant AI for a 2D third-person shooter game. Participants suggest using established C++ machine learning libraries like Boost and ML Pack, arguing that custom AI coding is often unnecessary due to available tools. There is a debate about the definition of game AI, with some asserting it is more of a marketing term than true artificial intelligence. The conversation highlights the complexity of AI design and the need for tailored resources to meet the poster's specific requirements.
DeVaughn_B970
Messages
7
Reaction score
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
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?
 
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.
 
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.
 
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...
 
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.
 
Game AI has little, if anything, to do with machine learning.
 
  • Like
Likes Tom.G and Vanadium 50
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?
 
Back
Top