This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val wager = "Great! How much do you want to wager?" | |
val leave = "Well, thanks for coming out today, partner." | |
val again = "I didn't quite catch that, sonny. You'll have to speak up." | |
val get = readLine() | |
class wagers | |
println(wager) | |
class leaves | |
println(leave) | |
class agains |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object coinFlip { | |
val wager = "Great! How much do you want to wager?" | |
val leave = "Well, thanks for coming out today, partner." | |
val again = "I didn't quite catch that, sonny. You'll have to speak up." | |
val get = readLine() | |
def continue(p: String): String = p.toLowerCase match { | |
case y "yes" => wager | |
case n "no" => leave |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CCCC | |
object coinFlip { | |
val wagers = "Great! How much do you want to wager?" | |
val headsTails = "Do you want to bet heads or tails? " | |
val freddy = "Remember, Honest Freddy needs you to bet in increments of 25 credits: " | |
val freddy2 = "If you don't bet in exact increments of 25 credits, Freddy will just bet 25 credits for you." | |
val heads = "Do you want to bet heads or tails? " | |
val heads2 = "If Honest Freddy doesn't understand whether you picked heads or tails, he'll just bet heads for you." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wager(bet: Int, heads: Int, total: Int, flip: Int): (Boolean, Int, Int) = { | |
if(total > 1000) = heads match { | |
case 0 => (false, 1, total-bet) | |
case 1 => (false, 0, total-bet) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object WagerGameAction extends GameAction { | |
def execute(gameState: GameState): GameState = gameState match { | |
case Wager(stake) => { | |
println(wagers) | |
print(increments25) | |
print(increments25ForYou) | |
val betVal = readLine() | |
val realBet = confirm(scala.math.abs(betVal.toInt)) | |
if (!afford(realBet, stake)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object coinFlip { | |
val wagers = "Great! How much do you want to wager? " | |
val increments25 = "Remember, Honest Freddy needs you to bet in increments of 25 credits: " | |
val increments25ForYou = "If you don't bet in exact increments of 25 credits, Freddy will just bet 25 credits for you. " | |
val headsTails = "Do you want to bet heads or tails? " | |
val freddyBet = "If Honest Freddy doesn't understand whether you picked heads or tails, he'll just bet heads for you. " | |
val leave = "Well, thanks for coming out today, partner. " | |
val again = "I didn't quite catch that, sonny. You'll have to speak up. " | |
val ready = "Are you ready for another match of Outback CoinFlip? " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object tttmeanderings { | |
sealed trait GameState | |
case class Welcome extends GameState | |
case class Ready extends GameState | |
case class Player extends GameState | |
case class GetMove extends GameState | |
case class Convert extends GameState | |
case class Process extends GameState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TTT API requirements | |
object tttmeanderings { | |
//make a move (which takes a board state gives me back the updated board state) | |
// | |
//ask who won (which only takes a board state that represents a finished game and tells me that X's won, O's won, or it was a draw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> combinations(3, List('a, 'b, 'c, 'd, 'e, 'f, 'g, h', i', j', k', l')) | |
res0: List[List[Symbol]] = List(List('a, 'b, 'c), List('a, 'b, 'd), List('a, 'b, 'e), ... | |
def combinations[A](size: Int, pool: List[A]): List[List[A]] = pool match { | |
case Nil => Nil | |
case h :: t => if(size <= 0) Nil else if (size == 1) { | |
list(h) :: combinations(size, t) | |
} else { | |
helper(h, combinations(size-1, t) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TTT API requirements | |
object tttmeanderings { | |
//make a move (which takes a board state gives me back the updated board state) | |
// | |
//ask who won (which only takes a board state that represents a finished game and tells me that X's won, O's won, or it was a draw) |
OlderNewer