RogueSharp
Show / Hide Table of Contents

Interface IWeightedPool<T>

An Interface for weighted collections from which items of type T can be chosen at random. Although the item is picked at random, weights will be considered. Items with higher weights will be more likely to be picked than items with lower weights.

Namespace: RogueSharp.Random
Assembly: RogueSharp.dll
Syntax
public interface IWeightedPool<T>
Type Parameters
Name Description
T

The type of item to be stored in the pool

Examples

A treasure lookup table in a board game could be implemented as a WeightedPool. A booster pack for a collectable card game could be implemented as a WeightedPool.

Methods

| Improve this Doc View Source

Add(T, Int32)

Add an item of type T to the WeightedPool with the given weight

Declaration
void Add(T item, int weight)
Parameters
Type Name Description
T item

The item to add to the WeightedPool

System.Int32 weight

The chance that the item will be picked at random from the pool when weighted against all other items. Higher weights mean it is more likely to be picked.

| Improve this Doc View Source

Choose()

Choose an item at random from the pool, keeping weights into consideration. The item itself will remain in the pool and a clone of the item selected will be returned.

Declaration
T Choose()
Returns
Type Description
T

A clone of the item of type T from the WeightedPool

| Improve this Doc View Source

Clear()

Remove all items from the WeightedPool. The WeightedPool will be empty after calling this method.

Declaration
void Clear()
| Improve this Doc View Source

Draw()

Take an item at random from the pool, keeping weights into consideration. The item will be removed from the pool.

Declaration
T Draw()
Returns
Type Description
T

An item of type T from the WeightedPool

  • Improve this Doc
  • View Source
RogueSharp © 2014-2020 Faron Bracy
Back to top