Adblock breaks this site

Checkers

Discussion in 'Programming General' started by googletimes, Oct 4, 2011.

  1. googletimes

    googletimes Active Member

    Joined:
    Jan 24, 2007
    Posts:
    245
    Referrals:
    0
    Sythe Gold:
    0
    Checkers

    I'm having some trouble figuring out how to code this java program. I'm a java newbie, so sorry if I may come off as extremely stupid if the answer is staring in my face. :)

    The aim of the program is to place only one checkers piece on a random black square on the checkers board. Then the checkers piece has to move to any adjacent black square at random.

    I've figured out how to code the checkers board but I don't understand how to get the checkers piece on a random black square. Any help would be appreciated.

    EDIT: Would I have to use Arrays? Because I haven't learned them yet..
     
  2. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    Checkers

    Have you made it so that you can place a piece on whatever square you want? If so, then you just need to use a random number generator.

    Code:
    int randomNumber = (int) (Math.random() * (high - low + 1)) + low;
    
    Where high and low are the ranges.
     
  3. googletimes

    googletimes Active Member

    Joined:
    Jan 24, 2007
    Posts:
    245
    Referrals:
    0
    Sythe Gold:
    0
    Checkers

    Thank you! I was actually stuck on this part.
     
  4. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    Checkers

    There are plenty of other ways to do it, but that's the way I always have used.
     
  5. blindkilla

    blindkilla Guru
    $25 USD Donor New

    Joined:
    Jun 22, 2005
    Posts:
    1,896
    Referrals:
    0
    Sythe Gold:
    6
    Discord Unique ID:
    282000633404456960
    Discord Username:
    sogord
    Checkers

    So just to be clear, was OP just looking for a way to randomly generate a number?
     
  6. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    Checkers

    That's what I thought at least. :S
     
  7. googletimes

    googletimes Active Member

    Joined:
    Jan 24, 2007
    Posts:
    245
    Referrals:
    0
    Sythe Gold:
    0
    Checkers

    Sort of but not really. I figured it out in the end anyways. All's good :)
     
< need help fixing this program | Help with a program >


 
 
Adblock breaks this site