Skip to content

Instantly share code, notes, and snippets.

@linuxsable
Created December 16, 2012 04:06
Show Gist options
  • Select an option

  • Save linuxsable/4303230 to your computer and use it in GitHub Desktop.

Select an option

Save linuxsable/4303230 to your computer and use it in GitHub Desktop.
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