![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
6:13pm - Well I missed work again today, feel awful about that. But what's done is done, and I have time to do other things. I was going to do another other thing, but Reddit seems to be having troubles, so I'm here instead.
Right now the way my Roguelike Game works, each actor takes a turn based on it's action_points and speed values. When the current actor's action points are greater than zero, they reduce their action points by the cost returned by their on_turn() method. In the case of GreenEnemy it uses the Astar map to find the player and move closer, or attack if it's next to the player. It does that all by code in the on_turn function.
Instead I want to have GreenEnemy (for example) have an AI module which is run to determine its actions, and this AI module will pump out chains of Commands that the Actor will follow.
Let's walk through an example.
GreenEnemy's Turn!
GreenEnemy's AI runs, and looks at the portion of the map in it's senses. Using that sensemap, it sees Player_1 is three squares west!
GreenEnemy's AI returns an Array of Commands. It's a one command array!
Player_1's Turn! They move one square east, foolishly putting them into attack range of the GreenEnemy!
GreenEnemy's AI runs, and looks at the portion of the map in it's senses. Using that sensemap, it sees Player_1 is in attack range.
GreenEnemy's AI returns an Array of Commands. It's a one command array!
GreenEnemy attacks Player_1!
Hmm... There's a problem with this example though. The AI is a black box. We're not seeing what goes on in there. I wasn't expecting it to only give out one command at a time, but that makes sense since it runs every turn for the enemy, so the enemy can only do one thing!
So let's look at the AI.
It gathers a sensemap from the GameMap, which is something I havent't implemented yet. Then it analyzes that sensemap with an algorithm that simulates it's thought process. In this case it would be something like Find Enemy? Enemy Near? Attack Enemy! Enemy Far? Approach Enemy! Don't Find Enemy? Random Wander!
That's a very basic AI.
I was thinking I'd have to make "Commands" for the Actors to act on that would be composed into complex actions, but now I'm not so sure. The commands might all just be one simple thing. Let's look at something other than an enemy or the player. Actors includes Items.
Player_1 sees Bone-in Ham!
Bone-in Ham idles, emptying its action points.
Player_1 stands over Bone-in Ham and picks it up!
Bone-in Ham goes to Player_1's inventory, and idles, emptying its action points.
Player_1 uses Bone-in Ham, eating it!
Bone-in Ham uses Feed to increase Player_1's food level! Bone-in Ham also "dies" disappearing from Player_1's inventory!
That's a multi-action right there! The Bone-in Ham just Fed the player AND died in the same turn! So I will have to use arrays of commands sometimes. And what is "Feed" exactly? That's the sort of command I was thinking about before. Like Attack and Move, but less generic. Something unique to food items.
I need to think more about actions. Should they be hard coded or created outside in a file? I think they should probably be hard coded.
6:49pm - I'm time stamping here 'cause I've been thinkin' a while and it's hard to measure otherwise. Anyways I just realized that "Attack" is more complicated than just "Attack". Moves like Approach and Avoid seem simple enough but they might differ too. Let me explain.
When you "Attack" you might do it in different ways. IRL you might punch, kick, chop, bite, whatever. In the game it's probably divided by unarmed and armed attacks, and armed attacks use the values of an equipped Actor, right? So that differs based on what you've got equipped.
On the other hand, maybe it isn't so different, since you're just attacking with whatever you're equipped with, or your base attack, whichever is highest, right?
The Move commands like Approach and Avoid might differ by your means of locomotion, but as long as that's accounted for in the Approach and Avoid commands, that should still work.
6:55pm - So let's think about the AI again for a bit here. I'm thinking that I could compose several 'default' AI programs, like Enemy or NPC or Item, which behave differently, and in the text file you could pick which one your Actor would use, along with setting its stats and appearance.
I'd have to program any unique AIs in code but it would be a lot harder to make an interpreter to allow unique AI programming from a file.
7:00pm - Alright so I've got my idea for the AI and the Commands, now how to code it... I figure when the actor's on_turn method is used it will run its AI program to get the Command array, then run the function in each Command.
That brings me back to implementing the Command pattern in my game, but I think I can do that with no problems.
Now that I've been thinking so hard for almost an hour though, I want to take a break, so I will.
8:19pm - After my break I went to Reddit to find some Battlemaps maybe for my game, but there weren't any suitable ones.
Now I'm feeling upset and discouraged, and I'm not sure what to do. I don't feel like working right now, and really I feel like if I force myself to do work I'm going to do bad work right now. So, I'm going to relax and play a different game or something.
Right now the way my Roguelike Game works, each actor takes a turn based on it's action_points and speed values. When the current actor's action points are greater than zero, they reduce their action points by the cost returned by their on_turn() method. In the case of GreenEnemy it uses the Astar map to find the player and move closer, or attack if it's next to the player. It does that all by code in the on_turn function.
Instead I want to have GreenEnemy (for example) have an AI module which is run to determine its actions, and this AI module will pump out chains of Commands that the Actor will follow.
Let's walk through an example.
GreenEnemy's Turn!
GreenEnemy's AI runs, and looks at the portion of the map in it's senses. Using that sensemap, it sees Player_1 is three squares west!
GreenEnemy's AI returns an Array of Commands.
Player_1's Turn! They move one square east, foolishly putting them into attack range of the GreenEnemy!
GreenEnemy's AI runs, and looks at the portion of the map in it's senses. Using that sensemap, it sees Player_1 is in attack range.
GreenEnemy's AI returns an Array of Commands.
GreenEnemy attacks Player_1!
Hmm... There's a problem with this example though. The AI is a black box. We're not seeing what goes on in there. I wasn't expecting it to only give out one command at a time, but that makes sense since it runs every turn for the enemy, so the enemy can only do one thing!
So let's look at the AI.
It gathers a sensemap from the GameMap, which is something I havent't implemented yet. Then it analyzes that sensemap with an algorithm that simulates it's thought process. In this case it would be something like Find Enemy? Enemy Near? Attack Enemy! Enemy Far? Approach Enemy! Don't Find Enemy? Random Wander!
That's a very basic AI.
I was thinking I'd have to make "Commands" for the Actors to act on that would be composed into complex actions, but now I'm not so sure. The commands might all just be one simple thing. Let's look at something other than an enemy or the player. Actors includes Items.
Player_1 sees Bone-in Ham!
Bone-in Ham idles, emptying its action points.
Player_1 stands over Bone-in Ham and picks it up!
Bone-in Ham goes to Player_1's inventory, and idles, emptying its action points.
Player_1 uses Bone-in Ham, eating it!
Bone-in Ham uses Feed to increase Player_1's food level! Bone-in Ham also "dies" disappearing from Player_1's inventory!
That's a multi-action right there! The Bone-in Ham just Fed the player AND died in the same turn! So I will have to use arrays of commands sometimes. And what is "Feed" exactly? That's the sort of command I was thinking about before. Like Attack and Move, but less generic. Something unique to food items.
I need to think more about actions. Should they be hard coded or created outside in a file? I think they should probably be hard coded.
6:49pm - I'm time stamping here 'cause I've been thinkin' a while and it's hard to measure otherwise. Anyways I just realized that "Attack" is more complicated than just "Attack". Moves like Approach and Avoid seem simple enough but they might differ too. Let me explain.
When you "Attack" you might do it in different ways. IRL you might punch, kick, chop, bite, whatever. In the game it's probably divided by unarmed and armed attacks, and armed attacks use the values of an equipped Actor, right? So that differs based on what you've got equipped.
On the other hand, maybe it isn't so different, since you're just attacking with whatever you're equipped with, or your base attack, whichever is highest, right?
The Move commands like Approach and Avoid might differ by your means of locomotion, but as long as that's accounted for in the Approach and Avoid commands, that should still work.
6:55pm - So let's think about the AI again for a bit here. I'm thinking that I could compose several 'default' AI programs, like Enemy or NPC or Item, which behave differently, and in the text file you could pick which one your Actor would use, along with setting its stats and appearance.
I'd have to program any unique AIs in code but it would be a lot harder to make an interpreter to allow unique AI programming from a file.
7:00pm - Alright so I've got my idea for the AI and the Commands, now how to code it... I figure when the actor's on_turn method is used it will run its AI program to get the Command array, then run the function in each Command.
That brings me back to implementing the Command pattern in my game, but I think I can do that with no problems.
Now that I've been thinking so hard for almost an hour though, I want to take a break, so I will.
8:19pm - After my break I went to Reddit to find some Battlemaps maybe for my game, but there weren't any suitable ones.
Now I'm feeling upset and discouraged, and I'm not sure what to do. I don't feel like working right now, and really I feel like if I force myself to do work I'm going to do bad work right now. So, I'm going to relax and play a different game or something.