Question: IN JAVA: Recursive Hexagon Puzzle IN JAVA General Directions: You are given seven hexagon tiles. Each tile has six triangular segments labeled with an emoji!
IN JAVA: Recursive Hexagon Puzzle IN JAVA
General Directions:
You are given seven hexagon tiles. Each tile has six triangular segments labeled with an emoji! . PIC 1
Each segment can have any emoji from the following list: alien, happy, pineapple, cat, pancakes, glasses (see above for corresponding emoji). The emojis do not have to be unique and can repeat themselves on a given hexagon tile.
You can download the emojis here.
Your task is to place 7 similarly labeled hexagon tiles onto a board such that a hexagon tile is placed in the center, with the remaining 6 tiles placed around the first. The requirement, is that adjacent segments of the hexagons must have the same emoji in order for the placement to be valid. Your program must use recursion to find a possible solution.
The following presents a possible example given a set of hexagon tiles. NOTE: The sides that have to match up are indicated with a red line.
PIC2
The input to the program will be a text file which will contain the emoji labels for each of the seven hexagon tiles. Each label will be separated by a comma and no spaces.
PIC 3
Example: In the text file the above tile would be indicated as:
alien,happy,pineapple,cat,pancakes,glasses
(Starting with alien and ending at glasses going clockwise.)
The program will take an input file which has the tile information for 7 hexagon tiles, and find and display a possible solution to the puzzle given. The program must solve the puzzle recursively. If a solution is found, then display the configuration of the hexagons on the console. If no solution is found display a message saying that there is no solution for the given hexagon tiles.
NOTE: Given a set of 7 hexagons, there may be more than one solution. For a score of 4 on this assignment, you only need to show one of the possible solutions. For a score of 5 you can show all possible solutions.
Additional Requirements:
If you include a GUI:
Make sure the GUI can render a solution or all solutions.
Include a button to choose an input file.
You must use the FileChooser library from JavaFX NOT JFileChooser from Swing.
If you do not include a GUI:
Make sure you still allow the user to choose a file. You can use the Swing JFileChooser for this option.
Your program must use recursion. Programs which do not use the correct recursion to find the solution will receive a score of 0.
Pro tips:
The idea with this one is very similar to the n-queens problem as far as trying all possible combinations and backtracking. Understand the concept of n-queens don't just try to copy it because that solution will not work exactly.
Comparing to n-queens:
Checking tiles at the next position is like checking a queen in the next row so checking the next tile position means going to the next level of recursion.
Checking a rotation at the current position is like checking a queen in each column of the row. You do not recurse for a rotation.
This problem is also similar to the String permutations. Every time you place a tile on the board you recurse with one less tile in the set of possible tiles. When you backtrack, you remove the last tile added and place it back in the set of possible tiles.
Tiles can be given in any order and with any initial rotation. Don't implement your program assuming that the tiles will already be in the correct order and rotated correctly. Your job is to have the program use recursion to find the solution.
Create a Hexagon class.
Always think clockwise rotations, this will help.
Solve the recursive algorithm BY HAND before you even think about touching the code. If you can't work out the logic on paper, you won't be able to work it out in the code.
When drawing a hexagon for the GUI:
Base the hexagon off of the center of the hexagon. An even easier way is to draw a triangle from the center point, and then rotate the triangle a certain amount of degrees about the center.
Place the emoji in the middle of the triangle segment using the hexagon center point as a reference. You may have some trial and error here until you get the picture placed correctly.
Create a method to draw a Hexagon given the x and y coordinates of the center. If you base everything off of the center then you only need to call this method 7 times with a different center point each time.
Even though the segments are labeled with emojis, internally you may want to associate a number to each emoji. 1 for alien, 2 for cat, and so on, so that way you can check matches based on numeric values instead of trying to compare actual pictures. When your GUI sees a 1 on a segment it would draw an alien, if it sees a 2 draw a cat and so on.
Don't rotate the center tile. Rotating the center tile means you will be rotating the entire picture and will be going through a rotation of the same recursive process that you already accepted or rejected.
Start early so you can come to me for help!
I will post test tilesets later.
Deliverables:
All .java source code files.
Exported Javadoc API, zipped
User Manual
Executable .jar file
Test Input:
Test Tile Set1 (Should have 1 solution)
Test Tile Set2
This should have 235,146,240 solutions.
Don't try to render all of these or print all of these out, use this test to see if you can find the correct number of solutions.
If you have less than this your algorithm is incorrect.
If you have 6 times this number it means you are doing a rotation of the first tile, which is also not correct.
Test Tile Set3 (Should have 14 different solutions)
TEST TILE SET1:
pineapple,happy,pineapple,alien,pancakes,glasses
alien,glasses,cat,happy,pancakes,happy
pineapple,glasses,happy,pancakes,cat,glasses
alien,pineapple,alien,glasses,pancakes,pineapple
alien,happy,cat,alien,glasses,pancakes
glasses,glasses,happy,alien,pancakes,cat
alien,cat,pineapple,alien,cat,cat
TEST TILE SET2:
cat,cat,cat,cat,cat,cat
cat,cat,cat,cat,cat,cat
cat,cat,cat,cat,cat,cat
cat,cat,cat,cat,cat,cat
cat,cat,cat,cat,cat,cat
cat,cat,cat,cat,cat,cat
cat,cat,cat,cat,cat,cat
TEST TILE SET3:
pineapple,happy,happy,alien,alien,alien
pineapple,alien,pineapple,cat,cat,cat
pineapple,pineapple,pineapple,alien,alien,alien
pineapple,alien,pineapple,alien,alien,alien
pineapple,pineapple,pineapple,cat,cat,cat
pineapple,cat,pineapple,cat,cat,cat
pancakes,pancakes,pancakes,alien,alien,alien
PIC1 PIC1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
