Has anyone actually won tic tac toe?

Well, in the case of TicTacToe there is only a finite (and also manageable) number of combinations of the playing field that you have to check in order to determine a possible winner.

Therefore, I would suggest that you define these combinations of fields at the beginning and check after each placement of a player whether a combination has possibly led to a victory:

Code: Select all

In [138] the fields to be checked are available as a list of `item getters`. This means that it is now very easy to get all the contents of the fields to be checked in a loop. For modeling, I simply take the values ​​1 and 4 as entries and form the sum over each triplet.

Player 1 wins with a total of 3 (can only be achieved with ones in a check combination), Player 2 with a total of 12 (3 * 4). Unused fields contain 0.

Ultimately, a function that determines a possible winner is limited to determining the sums based on the current playing field and the "checks" [142] and then testing them for 12 or 3:

Code: Select all

Since there can be a winner after every move, the whole thing could be simplified by transferring the player (or his "value") to the check function:

Code: Select all

Imho, that's pretty straightforward

encoding_kapiert = all (understand (read (info)) for info in (Leonidas slides, blog, slides & text incl. Python3, utf-8 everywhere))
assert encoding_kapiert