April 25, 2019, 04:17:35 AM

Author Topic: Strata Nova  (Read 776 times)

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1007
Re: Strata Nova
« Reply #30 on: April 12, 2019, 08:49:07 AM »
This is some weird code!!!   :o

I've needed to extend it so there is a range. think of this as an error range. So the target can be within a certain range of values to be true.

Next up I needed to add a key. You give a key so when it says "i'm done" it gives you the key. you can then use the key to check things.

So... aiX and aiY have a start and target (with a +-range) and a key so you know whats happening on completion

I can also see that I will need to add composits, so that 2 values (x,y) can be tracked as a single unit

Offline Derron

  • Hero Member
  • *****
  • Posts: 1953
Re: Strata Nova
« Reply #31 on: April 12, 2019, 09:28:51 AM »
For what do you need a "key"?
For what do you need a range value?

You are talking in riddles.


planet.GetDistance(otherObject)
-> if value is below planet.shipRange (or ship.GetRange() if you ask for a specific range instead of the range currently built ships have) then you can send them out to that planet without being afraid to be out of fuel
-> you could ignore the movement of a planet since "ship start" to keep it simple
-> or you just ask for a "ship.CanReach(otherObject)" which calculates everything (effective distance including movement of the target and targetting the target position)


What is that key for?
event: onShipArrivesTarget
add yourself/player as listener and throw away ship events you are not interested in.


Also you could always have methods to access information. Assume all planets are owned by "player" (human player or one of the cpu players).
player.GetInformationXYZ()
-> method checks diplomacy state and returns information or null

Same could be done for planets.
planet.GetPopulation() -> returns population if allowed or -1 for not allowed
planet.GetShipCount() -> ... same


