util module

dicewars.util.get_player_max_size(grid_areas, player_areas)

Calculate the maximal number of adjacent player areas.

Parameters
  • grid_areas (tuple(Area)) – Area instances of a Grid (Grid.areas)

  • player_areas (tuple(int) or list(int)) – indices of player’s areas in grid_areas

Returns

maximal number of adjacent areas in player_areas

Return type

int

dicewars.util.point_in_grid_cell(cell, map_x, map_y)

Test if a point is inside a (hexagonal) grid cell.

Parameters
  • cell (Cell) – Cell instance to test (one out of Grid.cells)

  • map_x (int or float) – point’s x coordinate (in unscaled map space)

  • map_y (int or float) – point’s y coordinate (in unscaled map space)

Returns

True if point is inside cell, else False

Return type

bool

dicewars.util.point_in_grid_area(grid, area, map_x, map_y)

Test if a point is inside a (polygonal) grid area.

Parameters
  • grid (Grid) – Grid instance that created the area

  • area (Area) – Area instance to test (one out of Grid.areas)

  • map_x (int or float) – point’s x coordinate (in unscaled map space)

  • map_y (int or float) – point’s y coordinate (in unscaled map space)

Returns

True if point is inside area, else False

Return type

bool

dicewars.util.pick_grid_cell(grid, map_x, map_y)

Find the (hexagonal) grid cell that encloses a point.

Parameters
  • grid (Grid) – Grid instance to search in

  • map_x (int or float) – point’s x coordinate (in unscaled map space)

  • map_y (int or float) – point’s y coordinate (in unscaled map space)

Returns

Cell instance if found, else None

Return type

Cell

dicewars.util.pick_grid_area(grid, map_x, map_y)

Find the (polygonal) grid area that encloses a point.

Parameters
  • grid (Grid) – Grid instance to search in

  • map_x (int or float) – point’s x coordinate (in unscaled map space)

  • map_y (int or float) – point’s y coordinate (in unscaled map space)

Returns

Area instance if found, else None

Return type

Area