Skip to content

Commit

Permalink
Refactor play-game function to be pure
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
practicalli-johnny committed Dec 29, 2018
1 parent cef31c5 commit c0ed5b4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/tictactoe_cli/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -217,4 +217,4 @@
(rest player-sequence))))))


(play-game)
(play-game starting-board player-sequence)

0 comments on commit c0ed5b4

Please sign in to comment.