Skip to content

Comments

Add param_social_dilemma: parameterized N-player social dilemma game#1482

Open
sriramsowmithri9807 wants to merge 7 commits intogoogle-deepmind:masterfrom
sriramsowmithri9807:master
Open

Add param_social_dilemma: parameterized N-player social dilemma game#1482
sriramsowmithri9807 wants to merge 7 commits intogoogle-deepmind:masterfrom
sriramsowmithri9807:master

Conversation

@sriramsowmithri9807
Copy link

Changes

1. open_spiel/python/games/param_social_dilemma.py

  • Added import ast for safe string parsing
  • Changed "payoff_matrix": None"payoff_matrix": "default" in _DEFAULT_PARAMS so pyspiel recognizes it as a valid kString parameter type
  • Updated constructor to check for "default" string instead of None
  • Added ast.literal_eval parsing with explicit dtype=np.float64 for custom payoff matrix strings
  • Added proper error handling with descriptive ValueError for malformed input

2. open_spiel/python/games/param_social_dilemma_test.py

  • Fixed test_custom_payoff_matrix: wrapped custom_payoff.tolist() with str() to pass as string

3. open_spiel/python/examples/param_social_dilemma_example.py

  • Fixed custom payoff matrix example: wrapped custom_payoff.tolist() with str() to pass as string

Testing

  • Python version: 3.13.5
  • open_spiel version: 1.6.11
Test Suite Result
param_social_dilemma_test.py (14 tests) ✅ All pass
param_social_dilemma_bots_test.py (8 tests) ✅ All pass
param_social_dilemma_example.py (5 scenarios) ✅ All complete

sriramsowmithri9807 and others added 4 commits January 24, 2026 09:24
…payoffs, and Axelrod-style bots

- Implemented flexible N-player simultaneous-move game (N >= 2)
- Added dynamic payoff matrices with configurable change probability
- Implemented stochastic rewards with Gaussian noise
- Created 7 Axelrod-style bots (TitForTat, GrimTrigger, Pavlov, etc.)
- Added comprehensive unit tests (21 test cases total)
- Included example scripts for MARL usage and bot tournaments
- Added documentation (README and implementation summaries)

Features:
- Variable number of agents (default: 3)
- Dynamic and non-stationary payoff structures
- Optional reward noise for robustness studies
- Full Python API exposure for all parameters
- Compatible with OpenSpiel's simultaneous-move game API

Files added:
- Core game implementation and tests
- Axelrod-style bots and bot tests
- Usage examples and tournament demonstrations
- Documentation files
- Changed payoff_matrix default from None (kUnset) to 'default' (kString)
  so pyspiel.load_game() accepts custom payoff matrix strings
- Added ast.literal_eval parsing with dtype=np.float64 for custom matrices
- Added proper error handling for malformed payoff matrix input
- All 14 game tests, 8 bot tests, and example script pass (Python 3.13.5)
@lanctot
Copy link
Collaborator

lanctot commented Feb 17, 2026

Does this replace #1458?

@sriramsowmithri9807
Copy link
Author

Yes sir!!

sriramsowmithri9807 and others added 2 commits February 20, 2026 17:07
…n pyspiel_test and CMakeLists

- Rename 'num_players' parameter to 'players' in param_social_dilemma to match
  OpenSpiel convention (fixes test_multiplayer_game failure)
- Add python_param_social_dilemma to EXPECTED_MANDATORY_GAMES in pyspiel_test.py
- Register param_social_dilemma tests in python/CMakeLists.txt
- Generate playthrough file for integration tests
- Update all tests, examples, and docs to use new parameter name
@lanctot lanctot self-requested a review February 20, 2026 22:08
Copy link
Collaborator

@lanctot lanctot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks. Tests are now passing.

A few changes please:

  1. AFAICT this is the param_social_dilemma implementation. Can you edit the name of the PR to reflect that?
  2. Please remove IMPLEMENTATION_SUMMARY.md and PR_SUMMARY.md
  3. Please follow step 9 of the "Adding a game" guide here (https://github.com/google-deepmind/open_spiel/blob/master/docs/developer_guide.md#adding-a-game); specifically, run pylint using the Google pylintrc file until there are no more lint errors.

Thanks!

self.assertEqual(legal_actions, [0, 1, 2])

def test_action_to_string(self):
game = pyspiel.load_game("python_param_social_dilemma")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make all the files 2-space indent to be consisten with the rest of the OpenSpiel code base?

…iles

- Convert param_social_dilemma.py to 2-space indentation
- Convert param_social_dilemma_test.py to 2-space indentation
- Fix pylint errors: dangerous-default-value, raise-missing-from,
  unused-argument, protected-access
- Remove IMPLEMENTATION_SUMMARY.md and PR_SUMMARY.md
- All files pass pylint with Google pylintrc
@sriramsowmithri9807 sriramsowmithri9807 changed the title Fixes the TypeError / SpielError when passing custom payoff matrices via pyspiel.load_game() in the param_social_dilemma game. Closes #1431 Add param_social_dilemma: parameterized N-player social dilemma game Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants