Posts

Showing posts from August, 2023

Optimizing the Lookup Function

Image
An Inelegant Solution  This is the current chip lookup function in BitNGo: 1 2 3 4 5 6 7 8 9 10 11 function check_boards(ltr, nm) //puts chips in played numbers { for (i= 0 ; i<boards.length; i++) //checks each board { if (boards[i][ltr].includes(nm)) //if it includes the number... { boards[i][ltr][boards[i][ltr].indexOf(nm)] = "X" ; //it marks it as "X" } } console.table(boards[ 0 ]); } This is a terrible solution because in it, we check every board in game. Let's say we have 8 boards playing, and only 2 of them contain the number that has been played. With this function, we would be unnecessarily, checking every board in the game. To avoid this, I have come up with the idea of indexing every board into an array, that way, we know which boards to look for. The idea came to me a couple of days ago, but it was today in Anatomy class that I decided to start working in the concept....

Newer Win Conditions

Image
 In my last post I went through the process of explaining the basic functioning of the small bingo simulator which I'm calling BitNGo. Now, I'm going to explain how each win condition works. This probably won't be a long post. Full Table This probably was the easiest one to code. We just make a for loop that checks if every letter of the board has the complete 5 chips. If every letter is indeed full, a bingo is announced. For this win condition, we applied the very useful array.prototype.every() function. 1 2 3 4 5 6 7 8 9 10 11 12 13 function wc_full_table() { if (played_nums.length >= 24 ) { for (i= 0 ; i<boards.length; i++) { if (boards[i][ 1 ].every(element => element === "X" ) && boards[i][ 2 ].every(element => element === "X" ) && boards[i][ 3 ].every(element => element === "X" ) && boards[i][ 4 ].every(element => element ...

BINGO! Or BitNGo

Image
A few weeks ago, I attended a family bingo game. Not so much happened, we won a couple of prizes, but nothing else. The thing is, I took notes and registered every number that came through before marking it, so I have a log of around 15 games. I thought about using that data to analyze it and do something with statistics. But things have taken a turn. I decided to just simulate a game of bingo in a small program that I decided to call "BitNGo", because uhhhh bits and computers and bingo. So yeah that's what I'm going to talk about in this post. Warning: Madness Ahead By the time I'm writing this, I have already written some lines of code, so I'll just try to explain how it works. Spoiler: I am going to absolutely abuse the use of arrays. And no, the "concept" that I first wrote on my whiteboard, doesn't necessarily have to make sense. Creating the boards First, I have to know how many boards I am going to have. As of right now, this needs to be d...