Skip to content

Instantly share code, notes, and snippets.

@shahradj
shahradj / cfr.py
Last active October 26, 2023 11:59
CFR implementation of five card stud
import random
from poker import POKER_BOX, Hand, Card
#poker.py can be found at https://gist.github.com/shahradj/1761a6a521c2649bdcc54996d2bb73ec
from gametree import GameTree, ACTIONS
#gametree.py can be found at https://gist.github.com/shahradj/ab6e2ea5ab8cb17ed287dda0c4796ed2
import numpy as np
import pandas as pd
import itertools
import copy
from collections import Counter
@shahradj
shahradj / gametree.py
Created January 8, 2019 00:09
Game Tree with regret matching
import numpy as np
ACTIONS = ['r', 'c', 'f'] # RAISE or CALL/CHECK or FOLD
class GameNode:
def __init__(self, info_set):
self.info_set = info_set
self.strategy_sum, self.regret_sum = np.zeros((2, len(ACTIONS)))
@shahradj
shahradj / poker.py
Created January 8, 2019 00:03
Hands in Poker
import itertools
from collections import Counter
# example string representation of card '8 Diamond': '8D'
RANKS = [str(i) for i in range(2, 11)] + ['J', 'Q', 'K', 'A']
SUITS = ['C', 'D', 'H', 'S']
POKER_BOX = [r+s for r,s in itertools.product(RANKS, SUITS)]
class Card:
def __init__(self, card):
@shahradj
shahradj / clustering.py
Created September 1, 2017 18:08
Perform clustering on mouse tracking data
import pandas as pd
from scipy.cluster.hierarchy import fclusterdata
from pymongo import MongoClient
import numpy as np
from datetime import *
import json
def saveToRelational(jsonPacket):
"""
save the received json packet to a relational database
@shahradj
shahradj / Prisoners2.py
Last active October 2, 2019 07:25
Playing the game of Prisoners Dilemma
class Game:
def __init__(self, max_game=100):
self.p1 = Player('Agent A')
self.p2 = Player('Agent B')
self.max_game = max_game
def play(self, avg_regret_matching=False):
def play_regret_matching():
for i in xrange(0, self.max_game):
self.p1.update_strategy()
@shahradj
shahradj / Prisoners.py
Last active October 2, 2019 07:25
Prisoners Dilemma
class Prisoners:
actions = ['SILENCE', 'SNITCH']
n_actions = 2
utilities = pd.DataFrame([
# SILENCE SNITCH
[ -2, -5], # SILENCE
[ -1, -3] # SNITCH
], columns=actions, index=actions)