Thread: Can somebody HELP ME with chessboard problems!

  1. #1
    Registered User
    Join Date
    Nov 2001

    Angry Can somebody HELP ME with chessboard problems!

    I need to put on a chessboard 5 queens so that don't attack each other and they cover the entire cheesboard.

  2. #2
    train spotter
    Join Date
    Aug 2001
    near a computer
    I think you mean you need to find, on an 8x8 grid,
    5 places where no diagonal, horz or vertical line meets. Is this right?

    If so create an int array
    #define MAX_SQUARES 8

    int iBoardArray[MAX_SQUARES][MAX_SQUARES];

    setup the queen locations in a point array (POINT is struc of two ints x,y or use int[2])

    POINT ptQueen[5];

    init both to zero with for loops.

    Place a queen in the 0,0 location (or get the user to select a location x,y) and set all the horz, vert and diags to one.

       //do vert (Y direction)
       //do horz (X direction)
       //do diag right to left
       //This finds the start of a diag line and    // ensures that it is in the array ie >=0
       //get the idea? ect
    Fill in the squares that are in the queens attacking zone and display the modified board
    Ask the user to select a new x,y for the second queen and test that all the locations are ==zero. If any are not (==one) then the queen can not be placed there.

    Allow the user to clear the board if they wish so need a menu.

    I did this in 5mins so may not be 100% or even close but will give you some ideas.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    There are 3 ways to do this:

    1) perfect algorithm.

    sorry, I can't think of one right now, but they do exist.

    2) brute force.

    Create a function that only checks your board. Create
    every possible variant of placing on board and run them
    all through your function to see which one is correct.

    3) trial and error

    let your program do the thing humans would do:

    place first queen in first row. mark fields below
    that are down or diagonal as occupied. proceed to next
    line. repeat. if you come to the last placement and it's
    ok, you are done. if you come to a line where you cannot
    place a piece, go back one line, take that piece away,
    eraze any occupied markings from your removed pieces
    and mark that place occupied. proceed with placing on the
    line of the removed place.

    ( obviously you cannot place queens in occupied spaces. )

    You can place 8 queens that way. Nice project.

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. Problems with the eight queens problem
    By Wicket in forum C++ Programming
    Replies: 1
    Last Post: 06-12-2008, 09:29 AM
  3. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  4. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM