• Log in or sign up for an account here: https://www.sythe.org/login

Checkers

googletimes

Active Member
Joined
Jan 24, 2007
Sythe Gold
0
Messages
245
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..
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
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.
 
Thank you! I was actually stuck on this part.
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
There are plenty of other ways to do it, but that's the way I always have used.
 
So just to be clear, was OP just looking for a way to randomly generate a number?
 
That's what I thought at least. :S

Sort of but not really. I figured it out in the end anyways. All's good :)
 
duelarena.gg
Back
Top