- Check if the board is full, meaning that all cells are occupied and not empty
- Then make sure there aren't any winning patterns for 'x' -- use your checkAll('x')
- Then make sure there aren't any winning patterns for 'o' -- use your checkAll('o')
- If all the above passed then it is a tie
firstPerson
Industrious Poster
4,044 posts since Dec 2008
Reputation Points: 851
Solved Threads: 625
Skill Endorsements: 15
It should be something like so, in psuedo code:
bool isFull(board){
bool isFull = true;
for i = 0 to board.length # 0 <= i <= 8
if board[i] != 'x' && board[i] != 'o'
isFull = false;
break;
return isFull;
}
firstPerson
Industrious Poster
4,044 posts since Dec 2008
Reputation Points: 851
Solved Threads: 625
Skill Endorsements: 15
def is_full(board):
return all(p in tuple('xo') for p in board)
or
def is_full(board):
return not ''.join(str(p) for p in board).strip('xo')
pyTony
pyMod
6,308 posts since Apr 2010
Reputation Points: 879
Solved Threads: 986
Skill Endorsements: 26