HomeArticlesProjectsBlogContact
Articles
ROCK PAPER SCISSORS Page 2
Colin Mitchell
Colin Mitchell
Make sure to subscribe to our newsletter and be the first to know the news.

Table Of Contents

01
GOING FURTHER
02
PLAYING THE GAME
03
FINAL NOTES

The game of Rock, Paper, Scissors … using a micro.

  • Page 1
  • Page 2

GOING FURTHER

The program can be extended in many ways.
The first addition is a recognition of the players choice. With only a single push button, it can be pressed one, two or three times for Rock, Paper, Scissors.
The flag file (file 1F) is incremented (by setting bit 5, then 6, then 7) each time the button is pressed. The button-press file is in the delay routine as this is the where the micro is looping most of the time.
A couple of things we have to consider are: How to debounce the switch and how to recognise the “end of play” for a player.
The switch debounce is contained within the delay routine.
Bit0 in file 1F is set when the button is pushed.
Each time the button is pressed, bit 5, then 6 then 7 is set. This indicates “Rock,” “Paper,” “Scissors.”

Del100   MOVLW 64h      ;100 loops = 100mS
         MOVWF 1B
Del101   NOP
         DECFSZ 1A,1
         GOTO Del101
         BTFSC 05,0     ;Is button pressed?
         GOTO Del103
         BCF 1F,0
Del102   DECFSZ 1B,1
         GOTO Del101
         RETURN
Del103   BTFSC 1F,0     ;First pass?
         GOTO Del102
         BTFSC 1F,5
         GOTO Del104
         BSF 1F,5       ;Set bit for Rock
         GOTO Del106
Del104   BTFSC 1F,6
         GOTO Del105
         BSF 1F,6       ;Set bit for Paper
         GOTO Del106
Del105   BSF 1F,7       ;Set bit for Scissors
Del106   BSF 1F,0       ;Set "button pressed" flag
         GOTO Del102

The next sub-routine to develop is called ”Score.” It takes the Player value and Computer value and works out the winner. It then increments the Player or Computer counter. The player value is contained in file 1F, bits 5, 6, 7. The computer value will 01, 02 or 04 in file 12h.
Player Score will be placed in file 17h and Computer Score will be placed in file 18h. The number of games is held in file 16h. When file 16h equals three games, ”I Lose,” ”You Lose” or “TIE” will be produced.

The value of the bits in files 1F and 12h are as follows:

File 1F,5
File 1F,6
File 1F,7
Player Rock
Player Paper
Player Scissors
File 12h,0
File 12h,1
File 12h,2
Computer Rock
Computer Paper
Computer Scissors
Score    BTFSS 1Fh,7    ;Player Scissors?
         GOTO Score2    ;Not player scissors
         BTFSS 12h,0    ;Computer Rock?
         GOTO Score1
         INCF 18h,1     ;Computer wins
         GOTO Score7
Score1   BTFSS 12h,1    ;Computer Paper?
         GOTO Score6
         INCF 17h,1     ;Player Scissors, Computer Paper
         GOTO Score7
Score2   BTFSS 1Fh,6    ;Player Paper?
         GOTO Score4    ;Not player paper
         BTFSS 12h,0    ;Computer Rock?
         GOTO Score3
         INCF 17h,1     ;Player wins
         GOTO Score7
Score3   BTFSC 12h,1    ;Computer Paper?
         GOTO Score6
         INCF 18h,1     ;Player Paper, Computer Scissors. Computer wins
         GOTO Score7
Score4   BTFSS 1Fh,5    ;Player Rock?
         GOTO Score7    ;Player not playing
         BTFSC 12h,0    ;Player Rock, Computer Rock?
         GOTO Score6
         BTFSS 12h,1    ;Player Rock, Computer Paper?
         GOTO Score5
         INCF 18h,1     ;Computer wins
         GOTO Score7
Score5   INCF 17h,1     ;Player wins
         GOTO Score7
Score6   INCF 17h,1     ;Draw
         INCF 18h,1     ;Draw
Score7   INCF 16h,1     ;INCrement the number of games.
         CLRF 1F
         RETURN

The next sub-routine produces “I Lose,” “You Lose:”

Table2   ADDWF 02h,1    ;Add W to the Program Counter to create a jump.
         RETLW 6Eh      ;y    format= gfedcba
         RETLW 3Fh      ;O
         RETLW 3Eh      ;U
         RETLW 00h      ;
         RETLW 38h      ;L
         RETLW 3Fh      ;O
         RETLW 6Dh      ;S
         RETLW 79h      ;E
         RETLW 00h      ;
         RETLW 0FFh     ;End of message


                        ;"Mess1" shows on 7-segment display: "I Lose"

Mess1    MOVLW 06       ;Show the letter "I"
         MOVWF 06
         CALL Show
         CALL Show
         MOVLW 0Ch
         MOVWF 12h      ;Jumper for table
Mess1A   CLRF 06
         CALL Show
         MOVF 12h,0
         CALL Table2
         MOVWF 06       ;Output to display
         MOVLW 0FFh     ;Detect end of Table
         XORWF 06,0
         BTFSC 03,2
         RETURN         ;End of Table detected
         INCF 12h,1     ;Jump to next letter
         CALL Show
         CALL Show
         GOTO Mess1A


                        ;"Mess2" shows on 7-segment display: "You Lose"

