When I was in school, I spent a lot of time reading about lectureship and experimenting with techniques to make my learning more efficient (cause I hated school and wanted to spend as little time studying as possible). What I came up with is a 3-step process. Ideally, you'd have both the docs and a solution on-hand.
If not, then you can go back to the scientific method: formulate a theory, test that theory and nothing else, formulate a new theory, repeat. In the context of game dev, this would usually mean putting print statements everywhere or watching vars in the debugger. It helps to have some sort of automated testing system for your game. This method is more general but also slower.
Anyway, if I have ideal conditions, then here's what I do:
- Solve the problem, while following the solution to a T.
- Solve the problem, only looking at the solution for hints.
- Solve the problem on my own without any help.
- If at any point, you see something you don't understand, look it up in the docs.
Also, spam asserts everywhere. Every time you make any assumption about your code, assert. You have no idea how often I've had things crash and burn because I've had values that weren't what I've thought. In the same vein, only develop one feature at a time and pay close attention to your APIs, e.g. Instead of trying to make 'enemy AI', make a path finding algorithm first, and then a state machine that responds to the path finding. And lastly, regularly rebuild small portions of your game from scratch. You'll get better over time, and better code is easier to maintain.