public bool ShaffleDeck(string nameDeck, ShuffleAlgo algo) { var currentDeck = GetDeckByName(nameDeck); var currentIndex = decks.IndexOf(currentDeck); List <TCard> shiffled = null; if (algo == ShuffleAlgo.Simple) { shiffled = FisherYates <TCard> .Shuffle(currentDeck.cards); } decks[currentIndex].ChangeCards(shiffled); return(true); }
private void shuffle() { ShuffleAlgo shuffle_algo = Config.sched.shuffle_algo; if (Config.sched.is_adaptive_shuffle) { double blp_thresh = Config.sched.adaptive_threshold * meta_mctrl.banks.Count; double rbl_thresh = Config.sched.adaptive_threshold; if (blp_diff > blp_thresh && rbl_diff > rbl_thresh) { shuffle_algo = ShuffleAlgo.Hanoi; } else { shuffle_algo = ShuffleAlgo.ControlledRandom; } } //rank_to_pid translation int[] pids = new int[Config.N]; for (int p = 0; p < Config.N; p++) { int r = rank[p]; pids[r] = p; } //shuffle proper switch (shuffle_algo) { case ShuffleAlgo.Naive: for (int r = 0; r < icluster_size; r++) { int pid = pids[r]; rank[pid] = (r + (icluster_size - 1)) % icluster_size; } break; case ShuffleAlgo.ControlledRandom: int step = icluster_size / 2 + 1; for (int r = 0; r < icluster_size; r++) { int pid = pids[r]; rank[pid] = (r + step) % icluster_size; } break; case ShuffleAlgo.Random: for (int r = icluster_size - 1; r > 0; r--) { int pid1 = Array.IndexOf(rank, r); int chosen_r = rand.Next(r + 1); int chosen_pid = Array.IndexOf(rank, chosen_r); rank[pid1] = chosen_r; rank[chosen_pid] = r; } break; case ShuffleAlgo.Hanoi: int even = 2 * icluster_size; int phase = shuffle_cnt % even; if (phase < icluster_size) { int grab_rank = (icluster_size - 1) - phase; int grab_pid = Array.IndexOf(rank, grab_rank); rank[grab_pid] = -1; for (int r = grab_rank + 1; r <= icluster_size - 1; r++) { int pid = Array.IndexOf(rank, r); rank[pid] = r - 1; } rank[grab_pid] = icluster_size - 1; } else { int grab_rank = (icluster_size - 1); int grab_pid = Array.IndexOf(rank, grab_rank); rank[grab_pid] = -1; for (int r = grab_rank - 1; r >= (phase - 1) % icluster_size; r--) { int pid = Array.IndexOf(rank, r); rank[pid] = r + 1; } rank[grab_pid] = (phase - 1) % icluster_size; } break; } //sanity check for (int r = 0; r < Config.N; r++) { int pid = Array.IndexOf(rank, r); Dbg.Assert(pid != -1); } }
private void Shuffle() { ShuffleAlgo shuffleAlgo = Config.sched.shuffle_algo; if (Config.sched.is_adaptive_shuffle) { double blpThresh = Config.sched.adaptive_threshold * GlobalBcount; double rblThresh = Config.sched.adaptive_threshold; if (_blpDiff > blpThresh && _rblDiff > rblThresh) { shuffleAlgo = ShuffleAlgo.Hanoi; } else { shuffleAlgo = ShuffleAlgo.ControlledRandom; } } //rank_to_pid translation int[] pids = new int[Config.N]; for (int p = 0; p < Config.N; p++) { int r = _rank[p]; pids[r] = p; } //shuffle proper switch (shuffleAlgo) { case ShuffleAlgo.Naive: for (int r = 0; r < _iclusterSize; r++) { int pid = pids[r]; _rank[pid] = (r + (_iclusterSize - 1)) % _iclusterSize; } break; case ShuffleAlgo.ControlledRandom: int step = _iclusterSize / 2 + 1; for (int r = 0; r < _iclusterSize; r++) { int pid = pids[r]; _rank[pid] = (r + step) % _iclusterSize; } break; case ShuffleAlgo.Random: for (int r = _iclusterSize - 1; r > 0; r--) { int pid1 = Array.IndexOf(_rank, r); int chosenR = _rand.Next(r + 1); int chosenPid = Array.IndexOf(_rank, chosenR); _rank[pid1] = chosenR; _rank[chosenPid] = r; } break; case ShuffleAlgo.Hanoi: int even = 2 * _iclusterSize; int phase = _shuffleCnt % even; if (phase < _iclusterSize) { int grabRank = (_iclusterSize - 1) - phase; int grabPid = Array.IndexOf(_rank, grabRank); _rank[grabPid] = -1; for (int r = grabRank + 1; r <= _iclusterSize - 1; r++) { int pid = Array.IndexOf(_rank, r); _rank[pid] = r - 1; } _rank[grabPid] = _iclusterSize - 1; } else { int grabRank = (_iclusterSize - 1); int grabPid = Array.IndexOf(_rank, grabRank); _rank[grabPid] = -1; for (int r = grabRank - 1; r >= (phase - 1) % _iclusterSize; r--) { int pid = Array.IndexOf(_rank, r); _rank[pid] = r + 1; } _rank[grabPid] = (phase - 1) % _iclusterSize; } break; } //sanity check for (int r = 0; r < Config.N; r++) { int pid = Array.IndexOf(_rank, r); Dbg.Assert(pid != -1); } }