Space Invaders, Markov Chains, & n-grams: A wee little experiment.

Select an invader, the length of the n-gram, click 'GENERATE' and it cycles through the options colouring each square based on the size of the current n-gram (the larger the n-gram the clearer the patterns become).

1.Select invader:
2.Set n-gram:
0
cycle:- | n-gram:- | -% correct

Ok, so it's largely pointless, and was just for me to have a bit of a play around using Markov chains and n-grams to generate something in javascript. Obviously this approach is usually used to create new things, or predict what comes next, rather than recreate existing things, but yeah, it's just an experiment (and it started out as a john conway 'game of life' sort of thing hence the black on white rather than white on black look...)

Markov chains and n-grams are often used for text generation, but it works for anything quantifiable, and in this case it looks at the colour of the previous square(s), and based on the pattern of black and white squares in each type of invader, colours the next square based on the probability that a black or white square occurs next in the sequence. The longer the n-gram - ie, the more previous squares are looked at to determine the next one - the more accurate the generated pattern (e.g. n-gram of '0' essentially just generates black and white squares based on the ratio of black to white squares in the pattern, and an n-gram of '5' means look at the colours of the previous 5 squares and colour the next one based on the probability of either a black or white square occurring next...).

I did try generating invaders based on all the patterns combined but they just looked sort of, er, shit.