-- Sep 13 In-Class Exercise
class PegBoard(Board):
def movePieces(self, x1, y1, x2, y2):
piece = self.board[x1][y1]
if piece == "x" or piece == "o":
self.add(piece, x2, y2)
else:
#clear the second location (x2,y2)
self.clear(x2, y2)
#clear the initial piece in both instances
self.clear(x1, y1)
def clear(self, x, y):
#sets a point on the board to "."
row = ""
for i in range(3):
if i == y:
row += "."
else:
row += self.board[x][i]
self.board[x] = row
b = PegBoard()
- add("x", 0, 1)
- draw()
print
- movePieces(0, 1, 1, 1)
- draw()
print
- add("o", 2, 2)
- draw()
print
- movePieces(1, 1, 2, 2)
- draw()
print
- movePieces(0, 0, 2, 2)
class PegBoard(Board):
def movePieces(self, x1, y1, x2, y2):
piece = self.board[x1][y1]
if piece == "x" or piece == "o":
self.add(piece, x2, y2)
else:
#clear the second location (x2,y2)
self.clear(x2, y2)
#clear the initial piece in both instances
self.clear(x1, y1)
def clear(self, x, y):
#sets a point on the board to "."
row = ""
for i in range(3):
if i == y:
row += "."
else:
row += self.board[x][i]
self.board[x] = row
b = PegBoard()
b.add("x", 0, 1)
b.draw()
print
b.movePieces(0, 1, 1, 1)
b.draw()
print
b.add("o", 2, 2)
b.draw()
print
b.movePieces(1, 1, 2, 2)
b.draw()
print
b.movePieces(0, 0, 2, 2)