Spades

Date: October-November 2021


Mockup of Spades

Overview

For my intro to programming class, 15-112, we were supposed to design a game or create something showing advanced learning in python for our term project. I elected to make spades. This was a game that was special to me as I played it often with my brothers growing up. Before we begin I should explain how spades works. It is a 4 player game with 2 teams of 2. Each player gets delt 13 cards. Each round of the game consits of 13 tricks and during each trick each player plays 1 card. The players must match the suit unless they are out of said suit. The highest card of the started suit wins. The caviot is that spades are trump cards. So if a spade is played the highest spade always wins. At the beginning of a round the players all go in a circle and "bid" or guess how many of the 13 tricks they think they can win with their cards. As you are a team your bids are combined. To explain scoring lets use an example. Lets say 2 people on a team bid 3 and 4. They have a combined bid of 7. If they make 7 it is +70 points. If they do not make 7 of the tricks it is -70 points.

Video Demo

When creating the game there were many challenges faced and choices made to get the project to where it is now. The main learning curves included learning alpha beta prunning to help the computers select cards, figuring out how to represent cards and how to then select cards, and creating an algorithm that looks at a hand of 13 cards and evaluates how many tricks will likely be won by a given hand. Another challenge was figuring out how to create the UI so that it is simplistic and elegant. I wanted it to look visually appealing while still providing a user with all the information they need to learn how to play.

Challenges

The biggest challenge while programming this game was creating and testing the minimax and alpha beta pruning algorithms. The goal was for the CPUs to look at all the cards that had been played and discarded during that round as well as the cards they were holding and the cards that had been played during that trick to determine which of their cards was best. If they had 0 chance of winning said trick they would select their lowest card that they can play. If they had a card that had a high chance of winning they would play it. While looking down all the branches of possible card combos that could be played it gives each branch a numerical evaluation and cuts off branches as it goes that are worse than branches surrounding it. This method allows for the CPUs to determine the worst possible scenarios in terms of cards played so they can play accordingly.

Alpha-Beta Prunning Diagram

Fig 1. Alpha Beta Prunning Diagram

Another big challenge when making this was how to represent and select cards. Cards were stored in a 3D array containing value, suit, and which hand they were assigned to. I could use this to get individual hands, all cards containing a suit, and get the value of cards as they were played to determine winning cards and help evaluate branches. I created a method to create the individual cards for display that could then be placed anywhere on the screen. The players cards were all displayed at the bottom of the screen and when selected it would move them to the center of the screen along with the CPU’s cards. This method of representing cards allowed versatility in terms of where on the screen cards were displayed.

Gameplay Pictures

lifestyle pic 2 of spades

Fig 2. Home Screen of Spades

lifestyle pic 1 of spades

Fig 3. Gameplay of Spades

lifestyle pic 3 of spades

Fig 4. Winning Screen of Spades

Changes I Would Make

If I had more time there are several things I would have added or changed. First off I have a lot more experience with UI now. I think the UI I made was decent but I believe now I would have been able to design a more interactive UI with animations. Furthermore, I would have refined the CPU algorithm to include nil as a potential option. Essentially if the CPU has a hand that is so bad that the expected number of tricks was 0 it would bid nil. If the CPU or player successfully didn’t make a single trick it would be +100 points but if they got a single trick it would be -100 regardless if their partner made their bid or not. I ran into some issues with the scoring system with this rule so I didn’t include it. Finally I would have changed some of the color scheme. Black on dark green has low contrast and is hard to read which I didn’t realize at the time. After taking more design courses and understanding the concept of contrast more this is absolutely something I would have considered when designing the interface the user interacts with.