2012-10-28 03:41:13 -07:00
|
|
|
import scala.xml.pull._
|
|
|
|
import scala.xml._
|
|
|
|
import scala.io.Source
|
|
|
|
|
2013-05-17 18:56:09 -07:00
|
|
|
Console.err.println("loading cards from " + args(0))
|
|
|
|
val src = XML.load(args(0))
|
2012-10-28 03:41:13 -07:00
|
|
|
|
|
|
|
Console.err.println("begin analysis")
|
|
|
|
for (card <- src \ "card") {
|
|
|
|
val name = (card \ "name").text
|
|
|
|
val cost = (card \ "cost").text
|
|
|
|
val loyalty = (card \ "loyalty").text
|
|
|
|
val pow = (card \ "pow").text
|
|
|
|
val tgh = (card \ "tgh").text
|
|
|
|
|
|
|
|
val types = card \ "typelist" \ "type"
|
2013-05-17 18:56:09 -07:00
|
|
|
val rules = card \ "rulelist" \ "rule" ++ card \ "multi" \ "rulelist" \ "rule"
|
2012-10-28 03:41:13 -07:00
|
|
|
|
2012-11-03 18:27:34 -07:00
|
|
|
val normalized_rules = rules
|
|
|
|
.filter(_.text.trim() != "")
|
|
|
|
.map(x => normalize(name, x.text))
|
|
|
|
.foreach(x => Console.println(x))
|
2012-10-28 03:41:13 -07:00
|
|
|
}
|
2012-11-03 18:27:34 -07:00
|
|
|
Console.err.println("complete analysis")
|
2012-10-28 03:41:13 -07:00
|
|
|
|
|
|
|
//normalize the rule text
|
2012-11-03 18:27:34 -07:00
|
|
|
def normalize(name:String, rule:String):String = {
|
|
|
|
val nameBeforeComma = if (name.contains(',')) {
|
|
|
|
name.substring(0, name.indexOf(','));
|
|
|
|
} else {
|
|
|
|
name
|
|
|
|
}
|
2012-11-02 21:49:30 -07:00
|
|
|
|
2012-11-03 18:27:34 -07:00
|
|
|
val abilityWord = if (!rule.startsWith("Choose") && rule.contains('—')) {
|
|
|
|
rule.substring(0, rule.indexOf('—') + 1)
|
2012-11-02 21:49:30 -07:00
|
|
|
} else {
|
2012-11-03 18:27:34 -07:00
|
|
|
name
|
2012-11-02 21:49:30 -07:00
|
|
|
}
|
|
|
|
|
2012-11-03 18:27:34 -07:00
|
|
|
rule
|
|
|
|
.trim
|
|
|
|
.replace(name, "@")
|
|
|
|
.replace(nameBeforeComma, "@")
|
|
|
|
.trim
|
2012-10-28 03:41:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Contains the information about the cards that is needed to play the
|
|
|
|
game.
|
|
|
|
|
|
|
|
<cardlist>
|
|
|
|
<card>
|
|
|
|
<name></name>
|
|
|
|
<cost></cost>
|
|
|
|
<loyalty></loyalty>
|
|
|
|
<typelist>
|
|
|
|
<type></type>
|
|
|
|
...
|
|
|
|
</typelist>
|
|
|
|
<pow></pow>
|
|
|
|
<tgh></tgh>
|
|
|
|
<hand></hand>
|
|
|
|
<life></life>
|
|
|
|
<rulelist>
|
|
|
|
<rule reminder=""></rule>
|
|
|
|
...
|
|
|
|
</rulelist>
|
|
|
|
<multi type="">
|
|
|
|
...
|
|
|
|
</multi>
|
|
|
|
</card>
|
|
|
|
...
|
|
|
|
</cardlist>
|
|
|
|
*/
|