Greetings! So for awhile now I’ve been trying to develop a split checker function for my bowling game. Since this issue is purely logic-based, I’m gonna try my best to fully explain what I did in my code, and what goal I’m trying to achieve here. I’m also going to post the code on pastebin because I always have issues trying to format my code correctly if I post it on my threads directly, hope that’s okay.
So, one way I wanted to start making this system is to put all of the standing pins into groups, which would be tables within a table. And, the end theory, if there’s 2 or more groups of pins found in the pin_groups table, I would then return true as it was calculated to be a split. You’ll notice in the code I have a pins_touching table, and what that is is that for each pin, there’s pins that can be around it. Those pins are specified in this table. I use this to determine if there’s touching pins standing that can be connected to a pin, and if so, that pin can be added to the same group as the pin in the loop. After the loop finishes running, if no connection can be made, then a new pin group is made with whatever pin was being tested.
I finally got this code working, however, I noticed it often makes multiple groups of pins when really there should only be one. An example of this is that I put up the entire back row of pins, so that’s four, all next to each other. For whatever reason, the code determined there were two groups of pins there, the two to the left side, and the two to the right side. Made no sense to me…
Probably a long, wordy, and poorly explained post. I could also answer any questions if I need to specify further, apologies for that. I have a hard time trying to explain logical issues with my code…
Thanks for reading!
Here’s the code local touching_pins = { ["Pin2"] = {["Pin3"] = true,["Pin4"] = true,["Pin5"] = - Pastebin.com
EDIT: It’s also worth mentioning that the standing_pins table is the table that is passed into the is_split function. (Those are the pins that the code iterates through and makes pin groups out of them)