I recently read a book about the game. There is a simple game of cooperation and non-cooperation. It is very interesting. The general idea is as follows:
This game is A simple abstraction of cooperation between people in real life. The specific content and rules can be summarized as "If A and B are both cooperative attitudes, it is A win-win situation, each person scored 3 points. If A's cooperation attitude and B's play were overcast, A cheated B and obtained B's interest, B scored 5 points and A scored 3 points, and vice versa. In the end, if both A and B do not cooperate, they will take A single shot and take two shots. If both of them are hard-working, each person deducts one point. "In this game, everyone has cooperated with people other than himself for 100 times, the person with the highest score wins.
I abstracted the code to C # using an interface to standardize participants, let them implement their own algorithms, and save the previous cooperation records with competitors through the generic list, the policy can be returned based on the cooperation record .. the interface code is as follows:
1 public interface ActorBase
2 {
3 bool Gamble (string OpponentName); // your policy is encapsulated in this function. true indicates cooperation. false indicates non-cooperation.
4 string GetUniqueCode (); // returns your name for the opponent to confirm your identity
5 int Score {get; set;} // total record Score
6 void AddRecord (string OpponentName, bool record); // used to add records of previous battles
7}
For my strategy, I maintain a cooperative attitude during my first cooperation, and determine whether to cooperate in the future based on the situation of my opponent and the previous step.
The Code is as follows:
1 public class CareySon: ActorBase
2 {
3 Dictionary <string, List <bool> Record; // used to save and Record
4 public Songyunjian () // constructor used to construct records
5