Writing a Tile-Matching Game
FP StyleHakim Cassimally
@osfameron, @lambdamcr
(({:colour :red} {:colour :red} {:colour :red} {:colour :blue} {:colour :blue}) ({:colour :green} {:colour :green} {:colour :red} {:colour :red} {:colour :blue})({:colour :red} {:colour :green} {:colour:blue} {:colour :blue} {:colour :blue})({:colour :green} {:colour :green} {:colour :green} {:colour :green} {:colour :blue})({:colour :red} {:colour :green} {:colour :green} {:colour :red} {:colour :blue}))
{:colour :blue:type :candy}
(map (partial partition-by :colour))
(map (partial partition-by :colour))
(map match)(defn match [groups](filter#(>= (count %) 3)groups))
(map match)(defn match [groups](filter#(>= (count %) 3)groups))
[0 0][ [1 0] [2 0]
[0 0][ [1 0] [2 0] [3 0]
[0 0][ [1 0] [2 0] [3 0] [4 0] ]
zip(defn zip [list1 list2](map vector list1 list2))
(defn zip-over-grid [list1 list2](map zip list1 list2))
(repeat (range)) (map repeat (range))
...
...
...
...
...
...
...
...
...
...... ...
...
...
...
......
...
+
(defn transpose [m](apply map vector m))
(defn points [runs](->> runs
(map count)(apply +)))
= 19
State or Change?
{:colour :blue:pos [0 1]:to [1 1]:animate :fall}
Display
User Input
Check Matches
Remove Matches
Adjust Score
Fall/Fill (animate)
{:score 0}:grid
}
{:score 0}:grid
}
Display
User Input
Check Matches
Remove Matches
Adjust Score
Fall/Fill (animate)
Display
User Input
Check Matches
Remove Matches
Adjust Score
Fall/Fill (animate)
{:score 0}:grid
:matches}
Display
User Input
Check Matches
Remove Matches
Adjust Score
Fall/Fill (animate)
{:score 0}:grid
:matches}
Display
User Input
Check Matches
Remove Matches
Adjust Score
Fall/Fill (animate)
{:score 5}:grid
}
Display
User Input
Check Matches
Remove Matches
Adjust Score
Fall/Fill (animate)
{:score 5}:grid
}
Display
User Input
Check Matches
Remove Matches
Adjust Score
Fall/Fill (animate)
{:score 5}:grid
}
THANK YOU!Any Questions?