コード例 #1
0
 def testEmptySquares(self):
     emptySquares = self.__board.emptySquares()
     self.assertEqual(len(emptySquares), 25)
     self.__board.move(Dimension(2, 2), 'O')
     emptySquares = self.__board.emptySquares()
     self.assertEqual(len(emptySquares), 16)
     self.assertEqual(emptySquares[0], Dimension(0, 0))
コード例 #2
0
 def testMoveHuman(self):
     move = Dimension(1, 1)
     self.__game.moveHuman(move)
     board = self.__game.getBoard()
     self.assertEqual(board._board[1][1], 1)
     self.assertEqual(board._board[1][0], 3)
     self.assertEqual(board._board[4][4], 0)
     move = Dimension(-1, -1)
     self.assertRaises(CoordError, self.__game.moveHuman, move)
     move = Dimension(1, 2)
     self.assertRaises(CoordError, self.__game.moveHuman, move)
コード例 #3
0
 def emptySquares(self):
     '''
     class method that appends into and returns a list containing all the empty squares on the board.
     in : - 
     '''
     emptySq = []
     for rowIndex in range(self.__height):
         for columnIndex in range(self.__width):
             if self._board[rowIndex][columnIndex] == 0:
                 emptySq.append(Dimension(rowIndex, columnIndex))
     return emptySq
コード例 #4
0
 def testCoordinatesValidator(self):
     self.assertRaises(CoordError,
                       self.__boardValidator.validateCoordinates, 1, 5,
                       self.__board)
     self.assertRaises(CoordError,
                       self.__boardValidator.validateCoordinates, 5, 1,
                       self.__board)
     self.__board.move(Dimension(0, 0), 'X')
     self.assertRaises(CoordError,
                       self.__boardValidator.validateCoordinates, 1, 1,
                       self.__board)
コード例 #5
0
 def __readMove(self):
     while True:
         try:
             print(
                 "Input the move you want to make! Format must be x <space> y !!"
             )
             print(">>>")
             coordinates = input().split(' ')
             return Dimension(int(coordinates[0]), int(coordinates[1]))
         except ValueError:
             print(
                 "Invalid format! Must be two integers with a space between them!"
             )
         except IndexError:
             print(
                 "Invalid format! Must be two integers with a space between them!"
             )
コード例 #6
0
 def getDimensions(self):
     '''
     in: - 
     out: a Dimension of (x,y) width and height 
     the method handles valueErrors as well as BoardErrors in case the input is incorrect.
     '''
     while True:
         print("Board width: ")
         try: 
             boardX = int(input())
             print("Board height: ")
             boardY = int(input())
             self.__boardValidator.validate(boardX,boardY)
             return Dimension(boardX,boardY)
         except ValueError: 
             print("Incorrect dimensions! Must be integers! ")
         except BoardError as be: 
             print(be)
コード例 #7
0
 def testWin(self):
     newBoard = Board(3, 3)
     newBoard.move(Dimension(1, 1), 'X')
     self.assertEqual(newBoard.isWon(), True)
コード例 #8
0
 def testMove(self):
     self.__board.move(Dimension(4, 4), 'X')
     self.assertEqual(self.__board._board[4][4], 1)
     self.assertEqual(self.__board._board[3][4], 3)
     self.assertEqual(self.__board._board[0][0], 0)