fix palettes

Implement palettes without using unsafePerformIO anymore for the
colors. Make an applyPalette function that could be used for changing
the palette midgame.
improve move adding algorithm to remove moves when backtracking
rework palettes and drawing code to use separate surfaces

Using fillRect as the primary drawing primitive was probably a bad idea,
in terms of efficiency. Instead, I now make separate surfaces for each
thing to draw, including each different color of tile. This also has the
benefit of generalizing well for alpha blending, which I want for the
cursor and its trail.

There's a bug though: the screen is black. Nothing seems to get drawn,
despite all the blitSurface calls returning true.
refactor palette generation code to make more palettes more easily
rewrite drawing code to be more responsive and fix black screen bug