Skip to content

Commit

Permalink
Tibs
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe committed Dec 1, 2009
1 parent e3d9135 commit 2e36c1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions dojo1/nmm.py
Expand Up @@ -39,9 +39,22 @@ def move(self, tgt, src=None, cap=None):
""" Move / place a piece. When moving, the piece is moved from src to tgt.
When placing, only tgt is specified. Cap implies that the move will
capture a piece.
We return False if the move was a failure, True if it was allowed.
"""
#if
return False
if src is None:
# We're trying to put a new piece down
return True
else:
# We're trying to move a piece
# Check that the target is empty
if self.data[tgt] != '+':
return False
# If we've got a source piece, we're moving a piece.
# If we're moving a piece, it must be our own.
if self.data[src] != self.next_turn:
return False
return True

# Returns notation for the current game position
def getPosition(self):
Expand Down
1 change: 1 addition & 0 deletions dojo1/nmm_test.py
Expand Up @@ -32,6 +32,7 @@ def testRepresentation(self):
def testMoveChecking(self):
Board = nmm.Board("0", "0", "a7,d7,g4", "a1,b2,c3", "W")

self.assertTrue(Board.move(src="a7", tgt="a4"))
# Can't place new men
self.assertFalse(Board.move(tgt="a4"))
# Can't move from vacant square
Expand Down

0 comments on commit 2e36c1d

Please sign in to comment.