diff options
author | Loïc Hoguin <[email protected]> | 2019-10-16 09:48:31 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-10-16 09:48:31 +0200 |
commit | 8459bebceb9533948193774371cbd9fd571b78ea (patch) | |
tree | dd8e5eb8aa21e68b47f2526a3db9a276ea0d4327 /articles/tictactoe | |
parent | 31cedd105e5f6ecfbfcb925d4703cdf7b5ae114f (diff) | |
download | ninenines.eu-8459bebceb9533948193774371cbd9fd571b78ea.tar.gz ninenines.eu-8459bebceb9533948193774371cbd9fd571b78ea.tar.bz2 ninenines.eu-8459bebceb9533948193774371cbd9fd571b78ea.zip |
Cowboy 2.7.0
Diffstat (limited to 'articles/tictactoe')
-rw-r--r-- | articles/tictactoe/index.html | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/articles/tictactoe/index.html b/articles/tictactoe/index.html index c7a10a36..85fbb025 100644 --- a/articles/tictactoe/index.html +++ b/articles/tictactoe/index.html @@ -74,7 +74,7 @@ <p>Writing an algorithm to check for victory sounds easy, right? It's easily tested, considering there's only 8 possible winning rows (3 horizontal, 3 vertical and 2 diagonal).</p> <p>In Erlang though, you probably wouldn't want an algorithm. Erlang has this cool feature called pattern matching which will allow us to completely avoid writing the algorithm by instead letting us match directly on the solutions.</p> <p>Let's first create a board. A board is a list of 3 rows each containing 3 columns. It can also be thought of as a tuple containing 9 elements. A tuple is easier to manipulate so this is what we are going to use. Each position can either contain an <code>x</code>, an <code>o</code>, or be <code>undefined</code>.</p> -<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -84,7 +84,7 @@ http://www.gnu.org/software/src-highlite --> <font color="#000080">undefined</font>, <font color="#000080">undefined</font>, <font color="#000080">undefined</font>}<font color="#990000">.</font></tt></pre> </div></div> <p>Now that we have a board, if we want to play, we need a function that will allow players to, you know, actually play their moves. Rows and columns are numbered 1 to 3 so we need a little math to correctly deduce the element's position.</p> -<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -93,7 +93,7 @@ http://www.gnu.org/software/src-highlite --> </div></div> <p>This function returns the board with the element modified. Of course, as you probably noticed, we aren't checking that the arguments are correct, or that the element was already set. This is left as an exercise to the reader.</p> <p>After playing the move, we need to check whether someone won. That's where you'd write an algorithm, and that's where I wouldn't. Let's just pattern match all of them!</p> -<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8 +<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> @@ -134,6 +134,10 @@ http://www.gnu.org/software/src-highlite --> + <li><a href="https://ninenines.eu/articles/cowboy-2.7.0/">Cowboy 2.7</a></li> + + + <li><a href="https://ninenines.eu/articles/gun-2.0.0-pre.1/">Gun 2.0 pre-release 1</a></li> |