added function to check board is legal