Permalink
Browse files

rock-paper-scissors draft complete

update license to exact match clojure license
  • Loading branch information...
1 parent 96f0b66 commit c96dc78986436b10d2b1bb74dc65ab89d32937be @stuarthalloway stuarthalloway committed Mar 10, 2010
Showing with 80 additions and 15 deletions.
  1. +0 −13 LICENSE
  2. +12 −0 README.markdown
  3. +1 −1 src/labrepl/lab.clj
  4. +66 −0 src/labs/rock_paper_scissors.clj
  5. +1 −1 src/solutions/rock_paper_scissors.clj
View
13 LICENSE
@@ -1,13 +0,0 @@
-Clojure labrepl
-Copyright 2010, Relevance, Inc.
-
-The lab solutions (files in the src/solutions directory) are licensed
-under the Eclipse Public License (see epl-v10.html).
-
-The lab platform (everything outside the lab solutions) is free for
-individual personal use. All other rights are reserved by Relevance,
-Inc. Contact Stuart Halloway (stu@thinkrelevance.com) if you have a
-question about using these materials.
-
-You must not remove this notice, or any other, from this software.
-
View
@@ -1,6 +1,18 @@
# labrepl for Clojure
Copyright (c) Relevance, Inc. All rights reserved.
+The use and distribution terms for this software are covered by the
+Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+which can be found in the file epl-v10.html at the root of this distribution.
+By using this software in any fashion, you are agreeing to be bound by
+the terms of this license.
+You must not remove this notice, or any other, from this software.
+
+# Breaking News
+
+The first use of the labrepl will be the March 15, 2010 run of the
+Clojure Studio: (http://pragmaticstudio.com/clojure). If you are looking
+at labrepl before that date, then QA is not complete. Expect a few oddities.
# Getting Started
View
@@ -7,7 +7,7 @@
[]
[:intro :names-and-places :its-all-data :project-euler
:mini-browser :unified-update-model :zero-sum :cellular-automata
- :defstrict])
+ :defstrict :rock-paper-scissors])
(defn lab-url
[lab-name]
@@ -0,0 +1,66 @@
+(ns #^{:skip-wiki true} labs.rock-paper-scissors
+ (:use labrepl.util solutions.rock-paper-scissors))
+
+(defn overview
+ []
+ [[:h3 "Overview"]
+ [:p "Clojure's protocols and types are a more powerful and flexible alternative to interfaces and classes. They solve the expression problem, allowing you to extend old things that you don't control, and allowing old code to easily use new, all with performance consistent with the fastest forms fof virtual invocation available on the host platform (e.g. Java)."]
+ [:p "We won't explore all the power at once. In this lab, you will get your feet wet using protocols and types to simulate players in the classic rock-paper-scissors game. I got the idea for this texercise from an episode of the " [:a {:href "http://www.rubyquiz.com/quiz16.html"} "Ruby Quiz"] "."]])
+
+(defn the-rules
+ []
+ [[:h3 "The Rules"]
+ [:ol
+ [:li "The rules are pretty simple. Rock beats scissors, scissors beats paper, and paper beats rock. Write an idiomatic Clojure function " (c dominates) " that returns the thing that dominates the argument passed in."
+ (showme dominates)]
+ [:li "Create a " (c choices) " set that contains the possible choices. Don't Repeat Yourself."
+ (showme choices)]
+ [:li "Create a " (c winner) " function that takes two players' choices, and returns the winner, or " (c nil) " for a tie:"
+ (showme winner)]
+ [:li "Create a " (c draw?) " predicate that takes two players' choices and returns true if they are a draw."
+ (showme draw?)]
+ [:li "Create an " (c iwon?) " predicate that takes two players' choices and returns true if the first player won."
+ (showme iwon?)]]])
+
+(defn the-players
+ []
+ [[:h3 "The Players"]
+ [:ol
+ [:li "All the players will conform to a " (c Player) " protocol. It should have two methods: "
+ [:ol
+ [:li (c choose) " takes a player and returns that player's choice"]
+ [:li (c update-strategy) " takes a player, that player's last choice, and the other player's last choice, returning the " (c Player) " for the next round"]]
+ (showme Player)]
+ [:li "Use " (c deftype) " to define a " (c Random) " player. " (c Random) " always picks at random, and never changes strategy based on what the other player is doing."
+ (showme Random)]
+ [:li "Create " (c Stubborn) ", who is initialized with a choice and sticks with it come hell or high water:"
+ (showme Stubborn)]
+ [:li "Create " (c Mean) ", who is a little more subtle. " (c Mean) "sticks with what worked last time, or plays at random following a loss:"
+ (showme Mean)]
+ [:li "Now let's play the " (c game) ", with three arguments: two players and a number of rounds. " (c game) " reads nicely as a loop with five arguments:"
+ [:ol
+ [:li "player 1"]
+ [:li "player 2"]
+ [:li "player 1's current score"]
+ [:li "player 2's current score"]
+ [:li "the number of rounds remaining"]]
+ "The game should return the two player's scores in a map."
+ (showme game)]
+ [:li "Try some games with the various players. Do the results match your intuition?"]]])
+
+(defn bonus
+ []
+ [[:h3 "Bonus"]
+ [:ol
+ [:li "Create some other strategies."]
+ [:li "Compare your solution with some of the " [:a {:href "http://www.rubyquiz.com/quiz16.html"}"Ruby Quiz solutions"] ". What are the salient differences?"]
+ [:li "How would you parallelize the code to spread games out to all your cores?"]
+ [:li "Extend the simulation to support " [:a {:href "http://www.samkass.com/theories/RPSSL.html"} "Rock Paper Scissors Spock Lizard"]]]])
+
+(defn instructions
+ []
+ (concat
+ (overview)
+ (the-rules)
+ (the-players)
+ (bonus)))
@@ -5,7 +5,7 @@
:scissors :rock
:paper :scissors})
-(def choices #{:rock :paper :scissors})
+(def choices (set (keys dominates)))
(defn random-choice []
(nth (vec choices) (rand-int (count choices))))

0 comments on commit c96dc78

Please sign in to comment.