Comments (4)
Regarding exercise 118, using while budget > 0
like it's presented means the game will tolerate "overspending" on the last enemy in the list. I believe the code as you present it can already be considered a solution to the exercise (it won't get stuck, it will simply overspend on whatever the next enemy costs).
Am I missing something, or should we be looking at code that wants to retry chanceList:next()
until the cost of the picked enemy fits within the remaining budget?
from blog.
You can solve that problem in multiple ways. The most straight forward to me would be to just not spawn an enemy if it overspends by adding if points - self.enemy_to_points[enemy] >= 0
before doing the points = points - self.enemy_to_points[enemy]
calculation. However this is the kind of thing that is really really small in the grand scheme of things so realistically I wouldn't worry about one enemy spending a few extra points.
from blog.
I apologize, I think I haven't made my point very well.
I mean that this statement in the exercise isn't true regarding the code provided in the lesson:
The while loop that takes care of finding enemies to spawn has one big problem: it can get stuck indefinitely in an infinite loop. Consider the situation where there's only one point left, for instance, and enemies that cost 1 point (like a Rock) can't be spawned anymore because that difficulty doesn't spawn Rocks.
It doesn't get stuck in an infinite loop because even if there's only 1 points left, it tolerates spending 3 points on the last enemy to bring points
to -2, after which the while
loop ends as expected.
By the way, thank you so much for making and distributing these lessons!
from blog.
Ah, I see. So the line that I mentioned in the previous comment should have been there in the first place and I guess I forgot to place it there. Now that I understand your question better:
Am I missing something, or should we be looking at code that wants to retry chanceList:next() until the cost of the picked enemy fits within the remaining budget?
I decided to not focus on that in the question because I wanted to make sure the reader understood the notion of stopping loops like that after a number of runs since it's a useful idea in lots of situations. But yea, in a real scenario you can change the probabilities of enemies as the number of points left changes. Although even in a real game I personally wouldn't do that because it's way more complicated than just using the naive solution.
from blog.
Related Issues (20)
- Psychedelics and Finishing Games
- Posting gamedev progress online HOT 1
- Neuroticism in Indie Gamedev HOT 1
- Easy Modes HOT 14
- Hey,
- Making rxi's lite my main text editor HOT 4
- Cancellation-proof automated cyberchains HOT 2
- Personality-led irrational behavior during the coronavirus pandemic HOT 3
- Object Management
- Springs
- Personality Trait Instance Archive
- Arguments on why developers might want to prevent streamers from streaming their game
- New Programming Taxonomies HOT 6
- Substack
- New site
- Borders vs. No Borders
- Game Ideas
- Why 1-based indexing is right for Lua
- Thoughts on making small games
- Why indiedevs shouldn't fear being cancelled
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.