Added a minimax function - still needs further testing.