Results 1 to 1 of 1
Thread: Tromino puzzle
- 03-23-2011, 03:50 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
Tromino puzzle
Hi,
I'm quite new to java. I'm trying to make a tromino puzzle (Golomb's inductive proof of a tromino theorem) using recursion and a divide-and-conquer method. The only thing I need to obtain is a matrix (2D-array) filled with ints. A tromino is formed by 3 same numbers (e.g. array[0][0] = 1, array[0][1] = 1 and array[1][0] = 1 form 1 tromino-shape. The little black square is represented as -1). I managed to do this for one square, but I have no idea how I can possibly fill the whole matrix. Any help? Thanks!
Java Code:public class TrominoPuzzle { private int[][] tile; private int counter; public int[][] tile(int k, int row, int col) { int tilelength = (int) Math.pow(2, k); tile = new int[tilelength][tilelength]; tile[row][col] = -1; counter = 1; drawTromino(8,row,col); return tile; } public void drawTromino(int length, int row, int col) { if (length != 1) { if (row <= length/2 && col <= length/2) { tile[length/2-1][length/2] = counter; tile[length/2][length/2] = counter; tile[length/2][length/2-1] = counter; counter++; drawTromino(length/2,length/2-1,length/2-1); } if (row <= length/2 && col > length/2) { tile[length/2-1][length/2-1] = counter; tile[length/2][length/2-1] = 55; tile[length/2-1][length/2] = counter; counter++; drawTromino(length/2,length/2-1,length/2); } if (row > length/2 && col <= length/2) { tile[length/2-1][length/2-1] = counter; tile[length/2-1][length/2] = counter; tile[length/2][length/2] = counter; counter++; drawTromino(length/2,length/2,length/2-1); } if (row > length/2 && col > length/2) { tile[length/2-1][length/2-1] = counter; tile[length/2-1][length/2] = counter; tile[length/2][length/2-1] = counter; counter++; drawTromino(length/2,length/2,length/2); } } } }
Similar Threads
-
Crypto puzzle
By morello in forum Advanced JavaReplies: 0Last Post: 02-26-2011, 09:23 PM -
Making a puzzle game, need help!
By Atriamax in forum Advanced JavaReplies: 1Last Post: 12-30-2010, 12:55 AM -
15 puzzle using 2d arrays
By GPB in forum New To JavaReplies: 1Last Post: 05-26-2010, 12:35 AM -
N-Puzzle Help!
By evan42781 in forum New To JavaReplies: 12Last Post: 04-29-2009, 11:34 PM -
Need help with Trees...(8-puzzle)
By ventrue in forum New To JavaReplies: 2Last Post: 03-23-2009, 11:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks