Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Showing with 49 additions and 4 deletions.
  1. +0 −4 README
  2. +18 −0 README.md
  3. +14 −0 app/controllers/Application.scala
  4. +15 −0 app/views/statistics.scala.html
  5. +2 −0 conf/routes
View
4 README
@@ -1,4 +0,0 @@
-This is your new Play 2.0 application
-=====================================
-
-This file will be packaged with your application, when using `play dist`.
View
18 README.md
@@ -0,0 +1,18 @@
+## Monty Hall using Play 2.0 with Scala
+This is the source code for the Monty Hall Problem i used to demo the Play framework 2.0 at a hacking night at Evry in Gothenburg april 2012.
+
+There are branches for each step in the development.
+
+* 00_play_new
+* 01_enter_player_name
+* 02_choose_door
+* 03_stay_or_switch
+* 04_tests
+* 05_statistics
+
+### More on the Monty Hall problem
+http://en.wikipedia.org/wiki/Monty_Hall_problem
+
+### License
+This little app is licensed under WTFPL
+http://sam.zoy.org/wtfpl/
View
14 app/controllers/Application.scala
@@ -71,4 +71,18 @@ object Application extends Controller {
}.getOrElse(NotFound)
}
+ def statistics(noOfGames: Int) = Action {
+ val games = for (i <- 1 to noOfGames) yield {
+ val game = Game(playerName = "Kayser Söze")
+ game.initialPlayerDoor = 1
+ val goatDoor = game.goatDoor
+ if (goatDoor == 2)
+ game.stayOrSwitch(3)
+ else
+ game.stayOrSwitch(2)
+ game
+ }
+ Ok(html.statistics.render(noOfGames, games.filter(_.won).length));
+ }
+
}
View
15 app/views/statistics.scala.html
@@ -0,0 +1,15 @@
+@(gamesRun: Int, gamesWon: Int)
+
+@import helper._
+
+@main(gamesRun + " Games run") {
+
+<div class="main-content start">
+
+ <div class="doors">
+ <h3>Running @gamesRun games, we won @gamesWon, by switching door all the time.
+ This is @{ "%1.2f" format gamesWon.toDouble / gamesRun.toDouble * 100 }%.
+ </h3>
+ </div>
+</div>
+}
View
2 conf/routes
@@ -10,5 +10,7 @@ GET /games/:id controllers.Application.game(id: L
POST /games/:id/selectDoor/:doorNo controllers.Application.selectDoor(id: Long, doorNo: Int)
POST /games/:id/stayOrSwitch/:doorNo controllers.Application.stayOrSwitch(id: Long, doorNo: Int)
+GET /statistics/:noOfGames controllers.Application.statistics(noOfGames: Int)
+
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)

No commit comments for this range

Something went wrong with that request. Please try again.