(Note: I deliberated for a long time if my question is the same as this one. In the end I felt it's different enough, but feel free to point out otherwise.)
OP asks a question, and posts a sizeable chunk of code. They've clearly been working hard on it, but now they've hit a roadblock and thus are turning to us for help. They've done their homework, they describe their problem and what they've been trying. By all accounts, their question should merit an answer.
The problem is, their code is fundamentally flawed. It's not that there's some little thing they neglected or misunderstood; it's wrong on a conceptual level, and that wrongness has manifested in so many small ways in the code. Basically, the most helpful answer I could give would be "Start over".
These kinds of questions make me feel trapped. Simply flagging the question as "too broad" or "off topic" feels unfair, since the question is specific and the OP has definitely put in the work. I could help the OP kludge together a solution that could get their code to run, but that feels even less helpful, since I'd be encouraging their really bad practices. And explaining everything that's wrong with the code would take inordinately long (not to mention it would probably be pretty crushing for the OP, even though it's for the best in the long run). It just feels like there's no good answer.
So, I was wondering: do others have strategies for how to handle a situation like this?