problem in evaluation method of connect four.
Here is the entire source code.
package connectfour;
import java.io.*;
import java.util.*;
public class Connectfour {
private static final int WIDTH = 7, HEIGHT = 6;
private static final int MAX_RECURDEPTH = 4;
private static BufferedReader in;
private int[][] grid = new int[WIDTH][HEIGHT];
private int[] columnHeight = new int[WIDTH];
private static int recurDepth = 0;
static int r = 0;
public static void main(String[] args) {
in = new BufferedReader(new InputStreamReader(System.in));
new Connectfour();
}
public Connectfour() {
Scanner read = new Scanner(System.in);
int column, p;
int player = 1;
System.out.println("Who play first?");
System.out.println("1.Player");
System.out.println("2.Computer");
p = read.nextInt();
player = p;
int move = 0;
double value = 0;
Vector moves = new Vector();
int mov = 0;
while (true) {
if (player == 1) {
printGrid();
do {
System.out.println("Make your move (1-7): ");
column = readInt() - 1;
} while (column < 0 || column >= WIDTH || columnHeight[column] >= HEIGHT);
} else {
moves.removeAllElements();
column = 0;
value = 0;
double prevValue = -MAX_RECURDEPTH - 1;
for (int x = 0; x < WIDTH; x++) {
if (columnHeight[x] >= HEIGHT) {
continue;
}
if (move == 0) {
moves.add(new Integer(3));
break;
}
if (p == 2 && move == 1) {
moves.add(new Integer(3));
break;
}
value = minmax(2, x);
if (value > prevValue) {
moves.removeAllElements();
prevValue = value;
}
if (value == prevValue) {
moves.add(new Integer(x));
}
}
move++;
System.out.println("VAlue=" + prevValue);
if (moves.size() > 0) {
Collections.shuffle(moves);
column = ((Integer) moves.get(0)).intValue();
}
if (moves.size() == 0) {
System.out.println("Its a draw.");
break;
}
}
grid[column][columnHeight[column]] = player;
if (player == 2) {
System.out.println("I PUT MY CHECKER IN " + (column + 1));
}
columnHeight[column]++;
int haswon = 0;
haswon = fourInARow();
if (haswon > 0) {
printGrid();
if (player == 2) {
System.out.println("I WON");
} else {
System.out.println("YOU WON");
}
break;
}
mov++;
System.out.println(" MOVE= " + mov);
player = 3 - player;
}
}
double minmax(int player, int column) {
double value = 0;
double v;
if (columnHeight[column] >= HEIGHT) {
return 0;
}
recurDepth++;
grid[column][columnHeight[column]] = player;
columnHeight[column]++;
if (fourInARow() > 0) {
if (player == 2) {
value = MAX_RECURDEPTH + 1 - recurDepth;
System.out.println("player 2= "+value);
} else {
value = -MAX_RECURDEPTH - 1 + recurDepth;
System.out.println("player 1="+value);
}
}
if( threeInARow()>0);
{
if(player==2)
{
value=MAX_RECURDEPTH-recurDepth;
System.out.println("three player 2"+value);
}
else
{
value=-MAX_RECURDEPTH-5+recurDepth;
System.out.println("three player 1 "+value);
}
}
if (recurDepth < MAX_RECURDEPTH || value == 0) {
value = MAX_RECURDEPTH + 1;
for (int x = 0; x < WIDTH; x++) {
if (columnHeight[x] >= HEIGHT) {
continue;
}
v = minmax(3 - player, x);
if (value == (MAX_RECURDEPTH + 1)) {
value = v;
} else if (player == 2) {
if (value > v) {
value = v;
}
} else if (v > value) {
value = v;
}
}
}
recurDepth--;
columnHeight[column]--;
grid[column][columnHeight[column]] = 0;
return value;
}
int threeInARow()
{
int i=0,j;
int player=0;
for (i = 0; i < 6 - 2; i++) {
for (j = 0; j < 7; j++) {
if ((grid[j]) == (grid[j][i+1]) && (grid[j]) == (grid[j][i+2]) ) {
return player;
}
}
}
//Horizontal
for (i = 0; i < 6; i++) {
for (j = 0; j < 7 - 2; j++) {
if ((grid[j]) == (grid[j+1]) && (grid[j]) == (grid[j+2])) {
return player;
}
}
}
//Diagonal '\'
for (i = 0; i < 6 - 2; i++) {
for (j = 0; j < 7 - 2; j++) {
if ((grid[j]) == (grid[j + 1]) && (grid[j]<span style="font-weight:bold;">) == (grid[j + 2])) {
return player;
}
}
}
// Diagonal '/'.
for (j = 2; j < 7; j++) // diagonal –/
{
for (i = 0; i < 6 - 2; i++) {
if ((grid[j]<span style="font-weight:bold;">) == (grid[j + 1]) && (grid[j]<span style="font-weight:bold;">) == (grid[j + 2])) {
return player;
}
}
}
return 0;
}
int fourInARow() {
int num, player;
for (int y = 0; y < HEIGHT; y++) {
num = 0;
player = 0;
for (int x = 0; x < WIDTH; x++) {
if (grid[x][y] == player) {
num++;
} else {
num = 1;
player = grid[x][y];
}
if (num == 4 && player > 0) {
return player;
}
}
}
for (int x = 0; x < WIDTH; x++) {
num = 0;
player = 0;
for (int y = 0; y < HEIGHT; y++) {
if (grid[x][y] == player) {
num++;
} else {
num = 1;
player = grid[x][y];
}
if (num == 4 && player > 0) {
return player;
}
}
}
for (int xStart = 0, yStart = 2; xStart < 4;) {
num = 0;
player = 0;
for (int x = xStart, y = yStart; x < WIDTH && y < HEIGHT; x++, y++) {
if (grid[x][y] == player) {
num++;
} else {
num = 1;
player = grid[x][y];
}
if (num == 4 && player > 0) {
return player;
}
}
if (yStart == 0) {
xStart++;
} else {
yStart–;
}
}
for (int xStart = 0, yStart = 3; xStart < 4;) {
num = 0;
player = 0;
for (int x = xStart, y = yStart; x < WIDTH && y >= 0; x++, y–) {
if (grid[x][y] == player) {
num++;
} else {
num = 1;
player = grid[x][y];
}
if (num == 4 && player > 0) {
return player;
}
}
if (yStart == HEIGHT - 1) {
xStart++;
} else {
yStart++;
}
}
return 0;
}
void printGrid() {
int x = 0;
int y = 0;
for (y = HEIGHT - 1; y >= 0; y–) {
for (x = 0; x < WIDTH; x++) {
if (grid[x][y] == 0) {
System.out.print(" . ");
} else if (grid[x][y] == 1) {
System.out.print(" X ");
} else if (grid[x][y] == 2) {
System.out.print(" Y ");
}
}
System.out.println();
}
System.out.println();
System.out.println(" 1 2 3 4 5 6 7 ");
}
int readInt() {
try {
String input = in.readLine();
int number = Integer.parseInt(input);
return number;
} catch (NumberFormatException e) {
return -1;
} catch (IOException e) {
return -1;
}
}
}
I tried to make the evaluation function of this game a bit better by putting threeInARow method, which tests for the player to have 3 in a row or not. I don't know what to put the evaluation value for this method.
all names of variables used are having the same meaning as that in English language, so it wont be much of problem while reading the code.
The problem is with the threeInARow(), if it is removed, the game functions very well. What I have intended is to give three in A row some value which is more than 0 and less than that of 4 in a row.
The bugged part of the code
<code> int threeInARow()
{
int i=0,j;
int player=0;
for (i = 0; i < 6 - 2; i++) {
for (j = 0; j < 7; j++) {
if ((grid[j]<span style="font-weight:bold;">) == (grid[j][i+1]) && (grid[j]<span style="font-weight:bold;">) == (grid[j][i+2]) ) {
return player;
}
}
}
//Horizontal
for (i = 0; i < 6; i++) {
for (j = 0; j < 7 - 2; j++) {
if ((grid[j]<span style="font-weight:bold;">) == (grid[j+1]<span style="font-weight:bold;">) && (grid[j]<span style="font-weight:bold;">) == (grid[j+2]<span style="font-weight:bold;">)) {
return player;
}
}
}
//Diagonal '\'
for (i = 0; i < 6 - 2; i++) {
for (j = 0; j < 7 - 2; j++) {
if ((grid[j]<span style="font-weight:bold;">) == (grid[j + 1]) && (grid[j]<span style="font-weight:bold;">) == (grid[j + 2])) {
return player;
}
}
}
// Diagonal '/'.
for (j = 2; j < 7; j++) // diagonal –/
{
for (i = 0; i < 6 - 2; i++) {
if ((grid[j]<span style="font-weight:bold;">) == (grid[j + 1]) && (grid[j]<span style="font-weight:bold;">) == (grid[j + 2])) {
return player;
}
}
}
return 0;
}
</code>
p.s I am a hobby programmer and student of electronics, so this is not my assignment or home work, its just I wanted to have a better evaluation method.
You should post code in between [source] and [/source] tags.
Writing a good evaluation function for connect four is not easy. Distinguishing between even and odd threats is key. You should first learn how to play yourself. I would start here.
Writing a good evaluation function for connect four is not easy. Distinguishing between even and odd threats is key. You should first learn how to play yourself. I would start here.
@Alvaro
Right now I just want to use an evaluation which first sees three in a row, if it has chance the grab it or else block if the opponent has the chance, by no ways I am planing to make the computer play perfect. Later on I would like to introduce an opening book for it(from the same site). The point is that my evaluation neither sees four in a row nor three in a row neither for it self nor for opponent. Something gone wrong in the evaluation of threeInARow, the value expression.
I will re post the entire code using the source tags.
Right now I just want to use an evaluation which first sees three in a row, if it has chance the grab it or else block if the opponent has the chance, by no ways I am planing to make the computer play perfect. Later on I would like to introduce an opening book for it(from the same site). The point is that my evaluation neither sees four in a row nor three in a row neither for it self nor for opponent. Something gone wrong in the evaluation of threeInARow, the value expression.
I will re post the entire code using the source tags.
[Source]package connectfour;import java.io.*;import java.util.*;public class Connectfour {private static final int WIDTH = 7, HEIGHT = 6;private static final int MAX_RECURDEPTH = 4;private static BufferedReader in;private int[][] grid = new int[WIDTH][HEIGHT];private int[] columnHeight = new int[WIDTH];private static int recurDepth = 0;static int r = 0;public static void main(String[] args) {in = new BufferedReader(new InputStreamReader(System.in));new Connectfour();}public Connectfour() {Scanner read = new Scanner(System.in);int column, p;int player = 1;System.out.println("Who play first?");System.out.println("1.Player");System.out.println("2.Computer");p = read.nextInt();player = p;int move = 0;double value = 0;Vector moves = new Vector();int mov = 0;while (true) {if (player == 1) {printGrid();do {System.out.println("Make your move (1-7): ");column = readInt() - 1;} while (column < 0 || column >= WIDTH || columnHeight[column] >= HEIGHT);} else {moves.removeAllElements();column = 0;value = 0;double prevValue = -MAX_RECURDEPTH - 1;for (int x = 0; x < WIDTH; x++) {if (columnHeight[x] >= HEIGHT) {continue;}if (move == 0) {moves.add(new Integer(3));break;}if (p == 2 && move == 1) {moves.add(new Integer(3));break;}value = minmax(2, x);if (value > prevValue) {moves.removeAllElements();prevValue = value;}if (value == prevValue) {moves.add(new Integer(x));}}move++;System.out.println("VAlue=" + prevValue);if (moves.size() > 0) {Collections.shuffle(moves);column = ((Integer) moves.get(0)).intValue();}if (moves.size() == 0) {System.out.println("Its a draw.");break;}}grid[column][columnHeight[column]] = player;if (player == 2) {System.out.println("I PUT MY CHECKER IN " + (column + 1));}columnHeight[column]++;int haswon = 0;haswon = fourInARow();if (haswon > 0) {printGrid();if (player == 2) {System.out.println("I WON");} else {System.out.println("YOU WON");}break;}mov++;System.out.println(" MOVE= " + mov);player = 3 - player;}}double minmax(int player, int column) {double value = 0;double v;if (columnHeight[column] >= HEIGHT) {return 0;}recurDepth++;grid[column][columnHeight[column]] = player;columnHeight[column]++;if (fourInARow() > 0) {if (player == 2) {value = MAX_RECURDEPTH + 1 - recurDepth;System.out.println("player 2= "+value);} else {value = -MAX_RECURDEPTH - 1 + recurDepth;System.out.println("player 1="+value);}}if( threeInARow()>0);{if(player==2){value=MAX_RECURDEPTH-recurDepth;System.out.println("three player 2"+value);}else{value=-MAX_RECURDEPTH-5+recurDepth;System.out.println("three player 1 "+value);}}if (recurDepth < MAX_RECURDEPTH || value == 0) {value = MAX_RECURDEPTH + 1;for (int x = 0; x < WIDTH; x++) {if (columnHeight[x] >= HEIGHT) {continue;}v = minmax(3 - player, x);if (value == (MAX_RECURDEPTH + 1)) {value = v;} else if (player == 2) {if (value > v) {value = v;}} else if (v > value) {value = v;}}}recurDepth--;columnHeight[column]--;grid[column][columnHeight[column]] = 0;return value;}int threeInARow(){int i=0,j;int player=0;for (i = 0; i < 6 - 2; i++) {for (j = 0; j < 7; j++) {if ((grid[j]) == (grid[j][i+1]) && (grid[j]) == (grid[j][i+2]) ) {return player;}}}//Horizontalfor (i = 0; i < 6; i++) {for (j = 0; j < 7 - 2; j++) {if ((grid[j]) == (grid[j+1]) && (grid[j]) == (grid[j+2])) {return player;}}}//Diagonal '\'for (i = 0; i < 6 - 2; i++) {for (j = 0; j < 7 - 2; j++) {if ((grid[j]) == (grid[j + 1]) && (grid[j]<span style="font-weight:bold;">) == (grid[j + <span class="cpp-number">2</span>])) {<br><span class="cpp-keyword">return</span> player;<br>}<br><br>}<br>}<br><span class="cpp-comment">// Diagonal '/'.</span><br><span class="cpp-keyword">for</span> (j = <span class="cpp-number">2</span>; j < <span class="cpp-number">7</span>; j++) <span class="cpp-comment">// diagonal –/</span><br>{<br><span class="cpp-keyword">for</span> (i = <span class="cpp-number">0</span>; i < <span class="cpp-number">6</span> - <span class="cpp-number">2</span>; i++) {<br><span class="cpp-keyword">if</span> ((grid[j]<span style="font-weight:bold;">) == (grid[j + <span class="cpp-number">1</span>]) && (grid[j]<span style="font-weight:bold;">) == (grid[j + <span class="cpp-number">2</span>])) {<br><span class="cpp-keyword">return</span> player;<br>}<br><br><br>}<br>}<br><br><span class="cpp-keyword">return</span> <span class="cpp-number">0</span>;<br><br><br>}<br><br><span class="cpp-keyword">int</span> fourInARow() {<br><span class="cpp-keyword">int</span> num, player;<br><br><span class="cpp-keyword">for</span> (<span class="cpp-keyword">int</span> y = <span class="cpp-number">0</span>; y < HEIGHT; y++) {<br>num = <span class="cpp-number">0</span>;<br>player = <span class="cpp-number">0</span>;<br><span class="cpp-keyword">for</span> (<span class="cpp-keyword">int</span> x = <span class="cpp-number">0</span>; x < WIDTH; x++) {<br><span class="cpp-keyword">if</span> (grid[x][y] == player) {<br>num++;<br>} <span class="cpp-keyword">else</span> {<br>num = <span class="cpp-number">1</span>;<br>player = grid[x][y];<br>}<br><span class="cpp-keyword">if</span> (num == <span class="cpp-number">4</span> && player > <span class="cpp-number">0</span>) {<br><span class="cpp-keyword">return</span> player;<br>}<br>}<br>}<br><br><span class="cpp-keyword">for</span> (<span class="cpp-keyword">int</span> x = <span class="cpp-number">0</span>; x < WIDTH; x++) {<br>num = <span class="cpp-number">0</span>;<br>player = <span class="cpp-number">0</span>;<br><span class="cpp-keyword">for</span> (<span class="cpp-keyword">int</span> y = <span class="cpp-number">0</span>; y < HEIGHT; y++) {<br><span class="cpp-keyword">if</span> (grid[x][y] == player) {<br>num++;<br>} <span class="cpp-keyword">else</span> {<br>num = <span class="cpp-number">1</span>;<br>player = grid[x][y];<br>}<br><span class="cpp-keyword">if</span> (num == <span class="cpp-number">4</span> && player > <span class="cpp-number">0</span>) {<br><span class="cpp-keyword">return</span> player;<br>}<br>}<br>}<br><br><span class="cpp-keyword">for</span> (<span class="cpp-keyword">int</span> xStart = <span class="cpp-number">0</span>, yStart = <span class="cpp-number">2</span>; xStart < <span class="cpp-number">4</span>;) {<br>num = <span class="cpp-number">0</span>;<br>player = <span class="cpp-number">0</span>;<br><span class="cpp-keyword">for</span> (<span class="cpp-keyword">int</span> x = xStart, y = yStart; x < WIDTH && y < HEIGHT; x++, y++) {<br><span class="cpp-keyword">if</span> (grid[x][y] == player) {<br>num++;<br>} <span class="cpp-keyword">else</span> {<br>num = <span class="cpp-number">1</span>;<br>player = grid[x][y];<br>}<br><span class="cpp-keyword">if</span> (num == <span class="cpp-number">4</span> && player > <span class="cpp-number">0</span>) {<br><span class="cpp-keyword">return</span> player;<br>}<br>}<br><span class="cpp-keyword">if</span> (yStart == <span class="cpp-number">0</span>) {<br>xStart++;<br>} <span class="cpp-keyword">else</span> {<br>yStart–;<br>}<br>}<br><br><span class="cpp-keyword">for</span> (<span class="cpp-keyword">int</span> xStart = <span class="cpp-number">0</span>, yStart = <span class="cpp-number">3</span>; xStart < <span class="cpp-number">4</span>;) {<br>num = <span class="cpp-number">0</span>;<br>player = <span class="cpp-number">0</span>;<br><span class="cpp-keyword">for</span> (<span class="cpp-keyword">int</span> x = xStart, y = yStart; x < WIDTH && y >= <span class="cpp-number">0</span>; x++, y–) {<br><span class="cpp-keyword">if</span> (grid[x][y] == player) {<br>num++;<br>} <span class="cpp-keyword">else</span> {<br>num = <span class="cpp-number">1</span>;<br>player = grid[x][y];<br>}<br><span class="cpp-keyword">if</span> (num == <span class="cpp-number">4</span> && player > <span class="cpp-number">0</span>) {<br><span class="cpp-keyword">return</span> player;<br>}<br>}<br><span class="cpp-keyword">if</span> (yStart == HEIGHT - <span class="cpp-number">1</span>) {<br>xStart++;<br>} <span class="cpp-keyword">else</span> {<br>yStart++;<br>}<br>}<br><span class="cpp-keyword">return</span> <span class="cpp-number">0</span>;<br>}<br><br><span class="cpp-keyword">void</span> printGrid() {<br><span class="cpp-keyword">int</span> x = <span class="cpp-number">0</span>;<br><span class="cpp-keyword">int</span> y = <span class="cpp-number">0</span>;<br><br><span class="cpp-keyword">for</span> (y = HEIGHT - <span class="cpp-number">1</span>; y >= <span class="cpp-number">0</span>; y–) {<br><span class="cpp-keyword">for</span> (x = <span class="cpp-number">0</span>; x < WIDTH; x++) {<br><span class="cpp-keyword">if</span> (grid[x][y] == <span class="cpp-number">0</span>) {<br>System.out.print(<span class="cpp-literal">" . "</span>);<br>} <span class="cpp-keyword">else</span> <span class="cpp-keyword">if</span> (grid[x][y] == <span class="cpp-number">1</span>) {<br>System.out.print(<span class="cpp-literal">" X "</span>);<br>} <span class="cpp-keyword">else</span> <span class="cpp-keyword">if</span> (grid[x][y] == <span class="cpp-number">2</span>) {<br><br>System.out.print(<span class="cpp-literal">" Y "</span>);<br><br><br>}<br><br><br><br>}<br><br>System.out.println();<br>}<br>System.out.println();<br><br>System.out.println(<span class="cpp-literal">" 1 2 3 4 5 6 7 "</span>);<br><br><br><br><br>}<br><br><span class="cpp-keyword">int</span> readInt() {<br><span class="cpp-keyword">try</span> {<br>String input = in.readLine();<br><span class="cpp-keyword">int</span> number = Integer.parseInt(input);<br><span class="cpp-keyword">return</span> number;<br>} <span class="cpp-keyword">catch</span> (NumberFormatException e) {<br><span class="cpp-keyword">return</span> -<span class="cpp-number">1</span>;<br>} <span class="cpp-keyword">catch</span> (IOException e) {<br><span class="cpp-keyword">return</span> -<span class="cpp-number">1</span>;<br>}<br><br>}<br>}<br><br>[/Source]</pre></div><!–ENDSCRIPT–><br><br><br>The bugged code.<br><!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre><br><span class="cpp-keyword">int</span> threeInARow()<br>{<br><span class="cpp-keyword">int</span> i=<span class="cpp-number">0</span>,j;<br><span class="cpp-keyword">int</span> player=<span class="cpp-number">0</span>;<br><span class="cpp-keyword">for</span> (i = <span class="cpp-number">0</span>; i < <span class="cpp-number">6</span> - <span class="cpp-number">2</span>; i++) {<br><span class="cpp-keyword">for</span> (j = <span class="cpp-number">0</span>; j < <span class="cpp-number">7</span>; j++) {<br><span class="cpp-keyword">if</span> ((grid[j]<span style="font-weight:bold;">) == (grid[j][i+<span class="cpp-number">1</span>]) && (grid[j]<span style="font-weight:bold;">) == (grid[j][i+<span class="cpp-number">2</span>]) ) {<br><span class="cpp-keyword">return</span> player;<br>}<br><br>}<br>}<br><br><span class="cpp-comment">//Horizontal</span><br><br><span class="cpp-keyword">for</span> (i = <span class="cpp-number">0</span>; i < <span class="cpp-number">6</span>; i++) {<br><span class="cpp-keyword">for</span> (j = <span class="cpp-number">0</span>; j < <span class="cpp-number">7</span> - <span class="cpp-number">2</span>; j++) {<br><span class="cpp-keyword">if</span> ((grid[j]<span style="font-weight:bold;">) == (grid[j+<span class="cpp-number">1</span>]<span style="font-weight:bold;">) && (grid[j]<span style="font-weight:bold;">) == (grid[j+<span class="cpp-number">2</span>]<span style="font-weight:bold;">)) {<br><span class="cpp-keyword">return</span> player;<br>}<br><br>}<br><br>}<br><span class="cpp-comment">//Diagonal '\'</span><br><br><span class="cpp-keyword">for</span> (i = <span class="cpp-number">0</span>; i < <span class="cpp-number">6</span> - <span class="cpp-number">2</span>; i++) {<br><span class="cpp-keyword">for</span> (j = <span class="cpp-number">0</span>; j < <span class="cpp-number">7</span> - <span class="cpp-number">2</span>; j++) {<br><span class="cpp-keyword">if</span> ((grid[j]<span style="font-weight:bold;">) == (grid[j + <span class="cpp-number">1</span>]) && (grid[j]<span style="font-weight:bold;">) == (grid[j + <span class="cpp-number">2</span>])) {<br><span class="cpp-keyword">return</span> player;<br>}<br><br>}<br>}<br><span class="cpp-comment">// Diagonal '/'.</span><br><span class="cpp-keyword">for</span> (j = <span class="cpp-number">2</span>; j < <span class="cpp-number">7</span>; j++) <span class="cpp-comment">// diagonal –/</span><br>{<br><span class="cpp-keyword">for</span> (i = <span class="cpp-number">0</span>; i < <span class="cpp-number">6</span> - <span class="cpp-number">2</span>; i++) {<br><span class="cpp-keyword">if</span> ((grid[j]<span style="font-weight:bold;">) == (grid[j + <span class="cpp-number">1</span>]) && (grid[j]<span style="font-weight:bold;">) == (grid[j + <span class="cpp-number">2</span>])) {<br><span class="cpp-keyword">return</span> player;<br>}<br><br><br>}<br>}<br><br><span class="cpp-keyword">return</span> <span class="cpp-number">0</span>;<br><br><br>}<br></pre></div><!–ENDSCRIPT–>
Your code for "diagonal /" in threeInARow() is wrong. You have 2 <= j < 7, and then you add up to 2 to it...
I haven't tried to find any more problems in your program, but you should be more careful.
I haven't tried to find any more problems in your program, but you should be more careful.
Maybe I'm nuts - but it seems like you initialize player to zero and never change it. So your return value is zero, even if you've detected a 3 in a row
Quote: Original post by snak
Maybe I'm nuts - but it seems like you initialize player to zero and never change it. So your return value is zero, even if you've detected a 3 in a row
Ha, ha. I missed that too. Running your code through a few test cases is a good idea and would have caught this in a minute.
Thanks all of you for your help, now one more step of it, can any one tell me how to build an opening book for connect four (The resource is from the above link given by a user of this community.), I have no idea as to how to build it .
Do I have to study a database or something equivalent, I am just a hobby programmer with intermediate knowledge of Java
Do I have to study a database or something equivalent, I am just a hobby programmer with intermediate knowledge of Java
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement