Final step is implementing a heuristic function for nodes. AI now switches correctly