Shapley Machine: A Game-Theoretic Framework for N-Agent Ad Hoc Teamwork