Gold Miner
I created a simple random walker project called the “gold miner”. In the first chunk of the code, I created some global variables that every function can have access to, and then I thought in order for the random walker to know that the xy coordinate has gold under it, I need a 2-D grid for the entire canvas. I assigned the values of every block in the grid as false and then I created another function called createGold that randomized 50 golds in a 400 x 400 canvas and if the block has a gold under it I set it to true, why 79? Because gold is Au. Then the setUp function just set everything up and calls the required functions. The draw function is the most important part of this code, it initializes the walker at the xy position and the walker will start randomly walking in the xy direction. Every walk that walker takes checks if the block under has gold and the block is not undefined which is part out of the canvas. If there is a gold under the block, it increments the score and the last function is to display the score on the top left. To be honest I wanted to create a self-avoiding walker by using the data structure I learned last semester, I tried stacks and queues for the visited block but I did not reach my goal, then I watched the coding train video on the self-avoiding walker which was quite interesting and his approaching was a little different than mine. If I have time I will definitely complete this project by using the self-avoiding algorithm because who would mine a block that has just dirt under it? I also encountered a problem when I tried to display the score, the score just kept stacking up on each other on the top left screen as you can see which is a problem I need to solve.
Link to the code