mercredi 21 décembre 2016

Connect 4 against the computer

Alright, so I'm very beginner and programming a connect 4 game. I've got it all coded so that two players may play against each other, but I'm wanting to add a function to play the computer.

I don't need it to be really smart and figure out the best place to drop the piece, I just need to use something as simple as the random function to place it but I'm lost on how to do so.

Here's what my code for the basic structure of the game looks like:

{
    makeBoard();

    System.out.println("Choose 0 - 5 to pick which column to drop your piece!");
    System.out.println("R is red and Y is yellow.");
    System.out.println("Player 1, you are red. Player 2, you are yellow.");
    System.out.println("Good luck!");

    printBoard();

    boolean flag = true;

    while(flag)
    {
        dropRed();
        printBoard();

        if(!redCheck())
        {
            flag = false;
            break;
        } //check r


        dropYellow();
        printBoard();


        if(!yellowCheck())
        {
            flag = false;
            break;
        } //check y

    } // closes while

Any guidance is appreciated, and just let me know if you would like to see more of the code, thank you!




Aucun commentaire:

Enregistrer un commentaire