I spent majority or the day working on the 4 x 4 feature of my tic-tac-toe game. The way it evaluates wins (diagonal, horizontal, and vertical) needed to be changed which wasn’t too hard. The part that I spent more time that I’d like to admit on was getting the board to display properly. The 3x3 board was hardcoded to display 3 rows. Each of those rows was hardcoded to display 3 values with two “ | “ between them to act as the “board” and spacing between the board and values on the board. Getting that figured out didn’t take too long, but getting the display to account for two-digit numbers (and the spacing between them and the board) did take me a while. When all was said and done, I went to test and realized that there is a major hang up on hard mode playing on 4x4, so I still have to figure that out.

I decided to shift my focus onto my Wa-tor kata. The first step of this kata is to find a Gui that works for me and set it up. After searching around a bit, the GUI I settled on is Quil. It seems to be the only one I could find that was specifically made with Clojure in mind.

Importing the Library

You can add quil to your Leiningen project by adding [quil "4.3.1563"] to your dependencies in your project.clj and importing the changes. You can utilize the library by adding (:require [quil.core :as q]) to your namespace declaration.

defsketch

defsketch is how you start every Quil application. The first value it takes is the name you want to name your sketch function. After that you can start paring things to keywords. There is a full list of keywords, here but I’ll go over a few to get you started.

:title (sets the title on the top bar of the sketch, takes a string value)

:setup (specifies what to use as its setup function… more on that below)

:draw (specifies what to use as its draw function… more on that below)

:size (x and y of how many pixels length you’d like your window to be. Takes a vector [x y] as its value)

setup

The setup function is the first thing to get called and only gets called once. Its most important job is implementing quil’s framerate function that tells the application how often to call on the draw function every second.

draw

The draw function gets called x amount of times (defined by framerate in setup) per second. This is where you can decide on shapes to get drawn, colors, and positions of the shapes.

These are the 3 most fundamental functions of quil. There are hundreds of different functions quil’s library contains, and it’d take way longer than I have to explain them all, so here is a link to their api info. I may explain a few different functions here and there, but It’d take me way longer than I have in this apprenticeship to go over all of them.

I hope this helps you get started using quil!