Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Java logic question for a board game?
I am writing a very simple program similar to tic tac toe. I have the entire program completed, except for the ability to look for a cat's game type scenario. I know how to detect whether the entire board has been filled, but want to be able to detect whether there are any options for scoring, without the entire board having to be filled.
For example, if you have this
Let's say you have a 4x4 board, with the following:
x _ o _
o o _ x
_ o x _
_ x _ o
There are still several open spots, but no one could possibly score based on the moves. Rather than spending the next 7 turns proving this by filling up the board I want a method that can detect that there is a cat's game. I need to be able to do this for board sizes up to 7x7. I can't seem to work out a way in my head to do this.
Sorry I realize I missed an x in the bottom corner and someone could still score in the board I posted. Let's ignore this oversight and think about the question.
1 Answer
- ?Lv 710 years agoFavorite Answer
If your example counting diagonals, you have ten possible winning rows/columns/diagonals. (4 horizontal, 4 vertical, 2 diagonal.)
Start at the first row.
Is there an X? If so, if any of the next three cells have an O, it's a possible draw.
Is there an O? If so, if any of the next three cells have an X, it's a draw.
Etc.
If ALL possibles are ALL draws, you have a guaranteed cat's game.
Basically, if a cell is filled, if any of the other cells in that row/column/diagonal are filled with the opposing mark, you have a possible draw. Increment one to your possible draw counter. If your possible draw counter equals the number of possible winning conditions, cat's game.
Source(s): computer programmer myself