Return True if player is a winner on this TTTBoard.
(board, player)
| 69 | |
| 70 | |
| 71 | def isWinner(board, player): |
| 72 | """Return True if player is a winner on this TTTBoard.""" |
| 73 | # Shorter variable names used here for readablility: |
| 74 | b, p = board, player |
| 75 | # Check for 3 marks across 3 rows, 3 columns, and 2 diagonals. |
| 76 | return ((b['1'] == b['2'] == b['3'] == p) or # Across top |
| 77 | (b['4'] == b['5'] == b['6'] == p) or # Across middle |
| 78 | (b['7'] == b['8'] == b['9'] == p) or # Across bottom |
| 79 | (b['1'] == b['4'] == b['7'] == p) or # Down left |
| 80 | (b['2'] == b['5'] == b['8'] == p) or # Down middle |
| 81 | (b['3'] == b['6'] == b['9'] == p) or # Down right |
| 82 | (b['3'] == b['5'] == b['7'] == p) or # Diagonal |
| 83 | (b['1'] == b['5'] == b['9'] == p)) # Diagonal |
| 84 | |
| 85 | def isBoardFull(board): |
| 86 | """Return True if every space on the board has been taken.""" |