Didn't do a great job at explaining it to be fair. Basically, the code says: "Step in every direction, and for every direction you step in, repeat this"
recursion is tricky to get your head around at first but the basic idea is that it will pass a new direction to move in when it finds a valid one each time, so while it looks like it should check all 4 directions every loop it's actually adding new directions as it finds them and this is handled before it goes back to check the rest while the drone has a valid move direction it will move there and call the same logic again (so it will keep moving down a "branch" of the maze until it gets stuck (it'll be stuck when the only valid direction is the direction it came from) when it gets stuck the other functions that were previously being called are now allowed past the recursive call and it will automatically move back to the start of the branch and check every other direction / branch (the order it explores is set in the code).
I actually like the way you wrote the maze, pretty easy to understand, though it may be cleaner to loop through the directions instead of repeating the code in the solve function. The maze with loop is actually pretty easy and fun, just keeping track of where youve gone, especially since python has the 'in' keyword. In the maze with loop version, you also get the coordinate of the treasure, sorting which direction to go first makes it slightly harder but much faster, i had a lot of fun coding that BTW, if you want more power from sunflower farm, i recommend coding it so that it only picks the highest sunflower each time instead of scanning the entire field. You basically put the coordinate of each flower in a list along with their petal count, and find the max index. You can use max-heap(O(logn) each insertion) if you want a really fast farm, but slightly harder challenge
Thank you, this means a lot! There is a lot of stuff to clean up for sure. The harder mazes I would like to give a go as well. I could just go straight to the sunflower couldn't I...damn. Definitely something to think about. Thanks again :)
19:00 This is exactly why indentation dependent languages suck. 😆 Would never happen if you were enclosing the function block with brackets. EDIT: Holy shit, I never read the Maze hints, and Hint 3 is exactly how I solved the maze on the first go. 🤣 Actually... I still do, at least on the first pass. Good luck with the loops! Looking forward to your approach, if you decide to do it. 🙃
i find brackets worse because it is way easier to missplace a bracket and even with brackets you indent the code the same way for readability. so in 90% of the cases the code just has more brackets and doesn't look any different otherwise. and to one line code to make it shorter isn't really good besides when the code is part is "finished" and won't be edited in the foreseeable future. like ok i have seen code scripts with 10k lines that got shortened to 3k lines by removing all new lines, but it isn't really helping at all. it just makes it a bit easier to find where you are currently editing stuff. that is pretty much the only "advantage" of languages with brackets for blocks.
@dovos8572 I used to have this mentality (not liking brackets) as I was taught coding in Python. The thing is it is easy to miss empty spaces when reading code. Explicit brackets are not easily missed. Also in certain situations, the code would not even compile and the IDE would tell you (like the situation with my unintended 'return').
@@KedrigernGaming well that depends on the IDE tho. if you code in godot, then it will complain about all syntax errors before you even reached the play button. another thing is that this game isn't actually python but just a look alike and it has it's own syntax rules and conditions. not everything is the same and things like "match case" don't even exist.
@@dovos8572 It's all preference (and practice) really. To someone who's highly cognizant of the indentation, it's not a big deal. Same for someone who's familiar with bracketed languages. Though, I do enjoy being able to NOT follow the current indentation level for FURTHER readability. There are times when I want to group some lines together via increased indentation (beneath a starting line and not just separating them from the rest of the code by an obscene amount of white space), but they aren't explicitly within a new block. Other times, I enjoy being able to write entire blocks on one line, in a way that Python just doesn't cope with. As long as the block is encased in brackets and the lines are separated by semicolons, it's all the same to the compiler! (Though, to be fair, TFWR's implementation of "Python" doesn't allow for a lot of its fancy compression techniques) I grew up living in Basic languages (BASIC on Commodore64, QBASIC in DOS, Visual Basic) so I had neither. 🤣 You explicitly closed the block with a dedicated term for it. Even back then, I thankfully didn't neglect good indentation practice.
Just so you know, that error because of the unindented return cannot happen in real python. Return statements outside of a function are a syntax error. Also with proper ides (LIKE NEOVIM) and being used to it, you basically never have indentation issues. Its been years since I last had a problem with that. But yeah, identation can be tricky and annoying some times.
Happy to hear that! Thank you for the explanation. Yes, being used to it is a big part I feel. I am sure I would have caught it straight away had it been outside a { } block. Or you know...it would have never happened in the first place
my solution, not for the "challenge" version basically hug left wall and move though the maze. also have fun with cactus..... had a lot more trouble with cactus than mazes... ``` directions = [North, East, South, West] facing = 0 # loop until we find the treasure while get_entity_type() != Entities.Treasure: # turn left facing = (facing + 1) % 4 # attempt to move forward while not move(directions[facing]): # turn right facing = (facing - 1) % 4 harvest() ```
Hmm, the delicious taste of the Hubris of man, if only there were convenient tools to analyse what is happening at specific steps in the program to remove bugs, some kind of de-bugger :D
I have said it in almost every video, I am not buying the debugger :D This is a proper fun challenge! But it's true that normally I'd at least have print statements...now I don't even have that. I hope they make this into an achievement one day. "Complete the game without unlocking the debugger"
@@KedrigernGaming I know you've said it, that's the Hubris part :D Being able to place interrupts and print out variable contents is handy but by all means have lots of *FUN* without them, it's very entertaining ;)
@@KedrigernGaming The game has print statements, and you can open the console in the settings (only thing is, I dont remember whether it is part of the debugger unlock, dont think so though)
You experienced high discomfort watching that for a long period of time. I did not because I didn't see it. But the pain I felt once I realized... still no idea what is worse 😂
I have now! Interesting stuff. They have a few tries and on the first they just recon and find the optimal path. And the second pass they just go straight to the goal.
I realy think I have to buy the game xD I think I would have used a "right hand" solution. My Plan would be to always check weather to the right site of the drone is a hedge. Something like: Always loop from the first line Try to move straight ahead, if it doesnt work Turn Right and Check wheather you can move, if it doesnt work, turn twice #turning once would basicly mean you turn back from where you came from and then even if its slow keep repeating and check after every tile wheather you are above the treasure. Although this might not work in the game or is was to complex or slow to actually work .. this is my solution This Solution should work always if you loop from the top line ... and if there arent loops you always should be able to solve the maze eventually For loops I would implement a list that tracks every space I already entered ... although .. i dont know how to exit those fields .. only Idea would be to implement a check that tries to find a movable field that isnt the same as one I am on ... ok that sounded better in my head .. i know why I am a systemintegrator xD
edit: yes ... your solution is basicly the same as my Idea ... iterate over the lab until you bruteforce it ... Using cardinal directions helps with the check for the direction you came from
Your idea is very similar to the one suggested in the in-game hints. Basically hug a wall. A good solution for sure ;) As for a maze with loops I really thing the idea I mention in the video of remembering all tiles already visited and stopping the propagation of the code there when the same gets visited twice could work. But hey, gonna find the errors in these ideas once I actually start implementing this xD
@@KedrigernGaming I think the Idea of logging the fields you entered is actually smart. Though you should increase the check value for the repeated field to 3 or 4 before you reset If you run a dead end, the maze would immediately reset even if you might never have ran into the potential loop (say you run into the loop circle it once or twice and you should know you are in the loop) There is another idea I have though. Left hand Exit. If you try to move through the Maze via the right hand solution, you can escape a loop if you use the left hand solution. Loop until you saw a 2 fields for the third times then jump into the exit loop function where you look either for the first exit you can take to the left or backtrack to the field before you repeated the Loop for the third time and check basicly for different exits. My Idea for detecting a Loop just went into thin air If you can detect a loop though. You should save the loop into a matrix and iterate the Matrix over the level of the Maze (Maze0 no loops, Maze1 one loop and so on) Then you only have to use the other direction once you enter the maze Damn though it's hard to come up with good efficient solutions. Esp if you are literally blind and kinda have to bruteforce the solution
You missing that unindented return was painful, very simple but very annoying error lol
Not sure what's more painful. Not being able to figure it out or knowing and having to watch the desperation.
@@KedrigernGaming they're probably similarly painful but I came to the comments when I was in pain from cringing
I honestly don't understand how that maze solving algorithm works
Didn't do a great job at explaining it to be fair.
Basically, the code says: "Step in every direction, and for every direction you step in, repeat this"
recursion is tricky to get your head around at first but the basic idea is that it will pass a new direction to move in when it finds a valid one each time, so while it looks like it should check all 4 directions every loop it's actually adding new directions as it finds them and this is handled before it goes back to check the rest
while the drone has a valid move direction it will move there and call the same logic again (so it will keep moving down a "branch" of the maze until it gets stuck (it'll be stuck when the only valid direction is the direction it came from)
when it gets stuck the other functions that were previously being called are now allowed past the recursive call and it will automatically move back to the start of the branch and check every other direction / branch (the order it explores is set in the code).
I actually like the way you wrote the maze, pretty easy to understand, though it may be cleaner to loop through the directions instead of repeating the code in the solve function. The maze with loop is actually pretty easy and fun, just keeping track of where youve gone, especially since python has the 'in' keyword. In the maze with loop version, you also get the coordinate of the treasure, sorting which direction to go first makes it slightly harder but much faster, i had a lot of fun coding that
BTW, if you want more power from sunflower farm, i recommend coding it so that it only picks the highest sunflower each time instead of scanning the entire field. You basically put the coordinate of each flower in a list along with their petal count, and find the max index. You can use max-heap(O(logn) each insertion) if you want a really fast farm, but slightly harder challenge
Thank you, this means a lot!
There is a lot of stuff to clean up for sure. The harder mazes I would like to give a go as well.
I could just go straight to the sunflower couldn't I...damn. Definitely something to think about. Thanks again :)
19:00
This is exactly why indentation dependent languages suck. 😆 Would never happen if you were enclosing the function block with brackets.
EDIT:
Holy shit, I never read the Maze hints, and Hint 3 is exactly how I solved the maze on the first go. 🤣 Actually... I still do, at least on the first pass. Good luck with the loops! Looking forward to your approach, if you decide to do it. 🙃
Exactly! Sucks!!
I will, think I have an idea but we shall see. First I am excited to try the cactus puzzle though :)
i find brackets worse because it is way easier to missplace a bracket and even with brackets you indent the code the same way for readability. so in 90% of the cases the code just has more brackets and doesn't look any different otherwise.
and to one line code to make it shorter isn't really good besides when the code is part is "finished" and won't be edited in the foreseeable future.
like ok i have seen code scripts with 10k lines that got shortened to 3k lines by removing all new lines, but it isn't really helping at all. it just makes it a bit easier to find where you are currently editing stuff. that is pretty much the only "advantage" of languages with brackets for blocks.
@dovos8572 I used to have this mentality (not liking brackets) as I was taught coding in Python.
The thing is it is easy to miss empty spaces when reading code. Explicit brackets are not easily missed. Also in certain situations, the code would not even compile and the IDE would tell you (like the situation with my unintended 'return').
@@KedrigernGaming well that depends on the IDE tho.
if you code in godot, then it will complain about all syntax errors before you even reached the play button.
another thing is that this game isn't actually python but just a look alike and it has it's own syntax rules and conditions.
not everything is the same and things like "match case" don't even exist.
@@dovos8572 It's all preference (and practice) really. To someone who's highly cognizant of the indentation, it's not a big deal. Same for someone who's familiar with bracketed languages. Though, I do enjoy being able to NOT follow the current indentation level for FURTHER readability. There are times when I want to group some lines together via increased indentation (beneath a starting line and not just separating them from the rest of the code by an obscene amount of white space), but they aren't explicitly within a new block. Other times, I enjoy being able to write entire blocks on one line, in a way that Python just doesn't cope with. As long as the block is encased in brackets and the lines are separated by semicolons, it's all the same to the compiler! (Though, to be fair, TFWR's implementation of "Python" doesn't allow for a lot of its fancy compression techniques)
I grew up living in Basic languages (BASIC on Commodore64, QBASIC in DOS, Visual Basic) so I had neither. 🤣 You explicitly closed the block with a dedicated term for it. Even back then, I thankfully didn't neglect good indentation practice.
Just so you know, that error because of the unindented return cannot happen in real python. Return statements outside of a function are a syntax error.
Also with proper ides (LIKE NEOVIM) and being used to it, you basically never have indentation issues. Its been years since I last had a problem with that.
But yeah, identation can be tricky and annoying some times.
Happy to hear that! Thank you for the explanation.
Yes, being used to it is a big part I feel. I am sure I would have caught it straight away had it been outside a { } block. Or you know...it would have never happened in the first place
my solution, not for the "challenge" version
basically hug left wall and move though the maze.
also have fun with cactus..... had a lot more trouble with cactus than mazes...
```
directions = [North, East, South, West]
facing = 0
# loop until we find the treasure
while get_entity_type() != Entities.Treasure:
# turn left
facing = (facing + 1) % 4
# attempt to move forward
while not move(directions[facing]):
# turn right
facing = (facing - 1) % 4
harvest()
```
That is really nice!
Looking forward to trying the cactus puzzle.
Hmm, the delicious taste of the Hubris of man, if only there were convenient tools to analyse what is happening at specific steps in the program to remove bugs, some kind of de-bugger :D
I have said it in almost every video, I am not buying the debugger :D This is a proper fun challenge!
But it's true that normally I'd at least have print statements...now I don't even have that.
I hope they make this into an achievement one day. "Complete the game without unlocking the debugger"
@@KedrigernGaming I know you've said it, that's the Hubris part :D
Being able to place interrupts and print out variable contents is handy but by all means have lots of *FUN* without them, it's very entertaining ;)
I hope it is :D
@@KedrigernGaming The game has print statements, and you can open the console in the settings (only thing is, I dont remember whether it is part of the debugger unlock, dont think so though)
That indentation mistake was so painfull to watch😂
You experienced high discomfort watching that for a long period of time. I did not because I didn't see it. But the pain I felt once I realized... still no idea what is worse 😂
Welcome to developer life :D TBF in any decent IDE there would have been a warning about that misplaced return statement.
Right?!
But to be fair the entertainment value of the video would be cut in half...
Yeah, mazes! Was waiting for it for so long
Have you yet seen how damn fast robots can solve a maze?
I have now! Interesting stuff. They have a few tries and on the first they just recon and find the optimal path. And the second pass they just go straight to the goal.
1:30 there is a probability?? What??? No way I missed that
Welp now I already gave up playing
To be fair they seem to be changing the rules of the game under our hands..
I realy think I have to buy the game xD
I think I would have used a "right hand" solution. My Plan would be to always check weather to the right site of the drone is a hedge.
Something like:
Always loop from the first line
Try to move straight ahead, if it doesnt work
Turn Right and Check wheather you can move, if it doesnt work, turn twice #turning once would basicly mean you turn back from where you came from
and then even if its slow keep repeating and check after every tile wheather you are above the treasure.
Although this might not work in the game or is was to complex or slow to actually work .. this is my solution
This Solution should work always if you loop from the top line ... and if there arent loops you always should be able to solve the maze eventually
For loops I would implement a list that tracks every space I already entered ... although .. i dont know how to exit those fields .. only Idea would be to implement a check that tries to find a movable field that isnt the same as one I am on ... ok that sounded better in my head .. i know why I am a systemintegrator xD
edit: yes ... your solution is basicly the same as my Idea ... iterate over the lab until you bruteforce it ...
Using cardinal directions helps with the check for the direction you came from
Your idea is very similar to the one suggested in the in-game hints. Basically hug a wall. A good solution for sure ;)
As for a maze with loops I really thing the idea I mention in the video of remembering all tiles already visited and stopping the propagation of the code there when the same gets visited twice could work. But hey, gonna find the errors in these ideas once I actually start implementing this xD
@@KedrigernGaming I think the Idea of logging the fields you entered is actually smart.
Though you should increase the check value for the repeated field to 3 or 4 before you reset
If you run a dead end, the maze would immediately reset even if you might never have ran into the potential loop (say you run into the loop circle it once or twice and you should know you are in the loop)
There is another idea I have though.
Left hand Exit.
If you try to move through the Maze via the right hand solution, you can escape a loop if you use the left hand solution.
Loop until you saw a 2 fields for the third times then jump into the exit loop function where you look either for the first exit you can take to the left or backtrack to the field before you repeated the Loop for the third time and check basicly for different exits.
My Idea for detecting a Loop just went into thin air
If you can detect a loop though. You should save the loop into a matrix and iterate the Matrix over the level of the Maze (Maze0 no loops, Maze1 one loop and so on)
Then you only have to use the other direction once you enter the maze
Damn though it's hard to come up with good efficient solutions.
Esp if you are literally blind and kinda have to bruteforce the solution
Perfect timing for my lunch
i quite like your coding teachig, but i really hate your laguage. It is quite same to degrade your good educatio work with your s and f words.