Permalink
Browse files

changed everything, rewrote the code twice, added ai, added quil.

  • Loading branch information...
Marco Munizaga
Marco Munizaga committed Dec 7, 2012
1 parent 480bc33 commit 07f6890a8d98d0ba08ad267d98490fa6eedb8093
Showing with 1,332 additions and 123 deletions.
  1. +0 −1 .gitignore
  2. +4 −2 README.md
  3. +0 −103 chainshot2.clj
  4. +111 −0 flowchart.txt
  5. +3 −3 project.clj
  6. +34 −2 src/beadgame/chainshot.clj
  7. +355 −0 src/beadgame/chainshot2.clj
  8. +679 −0 src/beadgame/chainshot3.clj
  9. +5 −5 startBoard
  10. +0 −5 startBoardFlaw
  11. BIN target/beadgame-0.1.0-standalone.jar
  12. BIN target/beadgame-0.1.0.jar
  13. BIN target/beadgame-3.0-standalone.jar
  14. BIN target/beadgame-3.0.jar
  15. 0 target/native/linux/x86/.gitkeep
  16. BIN target/native/linux/x86/libgluegen-rt.so
  17. BIN target/native/linux/x86/libjogl.so
  18. BIN target/native/linux/x86/libjogl_awt.so
  19. BIN target/native/linux/x86/libjogl_cg.so
  20. 0 target/native/linux/x86_64/.gitkeep
  21. BIN target/native/linux/x86_64/libgluegen-rt.so
  22. BIN target/native/linux/x86_64/libjogl.so
  23. BIN target/native/linux/x86_64/libjogl_awt.so
  24. BIN target/native/linux/x86_64/libjogl_cg.so
  25. 0 target/native/macosx/x86/.gitkeep
  26. BIN target/native/macosx/x86/libgluegen-rt.jnilib
  27. BIN target/native/macosx/x86/libjogl.jnilib
  28. BIN target/native/macosx/x86/libjogl_awt.jnilib
  29. BIN target/native/macosx/x86/libjogl_cg.jnilib
  30. 0 target/native/macosx/x86_64/.gitkeep
  31. BIN target/native/macosx/x86_64/libgluegen-rt.jnilib
  32. BIN target/native/macosx/x86_64/libjogl.jnilib
  33. BIN target/native/macosx/x86_64/libjogl_awt.jnilib
  34. BIN target/native/macosx/x86_64/libjogl_cg.jnilib
  35. 0 target/native/windows/x86/.gitkeep
  36. BIN target/native/windows/x86/gluegen-rt.dll
  37. BIN target/native/windows/x86/jogl.dll
  38. BIN target/native/windows/x86/jogl_awt.dll
  39. BIN target/native/windows/x86/jogl_cg.dll
  40. 0 target/native/windows/x86_64/.gitkeep
  41. BIN target/native/windows/x86_64/gluegen-rt.dll
  42. BIN target/native/windows/x86_64/jogl.dll
  43. BIN target/native/windows/x86_64/jogl_awt.dll
  44. BIN target/native/windows/x86_64/jogl_cg.dll
  45. +1 −1 target/repl-port
  46. +1 −1 target/stale/dependencies
  47. +5 −0 test-boards/test1
  48. +22 −0 test-boards/test10
  49. +25 −0 test-boards/test11
  50. +5 −0 test-boards/test2
  51. +8 −0 test-boards/test3
  52. +8 −0 test-boards/test4
  53. +10 −0 test-boards/test5
  54. +10 −0 test-boards/test6
  55. +12 −0 test-boards/test7
  56. +16 −0 test-boards/test8
  57. +18 −0 test-boards/test9
