mardi 3 octobre 2017

Separating an random int by other int chances

I'm attempting to create a rock paper scissors game, but with an A.I. What I want the A.I to do is remember how many times they won with a weapon (rock,paper or scissors) or how they lost and which weapon they can use to comeback with it. It remembers it's chances.

The issue is that I want to use a Random Int to make the chances. Here's an example of what I have.

import java.util.Random;
public class Main {
    public static void main(String [] args) {
        Random rand = new Random();
        int rock = 3;
        int paper = 3;
        int scissors = 4;
        int total = rock + paper + scissors;
        int play = rand.nextInt(total) + 1;
        // this is where my problem is //
    }
}

With the int's as the remembering chances, I add all of them together, and getting a random number (in this case, a number between 1 and 12.). Once I get that, I want to separate that int into 3 parts. The rock chances, the paper chances and the scissor chances. 1 - 12, 1-3 will be rock, 4-7 will be paper and 8,12 will be paper.

I don't know how to separate the int like that, but once I know how, I can continue.




Aucun commentaire:

Enregistrer un commentaire