toaster_shuffle 1.0.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 46

shuffle

A library that shows off shuffling decks of cards for visualization purposes.

Created from templates made available by Stagehand under a BSD-style license.

Usage

A simple usage example:

import 'dart:math';

import 'package:shuffle/shuffle.dart';

main() {
  ShuffleIteration noShuffle = (List<int> deck, Random r) {
    return deck;
  };

  ShuffleIteration pickup = (List<int> deck, Random r) {
    List<int> next = [];
    for (int i = 0; i < 52; i++) {
      next.add(deck.removeAt(r.nextInt(deck.length)));
    }

    return next;
  };

  ShuffleIteration overhand = (List<int> deck, Random r) {
    // number of cards left in hand before shuffle ends
    int threshold = 5;
    int length = 52;
    int split = (length / 2).floor() + r.nextInt(10);

    while (length > threshold) {
      List<int> list1 = deck.sublist(0, split);
      List<int> list2 = deck.sublist(split, length);

      deck.setRange(0, length, list2 + list1);
      length = split;
      split = (length / 2).floor() + r.nextInt((length / 5).ceil());
    }
    return deck;
  };

  ShuffleIteration ruffle = (List<int> deck, Random r) {
    int length = 52;
    int split = (length / 2).floor() + r.nextInt(2);

    int i1 = 0;
    int i2 = split;

    List<int> temp = [];

    while (i2 < 52 || i1 < split) {
      int stand = r.nextInt(3) + 1;
      if (i1 + stand < split) {
        temp += deck.sublist(i1, i1 + stand);
        i1 += stand;
      } else if (i1 < split) {
        temp += deck.sublist(i1, split);
        i1 = split;
      } else {
        temp += deck.sublist(i2, 52);
        i2 = 52;
      }

      stand = r.nextInt(3) + 1;

      if (i2 + stand < 52) {
        temp += deck.sublist(i2, i2 + stand);
        i2 += stand;
      } else if (i2 < 52) {
        temp += deck.sublist(i2, 52);
        i2 = 52;
      } else {
        temp += deck.sublist(i1, split);
        i1 = split;
      }
    }
    return temp;
  };

  int decks = 100;

  Map<String, List<ShuffleStrategy>> shuffles = {
    "Initial Deck": [ShuffleStrategy(1, noShuffle)],
    "Random": [
      ShuffleStrategy(1, pickup),
      ShuffleStrategy(3, pickup),
      ShuffleStrategy(6, pickup),
    ],
    "Overhand": [
      ShuffleStrategy(1, overhand),
      ShuffleStrategy(3, overhand),
      ShuffleStrategy(6, overhand),
      ShuffleStrategy(10, overhand),
    ],
    "Ruffle": [
      ShuffleStrategy(1, ruffle),
      ShuffleStrategy(3, ruffle),
      ShuffleStrategy(6, ruffle),
      ShuffleStrategy(10, ruffle),
    ],
  };

  for (MapEntry<String, List<ShuffleStrategy>> e in shuffles.entries) {
    String name = e.key;
    List<ShuffleStrategy> list = e.value;

    for (ShuffleStrategy strategy in list) {
      for(int i=0; i < decks; i++){
      print(
          "$name, ${strategy.iterations}: ${Deck.defaultDeck(i)..shuffle(strategy)}");
      }
    }
  }
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

1.0.0

  • Initial version, created by Stagehand

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  toaster_shuffle: ^1.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:toaster_shuffle/shuffle.dart';
  
Version Uploaded Documentation Archive
1.0.1 Aug 3, 2018 Go to the documentation of toaster_shuffle 1.0.1 Download toaster_shuffle 1.0.1 archive
1.0.0 Aug 3, 2018 Go to the documentation of toaster_shuffle 1.0.0 Download toaster_shuffle 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example.

None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use toaster_shuffle.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
Dev dependencies
test ^1.0.0