diff --git a/LICENSE.txt b/LICENSE.txt index 7edcd1e..7c6e187 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 - Marcos Cardinot +Copyright (c) 2023 - Marcos Cardinot Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/example.jpg b/example.jpg deleted file mode 100644 index 2bd9247..0000000 Binary files a/example.jpg and /dev/null differ diff --git a/metadata.json b/metadata.json index 43c9871..3940bf7 100644 --- a/metadata.json +++ b/metadata.json @@ -1,16 +1,19 @@ { "type": "model", - "uid": "prisonersDilemma", + "uid": "prisonersDilemmaExtended", "version": 1, - "title": "Prisoner's Dilemma Game", + "title": "Extended Prisoner's Dilemma Game", "author": "Marcos Cardinot", - "description": "It implements the experiment proposed by Nowak, M. A., & May, R. M. (1992). Evolutionary games and spatial chaos. Nature, 359(6398), 826. DOI: http://dx.doi.org/10.1038/359826a0", + "description": "It implements a generalized version of the experiment proposed by Nowak, M. A., & May, R. M. (1992). Evolutionary games and spatial chaos. Nature, 359(6398), 826. DOI: http://dx.doi.org/10.1038/359826a0", "supportedGraphs": ["squareGrid","edgesFromFile"], "pluginAttributesScope": [ - {"temptation": "double[1,2]"} + {"cc": "double[-1000,1000]"}, + {"cd": "double[-1000,1000]"}, + {"dc": "double[-1000,1000]"}, + {"dd": "double[-1000,1000]"} ], "nodeAttributesScope": [ {"strategy": "int{0,1,2,3}"}, - {"score": "double[0,16]"} + {"score": "double[-100000,100000]"} ] } diff --git a/plugin.cpp b/plugin.cpp index dff8eec..a0cfea7 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018 - Marcos Cardinot + * Copyright (c) 2023 - Marcos Cardinot * * This source code is licensed under the MIT license found in * the LICENSE file in the root directory of this source tree. @@ -11,8 +11,16 @@ namespace evoplex { bool PDGame::init() { - m_temptation = attr("temptation", -1.0).toDouble(); - return m_temptation >=1.0 && m_temptation <= 2.0; + const auto read = [this](auto& var, const auto& strategy) + { + var = attr(strategy, -999999.).toDouble(); + if (var < -1000. || var > 1000.) { + qDebug() << "Invalid payoff! " << strategy << var; + return false; + } + return true; + }; + return read(m_cc, "cc") && read(m_cd, "cd") && read(m_dc, "dc") && read(m_dd, "dd"); } bool PDGame::algorithmStep() @@ -62,10 +70,10 @@ bool PDGame::algorithmStep() double PDGame::playGame(const int sX, const int sY) const { switch (binarize(sX) * 2 + binarize(sY)) { - case 0: return 1.0; // CC : Reward for mutual cooperation - case 1: return 0.0; // CD : Sucker's payoff - case 2: return m_temptation; // DC : Temptation to defect - case 3: return 0.0; // DD : Punishment for mutual defection + case 0: return m_cc; // CC : Reward for mutual cooperation + case 1: return m_cd; // CD : Sucker's payoff + case 2: return m_dc; // DC : Temptation to defect + case 3: return m_dd; // DD : Punishment for mutual defection default: qFatal("Error! strategy should be 0 or 1!"); } } diff --git a/plugin.h b/plugin.h index e1ae2e8..c897d28 100644 --- a/plugin.h +++ b/plugin.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018 - Marcos Cardinot + * Copyright (c) 2023 - Marcos Cardinot * * This source code is licensed under the MIT license found in * the LICENSE file in the root directory of this source tree. @@ -20,7 +20,10 @@ class PDGame: public AbstractModel private: enum NodeAttr { STRATEGY, SCORE }; - double m_temptation; + double m_cc; + double m_cd; + double m_dc; + double m_dd; double playGame(const int sX, const int sY) const; int binarize(const int strategy) const;