CoopSim - A Computer Simulation of the Evolution of Cooperation. User's Manual

1 Introduction
2 Aknowledgements
3 License
4 Installation
5 First Steps - A guided tour through CoopSim
    5.1 Starting a predefined simulation
    5.2 Defining a new simulation
    5.3 Programming a new strategy
6 Comprehensive Overview
7 Advanced Topics
8 Further Reading

5.3 Programming a new strategy

The last step of this introductory walkthrough will show you how to add your own strategies to CoopSim, if you know the basics of the Python programming language. For the sake of brevity, I will only explain how to activate a custom strategy that has already been coded but deactivated by comment signs. In order to program your own strategy you have to change to the User Defined Strategies page in the main window. The page contains a simple text editor, where you can enter python program code:

[image: user_page.png]

As you can see, there is already quite a bit of program code there. This program code has been inserted for explanatory purposes. Every line starts with a “ which is a token for the python interpreter to treat the line as a comment and not to execute it. Try to locate the class definition of class LesserTFT. Reactivate this strategy by removing the comment sign in front of the class definition as well as the following single space character (this is important) so that the statement “class LesserTFT(Strategy):” starts in the very first column. Do the same for the following lines up to the line where the class LesserTFT is instantiated. This is line that reads “lesser_tft = LesserTFT()”. Remember that indentation has syntactical significance in Python, so beware of inadvertently changing the indentation while removing the comment signs and the following space character.

[image: user_page_modified.png]

Now select Edit Simulation from the Simulation menu (or click on the wrench symbol in the toolbar). If no errors have occurred in the program code you will now find a new strategy LesserTFT among the available strategies in the simulation setup dialog box. If you receive an error message, you may have forgotten to delete a single trailing space after the comment sign “ in one or more lines.

t g+ f @