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 expand_and_evaluate(self, parent, action, child): | |
if child.win is None: | |
# it's either a non-terminal node or a terminal node that hasn't been | |
# visited before | |
# using controller (which knows the rules of the game) to get the next state | |
next_state_obj, win = self.controller.get_next_state(parent.state, action) | |
next_state = next_state_obj.get_array_view() | |
if win is None: | |
# not a terminal node |
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
# backward passes of results from MCTS is handled through recursion | |
def selection(self, node, root = False, logging = False, actions = None): | |
# finds PUCT val for child nodes and returns the best child (the one with the max PUCT val) | |
# and the best action for parent | |
best_child, best_action = self.select_best_child(node, root) | |
# ignore this logging part, this is not the core part of this function | |
if(logging): | |
if actions == None: |
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 Node: | |
def __init__(self, state, model): | |
# saves state as a dictionary | |
self.state = state | |
# needs access to the neural network model | |
self.model = model | |
# W is the total reward and N is the number of playouts | |
self.W = 0 | |
self.N = 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
# if the current cell which is being handled has orbs of opposite color, then | |
# we need to decrease them from our opporbs count, | |
# because they will change to our color | |
if state.color[row][col] == -turn_color: | |
opporbs -= state.orbs[row][col] | |
myorbs += state.orbs[row][col] |
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
''' | |
row and col are the indices for the event cell | |
the '1' in the following line of code indicates | |
that one orb would be added in that cell | |
''' | |
queue = [(row, col, 1)] | |
while len(queue)>0: | |
row,col,val = queue.pop(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
# pygame graphics code part | |
''' | |
Creates the pygame window | |
Does drawing functions like drawing the grid using rectangles | |
and drawing orbs using circles | |
The most important function here is the gameloop function | |
which takes the stateview dictionary and updates the pygame display. | |
(If you're familiar with p5.js, the gameloop function is like draw, | |
and __init__ is like setup, | |
except that we would manually call the gameloop function in a loop) |
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 for game state; stores the player's turn | |
stores number of orbs and color as numpy arrays, treats the color | |
of a vacant cell as 0, +1 if red and -1 if green. | |
get_array_view is the most important function here | |
which returns a dictionary having a board view and | |
the player's turn | |
''' | |
class State: | |
def __init__(self, givenstate=None): |
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
data = None | |
if 'centers' in R.keys(): | |
data = R['centers'] | |
if sum([j['available_capacity_dose1'] for i in data for j in i['sessions'] if j['min_age_limit'] <= 18]) > 0: | |
dial() |
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
from datetime import date | |
import json | |
import time | |
import requests | |
from call import * | |
with open("data.json","r") as f: | |
data = json.load(f) | |
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode=%s&date=%s"%(data['pincode'], date.today().strftime("%d-%m-%Y")) |
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 construct_df(soup): | |
L = soup.findAll(True, {'class':['center-name-title','center-name-text', 'slots-box']}) | |
# obtaining class specific information from soup results | |
M = [] | |
for i in L: | |
class_names = i.get('class') | |
if class_names == ['center-name-title']: | |
ADD = i.get_text() |
NewerOlder