# Help on some work i got ! Reversi game

• March 22nd, 2011, 01:47 PM
benni7
Help on some work i got ! Reversi game
hey guys

i have a question i got for homework

the program is a basicly an Othelo/Reversi game

ive been writing some functions that changes the board according to legal playes
and now im being asked to create a function(BENEFIT) that counts the amount of enemy discs changeed based on the last play.

public static int benefit(int[][] board, int player, int row, int column){

int ans = 0;// YOU CAN CHANGE IT !!

return ans;
}//end of benefit

problem is its easied to count the maount of changes in the "play" function using COUNT++;

but i have no idea how am i suppose to use Benefit Function in order to count those changes. moreover it should sum the total amount of changes not only change per row/col/diagonal , instead it needs to return the changes of row+col+diagonal of a single play.

can anyone help me out?

heres some of the play function if it helps (the way ive written it anyways):
public static int[][] play(int[][] board, int player, int row, int column){
if (isLegal(board,player,row,column)){
if (isLegalrowright(board,player,row,column)){
//switching row right according to rules
int j=column;
while (j<=board[row].length-1&&board[row][j]!=player){
board[row][j]=player;
j=j+1;
}//while

}
if (isLegalrowleft(board,player,row,column)){
//switching row left according to rules
int j=column;
while (board[row][j]!=player&&j>=0){
board[row][j]=player;
j=j-1;
}//while
}
exc...
u can see adding co++ after board[row][j]=player will be the easiest solution but its not what i asked .. sadly.

thanks for help and sorry for length.
• September 22nd, 2011, 02:16 AM
dabdi
Re: Help on some work i got ! Reversi game
You need to scan through eight directions and check if opponent discs can be flipped.
So if you have an 8x8 board, and a point class with (x,y) coordinates, you would flip disks in one direction as follows:
Code java:

```int flipDisks(Point from, Point dir, int side) { int count = 0; for(Point to = from;;to += dir) if( color[to] == !side) count++; else if(color[to] == edge) return 0; else break; return count; }```
This scans in one direction until it encounters an edge or a disk of our own color. If we encounter an edge
disks are not flipped. Opponent disks have to be sandwiched between two of our own IIRC.
Then do the flip for N,S,E,W,NW,NE,SW,SE directions and sum the counts to get the total.
• September 22nd, 2011, 07:43 AM
KevinWorkman
Re: Help on some work i got ! Reversi game
dabdi, I suggest you give this a read-through: http://www.javaprogrammingforums.com...n-feeding.html
• September 22nd, 2011, 09:04 AM
dabdi
Re: Help on some work i got ! Reversi game
Quote:

Originally Posted by KevinWorkman
dabdi, I suggest you give this a read-through: http://www.javaprogrammingforums.com...n-feeding.html

Kevinworkman, lighten up really! What exactly did you find spoon feeding here ? (a) OP did a lot of work by himself b) I gave him a pseudo code that would definitely _not_ work. Just demonstrates algorithm. (c) I made an effort to explain it and things he should worry about (d) I am quite knowledgeable about what I suggested. etcetra..
• September 22nd, 2011, 09:10 AM
KevinWorkman
Re: Help on some work i got ! Reversi game
I don't feel the need to lighten up really. Nothing I said was angry or threatening- I simply suggested you read an article, based on a few posts I've seen you make recently. The spoon-feeding policy is something to be aware of, especially when answering questions about homework. I'm not sure what your code is supposed to do, or how it relates to the OP's problem (maybe you're better at deciphering broad questions than I am), so I'm not going to fight about it. It's just something to think about as you continue attempting to answer questions.
• September 22nd, 2011, 09:31 AM
dabdi
Re: Help on some work i got ! Reversi game
Quote:

Originally Posted by KevinWorkman
I don't feel the need to lighten up really. Nothing I said was angry or threatening- I simply suggested you read an article, based on a few posts I've seen you make recently.

No thank you. Again what exactly did you find wrong with my _other_ posts ??
Quote:

The spoon-feeding policy is something to be aware of, especially when answering questions about homework. I'm not sure what your code is supposed to do, or how it relates to the OP's problem (maybe you're better at deciphering broad questions than I am), so I'm not going to fight about it.
Then let it go. Hint I have reversi programs that 99% humans could not beat.
Quote:

It's just something to think about as you continue __attempting__ to answer questions.
Unbelievable how I spend my time is none of your business. If you think I broke forum rules mention your reasons , otherwise go away.
• September 22nd, 2011, 09:44 AM
KevinWorkman
Re: Help on some work i got ! Reversi game
Quote:

Originally Posted by dabdi
No thank you. Again what exactly did you find wrong with my _other_ posts ??

You simply have a habit of posting full code solutions, and if you'd read the link I posted, you'd know that doing so robs people of the process of working through a problem. It's also considered cheating by many educational institutions (in my current class, if we get code from the internet, he gives us a grade and then takes the negative of it, so the better the code we copy is, the worse we do).

Quote:

Originally Posted by dabdi
Then let it go. Hint I have reversi programs that 99% humans could not beat.

I'm not sure who you're trying to impress. My only interest in this site is to help people learn how to program- and providing code (especially incomplete or incorrect code) does not help them learn. Posting examples, or tutorials, or asking for clarification are better ways to help somebody work through a problem.

Quote:

Originally Posted by dabdi
Unbelievable how I spend my time is none of your business. If you think I broke forum rules mention your reasons , otherwise go away.

Sounds like you're the one who needs to "lighten up". I've mentioned my reasons above. I also said, several times, that I'm not actually accusing you of anything- you're just approaching a line, so I'm making you aware of it. Continued violations will result in moderator action. Continued arguing in this post will get it locked (which wouldn't help the OP, so please don't make me do that). If you want to discuss this further, send me a PM.
• September 22nd, 2011, 11:16 AM
dabdi
Re: Help on some work i got ! Reversi game
Sent you a PM.
• September 22nd, 2011, 11:36 AM
copeg
Re: Help on some work i got ! Reversi game
Quote:

While we will help you with your homework/other projects, realize we won't do it for you. If we see that you have at least given some effort, we will try to assist you free of charge (aka. posting code, giving us your thoughts on how to solve the problem). Providing homework solutions in full or in part is frowned upon, and contributions that are considered as such will be subject to moderation (editing and/or deletion)
I do hope you read the link Kevin provided, as it contains information that goes hand in hand with the above policy.

...and please note that the initial question was posted more than half a year ago.
• September 22nd, 2011, 11:38 AM
KevinWorkman
Re: Help on some work i got ! Reversi game
Quote:

Originally Posted by copeg