frankkarsten

Deckdata-parser

Apr 8th, 2015
331
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package deckdataparser;
  2.  
  3. import java.io.*;
  4. //Note: I have no experience with reading/writing from files, so this has been built with a bit of Googling and trial-and-error.
  5. //So, it can probably be made much cleaner and more convenient.
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         FileReader frs = null;
  12.         FileWriter fws = null;
  13.         StreamTokenizer in = null;
  14.         PrintWriter out = null;
  15.         String cardName = null;
  16.         String cardNameAndNumber = null;
  17.         boolean DeckMode = true;
  18.         boolean LandMode = false;
  19.         boolean CreatureMode = false;
  20.         boolean SpellMode= false;
  21.         double cardAmount = 0;
  22.         Card[] expDeck = new Card[10000];
  23.         int NumberOfCards = 0;
  24.         int NumberOfDecks = 0;
  25.         int TotalLands = 0;
  26.         int TotalCreatures = 0;
  27.         int TotalSpells = 0;
  28.         boolean CardAlreadyKnown=false;
  29.  
  30.         try {
  31.             //frs = new FileReader("E:\\Deck.txt");
  32.             frs = new FileReader("/Users/fkarsten/Desktop/Deck.rtf");
  33.             //fws = new FileWriter("E:\\ExpDeck.txt");
  34.             fws = new FileWriter("/Users/fkarsten/Desktop/ExpDeck.txt");
  35.             in = new StreamTokenizer(frs);
  36.             out = new PrintWriter(fws);
  37.             in.nextToken();
  38.             while (in.ttype != StreamTokenizer.TT_EOF) {
  39.               if (in.ttype == StreamTokenizer.TT_NUMBER){
  40.                 cardAmount = in.nval;
  41.                 cardName = "";
  42.                 in.nextToken();
  43.                 while (in.ttype == StreamTokenizer.TT_WORD) {
  44.                     cardName = cardName + in.sval;
  45.                     in.nextToken();
  46.                 }
  47.                 //So now we have read the line and put the contents in cardAmount and cardName.
  48.                 for (int j=1; j<=cardAmount; j++){
  49.                     if (j==1) {cardNameAndNumber="1st"+cardName; System.out.println("1 "+cardName);}
  50.                     if (j==2) {cardNameAndNumber="2nd"+cardName; System.out.println("2 "+cardName);}
  51.                     if (j==3) {cardNameAndNumber="3rd"+cardName; System.out.println("3 "+cardName);}
  52.                     if (j==4) {cardNameAndNumber="4th"+cardName; System.out.println("4 "+cardName);}
  53.                     if (j==5) {cardNameAndNumber="5th"+cardName; System.out.println("5 "+cardName);}
  54.                     if (j==6) {cardNameAndNumber="6th"+cardName; System.out.println("6 "+cardName);}
  55.                     if (j==7) {cardNameAndNumber="7th"+cardName; System.out.println("7 "+cardName);}
  56.                     if (j==8) {cardNameAndNumber="8th"+cardName; System.out.println("8 "+cardName);}
  57.                     if (j==9) {cardNameAndNumber="9th"+cardName; System.out.println("9 "+cardName);}
  58.                     if (j==10) {cardNameAndNumber="10th"+cardName; System.out.println("10 "+cardName);}
  59.                     CardAlreadyKnown=false;
  60.                     for (int i=1; i<=NumberOfCards; i++) {
  61.                         if (cardNameAndNumber.equals(expDeck[i].Name) && DeckMode==expDeck[i].DeckNotSideboard) {
  62.                             expDeck[i].Total++;
  63.                             CardAlreadyKnown=true;
  64.                             if (SpellMode && DeckMode) {TotalSpells++;}
  65.                         }
  66.                     }
  67.                     if (!CardAlreadyKnown) {
  68.                         NumberOfCards++;
  69.                         expDeck[NumberOfCards] = new Card();
  70.                         expDeck[NumberOfCards].Total=1;
  71.                         expDeck[NumberOfCards].DeckNotSideboard=DeckMode;
  72.                         expDeck[NumberOfCards].Name=cardNameAndNumber;
  73.                     }
  74.                 }
  75.                
  76.                 if (cardName.equals("DECK")) {
  77.                     DeckMode=true;
  78.                     NumberOfDecks=NumberOfDecks+1;
  79.                 }
  80.                
  81.                 if (cardName.equals("SIDEBOARD")) DeckMode=false;
  82.               }
  83.               else {in.nextToken();}
  84.             }
  85.  
  86.             out.println("Expected Deck (Average of "+NumberOfDecks+" decks)"); System.out.println("Expected Deck (Average of "+NumberOfDecks+" decks)");
  87.             for (int i=1; i<=NumberOfCards; i++) {expDeck[i].Average=expDeck[i].Total/NumberOfDecks;}
  88.            
  89.             for (int i=1; i<=NumberOfCards; i++){
  90.                 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") ) {
  91.                     out.print(Math.round(expDeck[i].Average*100)/100.0+" "); System.out.print(Math.round(expDeck[i].Average*100)/100.0+" ");
  92.                     out.println(expDeck[i].Name); System.out.println(expDeck[i].Name);
  93.                 }
  94.             }
  95.  
  96.             out.println("Expected Sideboard"); System.out.println("Expected Sideboard");
  97.             for (int i=1; i<=NumberOfCards; i++){
  98.                 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") ) {
  99.                     out.print(Math.round(expDeck[i].Average*100)/100.0+" "); System.out.print(Math.round(expDeck[i].Average*100)/100.0+" ");
  100.                     out.println(expDeck[i].Name); System.out.println(expDeck[i].Name);
  101.                 }
  102.             }
  103.  
  104.         }
  105.         catch (FileNotFoundException ex) {
  106.             System.out.println("File not found "+ex.getMessage());
  107.         }
  108.         catch (IOException ex) {
  109.             System.out.println(ex.getMessage());
  110.         }
  111.         finally {
  112.             try {
  113.                 if (frs != null) frs.close();
  114.                 if (fws != null) fws.close();
  115.             }
  116.             catch (IOException ex) {
  117.                 System.out.println(ex);
  118.             }
  119.         }
  120.     }
  121. }
  122.  
  123. class Card {
  124.     double Average;
  125.     double Total;
  126.     String Name;
  127.     boolean DeckNotSideboard;
  128.     String CardType;
  129.     boolean Selected;
  130. }
  131.  
  132. /*
  133. Input data file in correct formatting contains the following:
  134. 0 DECK
  135. 4 Elvish Mystic
  136. 4 Goblin Rabblemaster
  137. 3 Heir of the Wilds
  138. 4 Rattleclaw Mystic
  139. 4 Stormbreath Dragon
  140. 4 Thunderbreak Regent
  141. 4 Boon Satyr
  142. 3 Surrak the Hunt Caller
  143. 7 Forest
  144. 7 Mountain
  145. 1 Haven of the Spirit Dragon
  146. 4 Temple of Abandon
  147. 4 Wooded Foothills
  148. 2 Draconic Roar
  149. 4 Craters Claws
  150. 1 Roast
  151. 0 SIDEBOARD
  152. 3 Hornet Nest
  153. 3 Destructive Revelry
  154. 3 Wild Slash
  155. 1 Nissa Worldwaker
  156. 3 Xenagos the Reveler
  157. 2 Roast
  158. 0 DECK
  159. 2 Ashcloud Phoenix
  160. 4 Elvish Mystic
  161. 4 Stormbreath Dragon
  162. 4 Sylvan Caryatid
  163. 4 Thunderbreak Regent
  164. 4 Courser of Kruphix
  165. 2 Dragonlord Atarka
  166. 3 Xenagos the Reveler
  167. 6 Forest
  168. 3 Mountain
  169. 3 Haven of the Spirit Dragon
  170. 2 Mana Confluence
  171. 2 Rugged Highlands
  172. 4 Temple of Abandon
  173. 4 Wooded Foothills
  174. 4 Draconic Roar
  175. 3 Craters Claws
  176. 2 Roast
  177. 0 SIDEBOARD
  178. 2 Arbor Colossus
  179. 2 Hornet Nest
  180. 2 Destructive Revelry
  181. 2 Wild Slash
  182. 1 Chandra Pyromaster
  183. 1 Nissa Worldwaker
  184. 1 Mob Rule
  185. 1 Roast
  186. 3 Seismic Rupture
  187. 0 DECK
  188. 4 Elvish Mystic
  189. 4 Goblin Rabblemaster
  190. 3 Heir of the Wilds
  191. 4 Rattleclaw Mystic
  192. 4 Stormbreath Dragon
  193. 4 Thunderbreak Regent
  194. 4 Boon Satyr
  195. 3 Surrak the Hunt Caller
  196. 6 Forest
  197. 5 Mountain
  198. 1 Haven of the Spirit Dragon
  199. 2 Mana Confluence
  200. 1 Rugged Highlands
  201. 4 Temple of Abandon
  202. 4 Wooded Foothills
  203. 2 Draconic Roar
  204. 4 Craters Claws
  205. 1 Roast
  206. 0 SIDEBOARD
  207. 1 Heir of the Wilds
  208. 3 Hornet Nest
  209. 3 Destructive Revelry
  210. 3 Wild Slash
  211. 1 Nissa Worldwaker
  212. 3 Xenagos the Reveler
  213. 1 Roast
  214. 0 DECK
  215. 4 Elvish Mystic
  216. 4 Fanatic of Xenagos
  217. 4 Heir of the Wilds
  218. 3 Rattleclaw Mystic
  219. 4 Stormbreath Dragon
  220. 4 Thunderbreak Regent
  221. 3 Boon Satyr
  222. 3 Surrak Dragonclaw
  223. 6 Forest
  224. 6 Mountain
  225. 2 Mana Confluence
  226. 1 Rugged Highlands
  227. 4 Temple of Abandon
  228. 4 Wooded Foothills
  229. 2 Draconic Roar
  230. 4 Craters Claws
  231. 2 Roast
  232. 0 SIDEBOARD
  233. 2 Hornet Nest
  234. 2 Whisperwood Elemental
  235. 2 Destructive Revelry
  236. 2 Wild Slash
  237. 1 Sarkhan the Dragonspeaker
  238. 3 Xenagos the Reveler
  239. 1 Arc Lightning
  240. 1 Barrage of Boulders
  241. 1 Roast
  242. 0 DECK
  243. 3 Ashcloud Phoenix
  244. 4 Deathmist Raptor
  245. 4 Elvish Mystic
  246. 4 Goblin Rabblemaster
  247. 2 Heir of the Wilds
  248. 4 Rattleclaw Mystic
  249. 4 Stormbreath Dragon
  250. 4 Thunderbreak Regent
  251. 5 Forest
  252. 4 Mountain
  253. 2 Haven of the Spirit Dragon
  254. 2 Mana Confluence
  255. 2 Rugged Highlands
  256. 4 Temple of Abandon
  257. 4 Wooded Foothills
  258. 3 Draconic Roar
  259. 3 Craters Claws
  260. 2 Roast
  261. 0 SIDEBOARD
  262. 3 Hornet Nest
  263. 3 Destructive Revelry
  264. 1 Plummet
  265. 2 Wild Slash
  266. 3 Xenagos the Reveler
  267. 1 Barrage of Boulders
  268. 1 Harness by Force
  269. 1 Roast
  270. 0 DECK
  271. 4 Deathmist Raptor
  272. 4 Elvish Mystic
  273. 4 Goblin Rabblemaster
  274. 3 Heir of the Wilds
  275. 4 Rattleclaw Mystic
  276. 4 Stormbreath Dragon
  277. 4 Thunderbreak Regent
  278. 3 Surrak the Hunt Caller
  279. 6 Forest
  280. 6 Mountain
  281. 2 Mana Confluence
  282. 1 Rugged Highlands
  283. 4 Temple of Abandon
  284. 4 Wooded Foothills
  285. 2 Draconic Roar
  286. 4 Craters Claws
  287. 1 Roast
  288. 0 SIDEBOARD
  289. 3 Hornet Nest
  290. 3 Destructive Revelry
  291. 3 Wild Slash
  292. 3 Xenagos the Reveler
  293. 1 Barrage of Boulders
  294. 2 Roast
  295. 0 DECK
  296. 2 Ashcloud Phoenix
  297. 2 Deathmist Raptor
  298. 4 Elvish Mystic
  299. 4 Goblin Rabblemaster
  300. 4 Rattleclaw Mystic
  301. 4 Stormbreath Dragon
  302. 4 Thunderbreak Regent
  303. 1 Boon Satyr
  304. 1 Dragonlord Atarka
  305. 2 Xenagos the Reveler
  306. 6 Forest
  307. 3 Mountain
  308. 2 Haven of the Spirit Dragon
  309. 2 Mana Confluence
  310. 2 Rugged Highlands
  311. 4 Temple of Abandon
  312. 4 Wooded Foothills
  313. 1 Atarkas Command
  314. 3 Draconic Roar
  315. 1 Arc Lightning
  316. 3 Craters Claws
  317. 1 Roast
  318. 0 SIDEBOARD
  319. 2 Hornet Nest
  320. 3 Outpost Siege
  321. 1 Boon Satyr
  322. 3 Destructive Revelry
  323. 1 Dragonlord Atarka
  324. 2 Arc Lightning
  325. 2 Roast
  326. 1 Scouring Sands
  327. 0 DECK
  328. 4 Elvish Mystic
  329. 4 Goblin Rabblemaster
  330. 1 Heir of the Wilds
  331. 4 Rattleclaw Mystic
  332. 2 Scaleguard Sentinels
  333. 4 Stormbreath Dragon
  334. 4 Thunderbreak Regent
  335. 3 Boon Satyr
  336. 3 Surrak the Hunt Caller
  337. 7 Forest
  338. 6 Mountain
  339. 1 Haven of the Spirit Dragon
  340. 2 Mana Confluence
  341. 4 Temple of Abandon
  342. 4 Wooded Foothills
  343. 2 Draconic Roar
  344. 3 Craters Claws
  345. 2 Roast
  346. 0 SIDEBOARD
  347. 4 Courser of Kruphix
  348. 2 Back to Nature
  349. 1 Dragonlord Atarka
  350. 3 Xenagos the Reveler
  351. 3 Arc Lightning
  352. 2 Roast
  353. /*
RAW Paste Data