d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Othello Reversi Java Project
Add Reply New Topic New Poll
Member
Posts: 9,664
Joined: Dec 22 2007
Gold: 845.30
Feb 29 2016 09:36pm
Code
while(rowsAbove >= 0){//this check positions upward
int i = 1;
boolean tempFlipArray[][] = new boolean[8][8];
if(gameBoard.board[tempRow - i][tempCol].equals(" _")){
tempFlipArray[tempRow - i][tempCol] = true;
rowsAbove--;
i++;
for(int r = 0; r < 8; r++){
for(int c = 0; c < 8; c++){
if(tempFlipArray[r][c])
arrayToFlip[r][c] = tempFlipArray[r][c];
}
}
}
else if(gameBoard.board[tempRow - i][tempCol].equals(" O")){
tempFlipArray[tempRow - i][tempCol] = true;
rowsAbove--;
i++;
}
else
break;


I can not figure out at all how to get the things to flip over. Does anyone have any guesses? The game of reverse checks every direction and the board has x and o. _ stands for a potential move and "." stand for just an empty space. I'm trying to make it check all positions upward in this while loop and Idk how to make sure they all work. any ideas
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Feb 29 2016 10:24pm
not sure what you want, you want to find every possible piece that might need to be updated after a piece is placed?
Member
Posts: 9,664
Joined: Dec 22 2007
Gold: 845.30
Feb 29 2016 10:36pm
yes. all 8 directions, left right top bottom and the diagonals. play a quick game of reversi and you'll see what i mean
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Feb 29 2016 10:39pm
i dont think anyone's interested in playing reversi to figure out what you're doing.

if it's only 8 spots, why not hard code them?

row-1 col - 1; row-1 col; row-1 col+1
row col-1; row col+1
row+1 col - 1; row+1 col; row+1 col+1

make sure to check boundaries in case you're at an end/corner
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Feb 29 2016 11:15pm
Quote (carteblanche @ Feb 29 2016 09:39pm)
i dont think anyone's interested in playing reversi to figure out what you're doing.

if it's only 8 spots, why not hard code them?

row-1 col - 1; row-1 col; row-1 col+1
row col-1; row col+1
row+1 col - 1; row+1 col; row+1 col+1

make sure to check boundaries in case you're at an end/corner


this is what i was thinking off using an m x n matrix, piece placed at x,y; pseudo/python code, hopefully I didn't reverse the logic anywhere

vertical checking:
for i from 0 to m:
if i !=x
checkpiece(i,y)

horizontal checking
for i from 0 to n:
if i != y:
checkpiece(x,i)

negative slope diagonal checking
starty = y
while x > 0 and y > 0:
x = x - 1
y = y - 1
for i from 0 to n:
if i !=starty:
checkpiece(x,y)

positive slope diagonal checking
starty = y
while x < m and y > 0:
x = x + 1
y = y - 1
for i from 0 to n:
if i != starty:
checkpiece(x,y)







Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Feb 29 2016 11:19pm
sorry jsp chewed that up pretty good, and i'm not allowed to edit posts!

Code
vertical checking:
for i from 0 to m:
if i !=x
checkpiece(i,y)

horizontal checking
for i from 0 to n:
if i != y:
checkpiece(x,i)

negative slope diagonal checking
starty = y
while x > 0 and y > 0:
x = x - 1
y = y - 1
for i from 0 to n:
if i !=starty:
checkpiece(x,y)

positive slope diagonal checking
starty = y
while x < m and y > 0:
x = x + 1
y = y - 1
for i from 0 to n:
if i != starty:
checkpiece(x,y)
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll