parent
eb7a09fc19
commit
af6ba02012
@ -1,7 +0,0 @@ |
||||
name := "Weeapass" |
||||
|
||||
version := "1.0" |
||||
|
||||
scalaVersion := "2.10.1" |
||||
|
||||
libraryDependencies += "com.beust" % "jcommander" % "1.30" |
@ -1 +0,0 @@ |
||||
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.4.0") |
@ -1,38 +0,0 @@ |
||||
package org.hjiri.weapass |
||||
import com.beust.jcommander.{JCommander, Parameter} |
||||
|
||||
|
||||
/** |
||||
* Created with IntelliJ IDEA. |
||||
* User: jcd |
||||
* Date: 4/25/13 |
||||
* Time: 9:46 PM |
||||
*/ |
||||
object Launcher extends App{ |
||||
object Args { |
||||
// Declared as var because JCommander assigns a new collection declared |
||||
// as java.util.List because that's what JCommander will replace it with. |
||||
// It'd be nice if JCommander would just use the provided List so this |
||||
// could be a val and a Scala LinkedList. |
||||
@Parameter( |
||||
names = Array("-l"), |
||||
description = "When genelatingu wolds use L instead of R") |
||||
var lefto: Boolean = false |
||||
|
||||
@Parameter( |
||||
names = Array("-s"), |
||||
description = "When generating wordsh ushe S instead of SH") |
||||
var shisi: Boolean = false |
||||
} |
||||
|
||||
if (args != null){ |
||||
new JCommander(Args, args.toArray : _*) |
||||
} |
||||
val s:SyllableGenerator = new SyllableGenerator(!Args.shisi, !Args.lefto) |
||||
val w:WordGenerator = new WordGenerator(s) |
||||
for (i <- 1 to Randomizer.pickInt(2,5)){ |
||||
System.out.print (w.generateWord.toString+" ") |
||||
} |
||||
|
||||
|
||||
} |
@ -1,24 +0,0 @@ |
||||
package org.hjiri.weapass |
||||
|
||||
import scala.util.Random |
||||
|
||||
/** |
||||
* Created with IntelliJ IDEA. |
||||
* User: jcd |
||||
* Date: 4/25/13 |
||||
* Time: 11:54 PM |
||||
*/ |
||||
object Randomizer { |
||||
|
||||
val secuRnd: Random = Random.javaRandomToRandom(new java.security.SecureRandom()) |
||||
|
||||
def pickWithProb(prob:Double):Boolean = { |
||||
secuRnd.nextDouble() <= prob |
||||
} |
||||
def pickFrom[T](prob:List[T]): T = { |
||||
prob(secuRnd.nextInt(prob.size)) |
||||
} |
||||
def pickInt(min:Int,max:Int):Int = { |
||||
min + secuRnd.nextInt(max - min) |
||||
} |
||||
} |
@ -1,12 +0,0 @@ |
||||
package org.hjiri.weapass |
||||
|
||||
/** |
||||
* Created with IntelliJ IDEA. |
||||
* User: jcd |
||||
* Date: 4/26/13 |
||||
* Time: 12:14 AM |
||||
*/ |
||||
object Rarity extends Enumeration{ |
||||
type Rarity = Value |
||||
val Common, Uncommon, Youon, Epic, EpicAlt = Value |
||||
} |
@ -1,14 +0,0 @@ |
||||
package org.hjiri.weapass |
||||
|
||||
/** |
||||
* Created with IntelliJ IDEA. |
||||
* User: jcd |
||||
* Date: 4/25/13 |
||||
* Time: 9:49 PM |
||||
*/ |
||||
class Syllable (val consonant: String, val vowel: String, val isYouon: Boolean){ |
||||
val value: String = consonant + vowel |
||||
val consonantOnly : Boolean = vowel == "n" |
||||
val vowelOnly : Boolean = consonant == "" |
||||
override def toString:String = value |
||||
} |
@ -1,83 +0,0 @@ |
||||
package org.hjiri.weapass |
||||
|
||||
/** |
||||
* Created with IntelliJ IDEA. |
||||
* User: jcd |
||||
* Date: 4/25/13 |
||||
* Time: 9:54 PM |
||||
*/ |
||||
class SyllableGenerator (val sInsteadOfsh: Boolean = false, val righto: Boolean = true){ |
||||
val sh = if (sInsteadOfsh) "s" else "sh" |
||||
val r = if (righto) "r" else "l" |
||||
val j = "j" // add option to replace with z? |
||||
|
||||
val commonConsonants = "k" :: sh :: "t" :: "h" :: "n" :: "m" :: r ::Nil |
||||
val uncommonConsonants = "g" :: j :: "d" :: "p" :: "b" ::Nil //gojūon |
||||
val youonConsonants = "y"::Nil //or youon |
||||
val epicConsonants = "w"::Nil |
||||
val epicConsonantsAlt = "v"::Nil |
||||
|
||||
//if (useX) consonants = consonants :+ "x" |
||||
|
||||
val forW = "a"::"o"::Nil // wa\wo |
||||
val forWRare = "i"::"e"::Nil //wi\we |
||||
val forAll = "u"::Nil |
||||
|
||||
val forCommon = forW:::forWRare:::forAll |
||||
val forYouon = forW:::forAll |
||||
|
||||
/** |
||||
* Generates full syllable, consonant+vowel |
||||
* @param youonForce force creating ya\yo\yu syllable |
||||
* @param youonProhibit don't create ?ya\?yo\?yu syllables, for word creation. |
||||
* @return resulting syllable |
||||
*/ |
||||
def generateSyllableF(youonForce:Boolean, youonProhibit:Boolean):Syllable = { |
||||
val rarity = |
||||
if (youonForce){ |
||||
Rarity.Youon |
||||
} else if (Randomizer.pickWithProb(0.80)){ |
||||
Rarity.Common |
||||
} else if (Randomizer.pickWithProb(0.70)){ |
||||
Rarity.Uncommon |
||||
} else if (Randomizer.pickWithProb(0.60)){ |
||||
Rarity.Youon |
||||
} else if (Randomizer.pickWithProb(0.75)){ |
||||
Rarity.Epic |
||||
} else { |
||||
Rarity.EpicAlt |
||||
} |
||||
|
||||
val consonants = rarity match { |
||||
case Rarity.Common => commonConsonants |
||||
case Rarity.Uncommon => uncommonConsonants |
||||
case Rarity.Epic => epicConsonants |
||||
case Rarity.Youon => youonConsonants |
||||
case Rarity.EpicAlt => epicConsonantsAlt |
||||
} |
||||
val consonant = Randomizer.pickFrom(consonants) |
||||
val probOfYouon = if (consonant == j) 0.05 else 0.15 |
||||
var generatedYouon = false |
||||
val vowel = |
||||
if (!youonForce && !youonProhibit && rarity != Rarity.Youon && Randomizer.pickWithProb(probOfYouon)){ |
||||
generatedYouon = true |
||||
generateSyllableF(youonForce = true, youonProhibit = false).toString |
||||
} else { |
||||
val vowels = rarity match { |
||||
case Rarity.Uncommon | Rarity.Common => forCommon |
||||
case Rarity.Epic => if (Randomizer.pickWithProb(0.65)) forW else forWRare |
||||
case Rarity.Youon => forYouon |
||||
case Rarity.EpicAlt => forAll |
||||
} |
||||
Randomizer.pickFrom(vowels) |
||||
} |
||||
new Syllable(consonant,vowel,generatedYouon) |
||||
} |
||||
def generateSyllableF:Syllable = generateSyllableF(youonForce = false, youonProhibit = false) |
||||
|
||||
def generateSyllableV(useN:Boolean):Syllable = { |
||||
val letters = if (useN) "n"::Nil else forCommon |
||||
new Syllable("",Randomizer.pickFrom(letters),false) |
||||
} |
||||
|
||||
} |
@ -1,33 +0,0 @@ |
||||
package org.hjiri.weapass |
||||
|
||||
/** |
||||
* Created with IntelliJ IDEA. |
||||
* User: jcd |
||||
* Date: 4/26/13 |
||||
* Time: 11:04 AM |
||||
*/ |
||||
class Word (val lentgh:Int){ |
||||
var numOfN = 0 |
||||
var numOfYouon = 0 |
||||
var numOfFSyllables = 0 |
||||
var numOfVSyllables = 0 |
||||
private val value:StringBuilder = new StringBuilder() |
||||
def append(syllable:Syllable){ |
||||
value.append(syllable.toString) |
||||
} |
||||
override def toString:String = { |
||||
value.toString() |
||||
} |
||||
def n():Int = { |
||||
numOfN / lentgh * 100 |
||||
} |
||||
def youyon():Int = { |
||||
numOfYouon / lentgh * 100 |
||||
} |
||||
def fsyl():Int = { |
||||
numOfFSyllables / lentgh * 100 |
||||
} |
||||
def vsyl():Int = { |
||||
numOfVSyllables / lentgh * 100 |
||||
} |
||||
} |
@ -1,27 +0,0 @@ |
||||
package org.hjiri.weapass |
||||
|
||||
/** |
||||
* Created with IntelliJ IDEA. |
||||
* User: jcd |
||||
* Date: 4/26/13 |
||||
* Time: 11:03 AM |
||||
*/ |
||||
class WordGenerator(val sg:SyllableGenerator) { |
||||
def generateWord:Word= { |
||||
val word = new Word(Randomizer.pickInt(3,6)) |
||||
var lastYouon = false |
||||
for (i <- 0 to word.lentgh){ |
||||
val syllable = |
||||
if ((0 to 5 contains(word.n())) && Randomizer.pickWithProb(0.25)){ |
||||
sg.generateSyllableV(useN = true) |
||||
} else if ((0 to 15 contains(word.vsyl())) && Randomizer.pickWithProb(0.25)){ |
||||
sg.generateSyllableV(useN = false) |
||||
} else { |
||||
sg.generateSyllableF(youonForce = false, youonProhibit = lastYouon) |
||||
} |
||||
lastYouon = syllable.isYouon |
||||
word.append(syllable) |
||||
} |
||||
word |
||||
} |
||||
} |
Loading…
Reference in new issue