File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programming Diversions and the fly likes The Crowded Chessboard Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "The Crowded Chessboard" Watch "The Crowded Chessboard" New topic
Author

The Crowded Chessboard

Sameer Jamal
Ranch Hand

Joined: Feb 16, 2001
Posts: 1870
You are given a chessboard together with 8 queens, 8 rooks, 14 bishops, and 21 knights. The puzzle is to arrange the 51 pieces on the chessboard so that no queen shall attack another queen, no rook attack another rook, no bishop attack another bishop, and no knight attack another knight. No notice is to be taken of the intervention of pieces of another type from that under consideration - that is, two queens will be considered to attack one another although there may be, say, a rook, a bishop, and a knight between them.
1 - Queen, 2 - Bishop, 3 - Knight, 4 - Rook
Karthikeyan Rajendraprasad
Ranch Hand

Joined: Apr 16, 2003
Posts: 70
After a long time a tough puzzle.. will definately give a try.. hope there a is a solution for this


Karthikeyan<br />SCJP 1.4, SCWCD.
Karthikeyan Rajendraprasad
Ranch Hand

Joined: Apr 16, 2003
Posts: 70
hmm got the result atlast

Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
Originally posted by Karthikeyan Rajendraprasad:
hmm got the result atlast



How many Kings could be added to the puzzle and still have it solvable? Given this solution, I could easily add 7 King that can't attack each other. Is there a solution that allows 8, 9, or even 10 Kings to be added?
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
You mean Knights? Given this solution there are zero knights that can be added. Each empty square can be attacked by at least one knight. If those were kings it wouldn't be a solution because nearly all of them can attack another king.

Karthikeyan -
Awesome job solving this puzzle - I always wound up one piece shy. Either rook or knight as I was playing around with which one of these to try to place last.
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
Originally posted by Tim LeMaster:
You mean Knights? Given this solution there are zero knights that can be added. Each empty square can be attacked by at least one knight. If those were kings it wouldn't be a solution because nearly all of them can attack another king.

Karthikeyan -
Awesome job solving this puzzle - I always wound up one piece shy. Either rook or knight as I was playing around with which one of these to try to place last.


No, I'm fairly certain I mean Kings.

Starting with Karthikeyan's solution, I can place seven kings that can't atack each other:


(...where a kIng is represented by an 'I'.)

So there's seven kings. Every space that STILL empty is threatened by at least one of the seven kings, so we can't get another king on there without rearranging other pieces. Is it possible to rearrange the other 51 pieces so that you could fit on more kings that don't attack other kings?
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
I see I didn't realize you were adding a new piece to the puzzle.
Karthikeyan Rajendraprasad
Ranch Hand

Joined: Apr 16, 2003
Posts: 70
wrote a program that ran for hourssss to get this solution..

im tweaking it a little bit to get the required solution in a lesser time.

adding the king logic to it should not be a great deal.

lets see whether we can fill the remaining board with the kings.
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
Originally posted by Karthikeyan Rajendraprasad:
wrote a program that ran for hourssss to get this solution..

lets see whether we can fill the remaining board with the kings.


I assume your program uses a brute-force method -- is that right?

What is your outer-most loop? A loop through each of the pieces, trying to find a good place to put it? ...or a loop through each space on the board, looking for a good piece to put there?

Either way would work, but I wonder which would go faster.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The Crowded Chessboard
 
Similar Threads
MultiDimensional array doesnt work
How do i improve variable visibility?
How do i print a table with multidimensional array.
What is Enum?