Just think of the whole stuff as "API". If you do that then the functions become no longer "planet.GetPopulation()" but "GetPlanetPopulation()" which does additional checks for you and calls "return planet.GetPopulation()" if you are allowed.
Same to do for interaction ("BuyShip(planetID)". That way you could more easily add multiplayer, AI controls, human controls, ...


bye
Ron

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1007
Re: Strata Nova
« Reply #32 on: April 12, 2019, 10:32:04 AM »
ok first the range
the target = target +- range. that way you can have the AI report back to you when the target is reached or within range of the target

next is the key.
The key is just in identifier, you don't need to use it. but...
Lets assume you have set up 4 AI's and each AI can have a different 'parent'

AI[1] reports it has reached the target. how do you know what the parent of that AI is?
Unless you are passing the parent to the AI, all the AI can do is report it has reached the target...

If you give the AI a unique key (lets say the index of the parent (could be anything, so an int value is best) that is sending it),
you can check the AI.Key, and decide what to do next.

In this case the AI has finished it's task and we modify the parent (given the key), by whatever we need to do.

Using this means all we have to do is set up the AI'a, let them do their work, update them, and do something once they have finished

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1007
Re: Strata Nova
« Reply #33 on: April 12, 2019, 10:34:45 AM »
I should add that the signalling of the AI can occur at any time, all we are interested in is what to do when the signal is triggered.

Offline Derron

  • Hero Member
  • *****
  • Posts: 1953
Re: Strata Nova
« Reply #34 on: April 12, 2019, 11:10:24 AM »
To whom has the AI to signal back stuff? Who is interested in the fact that the AI knows that a ship is in range / a planet in reach ? Does the human player tell it to someone too?


Just update all AIs each update() you do.
The AI does something or not (it just updates their current task to do whatever the tasks need to do).
The AI has the information which player it controls (eg "playerID:int").

When it wants to know what planets it has access to:
API: GetPlayerPlanets(AI.playerID)
or direct: space.GetPlanets(AI.playerID)
... use the way to make sure that a player (human or CPU) cannot fetch information they are not allowed to retrieve. Eg. all know who is the owner of a planet so this information is publically available (planet.GetOwnerID()). Other stuff needs to be secured.
planet.SendShips(targetID) would be uncool to be publically available as with GetPlayerPlanets(enemyPlayerID)[0].SendShips(otherEnemyPlayerID) you could send out stuff.
That is where the API approach helps - every "API" gets a playerID assigned. The instance of the API is directly linked to a single player. That way "player.commands(or API).SendShipsFromPlanet(planetID, targetID)" is able to verify that the planetID belongs to the playerID stored in the API/command instance.


You can keep it simple if the AI is never done in an external/moddable file. So if the AI is stored in your own source code you can already make sure that it does only valid things. Then keep it simple and use "if planet.ownerID = playerID then planet.SendShips(targetID)".



@ finished task
If the AI finished its task it moves on with the next task. No need to inform anybody? Why should it? As said at the top of my post: does the human player inform others too once he finished checking all planet's ship production states?

The AI is like the human player: you split up all the possibilities you have into little tasks:
- check diplomacy
- check planet productions
- do military operations
- ...

Do nothing in parallel as the human could not do that too. Task by Task - and if you do it serious you even limit the AI a bit to be not too fast (adjust according to difficulty).
With this time limit in mind you might understand why the tasks need priorities - you cannot  execute all tasks in each AI cycle. You only have some ticks available (also to avoid lags - as some tasks are pretty time consuming). Means some tasks might even have to be split into multiple "cycles".
Imagine there are 1000 planets. Checking all of them each time means to check 1000 planets in milliseconds. Humans could not do that. Introduce "steps". Each AI cycle (or simple: during each ai.Update()) you increase the step. That way you know the progress of this task and could eg. scan the first 100, the second 100, ... planets. Like a human could do. One by one.

This cuts down AI processing time - i can tell you that a more complex AI (with more complex checks of properties, stored information about stuff happened in the past -> for proper estimations of what might happen next) can take some cpu cycles. So split up stuff.

Next to cutting down processing time this "step by step" and "priority" approach allows to "disturb" a task. Assume the human player is just checking some planets as the "under attack" sound is played and the screen turns red: of course he now reacts to this.
Doing a "step by step" thing means that you did not check every planet now (as the human was not able too). Yet the recalculation of priorities allows to now run the "UnderAttack" task for a quick reaction. Once this task is no longer of high priority (as the second-strike was executed and we are no longer under attack) the other tasks will be automatically executed then.

Goal of this to have a more "human like" reacting AI.

-----

Quote
In this case the AI has finished it's task and we modify the parent (given the key), by whatever we need to do.

It seems you think of the AI as a "decision maker". You ask the AI what it would do, fetch the information and then actually execute what the AI planned to do?

My approach is more of a "controller":
- human uses input device + GUI/HUD to execute commands (planet.SendShip())
- AI uses its own commands to do stuff (planet.SendShip())

In my idea the AI directly does its stuff, no further interaction or "return values" needed.

That way you could also easily replace the AI with a remote (network/internet) player as it just uses another layer (transport their "input device + GUI/HUD" via networking packages to you - and run the same commands then according to the incoming data).


Maybe at the end we talk about the same but as said I think you decouple the AI from the actual player object. More like a brain which you ask for decisions/help/what-to-do. While my idea is to give the player object an AI brain and let the player then do its stuff without my help.


bye
Ron

Offline mainsworthy

  • Jr. Member
  • **
  • Posts: 9
Re: Strata Nova
« Reply #35 on: April 13, 2019, 01:45:31 PM »
off on holiday, catchup in a few!

the A.I. is static because it needs to be doing stuff on its own in RTS, but the Values can be added or subtracted with the 3 opposing values, the opposing values are targetvalues for the 3 values of each entity, so if a planets growth is 1 population a year it will do that auto, but if your opposing value is +2 you would get 3 population , or it could be negative eg -3 then the pop would be -2 a year, the A.I. only has to be controlled by setting the 3 default values for every entity - the as things happen the opposing values get adjusted. I don't have time to read back what you've wrote, Im out the door on holiday guys bye for now.

PS: you guys need to go to humblebundle and grab the 8 bit game dev bundle, they have two bundles one is books but the other is graphics etc... do it now now now

Offline Derron

  • Hero Member
  • *****
  • Posts: 1953
Re: Strata Nova
« Reply #36 on: April 13, 2019, 01:51:07 PM »
@ mainsworthy (even if you are off on holiday now)
I do not understand what these "three values" have to say?
I am not talking about values which automatically grow, stay or decrease.

I am talking about algorithms making "decisions". For this other players have to be taken into consideration and actions have to be done according to stuff considered before.
Basic number values can just be used to "weight" actions:
a player attacks a planet? "defense priority :+ 1"
planet is nearby? prio :+ 2
planet is of ally? prio :+ 3 * SympathyForAllyMod() (so a sooner or later ending partnership could influence prio)
planet is nearby? prio :+ 1
planet is ours? prio :+ 100


Aside of that I do not understand how the 3 values lead to a "human like acting" AI.

PS: Why needs the AI to be "static" in an RTS? I am not talking about path finding or decision making for individual units of the AI. I am talking about the AI as a "player" (controlling the whole army of units).

bye
Ron

Offline chessish

  • Jr. Member
  • **
  • Posts: 8
Re: Strata Nova
« Reply #37 on: April 13, 2019, 10:03:00 PM »
I wish you good luck with this!

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1007
Re: Strata Nova
« Reply #38 on: April 14, 2019, 10:25:23 AM »
thanks for that :)
it's creeping along. Finally got the first ship operational: cargo transporter!

