added word generator. makes funny words. fixed bug with using only "u" for syllableV

master
Henry Jameson pirms 11 gadiem
vecāks f1f4f7d766
revīzija 0fb2d1019f
  1. 3
      src/Randomizer.scala
  2. 4
      src/SyllableGenerator.scala
  3. 31
      src/Word.scala
  4. 25
      src/WordGenerator.scala
  5. 63
      src/testing.sc

@ -16,4 +16,7 @@ object Randomizer {
def pickFrom[T](prob:List[T]): T = {
prob(secuRnd.nextInt(prob.size))
}
def pickInt(min:Int,max:Int):Int = {
min + secuRnd.nextInt(max - min)
}
}

@ -73,8 +73,8 @@ class SyllableGenerator (val useX: Boolean, val sInsteadOfsh: Boolean = false, v
}
def generateSyllableF:Syllable = generateSyllableF(youonForce = false, youonProhibit = false)
def generateSyllableV(includeN:Boolean):Syllable = {
val letters = if (includeN) forAll:+"n" else forAll
def generateSyllableV(useN:Boolean):Syllable = {
val letters = if (useN) "n"::Nil else forCommon
new Syllable("",Randomizer.pickFrom(letters),false)
}

@ -0,0 +1,31 @@
/**
* 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
}
}

@ -0,0 +1,25 @@
/**
* 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 25 contains(word.vsyl())) && Randomizer.pickWithProb(0.49)){
sg.generateSyllableV(useN = false)
} else {
sg.generateSyllableF(youonForce = false, youonProhibit = lastYouon)
}
lastYouon = syllable.isYouon
word.append(syllable)
}
word
}
}

@ -7,29 +7,42 @@
* sample workspace file to view how generator behaves.
*/
val s:SyllableGenerator = new SyllableGenerator(false, false, true)
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
val w:WordGenerator = new WordGenerator(s)
for (i <- 1 to 50){
System.out.println (w.generateWord.toString+" ")
}

Notiek ielāde…
Atcelt
Saglabāt