Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-13-2012, 11:35 PM   PM User | #1
bccurry
New to the CF scene

 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
bccurry is an unknown quantity at this point
Java AI Connect 4 Help!!!!!

I have an assignment to create a connect 4 project that has user as a player, has a regular automatic player, and has the option of having a smart player. I have created the other players, but I am confused as to how to create the smart player. I have decided to use the minimax algorithm to do so but I cannot get the code together to create it......this is what I have so far.



import java.io.*;
import java.util.*;

public class PickNextMoveSmart implements PickNextMove {

int evaluate(Board b,Player me, Player opp, MyTimer t) {
return me.finalScore();
}

int recurEvaluate(Board b, Player me, Player opp, MyTimer t, int depth){

if (depth == 8)
{
return evaluate(b, me, opp, t);
}
else
{
depth = depth + 1;
int max = -1000;
int column = -1;
for (int i = 0; i < Board.allmoves.size(); i++)
{

if (b.isValidMove(Board.allmoves.get(i)))
{
Player newme = me;
Player newopp = opp.addScore(b.nextScore(Board.allmoves.get(i)));
Board newboard = b.nextMove(Board.allmoves.get(i));
int newscore = recurEvaluate(newboard, newme, newopp, t, depth);
if (max < newscore) {
max = newscore;
column = i;
}



}


}
return max;
}




}

public Move nextMove(Board b, Player me, Player opp, MyTimer t) {


int bestscore = -1000;
int bestpos = -1;

for (int i = 0; i < Board.allmoves.size(); i++)
{
if (b.isValidMove(Board.allmoves.get(i)))
{
Player new_me = me.addScore(b.nextScore(Board.allmoves.get(i)));
Board new_board = b.nextMove(Board.allmoves.get(i));
int score = recurEvaluate(new_board, new_me, opp, t, 0);
if (score >= bestscore)
{
bestscore = score;
bestpos = i;
}
}
}

return Board.allmoves.get(bestpos);
}
}




Can anybody point me in the right direction?
bccurry is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:50 PM.


Advertisement
Log in to turn off these ads.