Thread: annoying problem, solution should be simple...

  1. #1
    Registered User
    Join Date
    Aug 2001

    annoying problem, solution should be simple...

    Hey all,

    Wednesday I started writing a console-based chess program in my C++ class and today I've gotten the basis for the program completed (need to add a check to see if there's check or checkmate, and AI in the future...).

    BUT tonight I remembered that I didn't put in a check to prevent pieces from jumping over other pieces, so I started going through and fixing it. While I was doing that, I added a couple of lines to my pawn movement code and now my pawns can't move at all.. hmm!!

    here's the pertinent code, with the parts I added in BOLD:

    if(board[x1][y1] == 'p')
    		if(x1 == 6) // for starting pawns
    			 if((x2 == (x1-1) || x2 == (x1-2)) && (y2 == (y1-1) || y2 == (y1+1)) && (board[x2][y2] == '_'))
    			 	cout << "Invalid move." << endl;
    			 	return false;
    			 if(x2 == (x1-1) || x2 == (x1-2) && (y2 != y1))
    			 	cout << "Invalid move." << endl;
            return false;
            if(x2 == (x1-2) && (x1-1) != '_')
              cout << "Invalid move." << endl;
              return false;
    			 	board[x1][y1] = '_';
    			 	board[x2][y2] = 'p';
    			 	return true;
    this is part of a class method for the class BOARD. The function is called Move, and takes 4 integers (x1, y1, x2, y2), and returns a bool statement (when it was working, it returned void, but I changed it for future functionality I'm adding - I don't see how that would change it though?)

    Any ideas? I have a feeling its a really obvious mistake, but those are the hardest for me to spot

    Here's the entire code if you need it:
    Last edited by Captain Penguin; 10-18-2002 at 04:43 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-22-2009, 02:35 AM
  2. Simple problem - my solution correct?
    By spadez in forum C Programming
    Replies: 15
    Last Post: 04-18-2009, 11:08 PM
  3. problem with A simple modeless messagebox
    By hanhao in forum C++ Programming
    Replies: 8
    Last Post: 07-05-2005, 11:18 PM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  5. Problem and Solution
    By DavidP in forum Tech Board
    Replies: 3
    Last Post: 08-18-2003, 02:23 AM