This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sample(n): | |
game_results = np.random.choice([1, -1, 0], size=n, p=[0.2, 0.15, 0.65]) | |
return game_results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |