I have studied functions, pointers, recursive(I suck at it though), file handling(slightly), loops and a bit of data structures. My final project of my semester is due very soon. I chose othello. Before I was able to succesfully make hangman. Now, this is my first time that I am trying a two player game. I would at least like to make human vs. human game in due time.

have been able to make the board of the game using char and I shall identity the positions of every block in the board by the row and coloumn number of the board which the user shall enter for that board 2D array. My question is, how do I get started with the player moves? A little push in the right direction would be very nice.

Thank you.

Ask for input
Accept input
Figure out what block the input signifies.

There is this thing I donot understand. Do I have to manually ask for input everytime? from the player 1 and player 2? I can not seem to grasp how I should keep a check on the board because I will have to stop asking for input when the board is full and no valid moves are left. I have to see if the players are making a valid move or not everytime they input a move.

Things are jumbling up. Sad face.

I assume this is a console program, not a graphical program, correct? It seems like you would have to ask for input every time. There is a white player and a black player. You ask the white player where he wants to place the white disk, then you place it there and you figure out what black chips need to reverse to white. Same thing for the black player. Redraw the board after you've figured that out.

As to your other questions, yes to all. You need to, at minimum, do all of the following before asking for a move.

  1. Make sure there is at least one legal move that can be made.
  2. Make sure the game is not over yet.

Once the user types in a move, you have to...

  1. Parse the user input into coordinates you can use.
  2. Make sure the coordinates entered are within the bounds of a board.
  3. Make sure the board does not already have a chip where the user is placing it.
  4. Make sure it's a legal move if any other tests need to be done.
  5. If the move is legal, recaluculate and redraw the board.
  6. If the game is over, display a message saying so.
  7. Otherwise give an error message and prompt again.
commented: Very helpful. +0

That is very helpul. I have been able to do the firsttwo mentioned points of the user entering his move. The rest of the things, I need to keep track of. I can simply use if else statements to check for the point number 3.

Now, the trouble that has been bothering me is from point 4. How do I check if the entered move is valid for outflanking the opponent's piece? Should I make a function called check which I should run for every user's move? and I will need to check every row, every coloumn. That is fine. But how do I check for pieces diagonally?

Your help is appreciated. Thank you for your patience.

This is not a trivial program. You'll need to spend a lot of time with pencil and paper tracing out the overall flow of the program. Each of the steps listed above will have sub-steps, and some of those steps will have sub-steps, etc.

Familiarize yourself thoroughly with the rules of Othello. It's been a while since I've played, so my advice is from memory. You'll need to verify that my understanding of what a legal move is accurate.

A legal move must comply to the following...

  • Coordinates are on the board (obviously)
  • Coordinates do not already have a piece
  • Coordinates are "next to" (including diagonally) at least one chip of the opposite color.
  • The move must result in at least one chip of your opponents becoming your chip.

First two are pretty easy. Third one is slightly harder. Fourth one is the hardest.

You have at most eight directions to check. If you are at an edge or a corner, obviously, you have fewer. You only check a direction if you have an opponent's chip located one unit away (including diagonally) in that direction. So a good helper function might be to determine which of the eight directions you need to check.

Presume you have a board that is represented by a 2 dimensionaly array of integers (0 = vacant, 1 = white, 2 = black). So after you have determined that this is a direction to check, you go off in that direction and four possibilities might happen.

  1. You hit an opponent's piece. Keep going.
  2. You hit your own piece. Stop and turn all the pieces in between the two pieces over.
  3. You hit a wall. Stop. There's nothing to flip.
  4. You hit a vacant spot. Stop. There's nothing to flip.

All of these tasks fit nicely into helper functions. It's quite a modular task. That makes it easier. Start attacking them one by one. You'll want to start with the ability to draw board and take user input. Then start taking things one at a time. Spend a few hours designing the whjole thing on pencil and paper first, then implement a function at a time, top-down.

