• Advertisement
Sign in to follow this  

Turn Based Game AI processing display

This topic is 961 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Good evening,

I am developing Turn Based Game and i noticed need for graphical representation for AI actions.

- Highlighting possible movement locations

- Highlighting a path to a location

- Moving through the path

- Selecting possible targets

 

Displaying npc "pack" behavior later on and etc.

 

So possible paths are:
1) AI action queue plan, so that AI would make action every hundred milliseconds. And GPU would not be frozen.

2) Place AI actions into separate thread.

 

I have tried (2) and its working quite well and it makes things done FAST. ALTHOUGH, code wasn't meant for multi-threading.

Thou architecture ensures that only ONE "control" at a time, can manipulate data.
Whilst AI is making its turn, player can not change any data, apart from interacting with UI, which is not accessible for AI.

But gameplay field is drawn from the data, AI is accessing.

 

Maybe someone has any experience with it? Or has any better long term and short term solutions. 

Share this post


Link to post
Share on other sites
Advertisement

Hello!

 

I think for a turn based game a queue for actions is the correct solution. It would be good to extend it even further to every character in the game even. Something similar to the example below:

// Have each of your characters inherit, or have, something that can be en queued in here
Queue characterQueue;
List waitList;

TurnQueue(priority) {
  // You could base priority on some stat or anything
  characterQueue = new Queue(priority);
}

Update() {
  character = characterQueue.Pop();

  // Insert character into wait list (before or after update)
  waitList.Insert(character);
  // Start and update the characters simulation
  character.Start();
  character.Update();

  // If the queue is empty all characters back into it
  if (characterQueue.Empty())
    AddListToQueue(waitList);
}

In regards to the frequency of the Update call. You can call it as often as you like and check if a character is currently in the middle of their move and if so return, otherwise continue and let the next character go or you can explicitly call it when a character has ended their turn.

 

I like this strategy because it can make solutions for some turn-based features a little easier. You can, for example, make the priority for the queue be some sort of 'agility' stat so the character with the highest agility will come first in the queue. You can also keep track of how often the queue empties and this can give you a number representing how many turns have elapsed since the start of battle. You can use that number for any status effects that might need to last for a certain number of turns.

 

As for your desire to represent things your AI is doing visually, it seems like a normal use case for whatever rendering strategies you are using. If you had a regular character moving around and needed to draw its path you'd probably construct a list of nodes that represented its path and send that to the renderer/gpu/fooBarDrawingThing for visual representation. You don't need to make it complicated by introducing a separate planning thread, I think. Maybe I am misunderstanding, do you want to display, visually, what the AI could do in the future? 

Share this post


Link to post
Share on other sites

My solution might not be the best one, but basically it is something like what DishSoap presented. With addition of using tweens to create a visualization for the actions that are going to happen.

 

For example on my game that I am making the solution is somewhat like

1) Pick next unit for moving.

2) Calculate the move the AI wants to make

3) Create tween that shows the ai-movement in screen.

4) Add the action the AI does such as attack after the tween

5) Use tween to animate the attack animation

6) Start tween

7) Play tween until its done.

8) Move to 1)

 

Basically while tween is playing, remove the controls from the player or possibility of changing turns. Now depending the logic of your game, if the AI can move any given piece on the board and the turn ends after AI has moved every single piece, picking the correct unit to move might cause some trouble or trying to evaluate how good a move truly is.

 

But yes I would probably look for Tweens as a solution for representing the movement. Most likely most of the game engines out there have some sort of solution for tweens.

Share this post


Link to post
Share on other sites

Thank you for your answers!

Ill look into them more carefully.
 

You don't need to make it complicated by introducing a separate planning thread, I think. Maybe I am misunderstanding, do you want to display, visually, what the AI could do in the future? 

Its rather simple on my i end, I go, enemy faction X, Y, Z goes.

 

Why i was thinking about separate threading is because AI has to think. Chose from all viable paths (cells), calculate most optimal one or use random roll if needed, go there, look arround for other npcs, identify their faction, chose the target if needed, attack it.

And i just need to highlight every option, because later on i plan to make combined group AI.

Like
(A) checks all the nodes around (map cells get highlighted).

(A) scans for surrounding pack members in his sight (highlights the members)

(A) initiates question to (B), asking what he thinks they should do next (highlighting (B), instead of (C))
(B) checks all the nodes around (map cells get highlighted)
(B) scans for surrounding pack members in hit sight (highlights the members)

(B) tells (A), that they need to kill (C) (both get highlighted)

(A) moves close to (C) (highlights)

(A) attacks (C) (highlights)

(B) attacks (C) (highlights)

 

And its all done in one turn.

 

DishSoap example is good, its just it will take damn a lot of time to make queue and cases for different possible scenarios.

 

Thread makes it easier, you just highlight the thing you need, and pause the thread for a while.

Share this post


Link to post
Share on other sites
Don't you give away too much information to the player?

I am quite interested what the AI thinks, and just by watching, I may get clues of its intentions. If it scans enemies near the left exit and ignores those near the right exit, that's useful information.


If you only animate decisions you already made, it should be fine, as you never show anything other than what is going to happen.

Share this post


Link to post
Share on other sites

What I did for my game was let the AI decide what to do 1 unit at a time. There thought process for the 1 unit would then be done over several loops. Skip the thought processes while actions(camera, moving or attacking, resulting text, etc...).

 

Every step is the next frame so that framerate is constant.

Who am I?

What is near me and should I move?

Where can I move?

Where should I move?

What is near me now?

What should I do?

Share this post


Link to post
Share on other sites

How much, time wise, ti t

 

What I did for my game was let the AI decide what to do 1 unit at a time. There thought process for the 1 unit would then be done over several loops. Skip the thought processes while actions(camera, moving or attacking, resulting text, etc...).

 

Every step is the next frame so that framerate is constant.

Who am I?

What is near me and should I move?

Where can I move?

Where should I move?

What is near me now?

What should I do?

 

How much, time wise, it took to complete this mechanism and how robust is it?

Share this post


Link to post
Share on other sites

Seems instant to the player but happens over several frames so that the framerate is never bogged by calculations.

 

For exmple a unit decides where to move and starts the action of moving. That suspends the AI from thinking because an action is taking place. The user is seeing the unit being selected then watching it move.

Edited by Adehm

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement