Skip to content

Instantly share code, notes, and snippets.

View tt293's full-sized avatar

Thomas tt293

  • London, United Kingdom
View GitHub Profile
@tt293
tt293 / game_state.py
Last active April 13, 2022 05:27
Abstract GameState class
class GameState(ABC):
@abstractmethod
def is_terminal(self) -> bool:
pass
@abstractmethod
def get_payoffs(self) -> List[int]:
pass
@abstractmethod
@tt293
tt293 / get_representation.py
Created May 17, 2020 14:37
Leduc InformationSet representation
def get_representation(self) -> str:
player_index = self.get_index(self.get_active_player())
player_card_rank = self.deck[player_index][0]
actions_as_string = "/".join([str(x) for x in self.history])
if self.round == Round.pre_flop:
community_card_rank = ''
else:
community_card_rank = self.deck[-1][0]
return f'{player_card_rank}/{community_card_rank}-{actions_as_string}'
@tt293
tt293 / leduc_handle_action.py
Created May 17, 2020 14:25
Leduc handle action
def handle_action(
self,
player: LeducPlayer,
action: LeducAction) -> LeducGameState:
next_state = copy.deepcopy(self)
@tt293
tt293 / leduc_ranks.py
Last active April 13, 2022 05:26
Leduc Hold'em Hand Ranks
def rank(hand: List[str]) -> int:
ranks = {
'KK': 1,
'QQ': 2,
'JJ': 3,
'KQ': 4, 'QK': 4,
'KJ': 5, 'JK': 5,
'QJ': 6, 'JQ': 6
}
from typing import List, Dict
import random
import numpy as np
import sys
Actions = ['B', 'C'] # bet/call vs check/fold
class InformationSet():
def __init__(self):
self.cumulative_regrets = np.zeros(shape=len(Actions))
@tt293
tt293 / kafkasetup.sh
Created August 27, 2018 16:05
Install kafka
# Install JDK 8
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.rpm
sudo yum install -y jdk-8u141-linux-x64.rpm
# Download and unzip Scala and Kafka
wget http://www.scala-lang.org/files/archive/scala-2.12.6.tgz
tar xvf scala-2.12.6.tgz
wget https://archive.apache.org/dist/kafka/0.8.1/kafka_2.12-2.0.0.tgz
tar zxvf kafka_2.12-2.0.0.tgz