I need to make some sort of algorithm for chess pieces. I need a king, which can move 1 square in any direction. I need a knight which can move one square forward, though forward is defined differently for each color, and one to the left, or the right, one forward, and two to the left or right, etc, a rook which can move basically along the x and y axis, a bishop which basically moves along the lines x = y and x = - y. And a queen which can move either like the bishop or like the rook.

I have an 8 by 8 grid and want to know how to make it check how each piece moves legally within that grid.