tictactoe.js
v1.0.3
Published
Yet another tic tac toe game written in javascript
Downloads
5
Readme
Tic Tac Toe written in Javascript (ES6) using Node.js
Requires Node.js 4.2+ and Babel
#To Run
This must be run using babel-node
for now since ES6 modules are not yet available in V8 yet, and as such are not in Node.JS yet.
Step 1: Install Babel:
npm install babel
Step 2: Run it:
babel-node bin/main.js
Step 3: ???
Step 4: Profit!11!!
How to play
- Specify Grid size (3x3 is the smallest; 12x12 is the largest)
- Choose whether you want to be X or O
- Computer has some intelligence, first it will try to select the corners and then after that will randomly pick a spot.
- First player is randomly chosen
- It's got color thanks to the cli-color library
Notes about terminology used
Terminology for the diagonals is taken from Linear Algebra's Matrix terminology.
Major Diagonal: [0, 4, 8]
Minor Diagonal: [2,4,6]
0 | 1 | 2
--- --- ---
3 | 4 | 5
--- --- ---
6 | 7 | 8
About the design
WinConditions have a common super class of Condition
Computer Move strategies are each in their own class and again modular to improve testability with a common subclass of Strategy.
Grid Size must be square
(nxn)
and starts at 3x3 and maxes out at 12x12. This was due to it not looking great on my system.
This design can be very easily tweaked to handle the n-queens problem.
If we relax the requirement that the board size be square, then we have Connect Four.
This was ported from a similar implementation written in ruby.