You just need to figure out how your own brain works and work to it's benefit towards your programming goal. Just like we all learn differently, we also work and program differently. We all, however, have certain thresholds and must properly balance work with play. Our brains must have play and time to relax. It's like a muscle. Some of us reach our thresholds sooner than others, and sometimes at more frequent times of the year than others. I know that I'm more productive at certain times of the year. It is indeed an art form and it's the same with art or any other creative brain process.
For myself, I take it day-by-day. I learned that my own brain can go seriously long periods of heavy coding, often very long days (12-18 hour days of nonstop coding is common with me) and I can go days and days like this, sometimes entire weeks and months. This year for me is a case in point. I don't even remember the first half of the year!
However, I will always reach a point where my brain has had enough and I have to do a 180. I have to take a step back and do something entirely different. I have to work my brain on a different level, often on a much lower level for a while, while my higher brain (and logical aspects) recuperate. It's a balancing act. So sometimes I absolutely have to stop coding, even if I'm in the middle of something... just stop and walk away and do something much simpler for a while. If it means taking a week off, then so be it.
What always happens with me, is when I come back to coding... when I shift back into high gear... I'm completely refreshed. I'm often more productive when I allow myself to take these "steps back" than I am when I force myself to constantly run on overdrive all the time.
I can sit there and be dumbfounded by a problem for hours. I could be coding fine all day, conquering obstacles left and right.. and then I'll hit a road block. If I force myself to sit there for hours I just won't get anywhere. But if i stop, take a long break, possibly go to sleep or take a nap, I'll come back to the problem and almost instantly I'm able to work my way around whatever issue I had. So I learned to be able to read myself and my own brain's wiring very well.
I think ultimately we all need to, to become productive and successful programmers/game developers.
Also remember that you are what you eat. If you put good food into your body your brain will have everything it needs to over come obstacles and figure out problems. If you are putting terrible stuff in you will be working your brain on inadequate fuel. Most people, however, never make this fundamental connection and go their whole lives looking at all the other culprits.