Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This program is a modified solution to the
- Habitica Programming Challenge Guild
- November '19 challenge
- It checks if one UNO hand card could be
- dropped onto the top card on the pile
- Written by MetHorn
- Tested with online BF interpreter at
- https://copy(dot)sh/brainfuck/
- Input Registers:
- Register R0 and R1 = card value (0 to 9)
- Register R2 and R3 = color (g = green | r = red
- | n = blue | y = yellow)
- Return values:
- 0 = Card can't be played
- 1 = Card can be played
- Lets start:
- Init Flag in R4 to 1 = Card can be played
- >>>>+<<<<
- Read hand card value to R0 and
- increment pointer
- ,>
- Read pile card value to R1 and inc p
- ,>
- Read hand card color to R2 and inc p
- ,>
- Read pile card color to R3
- ,
- Pointer back to R1
- <<
- Now lets compare the card values
- [<->-] Decrement R0 and R1 until R1 is 0
- < Back to R0
- [ This block is only executed if R0 != 0
- Since the values are different check
- the colors now
- [-] R0 = 0
- >>> Pointer to R3
- [<->-] Decrement R2 and R3 until R3 is 0
- < Back to R2
- [ This block is only executed if R2 != 0
- The values and colors are both different
- so the card in hand can't be played
- We have to return ASCII '0' which is 48
- Lets put 7*7-1 in R1
- << Pointer to R0
- [-] R0 =0
- +++++++ R0 = 7
- [>+++++++<-] R1 = R0 multiplied by 7
- >- Subb 1 from R1
- . Print R1
- >>>-<< Reset Flag at R4 and
- Pointer back to R2
- [-] R2 = 0
- ]
- << Pointer to R0
- ]
- >>>> Pointer to R4 (Flag Card can be played)
- [ This block is only executed if R4 = 1
- If cards have same value and/or same
- color return 1
- So we have to return ASCII '1' which is 49
- Lets put 7*7 in R1
- <<<< Pointer to R0
- [-] R0 = 0
- +++++++ R0 = 7
- [>+++++++<-] R1 = R0 multiplied by 7
- >. Print R1
- < Pointer to R0
- ]
Add Comment
Please, Sign In to add comment