Your First Mod ‐ Adding a Strategy to Strategic Modeling - mechanikate/clipmod GitHub Wiki
Prerequisites:
- Learn how to set up a project
There are 8 base strategies in vanilla Universal Paperclips, including "RANDOM" or "TIT FOR TAT".
ClipMod lets you implement additional strategies.
The Strategy
class helps you implement these new strategies.
Its constructor signature is as follows:
class Strategy(name: String, moveFunction: (currentPos: int) -> int, moveDescription: String, pid: int, modid: String)
The meaning of each parameter is:
name
: The name of the strategy, usually all caps, e.g."BEAT LAST"
moveFunction
: A function taking in 0 parameters and outputting an integer. There are some key values you can use:aa
: Your top-left payoff,ab
: Your top-right payoff,ba
: Your bottom-left payoff,bb
: Your bottom-right payoff,currentPos
: This is the 1 parameter to the function, and represents the position (left or top) you're in. Left is1
, top is2
,vMovePrev
: The previous move of the left player,hMovePrev
: The previous move of the top player.
moveDescription
: A short synopsis on how your strategy works for the project you'll need to build for this strategypid
: Sharespid
values withProject
s, TL;DR: don't put any duplicate values, decimals, or negative valuesmodid
: The name of your mod in camelCase.
To actually use the strategy for testing and whatnot, use the class method toProject
in the following format:
Strategy.toProject(requiredOps: int, requiredProjects: String[])
Here's what each parameter means:
requiredOps
: the operations needed to enable this strategyrequiredProjects
: theid
fields inprojects
for each of the projects required prior to enabling this strategy. So if I wanted to require the "A100" strategy to enable this strategy, I'd useprojectButton60
as that is theid
field of theprojects
entry for "A100".
Aftewards, you can just set this up the same way as a project:
clipHooks.push(() => {
new Strategy(...).toProject(...).setup();
});
Example
For an example strategy, look at the following code:
clipHooks.push(() => {
new Strategy("ENIGMA", (a)=>{
const biggestPayoff = findBiggestPayoff(); // calculate biggest payoff from vanilla implementation
const greedyFactor = Math.random() >= 0.1; // will we be greedy?
if(biggestPayoff == 1 || biggestPayoff == 3) return greedyFactor ? 1 : 2;
return greedyFactor ? 2 : 1;
}, "Be GREEDY 90% of the time and GENEROUS the other 10%", 2, "obsceneMod").toProject(5000, ["projectButton60"]).setup();
});
The 1st parameter is the name ("ENIGMA"), the 2nd is the logic, the 3rd is the description, the 4th is the ID of the strategy, the 5th is the mod ID. After that, we convert it to a project requiring 5000 ops and the "A100" strategy to be enabled, set it up, and we're home free.