We only have, like, a few clusters. And then we'll only find one target. And then if we have a location to go to, we'll execute a move action. Otherwise, and this is where it gets really important, we'll execute a complete action. So, the important thing here is that each of these functions always needs to return an action. Or sorry. It always needs to mutate the game state. So, either the unit is going to move or it's going to complete, which means it won't take any other actions.
Because the problem you run into, otherwise, if you run this action function in a loop, it will enter the move function and then always try to recompute all of this, only to realize there's nowhere to go. So, you always need to make sure every one of these functions, when there's no more actions to take, they return null or they mutate the game state so that you can go back into that function to move the next unit. So, ideally, as you execute game actions here, the number of available units trends down to zero so that you can enter the endTurn function here.
All right, now, let's figure out this whole thing about how to actually move. There's a very common algorithm. There's many algorithms to search about, search on a 2d grid about where you're going. I landed on A star, it works really well for this type of game. And the one thing here is that you're basically doing depth-first search on a 2d grid to figure out where you should go and you're trying to do that in the fastest possible way with the lowest amount of cost. If we just look at the game map, this unit cannot go into the mountains and it costs more to go into the forest than staying on the street. So, we're trying to optimize how do we get from this green tile, from this unit to over here. In this case, there's only one path, right? But we still need to figure out, okay, is this the way to go or should we go through the river. But you know, this unit can't go through the river, so once you do this sort of path searching, you kind of have walls or you have a higher movement cost than certain tiles. And then once you have this radius and this ability to figure out where can this unit go, then we can figure out, okay, what are the interesting positions on a map and then figure out if the unit can actually travel there.
This is obviously a simplified version of it, but here's like three things that you could look at. The actual implementation in Athena Crisis is like a couple hundred lines, depending on the state of the game and the unit that you're asking about what to do. So, for example, units can capture buildings, units can attack others, units can supply other units with fuel and ammo. So, for example, you might have a system here where a unit that can supply others will think that other units if they're low on ammo, right? Or in this case, if the unit doesn't have an attack or it's out of ammo, it is in danger. So, if it's at the front lines, it will actually think the interesting locations are the buildings back at where my bases are. And through that, if we feed that into the system that I outlined, that unit will try to retreat. And here, for example, if the unit has the ability to capture other buildings, then the most interesting place to go to is other buildings that are owned by the opponent. And finally, if the unit has regular attacks, most likely it will find other units interesting to go to, like opposing units to go to.
And so, now let's think about this whole thing with clusters.
Comments