To solve the curse of dimensionality and structure credit assignment in multi-agent reinforcement learning, a learning method based on K-Means is proposed in this paper. With this method, state space explosion is avoided by classifying states into different clusters using K-Means. The roles are dynamic assigned to agents and the corresponding set of characteristic behaviours is established by using K-Means algorithm. The credit assignment function is designed according to factors like the weight of roles. The experimental results of the multi-robot cooperation show that our scheme improves the team learning ability efficiently. Meanwhile, the cooperation efficiency can be enhanced successfully.