Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraforming #742

Open
byorgey opened this issue Oct 10, 2022 · 8 comments
Open

Terraforming #742

byorgey opened this issue Oct 10, 2022 · 8 comments
Labels
C-Moderate Effort Should take a moderate amount of time to address. G-Terrain An issue relating to world terrain. G-World An issue having to do with world design, world generation, etc. L-Commands Built-in commands (e.g. move, try, if, ...) in the Swarm language. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. Z-Feature A new feature to be added to the game. Z-Performance This issue concerns memory or time efficiency of the Swarm game.

Comments

@byorgey
Copy link
Member

byorgey commented Oct 10, 2022

Now that we have custom terrain (#1775), and especially if we add something like #205 , it should be possible for robots to programmatically change the terrain.

This would require reworking the way that we store terrain values, since currently there is no way to store/remember any terrain values other than the ones that are generated by the world function. We could probably do something similar to the way that we currently store entities.

@byorgey byorgey added the Z-Feature A new feature to be added to the game. label Oct 10, 2022
@xsebek
Copy link
Member

xsebek commented Oct 10, 2022

The natural solution would be to add a terraform command that would require God's capability. 😇

I am not sure what is the best structure to represent tiles or if we even need to optimize it if can not measure it realistically yet. I suppose we could run one tick with a mutable array and get back a normal one by using runSTArray. 🤔 EDIT: As would need to make a copy if it is ever edited - laziness might be enough to protect us from the performance penalty.

EDIT2: Actually we probably could simply collect the updates and execute them all at once at the end of the tick - if more are in the same tile then it will be very efficient.

@xsebek xsebek added C-Low Hanging Fruit Ideal issue for new contributors. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. G-World An issue having to do with world design, world generation, etc. L-Commands Built-in commands (e.g. move, try, if, ...) in the Swarm language. Z-Performance This issue concerns memory or time efficiency of the Swarm game. labels Oct 10, 2022
@xsebek
Copy link
Member

xsebek commented Oct 10, 2022

I think a good performance test would be to run a line of robots across the screen and change the terrain of every visible location.

We could run that a few times, left to right and back again, like windshield wipers.

Compare that with the same run with the terraform replaced by noop and see if it is even noticeable to the player.

@byorgey
Copy link
Member Author

byorgey commented Oct 11, 2022

Using actual mutable arrays for the terrain seems problematic; see the discussion at #30 . Another possibility would be to do something similar to entities: we have a base, immutable array storing initial terrain values, and then a map of "overrides". To look up the terrain value for a particular cell you first look it up in the override map, and then fall back to the base array if you don't find it.

@xsebek
Copy link
Member

xsebek commented Oct 11, 2022

I think with terraforming the common use case will be doing sweeping terraforming of an area once and then leaving it as is.

See my EDIT2 - if we collect the terrain updates at the end of the tick, we can update the pure immutable array once. So if you have a lot of robots changing the terrain at the same time it will be more efficient but the data can stay immutable. This will be particularly useful for As which must not change the original immutable array and in fact, it will never even get to it because it does not run in ticks.

@xsebek
Copy link
Member

xsebek commented Oct 11, 2022

As another thought, we should add a counterpart function scanTerrain: cmd (unit + text). Should be trivial to add. 🙂

@byorgey
Copy link
Member Author

byorgey commented Oct 11, 2022

I think updating the immutable terrain array once per tick is probably too frequent. Imagine you just have one robot walking back and forth changing the terrain - it can only affect one square per tick and you would be regenerating the entire tile every tick. But I can imagine buffering a bunch of terrain updates and then regenerating the immutable tile array once enough updates have accumulated.

@xsebek
Copy link
Member

xsebek commented Oct 11, 2022

I bet it would not be so bad, especially if the compiler can figure out that we will not need the original array anymore. But we will have to try measure it and see. 🙂

@byorgey
Copy link
Member Author

byorgey commented Oct 11, 2022

I think it will be bad 😄 But yes, we will have to benchmark it!

@byorgey byorgey added C-Moderate Effort Should take a moderate amount of time to address. and removed C-Low Hanging Fruit Ideal issue for new contributors. labels Apr 7, 2023
@byorgey byorgey mentioned this issue May 3, 2024
@byorgey byorgey added the G-Terrain An issue relating to world terrain. label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Moderate Effort Should take a moderate amount of time to address. G-Terrain An issue relating to world terrain. G-World An issue having to do with world design, world generation, etc. L-Commands Built-in commands (e.g. move, try, if, ...) in the Swarm language. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. Z-Feature A new feature to be added to the game. Z-Performance This issue concerns memory or time efficiency of the Swarm game.
Projects
None yet
Development

No branches or pull requests

2 participants