A lot of times I used to play trap games in chess; most of the times I won the game. But the my question is this: is it good strategy to play a trap game when facing a rated chess player?
I am not fond of opening traps. If an opening you like to play happens to have a trap in it, that's fine; by all means exploit the trap. What I don't like is going out of one's way to learn a variation just because it has a trap in it. For example, the Queen's Gambit Accepted with 3.e3 has this well known trap:
[fen ""] 1.d4 d5 2.c4 dxc4 3.e3 b5 4.a4 c6 5.axb5 cxb5 6.Qf3
...and now black's only option to save his rook is to give up his knight. It's a lovely little trap, and if you like 3.e3 no matter how black responds, then by all means you should learn the trap. But you shouldn't play 3.e3 just because you hope your opponent falls for the trap; I personally prefer 3.e4 to try to grab the center, but that's just my personal preference.
I don't like winning via an opening trap because there isn't really any skill involved other than memorization. If you start winning a large portion of your games through opening traps, your rating will go up... and then you will face opponents who know your traps and you won't know how to beat them, because you didn't learn any actual skills on the way up.
Trying to draw or even win a lost game with a swindle is a different matter. I occasionally do this, and it's fun when it works (though your opponent will have a different opinion!), but I only do this if I would otherwise resign.
In my experience I feel the only way that I can play a 'ranked'(assuming considerable higher rating) than myself is to play wild, attacking lines in the hopes of trapping them to victory(assuming that is what you mean by 'trap games'). I usually tie this in with the term I've read, "hope chess". Hoping your opponent doesn't see what you are trying to do for a win without having a plan when it fails.
Using positional strategy the ranked player is simply going to be beat me. There's a reason they are ranked. They have the understanding, knowledge and experience I have not obtained yet. When I start getting around the 100 pt. rating difference and I'm on the low end I've only got about a 30% chance of winning so I'm putting my money on the wild, attacking games in the hopes of trapping them for a win by them blundering.
While I do believe the best way to get better is to play people who are better than you, I don't necessarily believe this is a good long term strategy with playing like this. I would always bet a ranked player is going to see the traps more often than not and I would be concerned the position would be lost after the trap fails.
Each and every ranked player knows about most of the traps and defences, while playing to each other (as the both players know the trap) traps are useless, that's why you see in professional matches also, high rated players start by developing pieces. If you want to give a good fight to a ranked player it is better that you not use that trap because it is sure that he might have seen it somewhere and will know how to use it for his profit....
The occasional trap game is entertaining and can even be illuminating but, at normal time controls, experience suggests that such traps seldom prosper against opponents stronger than FIDE 1800.
Here is a typical example.
[fen ""] [title "Krystl (1795) v Travnicek (1975), Czechia, 1997"] 1. g4 d5 2. Bg2 Bxg4 3. c4 Nf6 4. cxd5 Nxd5 5. Qb3 Be6 (5... Nb6? 6. Bxb7) 6. Qxb7 Nb6 7. Nc3 Qd7 8. d3 c6 9. Qxd7+ Bxd7 10. Be3 e6 11. Bd4 c5 12. Be5 Nc6 13. Bc7 Rc8 14. Nb5 Nb4 15. Nd6+ Bxd6 16. Bxd6 Bc6 17. Nf3 Nc2+ 18. Kd2 Nxa1 19. Rxa1 Kd7 20. Bg3 f6 21. Rc1 Rhd8 22. Rxc5 Bxf3 23. Rxc8 Bxg2 24. Rc7+ Ke8 25. Rxg7 Rd7 26. Rg4 Bd5 27. b3 a5 28. Rg8+ Kf7 29. Rb8 Bb7 30. e4 e5 31. f4 f5 32. Bf2 Nc8 33. fxe5 fxe4 34. d4 Ke6 35. Ke3 Kd5 36. Be1 Kc6 37. e6 Rd5 38. Bh4 Kc7 39. e7 Bc6 40. Bg3+ Nd6 41. Bxd6+ Kxd6 42. e8=Q Bxe8 43. Rxe8 Rh5 44. Kxe4 Rxh2 45. a4 Re2+ 0-1
Counterexamples exist but good counterexamples are hard to find.
[fen ""] [title "Jovanovic (2330) v Milanovic (2480), online, 2005"] 1. e4 e5 2. d4 exd4 3. f4 Nc6 4. Nf3 Bc5 5. Bd3 Nf6 6. O-O Qe7 7. a3 a5 8. Nbd2 O-O? 9. e5 Ng4 10. Bxh7+ Kh8 11. Ng5 d6 12. Bd3 dxe5 13. Qe1 exf4 14. Qh4+ Nh6 15. Nde4 Ne5 16. Bxf4 Ng6 17. Qg3 Nxf4 18. Rxf4 Bd6 19. Nxd6 Qxd6 20. Qf2 Qd5 21. Qh4 c5 22. Rf6 Kg8 23. Bh7+ Kh8 24. Rxh6 gxh6 25. Qxh6 Qxg5 26. Qxg5 Kxh7 27. Rf1 f5 28. Rf4 1-0
Trap games remain a part of the game of chess and a part of chess lore—a minor part, but a part nevertheless. At the lower ratings, trap games even serve a salutary purpose insofar as they serve to teach their victims to sidestep the traps!
At the lower ratings at which the traps actually work, the occasional trap game can be fun to play for both sides; but at the higher ratings, even games like the diagrammed Jovanovic v Milanovic (in which Black plays not very but only somewhat badly) rarely occur.
At any rating, if trap games are too often tried, trap games tend to warp and stunt a player's understanding of the game of chess. The player who plays a trap game must be prepared to lose if his or her trap is detected, so even at the lower ratings, more than occasional use can hardly be recommended.
And at the higher ratings? Sorry, but over FIDE 1800, experience appears to contradict the trap game. The attempt just doesn't work.
Because opponents rated much higher will seldom lose in any case, the conjecture that a trap game might maximize one's meagre chances does seem reasonable, so your question is a good one. However, the answer seems to be this: over-the-board experience teaches that one can maximize meagre chances against much-higher-rated opponents by just playing good moves.