# minimax for dot and box game

• March 24th, 2014, 07:19 PM
muffler
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
• March 24th, 2014, 07:29 PM
Norm
Re: minimax for dot and box game
Quote:

how to return a horizontal/vertical, column, row
Define a class to hold what needs to be returned and return an instance of it.
• March 24th, 2014, 07:36 PM
muffler
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);

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

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?
• March 24th, 2014, 07:42 PM
Norm
Re: minimax for dot and box game
[code=java]
[/code]
to get highlighting and preserve formatting.
• March 24th, 2014, 07:47 PM
muffler
Re: minimax for dot and box game
Code java:

```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.
• March 25th, 2014, 06:12 AM
Norm
Re: minimax for dot and box game
The code has lost its formatting. There isn't any indentations for nested statements.

Quote:

make a minimax class and pass those parameters to the rest of the code
That sounds like what I was talking about.