1 kyu
Puzzle Fighter
49 of 176docgunthrop
Loading description...
Games
Logic
Game Solvers
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
So after reading all of the other questions, and not really finding an answer to the one I had, I thought I'd ask it
In the context of Power Gems What would the power gem look like in the following situation
if the formed power gems look like
1's and 2's being the power gem id and the S's being single. The explanation of the game mentioned how when power gems are formed, the higher elevation takes priority, and when a gem wants to 'grow' it tries to form a new power gem and then combine with others at the same level, but what if the gems are already formed, and there are 2 options for 'growing'?
Would the formation of power gems look like
or
assuming they are the same color
Priority goes to the Power Gem with higher elevation, so in your example the first case would be the correct result.
Should be updated to Python 3.8
to @kazk (or anyone else on admin team):
When attempting to republish the kata with Python default to 3.8, I get an error message stating that
Default version is not a supported version
. How can I resolve this?could you fork my solution, with the entire new version (preloaded + tests)?
done
@Blind4Basics: 👍
This comment has been hidden.
I guess this covers that, so nevermind.
Awesome kata! I downloaded the game to try it out myself, and I'm definitely of the opinion that the kata is the more entertaining of the two.
Python translation: uncommenting
see_states = True
doesn't seem to work (I'm only told my solution was wrong and the expected final answer, but no step-by-step info to help me debugging), at least for tests (I did not submit my solution). Or, is it designed to work with "real" test cases only so I have to debug the example tests on my own?ok, replying myself: I've just passed example tests, and the step-by-step debug info works for real tests.
This is an intersting problem and I've already started coding. However, it's not very clear to me that how to expand exsiting Power Gems. Suppose the following board just after dropping the pair (I don't know whether it's a reachable state, but...)
All the gems are red, the number denotes the id of power gems (0 are indivial, 1 is the 1st power gem, 2 is the 2nd power gem). After merging individual gems:
Now, will all the gems (2 individual gems + 4 power gems) merge into a giant power gem? If not, what's the exact rule of merging? Thanks!
EDIT: board in the last edition was wrong...
In your given board, none of them will merge. For power gems to merge, they should have same exact height (if you want to merge horizontally), and start at same elevation. (similar with vertical merging)
For example: 0 - empty place, 1,2 - power gems (let's assume all non-0s are red)
1 would merge with 2. But in case of:
No merge would happen, because heights are different. Here's an example of successful vertical powergem merge:
Last example of singles merging with a powergem: (S - non-powergem pieces)
Singles will merge with powergem 1, and that's it (no merge with 2)
Does that make it any clearer? TBH you have to read the rules many times to understand exactly how it works.
Thanks! That's very clear. Just to confirm: Power gems are processed from top to bottom, left to right? For example:
We process 1 first, so 1 is able to expand, but 2 cannot. If we process 2 first then only 2 can expand.
Also, merging can take several steps, like this?
1 first expands to left and right, then expand down so all of them merge into a giant power gem?
It's been some time since I solved it, but from what I remember, first all non-powergem pieces form gems, if possible (top to bottom, left to right), then merging single pieces with gems (horizontally first, then vertically), then merging gems with other gems.
I'm not sure how to interpret that first board, but if I understood correctly, then 1 would expand left once, then 2 would merge with G (horizontal growth priority)
And yes, merging can occur many times: in your second board, 1 would merge with S on left AND right side, then it would merge with gem2 to form 1 massive powergem.
At least that's how I remember these interactions, I could be wrong :D
Edit: for the first board, let's say those S weren't there. I think 2 would merge first, even though 1 is higher, because of horizontal growth first, as mentioned previously.
Thank you! I'll try.
Oops, I was in a hurry when replying the last time, and now that I found I didn't make it clear that in my last example, S,1,2 are all red gems, so they cannot merge with Green gems. So maybe 1 expand left one, 2 cannot expand? Anyway, I'll try myself soon, and thanks again!
Another small question: can crash gems be part of a power gem? I think not, but I can't find a clear rule about it. Technically, a crash gem also has a color anyway.
Yeah, seems correct.
No, because as soon as it touches another gem of its color (if another gem lands next to it), no matter if powergem or not, everything around it gets destroyed (including itself ofc).
Btw, there's 1 tip that I can give you, and it's that the tests are very thorough and you have to account for every possibility. You may think you could take some shortcuts, or avoid certain situations, but it won't work. Soon enough, you can end up with a lot of spaghetti code :P
huh? I thought it only destroy itself if it LANDS on a gem of its color. What about this:
First,
rB
lands on the ground on step 1, then a vertical pairRR
lands immediately to its left on step 2. Willr
destroy BB to its left and also destroy itself in step 2? If no, then we can throw another verticalRR
onr
then theoretically we got a 2x2 red gem containing one crash gem.Oh, thanks! Then I'm giving myself an additional challenge to minimize the time spent from submitting my first solution to solving this problem 8-)
That would be rainbow gem. Crash gems trigger around it too. In your given board, it would destroy RR on left, and if B was R, it would clear the entire board at once.
ahhhh... you're right! I misread this part. Thank you!
Thank you, B1ts, I solved it! But I'm not sure whether it handles everything correctly. Tests are random... Anyway, can't way to see others' solution 8-)
That's awesome news, congrats on solving it!
Finished all doc's purple katas. Enjoyed every of them. Many thanks.
👉😺👉 Righteous! 🙌
I exceed the time limit :( How much I can do 130
My Graphic Test ◄
I have randomly tried the tests and had no errors
So your solution is correct but needs to be faster?
haha yes. I managed to overcome by making it more efficient. It was redundant in some parts.
Seems after the last markdown update, the images are displaced from their intended position. Quite clear from this screenshot:
Thanks for the heads up. I made a fix to the alignment for the images so there's no longer any overlap. Only thing is it doesn't look as aesthetic as it did before (ie. had evenly-sized borders around each image before CW's markdown change), but it should be ok.
I have a question: the power gem behaviour is quite confusing, but if you have the board state of where all the colours are, are you able to unambiguously tell where the power gems are, or do you have to keep track of them also, in order to manage merging behaviour?
you have to keep track of them on your own.
Thank you very much, hopefully that saves me some time haha.
One other question, do you have to account for colliding into the active playing field when moving the piece, or can it be modelled as being dropped from above the playing field? I know it says you can in the detail text but the image diagrams seem to imply otherwise.
It is modeled as being dropped from above the playing field.
What is the meaning of "elevation" in this context?
Elevation is in reference to the vertical position. Higher elevation == higher vertical position.
"vertical" position?(do you mean the topmost point of gem?)
I think my question is not clear. In the case of a point object I can define the term elevation as the vertical distance from the bottommost point of the environment to the point of consideration.(Like 1 KM from sea level i.e. the vertical distance between the point of consideration to the level of sea).
But in the case of extended body, I am asking which part of the body(that can be (bottommost, topmost, center) of the body) one have to consider to take to find the distance from bottom of the environment(here the ground of board)?
It's determined by the top row of the respective power gem. If this does not clarify, please provide an example of the scenario you're describing.
EDIT: yes, topmost point of gem.
i am confused in this scenario
left side is mine and right side is expexted but i dont understand why
when
b
decend onB
((8,3)) it will directly destroy releated colors and thenB
will decend onY
(8,2)It's because the gem pair gets disjointed. In the Description:
Below is the breakdown. If this answers your question, go ahead and mark as resolved.
Below, the green Gem will combine with other adjacent ones to form a Power Gem, and at the same time the blue Crash Gem will shatter along with the two blue Gems below. The result is the middle frame, rather than the last frame.
considering this example, as soon as
b
lands upon (8,3)(B
not landed yet) it will destroy related colors and thenB
lands (in above example as soon as green color touches other green colors (blue crash color is not landed yet) and converts into power green gem then blue crash color disjoints itself and lands on another blue color and destroy it)(: timing matters)
The
b
crash gem begins exploding connected gems after theB
gem has disjointed and landed. The section of the Description you're referring to, How Moves Work, provides the sequence of events; refer to steps 2 and 3, specifically:nevermind i solved, i just overcomplicated some parts like timing and all
and i have to say this is a brilliant kata and keep creating this type of katas :]
Glad to hear it 😎
does we have to apply movement along with descending pair(like in real game) or we have to do all the movements first then descend on playfield??
It's in the description under Game Mechanics, but there's a lot of information to process so its understandable that things get overlooked.
i did see this one, but i thought the other way; btw thanks for confirming :]
I had the same question. Let me clarify, does "above the field" mean in the 0th and 1st rows, or in general above the field? The last option is apparently excluded, since the drop alley is 1 cell wide. It turns out that before moving, I need to check if there are any obstacles in the next field, am I right? With the movement to the right and left - everything seems to be clear - they should be blocked by an obstacle, but what about turns - should they just be blocked too? How should a counterclockwise turn from a horizontal position to a vertical one take place if the pair is in the first row: should the first gem go into the second row, and should the second onebe above it (should it be shift in vertical position)?
I don't understand the rule for this (9th of the Fixed test)
32 th move
The expected result is like if the move 33 was canceled. But i not understant why (which rules applied here ?)
"If at any point in the game a stack of Gems goes above the top row, terminate the process and return the game state before the last move. This applies to Crash Gems and Rainbow Gems as well; their position is taken into account before their effect."
But the stack of Gems goes never above the top row
There's a gem pair that precedes the
0G RRA
gem move:BB LL
This pair pushes the 2nd column above the top line, thereby terminating the game.
So simple ... thanks you !
This has so much text at the beginning I'm not even gonna touch it.
XD you've never seen my katas, then... XD
yep, maybe part of what made it a 1kyu was having the patience to read through it all? 🤔
Reading the description is far to be the hardiest part of this kata ;)
It's very well explained, and examples provided in it are very useful (even without needing to start training for discover the provided fixed test).
However, it's a nightmare to debug, even if I've spent hours to build pretty html log tools :D
Many thanks for all your wonderful katas docgunthrop!
Glad to hear you enjoyed it. Funny thing about this kata is that I didn't find a definitive source for all the behaviors, so some of them had to be verified by watching gameplay footage ¯\_(ツ)_/¯
Holy GOD that was a slog. 10/10 10 hours well-spent.
I'm confused by this transition:
In the first step, there are cannot be any Power Gems, as they are no squares of 4 or more blocks. Thus, the formation of all Power Gems seem in the second step must take place during this single transition. A Rainbow gem falls on Row 4, hitting the Yellow atop column 4. A Red hits atop that Rainbow Gem, but does not form any Power Gems. All Yellows simultaneously break, leading to this:
The gems fall, settling to this conformation.
Power gem formation takes place, leading to a 2x2 Red in rows 7 and 8 atop a 3x3 Red in rows 9 and 10. Note that the bottom 2x3 Power Gem lies atop a single Red in the bottom left corner. The green Crash Gem triggers, leading to the bottom falling out of the picture, but because of the 2x3 Power Gem, the Reds should not fall. Why does the answer show the Reds falling?
After the gems fall, priority should be given to a power gem formation at a higher level, so in this case, the red gems at row 7. These can expand vertically up to a height of 4, leaving you with a 2x4 red power gem above the
gG
at row 11. After this power gem formation, no other power gems can form. After the green gems are destroyed, the red 2x4 power gem can fall and expand leftwards.But we are told that "In the case where an existing Power Gem can expand by increasing vertically or horizontally, priority goes to horizontal growth." In this case, via pic 3, you would be able to form a 2x3 in rows 9 and 10, expanding over the (11, 0) Red, BEFORE falling due to the greens exploding. Why would you expand vertically when you are explicitly told to expand horizontally whenever possible? Should I explode the greens before forming gems?
Because you can't expand horizontally. The highest possible row for a power gem formation is 7. So, a 2x2 power gem initially forms in rows 7 and 8.
The power gem first tries to expand horizontally, but it can't as there is a blue gem on either size of it.
It then tries to expand horizontally and manages to expand to a height of 4, so is now a 2x4 power gem.
So you get the 2x2 in rows 7 and 8. Now, the board looks like
Does this then transition to
?
Yeah, and then expands to
Okay, but then on another problem, we see this transition:
This indicates the following configuration:
Which prioritizes expanding horizontally, even though it starts from the same situation as in my first sequence.
Whereas in the first sequence, the 2x2 at the top expands down to a 4x2 and blocks the formation of a 2x3, in this second sequence, the 2x2 is ignored and a 2x3 results. What is the difference?
Sorry for the late reply.
New power gem formation happens first, so in this case, the 3x2 power gem on row 9 is formed.
Thanks, no worries. That you are answering at all is a blessing :)
...but then why doesn't new power gem formation occur in example 1, thus blocking the 4-tall from occurring?
By example 1, do you mean your original question?
When a power gem is first formed, it wants to be made as big as possible. This initial expansion happens during the formation of the power gem.
Ahhhhhhhhh. So, in Example 1, all the singletons hit at the same time, so they resolved into the max size item possible in a single step. In the Example 2, the 2x2 on the top already existed, so it was ignored by the 6 gems below it until they had already resolved into a horizontal 2x3.
Yeah that's right :)
Thanks Avanta, you are a true G <3
No problem, glad I could help :) Congrats for solving the kata too :D
I guess I can resolve the question, now that you've solved it :P
@Avanta, thanks for fielding this inquiry like a pro 👍
No problem :)
really enjoyed this kate. would rate it 2kyu though
except you didn't solve it, for now...
7 months later, you still didn't solve it ^^
... Anyway, I really enjoyed too this kata, but conversely, I would rate it 1 Dan though ;P
...phew... Finally got through this... x/
java translation, please review and approve.
Note:
cheers!
Wow, once again spectacular work, B4B! Approved 👍
Thanks for this B4B. I was struggling to get through the Javascript version.
ruby translation, please review and approve.
(Note: double rainbow gems added in the random tests)
cheers!
Approved! 🖖
Order of crash gem and rainbow gem destruction is unspecified in the description. If crash gems destroy first, they can eliminate the gem below the rainbow gem, with the rainbow then falling further onto another gem or the bottom. I suppose one could reason that rainbow gems should process before crash gems.
Thanks for bringing this up,
@gdbaldw
.The Description has been updated with the following note:> NOTE: In the case where both a Rainbow gem and a Crash gem land during the same move, the effects of the Rainbow gem occur before the Crash gemEDIT: Since the only time this would matter is when the gem color affected by the Rainbow Gem and Crash Gem are the same, it doesn't make a difference. The Rainbow Gem would destroy all gems of the respective color, including the Crash gem.
"Since the only time this would matter is when the gem color affected by the Rainbow Gem and Crash Gem are the same, it doesn't make a difference. The Rainbow Gem would destroy all gems of the respective color, including the Crash gem."
Isn't it still possible that this makes a difference? What if there are gems of the same color not directly linked to the spot of the crash gem -- then, if the crash gem destroys all the local same-colored gems first and the rainbow one subsequently falls to the floor, the unconnected same-colored gems would remain; but if the rainbow is processed first, they would be removed. Or am I missing something?
@monstaber, in that scenario all affected gems (that get shattered) are proc'd during the same move.
Also note in the Description (with added emphasis):
If this doesn't answer your question, you'll need to provide a more clear description of your scenario.
This comment has been hidden.
BTW, you should remove the end of this part of the description:
It's misleading since it can make think that one has to resolve the rainbow gems, meaning, explode the related gems, then drop the ones above and only then resolve the crash gem. But considering the last test I suggested below and the other specification where you're asking for a simultaneous resolution of the effect of all gems after they are dropped, that's somehow "inappropriated".
Thanks, the Description has been amended accordingly and the test suggestions have been added to the final test suite.
This comment has been hidden.
Added to the final tests and increased the number of random tests from 100 to 200. Thanks again for your insights; they've definitely contributed in making this a much improved kata.
This comment has been hidden.
Thanks for catching that. It turned out to be a simple fix for a rarely occurring situation.
This comment has been hidden.
It must be quite rare as I haven't encountered it after running thousands of tests. I'll see if I can reproduce this.
Found the source of error and fixed it, so this error shouldn't happen anymore.
nice. :)
X-/
Description really needs clarifications:
Description:
But I understoof that as "of whichever color Gem they land on", not "all Gems of the color of the one they land on".
Kata was fun... Now it isn't really anymore, when I have to dig tens of minutes in huge debug console printing to realize this type of things... :/ (the fixed tests really need a rainbow gem, so).
Is this an issue? It seems clear in the first sentence:
It sounds pretty the much the same as what you have...
Yes it does ("sounds pretty much the same"), except that the wording can be understood in two different ways (the issue isn't in the code, it's in the description! ;) )
(might be related to "mother tongue or not", too)
This comment has been hidden.
ha? Didn't see it, sorry. So might be it isn't enough "self explaining" since my code does pass the fixed test (already for 2 hours, actually).
=> Might be that it does not have separated gems of the same color? Or another action later compensates this fact.
Hopefully the edit makes it more clear:
Sounds good.
Meh! Here I feel a bit deceived...! ;o
You need to add more informations about the methods resolution order in the description: You didn't explain anywhere that you expect that the power gems have to be formed BEFORE the crash and rainbow gems explode. Actually, that's in contradiction with what I said below about the MRO:
and to what you seemed to agree to (even if the case is not fully the same, yes: there, we were talking about creating gems after droping of the gems):
But I just encountered that case:
So,
I'm sorry, my mistake. Each Gem in a pair lands at the same time and their effects occur simultaneously. I've added this along with a graphic in the Description. This is consistent with the effects in the actual game.
wouldn't that rather be:
"Each gem has effect as soon as it lands on another gem. If both gems land at the same time, both effects apply", so that it's fully described for all cases?
But that means I can garbage a whole part of my code, now... :( (wanting to keep the description short is a nice idea, but not for hard katas like this one!)
I think the actual addition to the Description makes it more clear than what I wrote in the comment above.
If you go to the last part of the section Power Gem Formation Priority, you'll see where I added an image reference and the wording. Does it seem clear this time?
The image sounds good, yes. But I really feel like the text doesn't exactly tell the same thing. The picture rather sounds like what I said above (the green gem will actually land first, form its power gem, and the blue crash gem will have effect two "steps" after. Doesn't that wording match your implementation? If so I really would like you to tell me because that's the way I understand your pictures. And if I have to garbage most of the code another time, I believe I'll just drop the kata! ;o )
I've added a section to the Description for this, until the header "How Moves Work:" which gives a full breakdown of the process. Let me know what you think.
ok, sounds good with that. I'll keep you posted.
\o/ FINALLY!! \o/
;)
😎 Nicely done! 👍 And thanks again for the suggestions!
fixed tests that would be nice to have in the sample tests:
Addressing each item in order:
1: In the Description it's written:
Tests that include such rotations were purposely included in the fixed tests to check for this. Unless I'm reading your suggestion wrong...
2: Already included, as mentioned in another reply.
3: There should be plenty of that in the random tests.
LLLLBB
, my code put the vertical pair on the last column instead of the second one. Maybe with theallow_raise=True
I would have been able to identify the thing earlier, though.allow_raise=True
!! ;)The debugger has been updated, so now you see the Gem pair along with the move instructions. Example below:
Also, added the suggested
allow_raise=True
; thanks for the tip.for debugging, you should display the tile used at each round with its moves. Because currently, when gems disappear, one has no idea of the reason why except that a crash or a rain gem landed somewhere.
(Really hard to debug, for now... ;o )
Also, it would be VERY useful that you do use
test.expect(..., allow_raise=True)
so that the test suite is stopped at the first failed assertion. It will make it far easier to follow where the problems are.Thanks, both have been implemented as suggested 👍
hi,
In a case like this, which square would have the precedence for making a power gem?
This one is more undebugable than the
Tower game
;-);D
I'm not at the debugging step yet: just implementing the different parts, for now (still the "powa" stuff to do). But yes I fear a bit this step in the process... ;o (but I'm not sure about what you said: in this one it seems easier to follow the state of the game step by step. At least, more than with the tower game).
Thanks for bringing this up,
@Blind4Basics
. I've updated the Description with the order of precedence in this situation.If we get a pair with 2 crash gems "ry", for example, and that it lands touching respectively R and Y groups of gems, what is the order of resolution of the actions? I suppose we explode both groups before making the remaining gems drop?
Yes, both groups of
R
andY
gems would shatter, and then any gems that are suspended in air will fall. Crash gems that explode simultaneously have no effect on each other.Thx.
In the same order of idea (french expression directly translated. Might not be good in english... ;o ), if the pair is "rY", landing against a R and Y groups, the MRO will be:
right? (maybe you should add those informations to the description?)
Yes, the
r
and any interconnectedR
s will explode, after which any suspended Gems will fall. If theY
Gem can form ann x m
(wheren >= 2
andm >= 2
) block with otherY
gems, then it forms a Power Gem.I believe this was mentioned in the Description or can be inferred from the Description examples, but feel free to post if anything is unclear.
Yes, basically it's inthere. But the examples (I didn't detail the one at the end) do not show this edge case where "Y" would form a powergem before explosions but not after anymore. So, since you didn't provide the full MRO, there are some tiny edge cases to figure out (As you saw, the logic was there, but I just needed confirmations. To tell the full MRO frankly would be spoiling the task, but currently, a few more details on these kinds of "edge cases" could be useful, IMO).
thx!
No problem; I wrote the Description in a way to keep it as short as possible while also including all the pertinent information to minimize any kind of guesswork. If you find another edge case that hasn't been addressed, feel free to raise a question. Thanks!
This comment has been hidden.
In python,
see_states
has no effect :oCan you elaborate? I just tested it and it appears to work fine. By setting
see_states
toTrue
, you should get a state-by-state print out for any failed tests.EDIT: the output is given if the structure of the returned value is valid (a newline-joined string with the correct dimensions).
Hi,
Yeah, I just saw that! My bad: I was so much focused on my classes I didn't see that your function was missing its return statement... ;s (shameful I am... ;) )
(note: did you see my message on github ?)
I didn't see a message on github; was it on the CW github page?
yeap, the github CW channel
Note: could be more useful to display the actual result at the end of the logs (nearer to the expected one, this way)Forget that, I'm too tired to read correctly the prompt... ;/
Damn, it's a stunning kata! 8-D
I still have to handle the power gems, but that was really fun, so far! (the last part might become brutal... :o )
This one is caused by
where there are both
0
andy
can destory blocks, but results different if you calculate in different order (0
first, ory
first), which should be put in description, or did i miss it.As always, thanks for your suggestions. I've added the detail to the Description:
To help with debugging, I've added a variable
seeStates
to the preloaded section. If set totrue
, the test results will show the current game state for each Gem pair. This applies to all tests except the 10 fixed tests in the final test suite.This comment has been hidden.
Thanks for the effort you put into spotting these errors. I've fixed both bugs; looks like you've already solved this kata.
Thanks for helping me debug this kata, @ZED.CWT. Now that the all the reported issues have been fixed and a state-by-state debugger is included with the tests, could you shorten your message above this to maybe 1 line so it doesn't take up too much of the Discourse section? I'd appreciate it 😉
I don't think OPs that has been replied can be edited anymore.
Maybe we can at least mark it spoiler
Yeah, that's fine; thanks!
This comment has been hidden.
You're correct, thanks for finding yet another bug. I've identified it, did some refactoring, and fixed it. Hopefully that's the last of them...
This comment has been hidden.
Nice job catching that. It was a rare-occurring bug and it's now fixed. Appreciate all your efforts,
@ZED.CWT
.I reach the expected state just before action
0G AARR
, and as you can see that the right most column is full for a vertical piece, so what should i do?Also, it is a nightmare to debug, you may kindly output states after every action if some assertions failed. I am okay if figuring it out is part of the game but at least please add this hint for fixed tests. If you are going to add hints for all tests, because the output may be huge if some solution fails on every tests, you can choose only output the first ten hints.
Thanks for pointing this out. I've added some clarification to the Description:
And also:
I'll make some changes to the output to make it easier to debug
UPDATE: Added game state details for each Gem pair in the Example Tests and added an additional Example Test.