Xugro wrote: ↑Sun Apr 06, 2025 10:53 am
If the players presses
up,
down,
down,
up, it should trigger Combo 2, but with your implementation it does not.
That's a great catch Xugro, thanks for finding it.
I like your buffer idea (Edit: and Dusoft's stack as well) -- I was also considering using an FFI byte array with each byte as the pressed key history, and then using memcmp() to quickly compare the sequence bytes to see if any matches, but that would require using a loop to test each special move, which I was trying to avoid using (just for the challenge).
After sleeping on it I think the branching problem that you described can be solved by improving the tree data structure, making the tree smarter.
Its use would remain almost the same: you'd build the tree as it was in that demo by registering all possible key sequences, then finally before you start using it you'd call another function to "finalize" the tree.
This finalization is done using an algorithm based on "crawlers" that add secondary/fallback connections to all nodes on the way as long as the crawlers had been performing the same sequences up to that point. At the end, all nodes will not only point to the next node in the original sequence as well as all possible sequences that could begin from that position, like in your up->down->left->right vs down->down->up problem. In this case the 'down' node of the first sequence would have a fallback connection to the first 'down' of the second sequence.
At the moment I don't have the motivation to implement this though, if I ever get to it I'll post it here.
PS Now that I think about it, it's better if we use FORWARD / BACKWARD for the horizontal direction instead of RIGHT / LEFT, because in fighting games, when the characters jump over each other and switch places on screen, they turn around to face the other side. So using an ambiguous name like this would let you define a sequence once and have it work no matter which side the character is facing.
TheFoxyHu3 wrote: ↑Sun Apr 06, 2025 5:08 pm
The for loop limit, can it be a function value? I don't understand this piece! If you could explain me, I'll be very grateful.
That's right, the "numerical for" (which iterates on a range of numbers) accepts expressions as the initial, the target and the (optional) step values. As long as those expressions evaluate to numbers then you can put anything inside those expressions like function calls, math, parenthesis etc.
This is valid Lua:
Code: Select all
for my_variable = (a + b * this_function(c)), other_function(d) do
-- Do something with 'my_variable' in here.
end
As long as those expressions evaluate to actual numbers, like 3 and 57.6134 for example, then you're good.