Our program follows the different sequences of a classical belote game, with 2 teams of 2 people: team 1 and team 2. Let’s see the different global steps:
- Of course, our program is composed of different variables, a “set up” in which you find the declaration of the pin’s mode (each is an input) and a “loop” which begins with different variables that have to be initialized. Interesting things are beginning now.
- Step one: after the distribution of the first five cards, we have to choose the trump. The program asks two questions via the LCD screen: who takes the trump and what’s the colour of the trump. We must answer by using the different associated buttons (one button for each team, four buttons for the colours and one button for each different card value). The program reads the state of the two buttons and comes in the condition loop which is satisfied. Each time the program has to wait that users push a button, we use a loop “do while” and a specific variable. As long as the user doesn’t push a button, the program doesn’t come into the conditional loop, the variable keeps the same value and the program comes back to the “do”. It’s the same logic for the choice of the trump. Each colour is associated to a number from one to four. The number of the trump is registered in a variable. After that, we can distribute the last three cards.
- Step two: we start the game. Remember that belote game is composed of several parts of eight hands as each player has got eight cards. Game is finished when a team reaches 1000 points.
- At the first hand of a part, team 1 always begins. For the following hands, the program increments itself with this part of code. After each part, the variable “start” is incremented.
- As the steps of a hand are always the same for each hand, we can use a loop “for” for the eight hands of a part. During a hand, each player has to encode the colour and the value of the card that he has just played.
- The encoding of the colour and the value is carried out by functions which return a number associated to the colour and the points associated to the value of the card. Finally, a third function compares the different cards to determinate which team wins the hand.
- The value and the colour of the card winning the hand (I mean the stronger card) are saved in variables. The comparison function compares the colour and the value of the trump, the stronger card and the card just played. If the comparison function returns “One”, the stronger card changes. It’s the same after each played card.
- At the end of the eight hands, the program encodes the “dix de der”, that depends on the team which has won the last hand, checks if there is a “capot” (if a team has won all the points), asks if there are some declarations (if so, the team encodes the value of the declaration) and finally checks if the takers have made their contract (which means they have to win half of the points).
- The score is registered and we come back to the begin of the program until a score reaches 1000 points.