Hello, that's an interesting question, as I am into sailing... I once met a British guy in Manilla. he was a sailor. I asked him if he was worried about pirates. He then went to his bedroom and came back with a Belgian FAL assault rifle and said: "Well, you come on deck like this, and make sure you smile and show them your rifle. They ask you if you want to buy some fish, you say no thanks, and they leave." That answer surprised me. He explained that pirates hate been shot at (who does..!?) so they go for the easy preys.. I am not sure it is always true, personally, I probably wouldn't count on it. My first line of defense: A good pair of binoculars. You need to know what their intentions are; do they have weapons? Disregarding the fact that most countries will arrest you for having a gun on board, I would have a reliable semi-auto rifle in .308 (for range), like an M-14 or Saiga in that caliber. The Saiga is based on the AK, so, probably very reliable. The .223 (5.56mm) won't penetrate as well as a .308 or equivalent .30. I would not suggest a scope. With the boats moving, you'd never be able to find theirs in your scope. You would have to practice a lot to get good with open sights in a choppy sea. Have lots of magazines, check their prices before buying the rifle. Oh, and forget handguns for pirates (not thiefs who board you at anchor). I heard once the saying "To a gunfight, bring a rifle and friends with rifles." With a handgun, you'd probably miss the pirate boat entirely. Shooting a stationary target when you're stationary is easy. Shooting a moving target when you're moving is a nightmare.
If the rifle I chose was also made of stainless steel, I'd get that model.. Keep it oiled and clean. Even stainless steel does rust. Also, keep in mind that shooting the gun is the easy part. Handling it, loading it, changing magazines and aiming in different positions is what requires the most practice. I would practice at sea a lot. Getting it out, loading, getting on deck, taking cover etc..
I would instruct the non-combattants to lay flat at the bottom of the boat below the waterline, since 2-3 feet of water will stop a rifle bullet (don't believe television). They should be the ones with handguns, not you up there on deck.
By the way, if I didn't have a gun, I would have a few glass bottles full of gasoline handy, with a rag in them, as well as a Zippo in my pocket.. Let them get close..
Other considerations: In some countries, the police/coast guards double-up as pirates during their free time! Don't count on your word to get you out of jail. This may sound harsh, but if I survived an encounter, meaning they didn't, I'd sink their boat with the bodies secured in it. If I didn't have time to call for help before, I wouldn't after.. Again, depending on location.
You need to learn about the law in the waters you sail in. The law on the books, but also the way it is practiced, or not, and how you could maybe get out with a bribe (very risky in some places, it could make things worse for you). Some guns are more "politically correct" than others. Some countries allow shotguns with one or two shots, manual. Sometimes bolt action rifles are allowed. Make sure you don't spent time in prison and lose your boat for having a gun.
I heard another funny story about a guy who was boarded by a group of armed men in the Carribeans. They seemed to want food and water (he didn't speak their language), so the boat owner gave them some meat and whatever else he had to eat. Before leaving, the leader gave him the only thing he had to thank him, a grenade!
So, you never know.. Some people survived pirate encounters by not resisting, some were brutally killed not resisting, and some survived shooting back.. Every situation is different.
Gil.