A Theory of Cooperation and Competition