There is no way to write software to avoid infringing patents, period, in the US right now. There are steps you can take to mitigate the problem.
- Get a relationship with a lawyer. They don't have to be on your staff. They don't even have to be on retainer. But scout some out ahead of time and know who you can trust if you do get an infringement notice.
- Don't educate yourself about specific patents in your field unless you intend from the start on licensing them. Knowingly infringing a patent carries more damages than ignorantly infringing one. Whatever you're doing, it violates patents; only worry about specificity when it happens.
- Don't build up a defensive patent portfolio. It'll just waste your time and money. The nature of a patent troll is that they own many/broad patents, threaten indiscriminately, and don't actually do anything so won't counter-infringe. The MAD strategy defensive portfolios are based on only works if you're capable of destroying the other company, and the other company is rational. Unless you're EA/Activision/etc you can't do the former, and if you're up against a patent troll you can't count on the later. (There are other reasons to build up patent portfolios, like if you want to inflate your company's perceived value to investors - but this road only leads to your patents being used to troll other people in the future.)
- Don't lose sleep over it. Zynga's getting sued. Would you swap your company's financials with Zynga's despite that? I sure would. They are getting sued because someone wants a piece of that gigantic Zynga pie, not because there's a company somewhere actually disadvantaged because Zynga did not license their patent. If you don't have fat stacks of cash, most of those organizations won't come knocking.
Oh, and
- Don't be a dick and copy someone else's game wholesale and try to undercut them just because it's probably legal. You'll still be a dick. Take good ideas when you find them, but be open and honest about your influences, and make the game you want to make because it's the game you think is important to make, not because it's the game you think you can get away with.