Skip to content

Commit

Permalink
Cannot place a piece in a board with an piece already on it
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisergishnu committed Oct 10, 2016
1 parent c7e5d71 commit 7d41f7c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions TetraVexKit/TetraVexBoardModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ open class TetraVexBoardModel {
return false
}

if board[x][y] != nil {
return false
}

var leftP : PieceModel? = nil
if 0 ... board.count-1 ~= x-1 && 0 ... board[0].count-1 ~= y {
leftP = board[x-1][y]
Expand Down
2 changes: 2 additions & 0 deletions TetraVexKitTests/TetraVexKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class TetraVexKitTests: XCTestCase {
let board = TetraVexBoardModel(width: 2, height: 2)
var r = board.addPieceToBoard(a, x: 0, y: 1)
XCTAssert(r == true)
r = board.addPieceToBoard(b, x: 0, y: 1)
XCTAssert(r == false)
r = board.addPieceToBoard(b, x: 1, y: 1)
XCTAssert(r == true)
r = board.addPieceToBoard(c, x: 1, y: 0)
Expand Down

0 comments on commit 7d41f7c

Please sign in to comment.