add card algorithm