From c0ed5b42124540b0ad2d6dc21fa54e6127237dd6 Mon Sep 17 00:00:00 2001 From: John Stevenson Date: Sat, 29 Dec 2018 16:03:02 +0000 Subject: [PATCH] Refactor play-game function to be pure Added arguments for the board and the player sequence to make the play-game a pure function (uses only arguments passed to it). There are still some side effects however that is only in printing out to the standard out. Using arguments allows you to start the game with different boards and a different player sequence. This can be useful for testing purposes too. --- src/tictactoe_cli/core.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tictactoe_cli/core.clj b/src/tictactoe_cli/core.clj index 764bde4..c39dc44 100644 --- a/src/tictactoe_cli/core.clj +++ b/src/tictactoe_cli/core.clj @@ -202,7 +202,7 @@ "The game loop. We iterate through the player sequence (alternate player turns) until there is a winner or the board is full." - [] + [starting-board player-sequence] (loop [board starting-board player-sequence player-sequence] (let [winner (winner? board)] @@ -217,4 +217,4 @@ (rest player-sequence)))))) -(play-game) +(play-game starting-board player-sequence)