and I will need to check every row, every coloumn. That is fine. But how do I check for pieces diagonally?

See above points. Don't check every row and column. Check every DIRECTION, including diagonally. Start where the piece is being placed, check every direction where an opponent has a piece in that direction. Then, as described, "walk" the board and see what you hit first in that direction (wall, your own piece, vacant spot).

My board is a char board containing black and white pieces represented by alphabets. I can successfully take input from the user. and check if the entered input lies on the board, if there is not aready a piece there. But there is this thing I can not fanthom, how to check if the game is not over? You check that by seeing is there are any valid moves left. And I am familiar with the rules of othello which confirm what a valid move is. But I can not put together the conditions of a valid move. And I was thinking if I could simply place a while loop until the game in not over and inside the two human vs. human players take turns and the game proceeds for valid moves and exits for invalid moves. Will the while loop work? Now, I think of it, if I have to take manually the use input everytime, when do I know how many times I have to ask for input?
Sort of having a brainfreeze because of the deadline that is literally over my head.

VernonDozier, thank you ever so much for your advice and tips, they are very helpful and I do have a clear picture of what I want but getting it done needs a 'how' for me at the moment. Thank you once more.

But there is this thing I can not fanthom, how to check if the game is not over? You check that by seeing is there are any valid moves left. And I am familiar with the rules of othello which confirm what a valid move is. But I can not put together the conditions of a valid move.

Turn the computer off.
Write down the rules.
Which one is most important? How would you test for that condition? Write down the steps.
Which one is next? How would you test for that? Write down the steps.
Keep it up until all the rules have bee tested.
You now have the basis for your test algorithm. Convert the algorithm into code and go through it over and over --step by step -- until it seems to work for all conditions.
Then, and only then, turn the computer on, type your new code into a function, and test test test.

And I was thinking if I could simply place a while loop until the game in not over and inside the two human vs. human players take turns and the game proceeds for valid moves and exits for invalid moves. Will the while loop work?

Yes.

Now, I think of it, if I have to take manually the use input everytime, when do I know how many times I have to ask for input?

What???? I have no idea what you are asking. Carefully rephrase the question.

Now, I think of it, if I have to take manually the use input everytime, when do I know how many times I have to ask for input?

What???? I have no idea what you are asking. Carefully rephrase the question.

I will do that right now, Define the rules. Absolutely.
I was asking in that question, that I will have to ask for input from the user for every turn manually? For example, it is first player's turn. He makes a move. I check if his move is legal. If it is, then i place it on the board. Next, it is the turn of the other player. I ask for input from the other player and repeat the same steps.

But it is a human. vs. human game and how will I know when to stop asking for input from the user (i.e. the game is over. How shall I know that? Or maybe, I should repeatedly test after every move if any valid moves are available. Yes? As soon as it turns to false, I prompt the game is over. )
So, is this going in the right direction?

Yes, you're going in the right direction...

ill do that right now, Define the rules. Absolutely.
I was asking in that question, that I will have to ask for input from the user for every turn manually? For example, it is first player's turn. He makes a move. I check if his move is legal. If it is, then i place it on the board. Next, it is the turn of the other player. I ask for input from the other player and repeat the same steps.

But it is a human. vs. human game and how will I know when to stop asking for input from the user (i.e. the game is over. How shall I know that? Or maybe, I should repeatedly test after every move if any valid moves are available. Yes? As soon as it turns to false, I prompt the game is over. )
So, is this going in the right

You will have to make function for valid move which will check valid move..... one functiion will be to change the turn back and forth between white and black player.... and ofcourse for game ending you will also make a function which will check whether the game is over after every move..... roughly your main loop which will run the game will look something like this:

while(FUNCTION TO CHECK GAME WILL CONTINUE OR END)
{
    if(FUNCTION TO CCHECK VALID MOVE??)
    {
        RE DRAW THE BOARD...
        CHANGE THE TURN...
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.