Developer Journal, Lughnasadh
Today, neopagansâespecially those who take their influence from the Celtsâcelebrate Lughnasadh, an ancient celebration marking the start of the harvest season. It probably inspired Christian Lammas, so even the non-neopagans have bread to eat.
And since man cannot live by breadâor even Redâalone (thanks, Iâll see myself out), letâs talk software.
Mystic T-Square
GitHub - jcolag/mystic-t-square
At least until a new idea or the occasional bug shows up, I consider Mystic T-Square complete, as a playable, two-player game.
The game now tracks statistics on questions asked and answered, plus who won various games, maintaining that data in the browserâs local storage. At the bottom of the right-hand panelâwhere the questions liveâyouâll now find buttons to show information about the game, the few game options available, and the statistics that I mentioned in the last sentence.
In many cases, since we only need to count things, the game updates its statistics through the following function.
function incrementStore(key) {
let value = localStorage.getItem(key);
if (value === null) {
value = 0;
} else {
value = Number(value);
}
if (!Number.isInteger(value)) {
return;
}
localStorage.setItem(key, value + 1);
}
In plain English, check the keyâquestionsAsked
, for exampleâreplace it with 0 if it doesnât exist, and make sure that we have a number, so that nobody tries to increment the API session token or some similar stored value. If we cleared those hurdles, update the value with the value plus one. Then, populating the statistics calls localStorage.getItem()
for each key, and inserts the results into the DOM.
The FutureâŚand the Present
I can see some potential directions, from here. The game could cache questions for the next game, rather than wasting whatever remains of the eight questions requested at the start of each. It could provide an option to limit the questions by category. Another possible option could allow the user to turn off the ârandom diversityâ code, limiting the tokens to lemon-yellow-faced, genderless emoji.
Of course, as described at some point, the game actually needs an automated player to handle the tiles. But that requires actually thinking through the math, so I donât expect it to just happen, like the other changes might.
Meanwhile, you can now play Mystic T-Square at its permanent home, hosted on GitHub. I didnât realize that deploying a (simple and static) site to GitHub pages only required turning it on. If you have played the game from its temporary location for testing, the old page will automatically forward you to the new page.
Redirection
Speaking of redirecting to the new page, I donât have this checked in anywhere, because it doesnât serve a real purpose. However, on the chance that anybody lands on this page looking for how to do handle redirection between webpages, the old Mystic T-Square page now looks like the following.
<html>
<head>
<meta http-equiv="Refresh" content="0; url='https://jcolag.github.io/mystic-t-square/'" />
<title>Mystic T-Square â Redirecting...</title>
</head>
<body>
If redirection doesn't work, try
<a href="https://jcolag.github.io/mystic-t-square/">here</a>.
</body>
</html>
And add whatever CSS that you might need, for the short time that the user will see the redirection page. If you feel particularly paranoidâI donât, here, because the stakes seem extremely lowâyou could also add some JavaScript on page load.
window.addEventListener('load', (e) => {
window.location.href = "https://jcolag.github.io/mystic-t-square/";
}
Between the HTML redirection, JavaScript redirection, and instructing the player to click through to the new location, that should work, no matter the browser.
Open Questions
If you do play Mystic T-Square with friends, please report back on the balance between players. Currently, the game simply alternates turns, one question and one tile movement. I decided on that primarily because it didnât require any further thought, but also because it didnât seem like the tile-moving players đ needed much power, since the trivia-playing players đ have a decent chance of foiling themselves, if a question comes up from a subject that they donât have familiarity with.
Of course, that line of thinking also sounds naĂŻve, so Iâd love to hear feedback on whether one tile moved per question answered feels right, seems too powerful, or not powerful enough, especially contrasted with how successful the trivia game goes.
Entropy Arbitrage
GitHub - jcolag/entropy-arbitrage-code
This week, I spent some time catching up on changes to the blog that I hadnât yet published.
To start, I made this change a long time ago, but then just forgot to do anything about it: The newsletter pull-out tab (to the right on this and every post, if you read these posts from my blog) now also points to my Buy Me a Coffee page, where people (you?) can (should?) âfollow meââwhich includes receiving the newsletter, plus announcements for each post to the blogâwithout sending me any money or even creating an account.
I also brought some library versions up to date.
The bigger deal, though? Primarily with the excuse of last Sundayâs post about redemption arcs, but potentially for more data-oriented posts in the future, blog posts can now show graphs, courtesy of Chart.js. If you didnât see it last week, check out this example.
Iâve only debugged the plugin for the line charts, so far, and even that, I have severely restricted to one specific use case: Mostly just showing changes in value over time, like the word counts for developer diary posts, shown above. But as I go, I expect to use the charts more, and will probably make the plugins a bit more sophisticated.
I should also mention that I havenât perfected the plugin, even for its narrow use case. Posts with a graph will need to include the library manually, for now.
<script src="/blog/assets/chart.js"></script>
I donât want to slow the page-load time for posts that donât use it, but I couldnât get a plugin to insert that reference automatically. In the ideal case, it would include the library a maximum of one time per post, but Iâd need to research to figure out how to do something like that, unless I want to build another complicated JSON object like I do for the GitHub plugin.
The approach that Iâve used has a nice aspect, because I store the data for the chart and read it from a separate file. This prevents me from cluttering a post like this with individual word count numbers that the reader should never see, and makes it easier to share the data. I can also build on this: With more sophisticated processing of the data file than âput commas between the elements,â I can add labels and descriptions to the data that would help someone processing it on their own, but might have no use in the post. I may need to do something like this, anyway, if I ever want a pie or donut chart: The only practical way to handle the data, its labels, and (I imagine optionally) the colors would use tabular data.
Library Updates
I needed to bump library versions for Bicker. The blogâs code, too, but I already mentioned that.
Next
I see the library updates piling up, so I may focus on digging through them for the week, to buy myself some time to figure out the Mystic T-Square AI.
Also, now that Iâve gotten a taste for hosting things through GitHub Pages, I have to wonder how much work it would take my daily puzzle games and turn them into applications, rather than daily generated pages. I like the generated pages for ease of use and sharing, but they do take up space. I donât imagine that the Daily Nonogram would work well as an âapp,â since the randomness comes from Wikipediaâs server and requires heavy processing. But the Daily Iungimoji and Daily G.L.O.B.E. seem like they have sufficiently predictable requirements for each puzzle, that I could generate from the day.
Such a system wouldnât get the puzzles for days that I had already generated, of course, without a lot more work, but I could see archiving the old puzzles to supplement the new.
And thinking about Mystic T-Square again, I should probably take my ideas listed above and turn them into issues on the repository. It also definitely wouldnât hurt to comment the code; Iâve probably mentioned before that each bit of work that Iâve done seemed obvious and not in need of comment, but as an aggregate, it became less clear.
Credits: The header image is Puck Fair, Killorglin, Co. Kerry by an unknown photographer, long in the public domain.
By commenting, you agree to follow the blog's Code of Conduct and that your comment is released under the same license as the rest of the blog.
Tags: programming project devjournal