Java array Connect 4 search, help!
Posted on 2006-04-20
Ok, i am attempting to make a connect four like game in java, however i have hit a problem. The problem is searching for the four counters in a row! It is a little difficult to explain, but basicaly here is the code for searching for 4 next to eachother in a row (horizontaly accross the board) (which i thought should work, and find four in a row):
int noinrow = 0;
for (int row=0; row<6; row++)
for(int column=0; column<4; column++)
for(int check=0;check<3; check++)
noinrow = noinrow + 1;
c = c+1;
x = x +1;
c = x;
x = 0;
c = 0;
y = y +1;
d = d+1;
ok a few thing:
grid.get_pos(x,y) gets the value stored in the array at possition (x,y). The array is the connect four grid. Ether a 1 for player 1s counter or a 2 for player 2's counter is stored in the array, or 0 if empty.
winner - this displays a message box stating who is the winner.
the idea was that it would search along the bottom line, then the next line up etc. til if found, if any, four in a row.
Ok now i though this should work but it dosnt. I know this (if it worked) only searches along the rows (horizontaly) of the grid, but i figured if i could get this to work, i could, with ALOT of difficulty get the others to work - searching verticaly and diagonaly.
Anywhy, this dont work, can anyone suggest what is wrong, or other ways of doing it?
Any help would be MUCH appreciated. And i would be VERY greatfull for any help.