utils

Border

class gobigger.utils.structures.Border(minx, miny, maxx, maxy, random_generator=None)[source]
Overview:

used to specify a rectangular range

contains(position: Vector2) bool[source]
Overview:

To judge whether a position in this border.

Parameters:

position <Vector2>: the position to be judged.

Returns:

bool: True or False, whether the position in this border.

sample() Vector2[source]
Overview:

Randomly sample a position in the border.

Returns:

Vector2: the sampled position.

BaseCollisionDetection

class gobigger.utils.collision_detection.BaseCollisionDetection(border: Border)[source]

ExhaustiveCollisionDetection

class gobigger.utils.collision_detection.ExhaustiveCollisionDetection(border: Border)[source]
Overview:

Exhaustive Algorithm

solve(query_list: list, gallery_list: list)[source]
Overview:

For the balls in the query, enumerate each ball in the gallery to determine whether there is a collision

Parameters:

query_list <List[BaseBall]>: List of balls that need to be queried for collision gallery_list <List[BaseBall]>: List of all balls

Returns:
results <Dict[int: List[BaseBall]> return value
int value denotes:

the subscript in query_list

string value denotes:

List of balls that collided with the query corresponding to the subscript

PrecisionCollisionDetection

class gobigger.utils.collision_detection.PrecisionCollisionDetection(border: Border, precision: int = 50)[source]
Overview:

Precision Approximation Algorithm Divide the map into several rows according to the accuracy that has been set, dynamically maintain the row information in each frame, and search by row

get_row(x) int[source]
Overview:

Get the row coordinates of the ball

Parameter:

node <BaseBall>: The ball need to get its row coordinates

solve(query_list: list, gallery_list: list)[source]
Overview:

First, you need to sort the balls in each row according to the ordinate. For the balls in query_list, first abstract the boundary of the ball into a rectangle, then traverse each row in the rectangle, and find the first ball covered by the query through dichotomy in each row, and then Enumerate the balls in sequence until the ordinate exceeds the boundary of the query rectangle.

Parameters:

query_list <List[BaseBall]>: List of balls that need to be queried for collision gallery_list <List[BaseBall]>: List of all balls

Returns:
results <Dict[int: List[BaseBall]> return value
int value denotes:

the subscript in query_list

string value denotes:

List of balls that collided with the query corresponding to the subscript

RebuildQuadTreeCollisionDetection

class gobigger.utils.collision_detection.RebuildQuadTreeCollisionDetection(border: Border, node_capacity=64, tree_depth=32)[source]
Overview:

Build a quadtree on a two-dimensional plane in every frame, and query collisions in the quadtree

solve(query_list: list, gallery_list: list)[source]
Overview:

Construct a quadtree from scratch based on gallery_list and complete the query

Parameters:

query_list <List[BaseBall]>: List of balls that need to be queried for collision gallery_list <List[BaseBall]>: List of all balls

Returns:
results <Dict[int: List[BaseBall]> return value
int value denotes:

the subscript in query_list

string value denotes:

List of balls that collided with the query corresponding to the subscript

RemoveQuadTreeCollisionDetection

class gobigger.utils.collision_detection.RemoveQuadTreeCollisionDetection(border: Border, node_capacity=64, tree_depth=32)[source]
Overview:

Add delete operations for the quadtree, and dynamically maintain a quadtree

solve(query_list: list, changed_node_list: list)[source]
Overview:

Update the points in the quadtree according to the changed_node_list and complete the query

Parameters:

query_list <List[BaseBall]>: List of balls that need to be queried for collision gallery_list <List[BaseBall]>: List of all balls

Returns:
results <Dict[int: List[BaseBall]> return value
int value denotes:

the subscript in query_list

string value denotes:

List of balls that collided with the query corresponding to the subscript