Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package deckdataparser;
- import java.io.*;
- //Note: I have no experience with reading/writing from files, so this has been built with a bit of Googling and trial-and-error.
- //So, it can probably be made much cleaner and more convenient.
- public class Main {
- public static void main(String[] args) {
- FileReader frs = null;
- FileWriter fws = null;
- StreamTokenizer in = null;
- PrintWriter out = null;
- String cardName = null;
- String cardNameAndNumber = null;
- boolean DeckMode = true;
- boolean LandMode = false;
- boolean CreatureMode = false;
- boolean SpellMode= false;
- double cardAmount = 0;
- Card[] expDeck = new Card[10000];
- int NumberOfCards = 0;
- int NumberOfDecks = 0;
- int TotalLands = 0;
- int TotalCreatures = 0;
- int TotalSpells = 0;
- boolean CardAlreadyKnown=false;
- try {
- //frs = new FileReader("E:\\Deck.txt");
- frs = new FileReader("/Users/fkarsten/Desktop/Deck.rtf");
- //fws = new FileWriter("E:\\ExpDeck.txt");
- fws = new FileWriter("/Users/fkarsten/Desktop/ExpDeck.txt");
- in = new StreamTokenizer(frs);
- out = new PrintWriter(fws);
- in.nextToken();
- while (in.ttype != StreamTokenizer.TT_EOF) {
- if (in.ttype == StreamTokenizer.TT_NUMBER){
- cardAmount = in.nval;
- cardName = "";
- in.nextToken();
- while (in.ttype == StreamTokenizer.TT_WORD) {
- cardName = cardName + in.sval;
- in.nextToken();
- }
- //So now we have read the line and put the contents in cardAmount and cardName.
- for (int j=1; j<=cardAmount; j++){
- if (j==1) {cardNameAndNumber="1st"+cardName; System.out.println("1 "+cardName);}
- if (j==2) {cardNameAndNumber="2nd"+cardName; System.out.println("2 "+cardName);}
- if (j==3) {cardNameAndNumber="3rd"+cardName; System.out.println("3 "+cardName);}
- if (j==4) {cardNameAndNumber="4th"+cardName; System.out.println("4 "+cardName);}
- if (j==5) {cardNameAndNumber="5th"+cardName; System.out.println("5 "+cardName);}
- if (j==6) {cardNameAndNumber="6th"+cardName; System.out.println("6 "+cardName);}
- if (j==7) {cardNameAndNumber="7th"+cardName; System.out.println("7 "+cardName);}
- if (j==8) {cardNameAndNumber="8th"+cardName; System.out.println("8 "+cardName);}
- if (j==9) {cardNameAndNumber="9th"+cardName; System.out.println("9 "+cardName);}
- if (j==10) {cardNameAndNumber="10th"+cardName; System.out.println("10 "+cardName);}
- CardAlreadyKnown=false;
- for (int i=1; i<=NumberOfCards; i++) {
- if (cardNameAndNumber.equals(expDeck[i].Name) && DeckMode==expDeck[i].DeckNotSideboard) {
- expDeck[i].Total++;
- CardAlreadyKnown=true;
- if (SpellMode && DeckMode) {TotalSpells++;}
- }
- }
- if (!CardAlreadyKnown) {
- NumberOfCards++;
- expDeck[NumberOfCards] = new Card();
- expDeck[NumberOfCards].Total=1;
- expDeck[NumberOfCards].DeckNotSideboard=DeckMode;
- expDeck[NumberOfCards].Name=cardNameAndNumber;
- }
- }
- if (cardName.equals("DECK")) {
- DeckMode=true;
- NumberOfDecks=NumberOfDecks+1;
- }
- if (cardName.equals("SIDEBOARD")) DeckMode=false;
- }
- else {in.nextToken();}
- }
- out.println("Expected Deck (Average of "+NumberOfDecks+" decks)"); System.out.println("Expected Deck (Average of "+NumberOfDecks+" decks)");
- for (int i=1; i<=NumberOfCards; i++) {expDeck[i].Average=expDeck[i].Total/NumberOfDecks;}
- for (int i=1; i<=NumberOfCards; i++){
- if (expDeck[i].DeckNotSideboard==true && !expDeck[i].Name.equals("DECK") && !expDeck[i].Name.equals("SIDEBOARD") && !expDeck[i].Name.equals("LAND") && !expDeck[i].Name.equals("CREATURE") && !expDeck[i].Name.equals("SPELL") ) {
- out.print(Math.round(expDeck[i].Average*100)/100.0+" "); System.out.print(Math.round(expDeck[i].Average*100)/100.0+" ");
- out.println(expDeck[i].Name); System.out.println(expDeck[i].Name);
- }
- }
- out.println("Expected Sideboard"); System.out.println("Expected Sideboard");
- for (int i=1; i<=NumberOfCards; i++){
- if (expDeck[i].DeckNotSideboard==false && !expDeck[i].Name.equals("DECK") && !expDeck[i].Name.equals("SIDEBOARD") && !expDeck[i].Name.equals("LAND") && !expDeck[i].Name.equals("CREATURE") && !expDeck[i].Name.equals("SPELL") ) {
- out.print(Math.round(expDeck[i].Average*100)/100.0+" "); System.out.print(Math.round(expDeck[i].Average*100)/100.0+" ");
- out.println(expDeck[i].Name); System.out.println(expDeck[i].Name);
- }
- }
- }
- catch (FileNotFoundException ex) {
- System.out.println("File not found "+ex.getMessage());
- }
- catch (IOException ex) {
- System.out.println(ex.getMessage());
- }
- finally {
- try {
- if (frs != null) frs.close();
- if (fws != null) fws.close();
- }
- catch (IOException ex) {
- System.out.println(ex);
- }
- }
- }
- }
- class Card {
- double Average;
- double Total;
- String Name;
- boolean DeckNotSideboard;
- String CardType;
- boolean Selected;
- }
- /*
- Input data file in correct formatting contains the following:
- 0 DECK
- 4 Elvish Mystic
- 4 Goblin Rabblemaster
- 3 Heir of the Wilds
- 4 Rattleclaw Mystic
- 4 Stormbreath Dragon
- 4 Thunderbreak Regent
- 4 Boon Satyr
- 3 Surrak the Hunt Caller
- 7 Forest
- 7 Mountain
- 1 Haven of the Spirit Dragon
- 4 Temple of Abandon
- 4 Wooded Foothills
- 2 Draconic Roar
- 4 Craters Claws
- 1 Roast
- 0 SIDEBOARD
- 3 Hornet Nest
- 3 Destructive Revelry
- 3 Wild Slash
- 1 Nissa Worldwaker
- 3 Xenagos the Reveler
- 2 Roast
- 0 DECK
- 2 Ashcloud Phoenix
- 4 Elvish Mystic
- 4 Stormbreath Dragon
- 4 Sylvan Caryatid
- 4 Thunderbreak Regent
- 4 Courser of Kruphix
- 2 Dragonlord Atarka
- 3 Xenagos the Reveler
- 6 Forest
- 3 Mountain
- 3 Haven of the Spirit Dragon
- 2 Mana Confluence
- 2 Rugged Highlands
- 4 Temple of Abandon
- 4 Wooded Foothills
- 4 Draconic Roar
- 3 Craters Claws
- 2 Roast
- 0 SIDEBOARD
- 2 Arbor Colossus
- 2 Hornet Nest
- 2 Destructive Revelry
- 2 Wild Slash
- 1 Chandra Pyromaster
- 1 Nissa Worldwaker
- 1 Mob Rule
- 1 Roast
- 3 Seismic Rupture
- 0 DECK
- 4 Elvish Mystic
- 4 Goblin Rabblemaster
- 3 Heir of the Wilds
- 4 Rattleclaw Mystic
- 4 Stormbreath Dragon
- 4 Thunderbreak Regent
- 4 Boon Satyr
- 3 Surrak the Hunt Caller
- 6 Forest
- 5 Mountain
- 1 Haven of the Spirit Dragon
- 2 Mana Confluence
- 1 Rugged Highlands
- 4 Temple of Abandon
- 4 Wooded Foothills
- 2 Draconic Roar
- 4 Craters Claws
- 1 Roast
- 0 SIDEBOARD
- 1 Heir of the Wilds
- 3 Hornet Nest
- 3 Destructive Revelry
- 3 Wild Slash
- 1 Nissa Worldwaker
- 3 Xenagos the Reveler
- 1 Roast
- 0 DECK
- 4 Elvish Mystic
- 4 Fanatic of Xenagos
- 4 Heir of the Wilds
- 3 Rattleclaw Mystic
- 4 Stormbreath Dragon
- 4 Thunderbreak Regent
- 3 Boon Satyr
- 3 Surrak Dragonclaw
- 6 Forest
- 6 Mountain
- 2 Mana Confluence
- 1 Rugged Highlands
- 4 Temple of Abandon
- 4 Wooded Foothills
- 2 Draconic Roar
- 4 Craters Claws
- 2 Roast
- 0 SIDEBOARD
- 2 Hornet Nest
- 2 Whisperwood Elemental
- 2 Destructive Revelry
- 2 Wild Slash
- 1 Sarkhan the Dragonspeaker
- 3 Xenagos the Reveler
- 1 Arc Lightning
- 1 Barrage of Boulders
- 1 Roast
- 0 DECK
- 3 Ashcloud Phoenix
- 4 Deathmist Raptor
- 4 Elvish Mystic
- 4 Goblin Rabblemaster
- 2 Heir of the Wilds
- 4 Rattleclaw Mystic
- 4 Stormbreath Dragon
- 4 Thunderbreak Regent
- 5 Forest
- 4 Mountain
- 2 Haven of the Spirit Dragon
- 2 Mana Confluence
- 2 Rugged Highlands
- 4 Temple of Abandon
- 4 Wooded Foothills
- 3 Draconic Roar
- 3 Craters Claws
- 2 Roast
- 0 SIDEBOARD
- 3 Hornet Nest
- 3 Destructive Revelry
- 1 Plummet
- 2 Wild Slash
- 3 Xenagos the Reveler
- 1 Barrage of Boulders
- 1 Harness by Force
- 1 Roast
- 0 DECK
- 4 Deathmist Raptor
- 4 Elvish Mystic
- 4 Goblin Rabblemaster
- 3 Heir of the Wilds
- 4 Rattleclaw Mystic
- 4 Stormbreath Dragon
- 4 Thunderbreak Regent
- 3 Surrak the Hunt Caller
- 6 Forest
- 6 Mountain
- 2 Mana Confluence
- 1 Rugged Highlands
- 4 Temple of Abandon
- 4 Wooded Foothills
- 2 Draconic Roar
- 4 Craters Claws
- 1 Roast
- 0 SIDEBOARD
- 3 Hornet Nest
- 3 Destructive Revelry
- 3 Wild Slash
- 3 Xenagos the Reveler
- 1 Barrage of Boulders
- 2 Roast
- 0 DECK
- 2 Ashcloud Phoenix
- 2 Deathmist Raptor
- 4 Elvish Mystic
- 4 Goblin Rabblemaster
- 4 Rattleclaw Mystic
- 4 Stormbreath Dragon
- 4 Thunderbreak Regent
- 1 Boon Satyr
- 1 Dragonlord Atarka
- 2 Xenagos the Reveler
- 6 Forest
- 3 Mountain
- 2 Haven of the Spirit Dragon
- 2 Mana Confluence
- 2 Rugged Highlands
- 4 Temple of Abandon
- 4 Wooded Foothills
- 1 Atarkas Command
- 3 Draconic Roar
- 1 Arc Lightning
- 3 Craters Claws
- 1 Roast
- 0 SIDEBOARD
- 2 Hornet Nest
- 3 Outpost Siege
- 1 Boon Satyr
- 3 Destructive Revelry
- 1 Dragonlord Atarka
- 2 Arc Lightning
- 2 Roast
- 1 Scouring Sands
- 0 DECK
- 4 Elvish Mystic
- 4 Goblin Rabblemaster
- 1 Heir of the Wilds
- 4 Rattleclaw Mystic
- 2 Scaleguard Sentinels
- 4 Stormbreath Dragon
- 4 Thunderbreak Regent
- 3 Boon Satyr
- 3 Surrak the Hunt Caller
- 7 Forest
- 6 Mountain
- 1 Haven of the Spirit Dragon
- 2 Mana Confluence
- 4 Temple of Abandon
- 4 Wooded Foothills
- 2 Draconic Roar
- 3 Craters Claws
- 2 Roast
- 0 SIDEBOARD
- 4 Courser of Kruphix
- 2 Back to Nature
- 1 Dragonlord Atarka
- 3 Xenagos the Reveler
- 3 Arc Lightning
- 2 Roast
- /*
Advertisement
Add Comment
Please, Sign In to add comment