Skip to content

Instantly share code, notes, and snippets.

View Joseph94m's full-sized avatar

Joseph Moukarzel Joseph94m

View GitHub Profile
def sample(n):
game_results = np.random.choice([1, -1, 0], size=n, p=[0.2, 0.15, 0.65])
return game_results
SIZE = [12,24,48,96,128,192,256,384,512,768,1024,1256,1536,1768,2000]
ITERATIONS = 10000
winnings_best=[]
winnings_worst=[]
draw=[]
for k in range(len(SIZE)):
best_guy_wins=0
worst_guy_wins=0
@Joseph94m
Joseph94m / game-definition.py
Last active June 26, 2022 19:02
Class of the game of life
class Game:
def __init__(self, initial_state, rules,max_size):
self.initial_state = initial_state
self.rules = rules
self.max_size = max_size
def run_game(self, it):
state = self.initial_state
previous_state = None
progression = []
i = 0
@Joseph94m
Joseph94m / sparse-state.py
Last active March 25, 2019 19:36
Sparse representation of the game of life
class SparseSetState(State):
def __init__(self, grid):
self.grid = grid
def copy(self):
return SparseSetState(copy(self.grid))
def get_neighbours(self, elem, max_size):
#Returns the neighbours of a live cell if they lie within the bounds of the grid specified by max_size
l = []
@Joseph94m
Joseph94m / sparse-rules.py
Last active March 24, 2019 12:45
Sparse game of life rules
class SparseSetRules(Rule):
def apply_rules(self, grid, max_size,get_neighbours):
#grid = state.grid
counter = {}
for elem in grid:
if elem not in counter:
counter[elem]=0
nb = get_neighbours(elem, max_size)
for n in nb:
if n not in counter:
@Joseph94m
Joseph94m / Run-game-sparse.py
Created March 24, 2019 12:54
Running sparse game of life example
MAX_ITER = 1500
MAX_SIZE = 80
board = {(39, 40),(39, 41),(40, 39),(40, 40),(41, 40)}
rules = SparseSetRules()
game = Game(SparseSetState(board), rules,MAX_SIZE)
t = time.time()
rw = game.run_game(MAX_ITER)
print(time.time()-t)