Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Help on some work i got ! Reversi game

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Member
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    2
    Thanked 7 Times in 6 Posts

    Default 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:
    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.
    Last edited by dabdi; September 22nd, 2011 at 02:22 AM.

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Member
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    2
    Thanked 7 Times in 6 Posts

    Default Re: Help on some work i got ! Reversi game

    Quote Originally Posted by KevinWorkman View Post
    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..

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Member
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    2
    Thanked 7 Times in 6 Posts

    Default Re: Help on some work i got ! Reversi game

    Quote Originally Posted by KevinWorkman View Post
    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 ??
    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.
    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.

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help on some work i got ! Reversi game

    Quote Originally Posted by dabdi View Post
    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 View Post
    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 View Post
    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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Member
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    2
    Thanked 7 Times in 6 Posts

    Default Re: Help on some work i got ! Reversi game

    Sent you a PM.

  9. #9
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help on some work i got ! Reversi game

    Dabdi, please read section 7 of the forum announcements/rules:
    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.
    Last edited by copeg; September 22nd, 2011 at 11:39 AM.

  10. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help on some work i got ! Reversi game

    Quote Originally Posted by copeg View Post
    Dabdi, please read section 7 of the forum announcements/rules:


    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.
    Bahaha, good point. I'm locking this one.

    OP, if for some reason you do come back looking for an answer, feel free to repost your question (I'd advise asking a more specific question next time around though).
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. [SOLVED] Can't get JFreeChart to work
    By igniteflow in forum Java SE APIs
    Replies: 2
    Last Post: February 15th, 2011, 02:19 AM
  2. MergeSort won't work
    By joshft91 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 7th, 2011, 09:44 PM
  3. home work ..
    By shane1987 in forum Collections and Generics
    Replies: 8
    Last Post: November 16th, 2010, 09:45 AM
  4. begginer wondering why his guessing game won't work
    By Ligawulf in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 8th, 2010, 12:22 AM
  5. my run program does not work
    By rman27bn in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 16th, 2009, 09:13 AM