The three-pile trick is a well-known card trick performed with a deck of 27 cards which dates back to the early seventeenth century at least and its objective is to uncover the card chosen by a volunteer. The main purpose of this research is to give a mathematical generalization of the three-pile trick for any deck of ab cards with a, b ≥ 2 any integers by means of a finite family of simple discrete functions. Then, it is proved each of these functions has just one or two stable fixed points. Based on this findings a list of 222 (three-pile trick)-type brand new card tricks was generated for either a package of 52 playing cards or any appropriate portion of it with a number of piles between 3 and 7. It is worth noting that all the card tricks on the list share the three main properties that have characterized the three-pile trick: simplicity, self-performing and infallibility. Finally, a general performing protocol, useful for magicians, is given for all the cases. All the employed math techniques involve naive theory of discrete functions, basic properties of the quotient and remainder of the division of integers and modular arithmetic.