Let's call X the number of tokens than he has before start playing the game.
In the first game, he hits the jackpot and doubles the number of tokens that he has. So, after the first game, he has a double of X or 2X.
In the second game, James wins 12 more tokens. So, he has now 2X + 12 tokens.
In his third and final game, he loses 4 tokens. So, he has 2X + 12 - 4 tokens.
Now he has 170 tokens. It means that:
2X + 12 - 4 = 170
Therefore solving for X, we get:
Answer: 81 tokens