This project is call de Bruijn Card Trick which will create a "magic trick". You will arrange the the card deck in the order similiar to the order in UsedDeck.txt file. Then you will ask the player to cut a deck in random position. Next you will take out the 6 simultaneous card from the deck.
You will then ask the player to tell you only the COLOR of this 6-card. Then you will enter Black as 0, Red as 1 in the input window in this application. for example, if the 6 cards turn out to be RED-RED-BLACK-BLACK-RED-RED; you will enter 110011. The application will give you the right card that the player is holding
Click enter you will get the result as
To modify my code, you only need basic knowledge of Java and Data Structures(Lists, HashMap, LinkedHashMap, and I/O) and JavaFX ( in this code, the graphics were made mainly from JavaFX Dialog)
To start the program, there is 3 ways:
- Run the DeBruijnCardTrick.jar
- Run the DeBruijnCardTrick.exe (prefered)
- download the class CustomVoting and Candidate (remember to modify the package) and run it in a new project in IDE.
You should see a new window pops up
a De Bruijn sequence of order n on a size-k alphabet A is a cyclic sequence in which every possible length-n string on A occurs exactly once as a substring. Look at the picture for easier understanding how the sequence work
I generate a arbitary sequence included only Binary Number (0 and 1) base on de Bruijn's to create uniques sequence of 2 consisted only 1 or 0. You can use a program online at de Bruijn arbitrary sequences
In which you will type in the N as 52 as there are 52 cards in the deck and 2 as the Base because we only need BLACK and RED (0 and 1 respectively) for this magic trick
We will use this sequence to predict the specific cards (in this case will be go in set of 6) only base on the color
To do so, we will have a specific Card.java class to assign 52 cards
Then you can set the up 52-cards Deck in the DeBruijnCardTrick.java class
In this cased I will set up the orginal Deck which consisted of the full 52-cards in order first and then I will assign the separated usedDeck List for the game which only add elements from the Original List
- Note: You can use I/O java for the usedDeck List instead of initialize the whole list again
I will then set up a LinkedHashMap (which is better than HaspMap in this case because it will print the elements in insertion order - FIFO). The LinkedHashMap will included the key as the 47 6-element-substrings we get from the de Bruijn arbitrary sequence and the value as the 6-cards each substring will hold.
Finally, when put in the answer in the DialogBox, we will check (using Lambda Expression) in each of the .keyset of our LinkedHashMap -cardMap-
- De Bruijn sequence
- de Bruijn arbitrary sequences
- LinkedHashMap
- Lambda Expression
- JavaFX
- JavaFX Dialog
my roomate - Ashwin- for the idea and the math on the problem
Long Phan