The train has a sensor (probably a very simple color sensor) on the bottom that can read the little marker pieces that you place on the track to trigger various functionality. It also knows the approximate speed.
It's a relatively inexpensive toy aimed at young children. You shouldn't expect too much from it.