- Obtain deck of 52 cards
- Give 26 cards to Player 1 and 26 cards to Player 2
- Player 1 sets down one card
- Player 2 sets down one card
- If players ones card Is bigger than Players twos, Player one takes both cards and return to step 3
- If players twos card Is bigger than Players ones, Player two takes both cards and return to step 3
- If Player ones card = Players two card, return to step three until One player wins and takes all cards that round
- If Player one has 0 cards left, Player two wins
- If player two has 0 cards left, Player one wins
Introduction
The game of war is a card game typically played between two players. The game itself involves a 52-card deck being split into two hands. Each player then takes the top card of their respective decks and sees who has the higher card value, and the player with higher value takes both cards. The player who takes all the cards wins the game. In our version of the game, there are 26 rounds, and the winner of each round gets a point. Whoever has the most points at the end of the game wins.
User Manual
Hit the green run button
- This will cause the program to shuffle the deck and split the deck into two hands, which in turn will create two figures
Look at the two figures that pop up
- Each figure represents a hand. One hand is your hand and the other is the computers hand
As the game runs, follow along and compare the values of the cards to see who would get the point, you or the computer
The game will calculate which side gets the point, and at the end of twenty-six rounds, whoever has the most points wins!
Program Description for Developers
The variables used in the code for war include:
-randperm
-hand1
-hand2
-x
-y
-A
-B
The variable ‘randperm’ is the 52-card deck shuffled
The variable ‘hand1’ is the first 26 cards of the previously shuffled deck
The variable ‘hand2’ is the second 26 cards of the previously shuffled deck
The variable ‘x’ is the figure in which the image of hand1 is shown
The variable ‘y’ is the figure in which the image of hand2 is shown
The variable ‘A’ is set to represent hand1 and becomes the players hand
The variable ‘B’ is set to represent the computer and becomes the computers hand
A load command was used to load a MATLAB version of a deck of cards
A deck shuffling command was used to shuffle the MATLAB version of the deck of cards
An if elseif loop was used to compare the values of cards drawn
‘If’ variable A’s card value was higher than variable B’s card, then the score of player 1 would be raised by one point
‘Elseif’ variable B’s card value was higher than variable B’s card, then the score of the computer would be raised by one point
Discussion War:
The code starts by shuffling, and splitting a card deck, into two hands. It then evaluates the card values in order, using a while loop and if statements, and assigns the player with the highest value card a point. It does this 26 times then declares a winner. The main issue experienced during this code was the deck creation. Initially a deck was made and was meant to be split into two randomly with vector appendices. This issue was overcome by using another method, which involved random permutation, to create the initial deck.
Conclusion and Recommendations War:
The game is mostly out of the players control, so the game should have more player interaction, possibly by flipping cards by typing values. That way the player wouldn’t have to sit through the rounds while the computer assigns points to the player and computer. In conclusion, whilst the if values were sufficient in doing the job, more input values needed to be integrated to make the game more enjoyable.