Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: minimax for dot and box game

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default minimax for dot and box game

    Hello all, new poster.

    i need help with a dot and box game i am trying to do.

    I understand how minimax works and understand how the tic-tac-toe process works but i cannot figure it out for the dot and box game. I would like to know how to return
    a horizontal/vertical, column, row but cannot figure it out. in TTT you only get to input in a row/column but with d and b you have to add the dash in north/south/east/west.

    any help would be great.

    Nick


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: minimax for dot and box game

    how to return a horizontal/vertical, column, row
    Define a class to hold what needs to be returned and return an instance of it.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: minimax for dot and box game

    so if i have this code
    //While the game is active
    while (!((msg[0] == GameSocket.CLOSING) || (msg[0] == GameSocket.GAME_OVER))) {

    do {// want to change this to MINIMAX instead of random
    //play randomly
    int HorV, row, col;
    HorV = Math.random() < 0.5 ? 0 : 1;
    if (HorV == 0) { //Play horizontal Horizontal
    row = (int) (Math.random()*(size+1));
    col = (int) (Math.random()*(size));
    } else { //Play vertical
    row = (int) (Math.random()*(size));
    col = (int) (Math.random()*(size+1));
    }
    //Send move
    gs.sendMove(HorV, row, col);
    //Read result
    msg = gs.readMessage();
    //Read next message
    msg = gs.readMessage();
    } while (msg[0] == GameSocket.PLEASE_PLAY);

    //Then wait for my turn
    while (!((msg[0] == GameSocket.PLEASE_PLAY) || (msg[0] == GameSocket.CLOSING) || (msg[0] == GameSocket.GAME_OVER))) {
    msg = gs.readMessage();

    in the code above i want to change from random to MINIMAX with int HorV, row, col; being passed.

    all i would need to do is make a minimax class and pass those parameters to the rest of the code? am i going in the right direction?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: minimax for dot and box game

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: minimax for dot and box game

    do {
     
    //play randomly
    int HorV, row, col;
    HorV = Math.random() < 0.5 ? 0 : 1;
    if (HorV == 0) { //Play horizontal Horizontal
    row = (int) (Math.random()*(size+1));
    col = (int) (Math.random()*(size));
    } else { //Play vertical
    row = (int) (Math.random()*(size));
    col = (int) (Math.random()*(size+1));
    }
    //Send move
    gs.sendMove(HorV, row, col);
    //Read result
    msg = gs.readMessage();
    //Read next message
    msg = gs.readMessage();
    } while (msg[0] == GameSocket.PLEASE_PLAY);
     
    //Then wait for my turn
    while (!((msg[0] == GameSocket.PLEASE_PLAY) || (msg[0] == GameSocket.CLOSING) || (msg[0] == GameSocket.GAME_OVER))) {
    msg = gs.readMessage();

    sorry for last. this is just an extract of the rest of the code i have.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: minimax for dot and box game

    The code has lost its formatting. There isn't any indentations for nested statements.

    make a minimax class and pass those parameters to the rest of the code
    That sounds like what I was talking about.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. what is ... (triple dot) operator
    By hs82 in forum Threads
    Replies: 3
    Last Post: December 12th, 2017, 02:20 AM
  2. Making an input dialog box appear after closing a combo box
    By Shenaniganizer in forum What's Wrong With My Code?
    Replies: 14
    Last Post: November 11th, 2012, 06:22 PM
  3. Printing with Dot Matix Printer
    By TheQuickBrownFox in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: November 9th, 2012, 02:04 AM
  4. CONNECT FOUR GAME-MINIMAX TO ALPHABETA ALGORITHM
    By AJreal in forum Algorithms & Recursion
    Replies: 0
    Last Post: March 6th, 2011, 03:30 PM
  5. invisible box game
    By new2java in forum Loops & Control Statements
    Replies: 1
    Last Post: September 27th, 2009, 12:46 PM