Cue Ball Moving on a Train Problem

If the train is moving in a straight line at an unchanging speed, say 30 kilometers per hour, then everything inside the train is moving with it, all of the physics inside the train will work the same as if the train were not moving. The table, the ball, and you, if you are standing still in the train, are all going the same speed and direction as the train. So if you sit the ball on the table, it will not move. Now if the train accelerates to 40 kilometers per hour straight forwards, then the ball will seem to move straight backwards, as the train has accelerated. This is the same effect you feel pushing you back into a car seat when it accelerates forward quickly. If the train decelerates to 20 kilometers per hour, the ball will seem to roll forwards, just as you would feel a forward pull when slowing a car quickly. If the train turns left, the ball will seem to roll right, if the train turns right, the ball seems to roll left. Just as you feel pushed right or left in a turning car. This is due to the ball's inertia and to Newton's first law of motion. See;

Is train, therefore, moving to the left or the right ?

With respect to what ? There is no absolute movement and as such every movement must be analyzed from some reference point. So the answer is - depends. Therefore train has speed $v_{train/ground}$ with respect to ground, but at the same time it has also speed $v_{train/ball} = -v_{ball}$ with respect to cue ball. Train speed with respect to pool table is $v_{train/table} = 0$ and if there is some other train B at the moment going by near first train A, but in opposite direction, then train's A speed with respect to train B is: $$v_{trainA/trainB} = v_{trainA/ground}+v_{trainB/ground}$$ If train is moving away from some level crossing and at same moment some car is also receding from that crossing in a road, then train speed with respect to that car is : $$v_{train/car} = \sqrt{v^2_{train/crossing}+v^2_{car/crossing}}$$, according to Pythagorean theorem. Hope that helps !

This answer is incorrect because it does not account for the balls moving backwards with respect to the train.

In my pictures the train will be moving upwards (positive Y direction).

If the train retained its velocity in the positive Y direction when it turned, we can get the ball to hit either wall, depending on where the ball is, in relation to the centre of rotation. You can see how the balls have been moved by hitting the walls. The green ball hits the right wall (or, we should say the wall hits the ball!), the yellow ball hits neither wall, and the purple ball hits the left wall.

train turning sideways while moving in the same direction

However, trains do not move sideways! Trains always move forward or backward. If the train turns 90 degrees to the left, it won't continue moving along the positive Y direction. It will now be moving along the negative X direction. If the train stays the same speed, once it starts turning left, all the balls will hit the right wall (actually the right wall will hit the balls) because the train is now moving left (negative X direction) and the balls are not:

train turning slightly sideways and moving slightly sideways

They will also roll towards what used to be the front of the train (not shown), because the train now has less velocity in the positive Y direction than the balls do.

Conclusion: The balls will hit the right wall if the train turns left; by mirror symmetry, they will hit the left wall if the train turns right.