A toy project.
requires node
>= v4.0.0
$ npm start? Choose type (Use arrow keys)
❯ Human
ComputerThere are two types of players:
- Human: will take input from the keyboard
- Computer: uses an algorithm to find the best move for the given board
It is X[H: Joe]s turn:
a b c
───────────
1 │ │ │ │
│───────────│
2 │ │ │ │
│───────────│
3 │ │ │ │
───────────
? Choose empty cell (a1-c3)The algorithm used to find the best move is based on the Negamax search:
"a variant form of minimax"
It is, however, optimized in several ways:
- It looks for immediate winners: it checks all the available moves for an immediate
winner, and only if it does not find one, it actually starts checking the full tree of possible moves using negamax. - When doing the search, it uses a form of pruning, meaning that, when it finds a
winningmove, it does not check further moves. - It uses standard openings, based on analyzing the outcome of the first two moves. This is because, for the first move in the opening round, any choice ensures a
tie, and, for the the second move, there are some choices that result in atie, all the others beingloosers. So, if the best outcome when making the first move is atie, it makes no sense to compute it all the time. So, for the first round, the moves are:- if first: any move is good, but it will choose a corner, since it leaves the opponent only one move that is not
loosing(the center) - if second: depending on the first move, there are several choices available, but, in any case, choosing the
centeris a move that guarantees at least atie. Except, of course, if the first move is itself in the center, in which case, the algorithm will choose any corner.
- if first: any move is good, but it will choose a corner, since it leaves the opponent only one move that is not
- Format text using specific colors (for player names, signs, etc).
- Make some game aspects configurable (like table box chars), maybe from a settings file.
- Add other ways to take human input for moves.
- Add some others UIs (e.g. HTML)