Week 5 – Implementing Changing Difficulty Levels
April 7, 2023
Welcome to my fifth Senior Project blog, where I’ll go over the progress I made this week as well as my plan for the next two to three weeks. I’m working on implementing the different systems to change the difficulty that I went over in last week’s blog.
Tracking Wins And Losses
The first step to implementing a system to adjust difficulty based on wins and losses was to actually track that in the first place. This wasn’t too difficult, as I could just store this as two variables and update the correct one in the getWinner() method. However I also wanted to display some stats to the winner so that they could see their progress over time. It would (if it works correctly) display the user’s total win-loss ratio, as well as the results of their last 5 (maybe 10) games. Additionally, I would also try to use this area to show the user which player’s turn it is, as well show how many pieces were captured. Essentially try make the game look nicer than just the board.
In order to display more information though, I needed to actually make space for it. Extending the game window was as easy as changing the screen size, but this also increased the size of screen that the player could click on. Currently, every time the player clicks on the screen, a method calculates the board’s row and column. For example, if they click on screen coordinates (138, 245), this would return column 1 and row 2. However, with the board now having space outside the board, column 11 may get returned. Since the board array has no value of columns past 7 (0-7 exist), this lead to an error. Fixing this involved adding a check to ensure that the board’s coordinates that get returned actually exist, but I also needed to implement this in every spot in my code that the error could come from.
How The Changing Difficulty Will Work
Now that the win-loss tracker works and the game doesn’t crash when the user clicks on the extended area outside the actual board, I can work on actually increasing the difficulty level as the player improves and wins more, and decreasing it if they lose a lot. In this section, I’ll go over the plan for the next few weeks, some of which I have implemented already, and some of which I still need to. There will be 9 total difficulty levels for this game. Level 1 will have the computer play a random legal move. Levels 2 and 3 will have the computer look 1 move ahead, with level 3 using an improved method for calculating the board’s “score.” Levels 4 and 5 will look 2 moves ahead, with level 5 using the improved score algorithm. The same will be true with levels 6 and 7, and levels 8 and 9, looking 3 and 4 moves ahead.
The last games at each difficulty level will be tracked. If the user wins over 60% of the time at this difficulty after playing multiple games (winning 1/1 games would be 100% win rate, but I don’t want to bump up the difficulty after just one game), the difficulty will increase. If they win less than 40% of the time, it will decrease. After changing the difficulty, it will start counting wins and losses at the new difficulty, so that enough wins at a lower difficulty don’t continue to impact the user’s higher difficulty stats. For example, if a user wins 5/5 at a level 3, they may get moved up to level 4 (or maybe even 5). If they go on to only win 1/5 of their next games, they would be at a total of 6 wins out of 10 games. However, I wouldn’t want to consider this to be a 60% win rate and move them up more, as they actually lost 4/5 games at this difficulty. Instead, they would likely go down a level, as 1/5 (only considering the games at this difficulty) is lower than 40%.