This repository has been archived by the owner on Oct 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
From having "zones with cards" to "cards with zones" #122
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
260fb04
rules first steps
Masclins 0ab7be6
count-cards
Masclins 1a5311f
play-card
Masclins abf9ce4
victory-conditions
Masclins 9de9b1f
str player-id
Masclins 7d9142f
playing-id on play
Masclins 9f8dd72
get-game-as-player
Masclins 781a2b8
added some tests
Masclins 1966eeb
:player-ids
Masclins 092288e
coded ids
Masclins 0e9c14e
tests included
Masclins c4cc071
get-status
Masclins 6ba6f53
Create Game Lobby
041b5da
Join Game Lobby
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
(ns api.base-test | ||
(:require [expectations.clojure.test :refer :all] | ||
[clojure.test :as ctest] | ||
[mocking :as mocking] | ||
[api.base :as api] | ||
[configs.messages :as messages])) | ||
|
||
(ctest/use-fixtures :each mocking/mock-persistence) | ||
|
||
(defexpect create-game | ||
|
||
(let [game (api/create-game)] | ||
; Checking it has been created | ||
(expect | ||
#(contains? % :game-id) | ||
game) | ||
|
||
(expect | ||
#(contains? % :player-id) | ||
game) | ||
|
||
(expect | ||
#(= 5 (count (:rows %))) | ||
game))) | ||
|
||
(defexpect add-player | ||
(let [game (api/create-game) | ||
opponent (api/add-player (:game-id game))] | ||
(expect | ||
#(contains? % :player-id) | ||
opponent) | ||
|
||
(expect | ||
#(not (contains? % :error)) | ||
opponent) | ||
|
||
(expect | ||
true | ||
(= (:game-id game) (:game-id opponent))) | ||
|
||
; A third player causes an error | ||
(expect | ||
{:error messages/too-many-players} | ||
(api/add-player (:game-id game))) | ||
|
||
(expect | ||
false | ||
(= (:player-id game) (:player-id opponent))))) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns mocking | ||
(:require [persistence.persistence :as persistence])) | ||
|
||
(def mock-game (atom nil)) | ||
|
||
(defn mock-persistence | ||
[tests] | ||
(with-redefs | ||
[persistence/next-id (constantly 0) | ||
persistence/save-game (fn [a] | ||
(reset! mock-game a)) | ||
persistence/fetch-game (fn [x] | ||
@mock-game)] | ||
(tests)) | ||
(reset! mock-game nil)) |
File renamed without changes.
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(ns configs.player-ids) | ||
|
||
(def default-player-ids | ||
["p0" "p1"]) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns rules.count-cards) | ||
|
||
(defn count-cards | ||
"Count all cards that has keys as in condition an sums their summand" | ||
[game-state condition & summand] | ||
(let [k (vec (keys condition)) | ||
summand (first summand)] | ||
(reduce | ||
#(if (= (select-keys %2 k) condition) | ||
(if (some? summand) | ||
(+ %1 (summand %2 0)) | ||
(inc %1)) | ||
%1) | ||
0 | ||
(:cards game-state)))) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
(ns rules.create-game | ||
(:require [configs.hands :as hands] | ||
[configs.rows :as rows])) | ||
[configs.rows :as rows] | ||
[configs.player-ids :as player-ids])) | ||
|
||
(defn new-player | ||
"Creates a new player object" | ||
[hand] | ||
{ | ||
:hand hand | ||
}) | ||
(defn locate-in-hand | ||
"Creates location for a vec of cards on player's hand" | ||
[hand player] | ||
(vec (map #(assoc % :location [:hand] :owner player) | ||
hand))) | ||
|
||
(defn new-game | ||
"Creates a new game object" | ||
([] (new-game {})) | ||
([ini-config] | ||
{ | ||
|
||
:players (let [hands (:hands ini-config hands/default-hands)] | ||
[(new-player (first hands)) | ||
(new-player (second hands))]) | ||
|
||
:rows (vec (reduce | ||
#(concat %1 [{:limit %2 :cards []}]) | ||
[] | ||
(:limits ini-config rows/default-limits))) | ||
:next-play [nil nil] | ||
})) | ||
(let [player-ids (:player-ids ini-config player-ids/default-player-ids)] | ||
{ | ||
:player-ids player-ids | ||
:cards (let [hands (:hands ini-config hands/default-hands)] | ||
(vec (concat (locate-in-hand (first hands) (first player-ids)) | ||
(locate-in-hand (second hands) (second player-ids))))) | ||
:rows (vec (reduce | ||
#(concat %1 [{:limit %2}]) | ||
[] | ||
(:limits ini-config rows/default-limits))) | ||
:next-play {} | ||
}))) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost went crazy during the weekend til I realized that I needed to pass the player-ids to the
new-game
constructor (which is perfectly logical, I might add) instead of putting them byassoc
post-construction as with thegame-id
. In fact, I think thegame-id
should also be passed in and added to the game innew-game
to ease the logic (everything is done at construction instead of modifying stuff afterwards)