Loco going backwards only

I was running my Märklin 3511 „Schöne Württembergerin“ (which has done just over 600 scale km) and it was running beautifully as ever.

I reversed the train a bit and then I wanted to make it go forwards again, but instead,
it only went backwards! No amount of changing direction would make it go forwards. Even when its lights function was switched on, and could thus show that the locomotive was meant to be moving forwards, it went backwards instead.

I left it overnight in the hope that the decoder would reset itself after some hours without power, and tried again in the morning. Nope, still only backwards motion.

I took it off the layout and placed it on the treadmill and fed it some analog AC, still it only went backwards. I removed the coal from the tender to expose the electronics and found a black mark on the circuit board.

It did not seem to be a burn mark that is typical of a burnt out component, so I carefully cleaned it off with a small screwdriver. I tested the loco on the layout again but got the same result.

I considered running the loco backwards, pulling the train in reverse, but this loco does not have a coupling on the front, so that was not a solution. I then decided that I would try to reverse the motor leads so that the loco at least moves forwards and can pull its train around the layout. I needed to know which wires were delivering power to the motor so I took it back to the workbench and got out my voltmeter. I connected it to the layout digital power and turned it on.

It went forwards! I started at the wheels confirming that the wheels were in fact going forwards. I reversed it and they went backwards too. Forwards again - all working fine. It is an intermittent hardware problem.

So I then abandoned rewiring things and took it back to the layout, and tested it again, I was able to drive it forwards and then suddenly it was back to reverse only again. Very frustrating!

I kept changing direction until it went back into forwards mode, and then returned it to its rake of passenger coaches. I will try and remember not to throw it into reverse, and see if it behaves itself.

If not, I will remove the circuit board and look for gunk on the other side too, and possibly replace the special decoder. I will also look on the underside for any bad connections. I suspect it is not just a matter of a loose connection though, since a loose connection would more likely result in it not moving at all rather than moving in the wrong direction. It is as if an internal 'relay' (transistor?) is failing. 

I suspect the gunk I cleaned off is poop from a spider or small insect that has crawled up into the tender from below and perhaps there is more.