albrow / elara

Work-in-progress educational programming game
https://elaragame.com/
Other
73 stars 5 forks source link

possible issue with character and step count #89

Open MathFreak314 opened 2 months ago

MathFreak314 commented 2 months ago

I am going to write in such a was to try and avoid spoilers.

I am attempting to get all the star challenges and have ran into a possible issue for the challenges for Levels 4 and 22.

Level 4: For this one we are supposed to get a character count of 84. The hint for character count says that whitespace like space/tab/newline and comments don't count. However by doing some testing I found that the following code gets a character count of 8 however if you count the actual characters there are only 7. `fn f() {

}` I am wondering if there is something causing the character counter to miscount when functions are involved.

Level 22: for this one we are supposed to get a step count of 18 or fewer. However I noticed that when you run your code it starts are a step count of 1 so it seems like there may be an off by 1 error here.

albrow commented 1 month ago

Hi @MathFreak314 thanks for your feedback and hope you are enjoying the game 😄

FYI for anyone looking at this in the future because the level numbers/names might change:

Level 4:

Okay this is going to be really in the weeds but bear with me. In most programming languages there is a difference between significant and insignificant whitespace.

The way character counting works in Elara is that it uses the compact_script function provided by the Rhai crate. Since Elara is open source, you can actually see the code for this! The compact_script function eliminates insignificant whitespace but leaves significant whitespace in tact. That is why you are seeing the behavior you are seeing.

Now the question is... should character counts in the game work this way? The reason to not count insignificant whitespace and comments was that I wanted to make challenges fun and interesting. I want players to find creative ways to think outside the box and shorten their code. Incentivizing players to just remove newlines, tabs, and comments doesn't sound very fun to me. I think that still makes sense and insignificant whitespace should definitely not count.

Should significant whitespace count like how it does now? I'd need to think about that a bit. It might be less confusing since players could manually count the characters in their code without worrying about significant vs. insignificant whitespace. But since you can always look at the character count in the bottom right of the code editor, I'm not sure how many players are counting manually. Changing this would also have a possibly unintended side effect of incentivizing players to avoid using syntax that requires significant whitespace- e.g. functions, if statements, for loops.

Either way, you're right and something should change here! I will either change the way character counts work to include significant whitespace or update the in-game explanatory text to clarify that significant whitespace is counted.

Even with the way character counts work now, I promise there is a way to beat the challenge for level 4. Though to be fair, it is a little bit obscure and I'm considering removing or changing this particular challenge. If you want a clue, pay close attention to the data points in the final level of the game 😉 If you still can't figure it out from there, here is one final hint:

(Click to show challenge hint) There is a solution for every challenge in the source code. On every major release of the game, there is an automated process that tests these solutions to make sure they work. That way, I can be sure that all the levels and challenges in the game are beatable and I didn't break any of them.

Level 22:

You're absolutely right! I should change the step counter to be more intuitive.

Technically under the hood the first "step" of every level is just the initial state. The simulation that runs under the hood has to start somewhere, so that's why you're seeing what you're seeing.

But what I should do is change it so that this first "step" is called "step 0" instead of "step 1". That way if you count how many times G.R.O.V.E.R. moves or takes an action it will match the number of steps that you see on the screen. I think this will make the step counter more intuitive for players. I would also have to go back and adjust all the challenges accordingly.

But just like level 4, this challenge is definitely still beatable as-is. During playtesting, one player even surprised me by beating this level in just 14 steps! Just like with level 4, there is a clue for this challenge hidden in the data points on the final level of the game 😉

MathFreak314 commented 1 month ago

thank you, I'm definitely going to take another crack at those challenges then. I just didn't want to waste time on the off chance it was an off by one error type of thing. If I was off by 2 or more I probably wouldn't have mentioned anything, just seemed like it was worth pointing out 😀. Game is awesome, thanks for making it :-)

On Sat, Jul 20, 2024 at 4:38 PM Alex Browne @.***> wrote:

Hi @MathFreak314 https://github.com/MathFreak314 thanks for your feedback and hope you are enjoying the game 😄

FYI for anyone looking at this in the future because the level numbers/names might change:

  • Level 4 is referring to the level called "All By Yourself"
  • Level 22 is referring to the level called "Malfunction Detected"

Level 4:

Okay this is going to be really in the weeds but bear with me. In most programming languages there is a difference between significant and insignificant whitespace.

  • Significant whitespace is space that is required for the code to run. For example, in Rhai, the language used for Elara, you need to have a space between the fn keyword and the name of the function. If you don't have this space, then your computer isn't able to tell what you are trying to do. You might see a syntax error or unexpected results.
  • Insignificant whitespace is space that is not required. An example of insignificant whitespace in Rhai is the newline after the opening curly bracket of a function ({). It is conventional to add a newline after the bracket but technically not required and the computer will still understand what you're trying to do if you omit it. Try it yourself! You can see the code runs just fine.

The way character counting works in Elara is that it uses the compact_script function provided by the Rhai crate. Since Elara is open source, you can actually see the code for this https://github.com/albrow/elara/blob/c808887e8f55477b5df672bd20c4cbc5f43584b6/elara-lib/src/lib.rs#L222! The compact_script function https://docs.rs/rhai/1.19.0/rhai/struct.Engine.html#method.compact_script eliminates insignificant whitespace but leaves significant whitespace in tact. That is why you are seeing the behavior you are seeing.

Now the question is... should character counts in the game work this way? The reason to not count insignificant whitespace and comments was that I wanted to make challenges fun and interesting. I want players to find creative ways to think outside the box and shorten their code. Incentivizing players to just remove newlines, tabs, and comments doesn't sound very fun to me. I think that still makes sense and insignificant whitespace should definitely not count.

Should significant whitespace count like how it does now? I'd need to think about that a bit. It might be less confusing since players could manually count the characters in their code without worrying about significant vs. insignificant whitespace. But since you can always look at the character count in the bottom right of the code editor, I'm not sure how many players are counting manually. Changing this would also have a possibly unintended side effect of incentivizing players to avoid using syntax that requires significant whitespace- e.g. functions, if statements, for loops.

Either way, you're right and something should change here! I will either change the way character counts work to include significant whitespace or update the in-game explanatory text to clarify that significant whitespace is counted.

Even with the way character counts work now, I promise there is a way to beat the challenge for level 4. Though to be fair, it is a little bit obscure and I'm considering removing or changing this particular challenge. If you want a clue, pay close attention to the data points in the final level of the game 😉 If you still can't figure it out from there, here is one final hint: (Click to show challenge hint) There is a solution for every challenge in the source code. On every major release of the game, there is an automated process that tests these solutions to make sure they work. That way, I can be sure that all the levels and challenges in the game are beatable and I didn't break any of them. Level 22:

You're absolutely right! I should change the step counter to be more intuitive.

Technically under the hood the first "step" of every level is just the initial state. The simulation that runs under the hood has to start somewhere, so that's why you're seeing what you're seeing.

But what I should do is change it so that this first "step" is called "step 0" instead of "step 1". That way if you count how many times G.R.O.V.E.R. moves or takes an action it will match the number of steps that you see on the screen. I think this will make the step counter more intuitive for players. I would also have to go back and adjust all the challenges accordingly.

But just like level 4, this challenge is definitely still beatable as-is. During playtesting, one player even surprised me by beating this level in just 14 steps! Just like with level 22, there is a clue for this challenge hidden in the data points on the final level of the game 😉

— Reply to this email directly, view it on GitHub https://github.com/albrow/elara/issues/89#issuecomment-2241302069, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH3PIEUF33D5QQ7IXJYZRY3ZNLKF7AVCNFSM6AAAAABLDA2QXCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBRGMYDEMBWHE . You are receiving this because you were mentioned.Message ID: @.***>