moved shuffle to Player, deprecated GameAction.shuffle, and redirected to Player

This commit is contained in:
jendave
2011-08-06 09:37:58 +00:00
parent 54f96f92ee
commit 38fcd7cbb4
2 changed files with 43 additions and 2 deletions

View File

@@ -2469,7 +2469,10 @@ public class GameAction {
} }
//TODO: shuffling seems to change a card's unique number but i'm not 100% sure //TODO: shuffling seems to change a card's unique number but i'm not 100% sure
@Deprecated
public void shuffle(Player player) { public void shuffle(Player player) {
player.shuffle();
/*
PlayerZone library = AllZone.getZone(Constant.Zone.Library, player); PlayerZone library = AllZone.getZone(Constant.Zone.Library, player);
Card c[] = library.getCards(); Card c[] = library.getCards();
@@ -2485,8 +2488,6 @@ public class GameAction {
Collections.shuffle(list, random); Collections.shuffle(list, random);
Collections.shuffle(list, random); Collections.shuffle(list, random);
// random = java.security.SecureRandom.getInstance("SHA1PRNG");
Object o; Object o;
for(int i = 0; i < list.size(); i++) { for(int i = 0; i < list.size(); i++) {
o = list.remove(random.nextInt(list.size())); o = list.remove(random.nextInt(list.size()));
@@ -2503,6 +2504,7 @@ public class GameAction {
list.toArray(c); list.toArray(c);
library.setCards(c); library.setCards(c);
*/
}//shuffle }//shuffle
/** /**

View File

@@ -2,6 +2,9 @@
package forge; package forge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
public abstract class Player extends MyObservable{ public abstract class Player extends MyObservable{
@@ -305,6 +308,42 @@ public abstract class Player extends MyObservable{
throw new RuntimeException("Input_Draw : getDredgeNumber() card doesn't have dredge - " + c.getName()); throw new RuntimeException("Input_Draw : getDredgeNumber() card doesn't have dredge - " + c.getName());
}//getDredgeNumber() }//getDredgeNumber()
////////////////////////////////
public void shuffle() {
PlayerZone library = AllZone.getZone(Constant.Zone.Library, this);
Card c[] = library.getCards();
if(c.length <= 1) return;
ArrayList<Object> list = new ArrayList<Object>(Arrays.asList(c));
//overdone but wanted to make sure it was really random
Random random = new Random();
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Object o;
for(int i = 0; i < list.size(); i++) {
o = list.remove(random.nextInt(list.size()));
list.add(random.nextInt(list.size()), o);
}
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
list.toArray(c);
library.setCards(c);
}//shuffle
////////////////////////////////
//////////////////////////////// ////////////////////////////////
// //
// generic Object overrides // generic Object overrides