Help on writing a othello program

This is a discussion on Help on writing a othello program within the C Programming forums, part of the General Programming Boards category; I stop for a loooong time, Code: int updateBoard(char board[8][8], int player, int xpos, int ypos); The function updates the ...

  1. #1
    Registered User alice's Avatar
    Join Date
    Mar 2004
    Posts
    36

    Help on writing a othello program

    I stop for a loooong time,

    Code:
    int updateBoard(char board[8][8], int player, int xpos, int ypos);
    The function updates the board after placing a token at a board position. The parameter board is a 2D array, each element contains an integral value representing the status of the board
    position. The board position is empty if the value is 0, the board position is occupied by a token
    displaying white if the value is 1, and the token is displaying black if the value is 2. The
    parameter player can have value 1 representing that the white player is making this move, or 2
    representing that the black player is making this move. The parameters xpos and ypos
    represent the positions where the player's token is placed. The top-left position (xpos, ypos) is
    (0, 0).

    The function should return the number of tokens flipped by the move, or it returns íV1 if the
    move is an invalid move. A move is invalid if no token is flipped by this move.

    Anyone can give me some hints on how to do..? thk a lot

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Anyone can give me some hints on how to do..?
    Can you write down the exact steps on paper? Do you have a good idea of what is going on in you rmind? If not, you aren't familiar enough with the problem to come up with a solution. Judging from your question, it seems this is the case. Do some thinking before you start writing code and the program will be much simpler.
    My best code is written with the delete key.

  3. #3
    Welcome to the real world
    Join Date
    Feb 2004
    Posts
    50
    What exactly have you worked out so far? Do you have code that you could show us?

    After reading your problem, all you really have to do is to have 2 nested for loops to check the value of the array that represents the othello board and go from there.

    Post some code and then ask us a specific question as to where you are having a problem.

  4. #4
    Registered User alice's Avatar
    Join Date
    Mar 2004
    Posts
    36
    My procedure of doing:

    | upward: table[i][ypos] where i is descreasing starting from xpos

    | downward: table[i][ypos] where i is increasing starting from xpos

    - left: table[xpos][j] where j is decreasing starting from ypos

    - right: table[xpos][j] where j is increasing starting from ypos

    \ upward: table[i][j] where i and j decreasing starting from xpos and ypos

    \ downward: table[i][j] where i and j increasing starting from xpos and ypos

    / upward: table[i][j] where i descreased by 1 and j increased by 1 starting from xpos and ypos

    / downward: table[i][j] where i increased by 1 and j decreased by 1 starting from xpos and ypos

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    So if you are player 2, and currently at table[3][4], how do you check the first square to see if table[3][4] is valid? Waht are you checking for? And if you get the right value, what do you do next?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing a program to make a calendar
    By Northstar in forum C Programming
    Replies: 17
    Last Post: 11-07-2007, 11:34 AM
  2. writing a calendar program help please!!!
    By Newbie2006 in forum C Programming
    Replies: 7
    Last Post: 11-20-2002, 07:36 PM
  3. Replies: 5
    Last Post: 11-19-2002, 09:36 PM
  4. Help with a file writing program
    By pritesh in forum C Programming
    Replies: 3
    Last Post: 11-11-2001, 01:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21