#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0

    Checking for jumps on checkerboard


    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). 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.

    The image isn't showing up for me when I view the thread so here is the link: i.stack.imgur.com/ aXDl1.png

    If we assume the rows are 1-8 and the columns a-h then the marked checker on 7b is wrong. It should not be marked at all but it is checking the black checker in the upper right corner of it (6c). All red checkers do this. The checker on 6e is correct. It is looking to the lower right corner (7f) to see if there is a black there and an accompanying blank spot right after it. The red checker on 3f should be marked because there is a black checker in the lower left corner (4e) and an acompanying empty spot diagonally below it. The CheckRightJump method is fine but the CheckLeftMethod is wrong somehow.

    If I reverse the board (put red going up) then the problem is mirrored. The left jump method works but the right doesn't.

    Code:
    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) // Coded to check for red going down the board
    {
      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);  
      }  
    } 
    
     }//close checker class
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0
    Resolved.

    Changed row/col around in x/y variables.

IMN logo majestic logo threadwatch logo seochat tools logo