2015-02-12 + HW02 + HW03

posted Feb 12, 2015, 11:01 AM by Samuel Konstantinovich   [ updated Feb 12, 2015, 11:39 AM ]
Update to make it print nicely:
//update your line as follows:
return hide + clear + go(0,0) + ans + "\n" + show;
This basically does the following:
// hide the cursor
// clear the screen
// go to the top left
// draw the board(ans) 
// new line
// show the cursor.


HW02 and HW03 are both due the thursday after break!

HW02: KnightsTour.java
1. Initialize the board to 0, count starting with step 1, ending at step (n squared) 
     where n = width = height.
2. Do not print anything in any of these methods. (My driver will output to a text file, do not print extra stuff. )

required methods:
a.         KnightsTour(int size); //constructor that makes a size x size board.
b. String toString();
c. String  name(); // "last.first"  all lowercase
d. boolean solve(); //start from 0,0
e. boolean solve(int x,int y); //start from x,y
f. //your recursive function is referenced by the solve methods


solve and solve(x,y) 
Both should modify your board such that there are a set of n integers (1 to n)
that signify the order of the moves required to create an OPEN knights tour. You DO NOT have to restrict it to a closed tour. As long as you can make the n'th jump onto a cell with a 0, you are totally fine, and should return true. 


HW03: NQueens.java

Similar to the KnightsTour, you can practice your recursive backtracking skills.
"The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, column, or diagonal. The eight queens puzzle is an example of the more general n-queens problem of placing n queens on an n×n chessboard, where solutions exist for all natural numbers n with the exception of n=2 or n=3."

required methods:
a.         NQueens(int size); //constructor that makes a size x size board.
b. String  toString();
c. String  name(); // "last.first"  all lowercase
d. boolean solve(); //start from 0,0
e. *** boolean solve(int x); //start with a queen in position x of the first row or column.
f. //your recursive function is referenced by the solve methods


*** There are solutions that include a queen in any position in the 1st row or column. This allows you to find different solutions with your code. See wiki on solutions: http://en.wikipedia.org/wiki/Eight_queens_puzzle  
Comments