Skip to content

Instantly share code, notes, and snippets.

@RubenNL
Created November 18, 2021 10:36
Show Gist options
  • Select an option

  • Save RubenNL/0083c4bea7978a2d49b9087b3b0f5340 to your computer and use it in GitHub Desktop.

Select an option

Save RubenNL/0083c4bea7978a2d49b9087b3b0f5340 to your computer and use it in GitHub Desktop.

Revisions

  1. RubenNL created this gist Nov 18, 2021.
    28 changes: 28 additions & 0 deletions Bag.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    using System;
    using System.Collections.Generic;
    using System.Linq;

    namespace GUI
    {
    public class Bag
    {
    private readonly Random _random;
    private Queue<Matrix> _bag = new(); //using queue for easy pop/dequeue.

    public Bag(int seed)
    {
    _random = new Random(seed);
    }

    private void Fill()
    {
    _bag = new Queue<Matrix>(Matrix.GetMatrixes().OrderBy(_ => _random.Next()));
    }

    public Matrix GetNextMatrix()
    {
    if (_bag.Count == 0) Fill();
    return _bag.Dequeue();
    }
    }
    }