This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn annotate-assignments [apprentices duties] | |
(-> apprentices | |
(assign-foreman) | |
(assign-av av-experienced) | |
(assign-av av-novice) | |
(assign-all-required-duties duties) | |
(assign-all-remaining-apprentices duties) | |
)) | |
(defn assign [apprentices duties unavailable foreman] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String parseRequest() throws IOException { | |
String line = ""; | |
StringBuilder stringBuilder = new StringBuilder(); | |
while((line = clientRequest.readLine()) != null){ | |
stringBuilder.append(line + "--break--"); | |
if (line.equals("")) { | |
return stringBuilder.toString() + "--break--" + parseRequestBody(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String parseRequest() throws IOException { | |
String line; | |
StringBuilder stringBuilder = new StringBuilder(); | |
while((line = clientRequest.readLine()) != null){ | |
stringBuilder.append(line); | |
if (line.equals("")) { | |
return stringBuilder.toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String parseRequest() throws IOException { | |
String line = ""; | |
StringBuilder stringBuilder = new StringBuilder(); | |
while(clientRequest.ready()) { | |
stringBuilder.append((char) clientRequest.read()); | |
} | |
return stringBuilder.toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn next-move [board player-x player-o] | |
(player-move-message (current-piece board)) | |
(print-board board) | |
(let [move (get-move (current-player board player-x player-o) board)] | |
(if (valid-move? board move) | |
(apply-move board move) | |
(recur board player-x player-o)))) | |
(defn play [board player-x player-o] | |
(loop [board board player-x player-x player-o player-o] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def player-types ["human" "computer" "ai"]) | |
(defmulti get-move (fn [current-player board] (:player-type current-player))) | |
(defmethod get-move "human" [current-player board] | |
(get-human-move)) | |
(defmethod get-move "computer" [current-player board] | |
(get-random-move board)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; tictactoe.core.clj | |
(defn -main [] | |
(play (new-board 9) (get-player (first piece)) (get-player (second piece)))) | |
;; tictactoe.game.clj | |
(defn get-player [piece] | |
(let [player-type (get-player-type piece)] | |
(if (valid-type? player-type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def x-player-type (atom "human")) | |
(def o-player-type (atom "human")) | |
(def player-types ["human" "computer" "ai"]) | |
(defn current-player-type [board] | |
(if (= (current-player board) (first piece)) | |
@x-player-type | |
@o-player-type)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def x-player-type (atom "human")) | |
(def o-player-type (atom "human")) | |
(defn update-player-types [player-piece new-type] | |
(if (= player-piece (first piece)) ;; (first piece) is "X" | |
(reset! x-player-type new-type) | |
(reset! o-player-type new-type))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def player-types (atom [])) | |
(defn update-player-types [player-type] | |
(swap! player-types conj player-type)) | |
(update-player-types "human") | |
(update-player-types "computer") |