add BlackJack environment and fix save and load

- method names were swapped
This commit is contained in:
2020-03-01 13:51:47 +01:00
parent cff1a4e531
commit 18a702ba62
12 changed files with 337 additions and 2 deletions
@@ -0,0 +1,34 @@
package evironment.blackjack.cards;
import core.RNG;
import java.util.ArrayList;
public class CardDeck {
private ArrayList<Card> cards;
public CardDeck() {
cards = new ArrayList<>(Suit.values().length * Rank.values().length);
for(Suit s : Suit.values()) {
for(Rank r : Rank.values()) {
Card c = new Card(s, r);
cards.add(c);
}
}
}
/**
* We assume that cards are dealt from an infinite deck (i.e., with replacement)
* so that there is no advantage to keeping track of the cards already dealt.
* Therefore no card is removed from the deck.
*
* @return next card
*/
public Card nextCard() {
/*
nextInt(int bound) returns random int value from (inclusive) 0
and EXCLUSIVE! bound
*/
return cards.get(RNG.getRandom().nextInt(cards.size()));
}
}