I'll elaborate a bit on Barrie's point, which is correct, if disappointing.
The problem is that English spelling was not designed for Modern English. It was designed for Middle English, a very different language. When Middle English changed its pronunciation to become Modern English, English spelling did not change. Furthermore, English borrowed many thousands of words from other languages, which were of course pronounced differently, and spelled differently still.
The result is that one has to choose between two strategies in learning English words, however they are spelled -- this is not a problem confined to the letter I -- or else figure out some way to mix them.
Either you can actually learn the historical rules about pronunciation and learn to distinguish the different kinds of word each rule applies to -- which amounts to learning some basic linguistics,
Or you can do as Barrie suggested, and memorize 2 things about every word you learn -- (1) how it's spelled and (2) how it's pronounced (Kenyon and Knott is your friend here) -- and just ignore the possible but treacherous correspondences you might suspect between Middle English or foreign spellings and Modern English pronunciations.
The second option amounts to giving up all hope of making sense of English spelling. Most native English speakers do this, which is simpler for them, since they already know the pronunciation.
Since Anglophone education systems don't teach anything about English language, they never learn any different, and many still believe there should be a simple rule for pronouncing every letter.
The complete story is too complex to fit into an answer here.
The short story is that there are many accents in America, and there are many, many, many accents in Britain, and just exactly what happens to phonemic /ӕ/ and to phonemic /ɑ/ varies incredibly in many of them, so much so that things can sound like different words.
The thing you were probably noticing was the TRAP–BATH split, which occurs on both sides of the Altantic but moreso in Britain than America. However, there are quite a few other factors, too; it is by no means the only one affecting any of this. Some of those accents can even seem comical to those who don’t have it, and vice versa.
The medium story can be found here in the Wikipedia article on the “phonological history of English short a. I strongly suggest that you read it in full. It can be quite subtle, and perhaps surprising. I think you may be astonished at all the variants.
The long story can perhaps be found by chasing the bibliographic references provided there.
Best Answer
This is an extremely broad question, actually, and I doubt there can be a single, definite, comprehensive answer. I will try to provide a few quick-and-dirty rules of thumb, but be aware that you will probably find exceptions to every single one of them.
Also, as Colin Fine points out, note that things are not pronounced the same everywhere. For example, can't can be pronounced as /kaːnt/, /kɑːnt/, /kænt/, and /keənt/, depending on what variety of English we are talking about. As a second example, the vowels in Mary, marry, and merry sound identical in certain dialects but not in others.
All that being said, on to the rules of thumb.
First, the basics. Here are the Wiktionary usage notes for a:
Now on to details, which I will be more adapting than quoting from the essay "Hou tu pranownse Inglish" by Mark Rosenfelder. Note that the order of the following rules of thumb is important. As the author puts it, "to pronounce a word, you go down the list of rules, seeing if each one in turn applies, and applying it if it does".
Again, these "rules" are only approximations, so take them with a grain of salt (also, I hope I haven't thrown in a few typos or copy-paste mistakes).
For further reading, see these questions: