Created
December 16, 2012 04:06
-
-
Save linuxsable/4303230 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| window.App.Engine = | |
| matrix: [] | |
| moveHistory: [] | |
| initialized: false | |
| BLACK_STONE: 1 | |
| WHITE_STONE: 2 | |
| init: -> | |
| if @initialized | |
| throw 'already initialized' | |
| @initMatrix() | |
| @initialized = true | |
| # Setup a 19x19 matrix | |
| initMatrix: -> | |
| @matrix = for x in [0..18] | |
| for y in [0..18] | |
| 0 | |
| # Add a move to the matrix and the move list | |
| enterMove: (color, x, y) -> | |
| # Check extremes | |
| if x > 18 | |
| throw 'x out of bounds' | |
| if y > 18 | |
| throw 'y out of bounds' | |
| if @matrix[x][y] != 0 | |
| throw 'spot already taken' | |
| # Add to matrix | |
| @matrix[x][y] = color | |
| # Add to history | |
| @moveHistory.push(color: color, x: x, y: y) | |
| # How many moves in the match? | |
| getMoveCount: -> | |
| @moveHistory.length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment