Week 4: Development of the Rock-Paper-Scissors Game

 


What we have achieved-Week 4


When the Raspberry Pi computer receives information from the image processor, it follows the logic written in Python code to choose rock, paper, or scissors. It then immediately compares its choice with the recognized player’s choice, determines the game result, and displays it on the screen in real time.



Real-time demonstration screenshot

The Python code implements the logic for the Raspberry Pi computer's move selection as follows:

Start: The player makes a move, entering the game logic.

Determine if it is the first round:

  • First round: Randomly choose 0 (rock), 1 (scissors), or 2 (paper).
  • Non-first round: Select the next move based on the previous game result.

Based on the previous round's result:

  • Computer won: Repeat the player's previous move.
  • Player won: Choose the move that counters the player's gesture.
  • Draw: Choose the move that beats the tie gesture.

Save selection: Store the computer's current move.

Determine the winner: Compare the player's and computer's moves to decide the next round's state.

End: Wait for the next move.

Key code

In addition to improving the stability and accuracy of recognition, we also made many other attempts. To enhance the game's visual appeal, we experimented with displaying cartoon images of rock, paper, and scissors. When the user makes a rock-paper-scissors gesture, the Raspberry Pi computer will detect the gesture in real-time and display the corresponding move in the bottom right corner of the screen based on predefined logic. It will then compare both choices to determine the game result. If the player wins, the result will be displayed in gold at the top of the screen; if they lose, it will be shown in red; and if it's a tie, the result will appear in light blue.



Game screenshot


评论

热门博文