upoibroad.blogg.se

Let's play tic tac toe for my freedom meme
Let's play tic tac toe for my freedom meme






let

Spoiler alert: The interesting part is, that this already more or less resembles the Minimax algorithm that we'll look at next.Īs inefficient as this approach might look, it actually achieves insane results. We start with a utility function to count the amount of a given symbol on a board:

let

The board will be a simple array of arrays of strings we can do all these checks on. Is the field the player wants to play on already occupied?.Are the coordinates the player wants to play on part of the field?.Is it actually the turn of the player that want's to currently do a move?.In order to determine if a move is valid, we need to answer these questions: Since the majority of this post will be about teaching a machine to beat a human player, let's not spend too much time coding the actual game. A comment on Stackoverflow for the question on how to create a list of all unique Tic-tac-toe boards sets the number of possible game states at 5477, around 3.5 times less. These around 19k states include boards with all X's, three X's and one O, etc., so lots of boards that are technically against the rules.

let

But that's actually a gross overestimate. One could argue that therefore there are 3^9 = 19683 different possible game states. The player just happened to chose 2/1 for whatever reason.Įach cell can have one of three values, either empty, O or X. Notice that there would've been two moves to win for X, either 2/1 or 1/0. The last move (center row, right column, or 2/1 in zero-indexed X/Y coordinates with top-left being 0/0) was the winning move here. Enter fullscreen mode Exit fullscreen mode








Let's play tic tac toe for my freedom meme