(self)
| 154 | return 1 if self.winner == sym else 0 |
| 155 | |
| 156 | def get_state(self): |
| 157 | # returns the current state, represented as an int |
| 158 | # from 0...|S|-1, where S = set of all possible states |
| 159 | # |S| = 3^(BOARD SIZE), since each cell can have 3 possible values - empty, x, o |
| 160 | # some states are not possible, e.g. all cells are x, but we ignore that detail |
| 161 | # this is like finding the integer represented by a base-3 number |
| 162 | k = 0 |
| 163 | h = 0 |
| 164 | for i in range(LENGTH): |
| 165 | for j in range(LENGTH): |
| 166 | if self.board[i,j] == 0: |
| 167 | v = 0 |
| 168 | elif self.board[i,j] == self.x: |
| 169 | v = 1 |
| 170 | elif self.board[i,j] == self.o: |
| 171 | v = 2 |
| 172 | h += (3**k) * v |
| 173 | k += 1 |
| 174 | return h |
| 175 | |
| 176 | def game_over(self, force_recalculate=False): |
| 177 | # returns true if game over (a player has won or it's a draw) |
no outgoing calls
no test coverage detected