2 Replies - 975 Views - Last Post: 02 February 2014 - 08:34 PM Rate Topic: -----

#1 VinnyB   User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 4
  • Joined: 25-January 14

Checkerboard having faulty jump check logic

Posted 02 February 2014 - 12:00 PM

I am having a problem with my checkerboard that has been coded to check if there are possible legal jumps for red (the board is only coded assuming red is going down the board). A jump is when the checker leaps over one of the opponent's pieces, landing in a straight diagonal line on the other side. So the the left or right diagonal (going downwards for this scenario) has to be occupied with a black checker and then the next diagonal square has to be open to land on. My right jump logic is working but my left jump logic makes the checker think it is ok to jump on a black checker in the upper-right corner instead of the lower left. I put a yellow circle on each checker to see if the jump is possible.

Posted Image

The left red checker with the circle is wrong (looking to upper right square). The right checker is correct (checking lower right). The left checker shouldn't have any circle at all. The red circle on the third row, 6th column should be what a correct left jump is and have a circle.

I realize this might be confusing to understand, but basically the yellow circle is appearing when it shouldn't be because the left jump logic is wrong. It should only be yellow when the lower right/left corners are occupied by black and the next diagonal is open. It is currently doing upper and lower right corners.

public void paint(Graphics page)
{

setBackground(Color.white);
fillBoard(page); // draws the method that will draw the checkers         
placeCheckers(page, 7, Color.red);   //method to place the red checkers
placeCheckers(page, 9, Color.black); //method to draw  black checkers
CheckJumps(page);   //check if checkers can jump    
setSize (APP_WIDTH,APP_HEIGHT);

}

public void CheckJumps (Graphics page) 
{
  for (int row = 0; row < 6; row++)
     for (int col = 0; col < sq[row].length; col++)
       { 
        if (col < 2 && sq[row][col].getOccupy() && sq[row][col].getCheckerC() == Color.red)
           CheckRightJump(page, row, col);
        if (col > 5 && sq[row][col].getOccupy() && sq[row][col].getCheckerC() == Color.red)
           CheckLeftJump(page, row, col);
        if (col > 1 && col < 6 && sq[row][col].getOccupy() && sq[row][col].getCheckerC() == Color.red)        
        {
           CheckRightJump(page, row, col);
           CheckLeftJump(page, row, col);
        }  

       }        
}

//Checks  valid right-hand jumps
public void CheckRightJump (Graphics page, int row, int col)
{
  Circle c;
  int x = row * (APP_WIDTH/MAXSIZE);
  int y = col * (APP_HEIGHT/MAXSIZE);

  if (sq[row+1][col+1].getOccupy() && sq[row+1][col+1].getCheckerC() == Color.black && !sq[row+2][col+2].getOccupy())
  {   
      c = new Circle (x + 15, y + 15, 20, Color.yellow);
      c.draw(page);  
  }    
}

//Checks valid left-hand jumps
public void CheckLeftJump (Graphics page, int row, int col)
{
  Circle c;
  int x = row * (APP_WIDTH/MAXSIZE);
  int y = col * (APP_HEIGHT/MAXSIZE);

  if (sq[row+1][col-1].getOccupy() && sq[row+1][col-1].getCheckerC() == Color.black && !sq[row+2][col-2].getOccupy())
  {   
      c = new Circle (x + 15, y + 15, 20, Color.yellow);
      c.draw(page);  
  }  
} 

}



Is This A Good Question/Topic? 0
  • +

Replies To: Checkerboard having faulty jump check logic

#2 VinnyB   User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 4
  • Joined: 25-January 14

Re: Checkerboard having faulty jump check logic

Posted 02 February 2014 - 08:00 PM

*
POPULAR

Resolved.

Changing row/col around for x/y variables fixed it.
Was This Post Helpful? 7
  • +
  • -

#3 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: Checkerboard having faulty jump check logic

Posted 02 February 2014 - 08:34 PM

Glad you got it resolved! Thank you for sharing your solution!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1