Offline mainsworthy

  • Jr. Member
  • **
  • Posts: 9
Re: Strata Nova
« Reply #39 on: April 15, 2019, 03:30:06 PM »
@Derron, thanks cleared it up nicely for me, I was making a gaf not reading because I was packing, car broke so waiting for part at garage.

but if your talking about an A.I. there is two different ways to look at it , its the thought process & the practical implementation, I have seen people say they would like me to program a boardgame into a computer because they have designed an A.I... they have the thought process but the pracycal way to do it looks completely different to me atleast.

I think there are two ways to looks at it, EG analog & digital, we will never implement an analog A.I. that thinks like us, but a didgital has boundaries, boxes and borders.

I think if I was designing this I would look at the data like water, move all the data in a flow and where it swells it gets over the bank, or like magnets what a node wants and what it gives, so all the wants get fed and all the gives feeds the others, whats left is your swell over the bank, so find all the surplus and figure out what the different parts can build, the surplus should include time as a surplus too, EG you may have a predicted weeks manufacturing & 1000 tons of food & 800 tons of oil & 300 tons of metal,,,, now your algo can choose what to make with it, it may decide on tanks with metal oil and manufacturing.

Im not a genious like you guys you've been at this longer. Just trying to put another viewpoint on it.

Offline Derron

  • Hero Member
  • *****
  • Posts: 1953
Re: Strata Nova
« Reply #40 on: April 15, 2019, 04:53:56 PM »
Thanks for your input.

I think you should not think in "what can I do with XYZ terms" but sometimes also "what is needed to be able to do".

In other words: the AI needs to have targets which sometimes cannot get simply expressed in some plain numbers (not exactly true as you can split your complex target into numbers "build up an army" = "at least X tanks, y foot soldiers ,... "). Also influence to decisions should be based on plenty of inputs to make them less predictable (while they "mathematically" are still predictable). The more input is taken into consideration the more interesting (and varying) it will play. This is why many of my gameobjects in TVTower contain "x * GetXyzMod() * GetAbcMod()" calculations. Behind each mod some other modifications and temp-wise "current values" (eg people currently in front of a TV, not at work, not in bed ...) build dynamically but still "reproduceable" numbers. This automates the process of audience flows (not strictly true as there is another algorithm in the game for this too) and other stuff as all these little wheels automatically influence other wheels.
This makes balancing a lot harder (because its hard to grasp what really influences something) but at least for me it feels more "magical" then (while you of course are able to understand the major factors in a calculation).

This is why eg "GetSympathyMod(playerID)" versus the planet owners in Strata might be more interesting than "5 * IsInWarWith(playerID)".



My approach of "tasks" is not in a "computer programme task" sense but like a task you as a human would tackle: "check your planets", "plan an attack", ...as said this is done that way to mimic a slightly "human-like" AI instead of a machine/follow-an-algorithm computer player.
Also this means that eg. the AI in TVTower does not cheat and "remembers" stuff etc.



bye
Ron

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1007
Re: Strata Nova
« Reply #41 on: April 19, 2019, 12:13:47 PM »
ok, back to scratch  ;D

There were all sorts of strange little things with the previous version. but brilliant for prototyping and seeing where the problems are.

taking all of what existed and starting again with the initial planets system. This time the display can be at any angle and zooming is supported, along with planets having moons. game speed is also included:




internally the code is now really simple. with classes added to simply things further

Next up will be to add a more refined version of the ship code to test things

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1007
Re: Strata Nova
« Reply #42 on: April 19, 2019, 03:32:23 PM »
trying to make the planetary orbits less flat:  8)



Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1007
Re: Strata Nova
« Reply #43 on: April 20, 2019, 07:49:01 AM »
more tweaking and a little visual stuff later and I think that the general systems are working well:


it has a much more sci-fi feel to it which I think is a good look to go for?

Offline 3DzForMe

  • Hero Member
  • *****
  • Posts: 560
Re: Strata Nova
« Reply #44 on: April 20, 2019, 08:01:03 AM »
Quote
it has a much more sci-fi feel to it which I think is a good look to go for?

Visually very impressive stuff - oh yes very good  :D