NeuroSwitch
NeuroSwitch was built using Visual Studio 2017, and written in C++.
For the visual aspects of the project, SFML was imported.
The textures used in game were made by Kenney Vleugels, and can be found here.
They come as part of a larger pack, but only the playing card textures were necessary for this project.
Here is an in-game NeuroSwitch screenshot from the 22nd of December, 2017.
Switch
Before we delve into the project, I should explain the rules of Switch.
Switch is a game that has a plethora of variants and probably has a few different aliases too. However, 'Switch' was the name my friends and I used when we'd play the game throughout our high-school years, and these are the rules with which we played:
Each player is dealt a set amount of cards (usually around 7, but can vary dependant on the number of players), and the player to the left of the dealer starts after the card on the top of the pack has been turned over.
The player must now either match the suit of the upturned card, or its type.
If the cards in their hand do not fit the criteria, then the player must pick up from the top of the pack, and the player to their left begins their turn.
The aim of the game is to play all of your cards and get "out."
The game can continue after someone has won; We used to play until last place had been decided and the loser ridiculed.
As you might expect, it isn't quite as simple as that though.
Certain cards have rules attached to them. There are varying permutations of these rules, but I'm going to use the rules I'm accustomed to.
Key:
In NeuroSwitch
Not in NeuroSwitch
| Card | Rule | Exception |
|---|---|---|
| [Runs] | If the player has several of the same type, they are permitted to play both together. The card that matches the most recently played card must be played first though. | |
| 2 | Next player picks up 2 cards | If the player has a 2 (or several 2s) of their own, resulting in the penalty being extended for the next player |
| 7 | Allows the player to play all of the cards in their hand that match the suit of the 7 in question. May also be topped off with a run of matching types. | |
| 8 | Next player misses a turn | If the player has an 8 (or several 8s) of their own, resulting in the penalty being extended for the next player |
| Black Queen | Next player picks up 5 cards | If the player has a black queen of their own, resulting in the penalty being doubled for the next player. |
| Red Queen | A red queen can cancel out the effects of a single black queen, and two can counteract two black queens. | |
| Ace | Player gets to nominate a suit for the next card to be played | The next player may override this with an ace (or aces) of their own |
| Jack | The direction of play is reversed |
-
Alterations:
- All rules that enforce a penalty on the next player are not available to be countered in NeuroSwitch.
- Runs of any kind are not possible in NeuroSwitch; Cards can only be played one-by-one.
- There is no function provided for players to nominate suits upon playing aces.
NeuroSwitch
The next image shows console output from the end of a game, and the displaying of the scoreboard.
Notice the column on the right showing the playstyle of each player, and in particular the hardcoded ones. "Human" just means that a human user is in control of that player, and they have free reign on how they wish to compete in the game. The automatic players are more interesting however.
Aggressive
The aggressive playstyle is coded so that the first thing the player does, if it is able to play, is to check whether or not it has a black queen within its hand. If not, it will then check for a two, and failing that it will check for an eight. The aggressive playstyle will always play the cards that will negatively affect the opposition first, before settling for the first playable card in its hand if it has none that will do so.
Unaggressive
Unaggressive, as you might expect, does the exact opposite. Unaggressive attempts to avoid the power cards unless they are the only playable cards within their hand. This tends to yield poor results.
Random
The previous two playstyles will just play the first playable card in their hand (if their attempted conditions are not met). Random does not. While it does use the same code and pick the first legally playable card in its hand, it gives the hand a good shuffle before doing so. Thus, the first playable card can vary.
These are almost like dummy players. The goal of the project is to implement an Artificial Neural Network that will learn how to play the game and improve over time, based on the results of a large quantity of games and generations.
For now, these allow me to play the game and test that there are no issues with the game. I need to know that the game itself is working properly before I start to implement artificial intelligence, as finding a bug at a later stage would render any data gathering that had been done to that point useless.
It can be fun to play against these automatic strategies too!
The results of each completed game are also being recorded in a text file. It shows much the same as the previous screenshot, but with the inclusion of the current date and time for more informative data to look back on.
This can be seen in the following screenshot.

To get a feel for how these hardcoded strategies performed, they were tested against one another. Below are a series of tables, showing the results of this testing.
| Number of Games | Aggressive Wins | Unaggressive Wins |
|---|---|---|
| 1000 | 552 | 448 |
First up, Aggressive vs Unaggressive. As you can see, the aggressive playstyle edged it. I was taken aback by the closeness of the results however, given that the unaggressive playstyle actively avoids playing cards that will negatively affect the opposition (to the best of its ability). I suppose this is testiment to the stochastic nature of the game.
| Number of Games | Aggressive Wins | Random Wins |
|---|---|---|
| 1000 | 501 | 499 |
Next, Aggressive vs Random. This was even tighter! It's harder to dispute the likelihood of this one however, as there's no way of knowing what the random player is going to play. That said, I'd still expect a strategy designed to attack the next player at any given opportunity to perform more strongly.
| Number of Games | Random Wins | Unaggressive Wins |
|---|---|---|
| 1000 | 539 | 461 |
Last up was Random vs Unaggressive.
I then decided to try all three playstyles together.
| Number of Games | Aggressive Wins | Unaggressive Wins | Random Wins |
|---|---|---|---|
| 1000 | 346 | 314 | 340 |
I started out by running one strategy against another, and then followed by having all three play games together and see who came out on top.
As the tables show, the aggressive playstyle is the most successful. However, perhaps surprisingly, it didn't have the convincing margin I'd anticipated.
The data from the above tables can be downloaded here.
Project Poster