A scenario similar to this has undoubtably been considered before but I haven't come across anything that is in the same vein. In any case, would this example be a specific type of contract/agreement and would it be legally enforceable.
Agreement: Person A is determined to stop smoking in six months time. Person A and Person B make an agreement whereby Person A shall deposit into an escrow account $10,000; if at the end of six months Person A has successfully stopped smoking then the agreement stipulates all the money is returned to him. If he fails in his goal and is still smoking after six months, then Person A has instructed that Person B shall be entitled to claim the $10,000 and spend however he wishes; it is intended to serve as an incentive and to discourage failure in achieving the goal.
What would a court say to Person A if - after 3 months he decided he was no longer interested to stop smoking and wanted his money back?