70
Writing a Tile-Matching Game FP Style Hakim Cassimally @osfameron, @lambdamcr

Writing a Tile-Matching Game - FP Style

Embed Size (px)

Citation preview

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}

Match 3

(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))

(filter seq)

Er...

[0 0][

[0 0][ [1 0]

[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))

(zip )

(zip )

(zip )

(zip )

(repeat (range)) (map repeat (range))

...

...

...

...

...

...

...

...

...

...... ...

...

...

...

......

...

+

=

(defn transpose [m](apply map vector m))

(defn points [runs](->> runs

(map count)(apply +)))

= 19

Filling

Filling

Filling

Filling

er....?

Filling

Filling

Filling

Filling

Filling

Filling

Filling

State or Change?

State or Change?

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?