Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Checking for Check in Chess

810341Mar 2 2011 — edited Mar 11 2011
Im trying to write a chess game and I need it to check for check but i am stuck. Below is the code that i am trying at the moment, i'm only using bq(black queen) and moveUP (in the northern direction of the board) to check at the moment - there are bp (black pawns etc..) and of course moveDOWN, moveLEFT etc.

Any help would be appreciated.
public boolean isNotCheck(boolean b) {
        index = start - end;

            for (int i = 0; i < ChessModel.LENGTH - 1; i++) {
                if(model.getSquareAt(i).image == wk)
                {
                    for(int j = i; j < ChessModel.LENGTH -1; j += moveUP)
                    {
                        if(model.getSquareAt(j).image == bq)
                        {
                            JOptionPane.showMessageDialog(null, "Check");
                            return false;
                        }
                    }
                }
            }
        return true;
    }
Edited by: 807338 on Mar 2, 2011 3:15 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 8 2011
Added on Mar 2 2011
15 comments
519 views