https://github.com/innovativeinventor/cgt
Calculating surreal numbers from combinatorial games
https://github.com/innovativeinventor/cgt
Last synced: 7 months ago
JSON representation
Calculating surreal numbers from combinatorial games
- Host: GitHub
- URL: https://github.com/innovativeinventor/cgt
- Owner: InnovativeInventor
- Created: 2021-01-08T05:11:47.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-22T01:11:56.000Z (over 5 years ago)
- Last Synced: 2025-02-26T14:45:27.264Z (over 1 year ago)
- Language: TeX
- Homepage:
- Size: 297 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Combinatorial game theory

Generalized deterministic recursive/dynamic combinatorial game theory calculator for evaluating the state of any two-person game that has a corresponding number.
Only uses vanilla python and pydantic (for type-checking).
Rationale:
> The best way to understand a process is to write a program automating it.
## Example game (Push)
```python
from cgt.game import GameTree
from cgt.pushpin import PushGame
case = PushGame(["", "L", "R"])
print(GameTree(case).value())
```
Output:
``` python
>>> -1.75
```
## Implementing your own game
```python
class AbstractGame():
"""
Example of required methods and functions that must be implemented
"""
def __init__(self, state: AbstractState = AbstractState()): # some state to pass to the game
raise NotImplementedError
def moves(self) -> List[Set[AbstractState]]: # return a list of a set of moves for each player
"""
Returns the possible moves left. If there are no moves left, return empty lists.
"""
raise NotImplementedError
def apply(self, state: AbstractState): # takes a state and applies it to the game
"""
Apply a move or "state" return by moves.
"""
raise NotImplementedError
@staticmethod
def prune_states(self, state: AbstractState) -> AbstractState:
"""
Normalizes the state
"""
raise NotImplementedError
```
For a real-live working example, see [`cgt/push.py`](/cgt/push.py)