Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelize the playing of games #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/crosscram/engine.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ gives the second player a transposed view of the board.)"
;; there or otherwise be up to no good.

(def over?
"Returns true if there are no horizontal moves possible, false otherwise.
"Returns true if there are no horizontal moves possible, false otherwise.
Takes a board as argument."
(complement game/can-move?))

Expand All @@ -45,9 +45,9 @@ Takes a board as argument."
(recur new-game (rest bot-funs))))))

(defn play-symmetric [game bot-a bot-b games-to-play]
(loop [scoreboard {}]
(if (= games-to-play (apply + (vals scoreboard)))
scoreboard
(let [g1 (winner (play game bot-a bot-b))
g2 (winner (play game bot-b bot-a))]
(recur (merge-with + scoreboard (score g1 g2)))))))
(let [play-round (fn [_]
(->> [(play game bot-a bot-b) (play game bot-b bot-a)]
(map winner)
(apply score)))]
(->> (pmap play-round (range games-to-play))
(reduce (partial merge-with +)))))
3 changes: 2 additions & 1 deletion src/crosscram/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
(:make-move fns-a)
(:make-move fns-b)
num-games)]
(println "Scores:" scores)))))
(println "Scores:" scores)
(shutdown-agents)))))