January, 5th, 2025
Hey there and welcome back to another blog post. I'm going to try and make this post a bit different than the others I have made so far. Maybe add a bit more actual coding to go along with my rambling. By this point I'm sure if you are here reading these you have at least a basic understanding of what I do and how programming works...if not...well...I'll try to translate it a bit and make it as relatible as possible. If that doesn't work either I hope my rambling is at least entertaining.
Alright so after getting this website up and running I was looking over my about me page and felt that my projects were a bit lacking. Sure my game from the React Game Jam is showcased but apart from that I only have projects made with tutorials. Which I am slowly beggining to realize even a freaking monkey could do. I would apologize to anyone reading this that has also made to-do lists or simple command line games with the help of a tutorial...but I won't. I was there too. I was super proud of the things I made and felt that since mine had a bit of my humor or a different font/color scheme that made it different from the original project, but that isn't exactly true either. So anyway, I decided that I wanted to make something new. Something fresh. Something I can do from scratch that I am familiar with. So I went with Farkle.
Farkle is a dice game, not unlike Yahtzee. That being said, if you have played Farkle before you know that it is NOT really like Yahtzee at all. So a quick run down. You have six dice that you need to roll. As long as you score on a roll you CAN roll again. If you have all scoring die you MUST roll again. If you ever do not score on a roll you Farkle and your turn is over. If you Farkle you do not get any points for that turn. Oh and you need at least 500 points on a turn to start even playing the game and have the ability to gain any points. Therefore if you Farkle before getting to that initial 500 your turn is over and you have zero points moving into the next round. The game, gets complicated. And if you noticed a pattern here, yes, this is a game of many conditionals/if statements. Something I seem to have overlooked when I decided to make this game instead of something more simple.
So yeah, Farkle is a game of conditionals. But that is definitely an over simplification considering basically all games are games of conditionals/rules. Once I realized this...well...I started to panic a bit. As I had already put a few hours into building this app. I already made the component for the die and for the held die vs the live die, and a half-decent user interface. Look I was already in the process and I promised myself I wouldn't back down. I started scoring by just counting the single one's and five's. Where one's are 100 points and five's count as 50 points. I managed to keep working with this sole scoring system and even implemented a round score so if you did roll all six die and didn't score your initial 500 and kept rolling with the previous score held you could keep working towards that 500 and keep playing the game. And it WORKED!!!
how ones and fives are scored
let score = 0;
diceValue.forEach((die) => {
if (die.value === 1) {
score += 100;
}
if (die.value === 5) {
score += 50;
}
});
return score;
The ones and fives worked, yes, but then came the actual scoring. I won't go too into detail about each combination of die that can score or what those scores are, as I did put the rules up in a picture. But needless to say it starts getting a bit complicated, and when you start getting into what a farkle is and how that effects the ENTIRE game, it got away from me pretty quick. I also found myself in my own conditional hell where I made a terrible convoluted mess of if statements while attempting to strong arm my way to an easy solution. SURPRISE it didn't work annnnd I was confused, by my own code. So...I knew some of it worked but I couldn't really tell what worked and what didn't. I proceeded to go through each line of code and each if statement and define what they did in different comments throughout my scoring.ts file. You can see somewhat of what that looked like below.
how ones and fives are scored
//if the number of dice held is more than or
// equal to 0 and keepRolling is true
// set keepRolling to false
if (numDiceHeld === 0) {
// setKeepRolling(false);
setTurnScore(turnScore);
}
//if any dice are held and keepRolling
// is false set the turn score to the
// value of the held dice
if (!keepRolling) {
setTurnScore(newTurnScore);
}
//if the number of dice held is equal
// to 6, set the turn score to
// newTurnScore, make all dice live
// again, roll dice and set
// keepRolling to true
if (numDiceHeld === 6) {
setTurnScore(newTurnScore);
setDiceValue((oldDice) =>
oldDice.map((prevValue) =>
({ ...prevValue, held: false }))
);
setFarkle(false);
rollDice();
setKeepRolling(true);
}
Long story short I did end up making sense of my code. That turned out to be just the beggining of the next part of my struggle. Did you notice that this was part 1 of making Farkle? Thats because I'm not done yet. Literally at this moment I am still working on the game. I just wanted things to still be fresh so I didn't have another blog post like the one about making this website where so much was lost in translation. That all being said I hope you look forward to seeing the final product as it will be linked on the about me page...maybe even the homepage if I'm feeling frisky. Well...until then I suppose. Thanks again for reading and for being my sounding board. I'll see you next time!
Thanks for reading, - Craig
AKA: Virtual Sobriety