refactors to fix #countPieces
implements board#legalMoves