annoying problem, solution should be simple...

This is a discussion on annoying problem, solution should be simple... within the C++ Programming forums, part of the General Programming Boards category; Hey all, Wednesday I started writing a console-based chess program in my C++ class and today I've gotten the basis ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    244

    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:

    Code:
    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;
            }
    			else
    			 {
    
    			 	board[x1][y1] = '_';
    			 	board[x2][y2] = 'p';
    			 	this->showBoard();
    			 	this->setTurn(2);
    			 	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:

    http://dydx.no-ip.com:8080/main.cpp
    http://dydx.no-ip.com:8080/board.h
    http://dydx.no-ip.com:8080/board.cpp
    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, 04:47 PM
  5. Problem and Solution
    By DavidP in forum Tech Board
    Replies: 3
    Last Post: 08-18-2003, 02:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21