View
@@ -2,7 +2,6 @@
/classes
/checkouts
pom.xml
-*.jar
*.sw?
*.class
.lein-deps-sum
View
@@ -10,14 +10,16 @@ All the ladies love Clojure!
To compile the code and package it into a jar, just run:
` lein uberjar `
-Or you can just run the standalone jar that's included in the target.
- ` java -jar target/beadgame-0.1.0-standalone.jar `
+The you can just run the standalone jar that's included in the target.
+ ` java -jar target/beadgame-3.0-standalone.jar `
When you start the game it will ask you for an initial board file, this board file is a space delimited columns, new lime delimited rows. You can use any colours.
Example initial boards are provided as startBoard, startBoard2 ...
The game will explain the rest of the instructions
+## Simple flow chart
+Check flowchart.txt
## License
View
@@ -1,103 +0,0 @@
-(ns beadgame.chainshot2)
-
-
-
-(defmacro dbg[x] `(let [x# ~x] (println "dbg:" '~x "=" x#) x#))
-
-
-
-
-(defn readFile
- "Read the file starting board file"
- [filename]
- (let [filecontents (slurp filename)]
- (println "Reading file" filename)
- (def file filecontents)))
-
-
-
-
-(comment
-
- The nodes wil work something like this
-
-
- {
- :right other-node
- :up nil}
-
-
- (def root-node
- { :right other-node
- :up nil})
-
- (def other-node2
- { :right nil
- :up nil})
-
- (def other-node
- { :right nil
- :up other-node2})
-
- (readFile "startBoard")
- (def file (reverse (clojure.string/split file #"\n")))
-
- (def file (map #(clojure.string/split % #" ") file))
-
- (def node-file (map (fn [row] (map #(assoc {:up nil :right nil} :val %) row)) file))
-
- ((first file) 0)
- (first node-file)
-
- (if (seq '(1))
- (println "truthy")
- (println "falsy"))
-
-
- (let [root-row (first node-file)]
- (loop [first-element (first root-row)
- rest-elements (rest root-row)]
- (if (seq rest-elements)
- (recur
- (conj-graph :right first-element (first rest-elements))
- (rest rest-elements))
- first-element)))
-
-
- (conj-array :right (first (first node-file)) (rest (first node-file)))
-
-
-
-
- )
-
-
-(conj-graph :right root-node other-node2)
-
-conj-graph
-
-(def a [:up :right])
-
-(defn conj-array
- "conj-graphs a root node to an array of items in that order"
- [direction root-node rest-elements]
- (loop [first-element root-node
- rest-elements rest-elements]
- (if (seq rest-elements)
- (recur
- (conj-graph direction first-element (first rest-elements))
- (rest rest-elements))
- first-element)))
-
-(defn conj-graph
- "Connects two nodes, the parents to the child.
- If there is alread a node on the parents right it will be recursively placed
- Specify the direction as in :up"
-
- [direction parent child]
- (if (nil? (parent direction))
- (assoc parent direction child)
- (assoc parent direction (conj-graph direction (parent direction) child))))
-
-
-))))))))))
View
@@ -0,0 +1,111 @@
+++-------------+
+| |
+| |
+| |
++--------------+
+
+
+
+
+
+
+
+
+
++-----------+
+| Main menu |
++----+------+
+ |
+ v
+ +-----------+
+ | play game |----------------------------------------------------+
+ | | |
+ +-----------+ v
+ +--------------+
+ +-----------+ | Prompt move |
+ | Genetic |----------------------+ +------>| |
+ | algorithm | | | | |
+ +-----------+ v | +--------------+
+ +----------------+ | |
+ +-----------+ | circle-of-life | | v
+ | greedy |-------+ | | | +--------------+
+ | search | | | | | | find-cluster |
+ +-----------+ | +----------------+ | | |
+ | | | | |
+ +-----------+ | v | +--------------+
+ | Exhaustive| | +----------------+ | |
+ | |-+ | |generate strands| | v
+ +-----------+ | | | | | +--------------+
+ | | | | | | choose-move |
+ | | +----------------+ | | |
+ | | | | | |
+ | | v | +------+-------+
+ | | +----------------+ | |
+ | | | fitness | +--------------+
+ | | +-> | |
+ | | | | |
+ | | | +----------------+
+ | | | |
+ | | | v
+ | | | +----------------+
+ | | | | selection |
+ | | | | |
+ | | | | |
+ | | | +----------------+
+ | | | |
+ | | | v
+ | | | +----------------+
+ | | +---| breed |
+ | | | |
+ | | | |
+ | | +----------------+
+ | |
+ | |
+ | | +-------------------+
+ | +------->| find-all-clusters |
+ | | |<---+
+ | | | |
+ | +-------------------+ |
+ | | |
+ | v |
+ | +----------------+ |
+ | | pick biggest | |
+ | | cluster | -----+
+ | | |
+ | +----------------+
+ |
+ |
+ |
+ |
+ | +-------------------+
+ | | max cluster from |
+ +--------------->| find-all-clusters |
+ +------------- | |
+ | +-------------------+ ---------------+
+ | | |
+ v v v
+ +-------------------+ +-------------------+ +-------------------+
+ | max cluster from | | max cluster from | | max cluster from |
+ | find-all-clusters | | find-all-clusters | | find-all-clusters |
+ | for children | | for children | | for children |
+ +-------------------+ +-------------------+ +-------------------+
+ | | |
+ v v v
+ ... +-------------------+ ...
+ | recursively |
+ | iterate |
+ | |
+ +-------------------+
+ |
+ v
+ ...
+
+
+
+
+
+
+
+
+
+
View
@@ -1,7 +1,7 @@
-(defproject beadgame "0.1.0"
+(defproject beadgame "3.0"
:description "Bitchin' Chainshot game"
:license {:name "GPL"
:url "http://www.gnu.org/licenses/gpl.html"}
- :dependencies [[org.clojure/clojure "1.4.0"]]
- :main beadgame.chainshot)
+ :dependencies [[org.clojure/clojure "1.4.0"] [criterium "0.3.1"] [quil "1.6.0"]]
+ :main beadgame.chainshot3)
View
@@ -58,7 +58,8 @@
; When we find an empty vector we get rid of it
(try
- (let [ color (getColor boardState x y) [startCol endCol] (findRange (getRow boardState x) y color) ]
+ (let [ color (getColor boardState x y)
+ [startCol endCol] (findRange (getRow boardState x) y color) ]
(vec (filterColumns boardState startCol endCol x y color)))
(catch Exception e boardState)))
@@ -87,7 +88,7 @@
(defn calculatePoints [currentState nextState]
(let [delta (- (piecesLeft currentState) (piecesLeft nextState))]
- (if (< 1 delta)
+ (if (< 2 delta)
(Math/pow (- delta 2) 2)
0 )))
@@ -109,6 +110,37 @@
(println "After you pick a move I will calculate how many points you \"deserve\"")
(println "After you have exhausted all the moves, the game is over and at least one of us will be dissapointed"))
+(comment
+ (printBoard currentState)
+ (println (readFile "startBoard"))
+ currentState
+ file
+ (keepPlaying currentState)
+ (def currentState (readFile "startBoard"))
+ (slurp "startBoard")
+
+ (def asdf (getPossibleMoves currentState))
+
+
+
+
+ (def asdf (filter #(< 1 (first %)) asdf))
+
+ (first asdf)
+
+ )
+
+(defn getPossibleMoves
+ "Returns a seq with delta pieces as well as the coordinatess forthe moves"
+ [currentState]
+ (let [startPieceCount (piecesLeft currentState)]
+ (->>
+ (for [x (range colLength) y (range rowLength)
+ :let [nextState (chooseMove currentState x y)
+ pointsGained (calculatePoints currentState nextState)]]
+ [pointsGained x y])
+ (filter #(pos? (first %)))))) ;only care about the moves which loose > 2 pieces because those are the only valid ones
+
(defn playGame []
"Would you like to play a game?"
(println "Would you like to play a game?")
Oops, something went wrong.

0 comments on commit 07f6890

Please sign in to comment.