Mess2    MOVLW 0Ah
         MOVWF 12h      ;Jumper for table
         GOTO Mess1A

Show     NOP            ;Create 250mS delay
         DECFSZ 1A,1
         GOTO Show
         DECFSZ 1B,1
         GOTO Show
...      RETURN

All the sub-routines are now ready for insertion into a program. The only feature we have to create is the “end of play” for one or two presses of the button.
This will be a simple “time-out” feature. The button-presses must be completed during the time when the random effect is showing, otherwise a wrong result will be entered. The random effects have been lengthened to give the player sufficient time to register his decision.
The Main routine must be altered to take the new sub-routines, but now we have a program that has feedback from the player.
Two “hidden” points we need to mention are:

  1. The pointer for the random “RPS” is file 0Dh. It is incremented in “Attract” and masked to produce a value up to 0F for Table. This gives a random start to the game.
  2. Bits 5, 6, and 7 of file 1F are tested to decide the winner of each game. Bit 7 is tested first as all results contain bit 5. This is a very important point worth noting.
    The table “jump-value” is incremented twice for each game to make the outcome more unknown. Anyone copying the table will have to locate each second value.

PLAYING THE GAME

To play the game, switch the project on. The Attract mode will show on the 8 LEDs.
Press the button and the first effect will appear.
Press the button one, two or three times to represent Rock, Paper or Scissors, before the effect disappears.
The computer choice will then appear. The program will then work out the winner in ”Score” and place the result in file 17h for the player or 18h for the computer. The game counter file (file 16h) will also be incremented.
After 3 games the results will appear.
The program will then go back to the Attract mode.

RPS-2.asm

FINAL NOTES

This program uses about one-third of the memory of the chip and has not been optimised. Some of the delays could be combined and the two tables could be combined. Some of the sub-routines could also be reduced by very clever programming, but why make things more-complex than needed?
A program such as RPS shows how to make the most of limited features. The two displays operate at the same time, so it is difficult to know which display will be operational, and the switch has to perform a number of functions.
You can increase the size of the display with illuminated pictures and add three buttons, to increase the impact as a promotional display. This would be ideal as an advertising display at a meeting/drinking venue or billboard etc.
It could even be made into a credit card game and given away FREE with a purchase of a promotional product etc. It could even be made into a drink coaster for a bar/cocktail venue, night-club.
Some-one will run with the idea and make millions.
It could be added to a FREE box of matches or attached to to any number of products.
All you need to do is combine it with a number of other games/ideas and you have the basis of a product/project worth marketing.
Once you understand each of the sub-routines you will able to add new features or design a totally different game.
The possibilities are almost limitless.
RPS has been created by hand and the only diagnostic tool was a sub-routine that displayed the value in File 1F onto the 8 LEDs to help get the button-press to work.
The same routine was used to see the contents in files 17h and 18h to get the “I Lose” etc to display correctly.
Of course it’s a lot of long, slow, work, but the requirements of the program rate fairly high in complexity and no other program or approach I have seen, can deliver any form of simplification. If you can show me a simpler approach than that described above, there is $10,000 in the offering.

Once you get to this level of programming, you will be ready for our next range of projects. These will include modules for the PIC16F84 as well as the PIC16F628. The index will contain all the latest information, so keep up with our developments and you will in the running for designing simple projects.

There are a number of discussion groups on the web concerning the dismissal of electronics staff who are not up-to-date in the digital/micro area.
All their training was in the analogue/RF area, and they now find themselves out of work.
One of the important points to understand is the constant change in electronics and if you don’t keep up with this advancement, you will be overtaken.
The enquirer on the web asked if anyone knew of a company employing personnel in the purely analogue/RF field.
My answer is simple. If a prospective employee has analogue/RF skills as well as micro/programming skills, the answer is clear-cut - he is readily employable.
I cannot see any new product being developed without the inclusion of digital concepts.
It may be an LCD screen, digital volume or digital on/off. Without a digital understanding your chances for long-term employment are virtually nil.
The addition of digital/micro to almost any product will bring it up-to-date and quite often reduce its cost. Every manufacturer is aiming for this and if he sees a staff member “falling behind” in concepts, he will be looking for new talent.
There is only one thing between you and the boss.

Money.
You must be able to pay your way two-fold.
All the projects we are presenting on our site are designed to start you at the beginning. This is the only site ANYWHERE to have this aim and to prove its success with tens of thousands of readers and sales of hundreds of thousands of kits.
As we have always said, take a few of our projects to an interview and you are absolutely GUARANTEED to leap-frog over all the other prospective applicants.
But you must be able to back-up the image you present at the interview with knowledge. And the only way to get this knowledge is by carrying out the practical side of electronics by building the projects and experimenting and experimenting and experimenting.
We have provided it all for you. It’s just a matter of fulfilling your side of the bargain. Start with the PIC LAB-1. It can show you so much.


Colin Mitchell

Colin Mitchell

Expertise

electronics
writing
PIC-Chips

Social Media

instagramtwitterwebsite

Related Posts

TODO
Transistor Test
© 2021, All Rights Reserved.

Quick Links

Advertise with usAbout UsContact Us

Social Media