Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍👩‍👦‍👦
Family means everything

Masoud Masoumi Moghadam masouduut94

👨‍👩‍👦‍👦
Family means everything
View GitHub Profile
View meta,py
class GameMeta:
PLAYERS = {'none': 0, 'white': 1, 'black': 2}
INF = float('inf')
GAME_OVER = -1
EDGE1 = 1
EDGE2 = 2
NEIGHBOR_PATTERNS = ((-1, 0), (0, -1), (-1, 1), (0, 1), (1, 0), (1, -1))
View gamestate.py
from numpy import zeros, int_
from unionfind import UnionFind
from meta import GameMeta
class GameState:
"""
Stores information representing the current state of a game of hex, namely
the board and the current turn. Also provides functions for playing game.
"""
@masouduut94
masouduut94 / union_find.py
Created Oct 23, 2020
disjoint sets data structure adapted to game of hex.
View union_find.py
class UnionFind:
"""
Notes:
unionfind data structure specialized for finding hex connections.
Implementation inspired by UAlberta CMPUT 275 2015 class notes.
Attributes:
parent (dict): Each group parent
rank (dict): Each group rank
groups (dict): Stores the groups and chain of cells
View json_parser_v12.py
import json
from os import makedirs
from os.path import exists, join
from bunch import bunchify
from datetime import datetime
class JsonMeta(object):
HOURS = 4
MINUTES = 59
SECONDS = 59
View test_scheduled_output.py
import unittest
import sys
from datetime import datetime
from os import listdir
from time import sleep
from tempfile import mkdtemp
from unittest.case import TestCase
# from json_parser import JsonParser
View json_parser_v11.py
def output(self):
output = {'video_details': self.video_details}
result = list(self.frames.values())
# Every bbox in each frame has to have `top_k_labels` number of labels otherwise error raises.
for frame in result:
for bbox in frame.bboxes:
if not bbox.labels_full(self.top_k_labels):
raise ValueError(
"labels in frame_id: {}, bbox_id: {} is not fulled before outputting.".format(frame.frame_id,
View json_parser_v10.py
class Bbox(BaseJsonParser):
"""
This class keeps the information of each bounding box in the frame.
"""
def __init__(self, bbox_id, top, left, width, height):
self.labels = []
self.bbox_id = bbox_id
self.top = top
self.left = left
View json_parser_v9.py
def add_label_to_bbox(self, frame_id: int, bbox_id: int, category: str, confidence: float):
bbox = self.find_bbox(frame_id, bbox_id)
if not bbox.labels_full(self.top_k_labels):
bbox.add_label(category, confidence)
else:
raise ValueError("labels in frame_id: {}, bbox_id: {} is fulled".format(frame_id, bbox_id))
View json_parser_v8.py
def find_bbox(self, frame_id: int, bbox_id: int):
if not self.bbox_exists(frame_id, bbox_id):
raise ValueError("frame with id: {} does not contain bbox with id: {}".format(frame_id, bbox_id))
bboxes = {bbox.bbox_id: bbox for bbox in self.frames[frame_id].bboxes}
return bboxes.get(bbox_id)
View test_json_parser_v3.py
def test_add_label_to_bbox(self):
# test if label exists in bbox
frame_one_id = 0
bbox_id = 1
bbox_xywh = (10, 20, 30, 40)
self.json_parser.add_frame(frame_one_id)
self.json_parser.add_bbox_to_frame(frame_one_id, bbox_id, *bbox_xywh)
categories = ['car', 'truck', 'bus']
confidences = [0.47, 0.85, 1]
You can’t perform that action at this time.