We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,166 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

TicTacToe- How to make it recognize a tie?

I've been trying for a while and can't figure it out
http://pastebin.com/4PZj2c9s

3
Contributors
7
Replies
2 Days
Discussion Span
4 Months Ago
Last Updated
8
Views
SumTingWong59
Newbie Poster
7 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
  • 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

I'm having trouble figuring out how to check if all squares are full, could I get some more help with that?

SumTingWong59
Newbie Poster
7 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

i am getting an invalid syntax error for that first line
sorry i havent learned bool yet :/
i also cant find anything about 'bool' after googling it

SumTingWong59
Newbie Poster
7 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

ok so i kind of understand bool now but still have no idea whats wrong
updated code: (line 36)
http://pastebin.com/9na85n80

SumTingWong59
Newbie Poster
7 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

back to square one, any other help would be very appreciated, all i need now is how to check if the board is full

SumTingWong59
Newbie Poster
7 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
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
Moderator
6,308 posts since Apr 2010
Reputation Points: 879
Solved Threads: 986
Skill Endorsements: 26

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0782 seconds using 2.69MB