Yes, I was a bit of a nerd back in the day.
In college, one of my classes was computer assisted circuit analysis, where we wrote circuit designing programs for Apple 2E computers, using Applesoft basic programming. The commands were close to Commodore basic so I wrote a program to control an interface board I built for my trains. Here's an old video of it and the description I put on youtube:
Sorry, it's an old tape. I used photo transistors under the track for inputs, the outputs were relays controlling the engine and electric switches to control the train, starting on the outer loop, going to the inside loop and back. The second video shows the board with logic chips, LED's, and relays controlled by the Commodore basic program I wrote back in the day.