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 compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 11 additions and 6 deletions.
  1. +0 −5 src/crosscram/bot.clj
  2. +11 −1 src/crosscram/core.clj
View
5 src/crosscram/bot.clj
@@ -1,5 +0,0 @@
-(ns crosscram.core)
-
-(defprotocol Bot
- (move [game player]
- ""))
View
12 src/crosscram/core.clj
@@ -93,7 +93,7 @@
(not (match/match (:next-player game)
:horizontal (horizontal-pair? pos-a pos-b)
:vertical (vertical-pair? pos-a pos-b)))
- (throw (Exception. "Not a valid vertical or horizontal shape"))
+ (throw (Exception. (str "Not a valid vertical or horizontal shape: " pos-a pos-b)))
;; is someone trying to play on a spot that is already
;; occupied?
@@ -112,5 +112,15 @@
(defn new-game [rows columns start-player]
{:board (board rows columns)
+ :rows rows
+ :columns columns
:next-player start-player
:history []})
+
+(defn play [game bot-a bot-b]
+ (loop [g game
+ bot-funs (cycle [bot-a bot-b])]
+ (if (over? g)
+ g
+ (let [new-game (apply play-piece g ((first bot-funs) g))]
+ (recur new-game (rest bot-funs))))))

No commit comments for this range

Something went wrong with that request. Please try again.