def testWin(self): b=Board() [b.mark(l,m) for l,m in ((2,'x'),(4,'x'))] self.assertFalse(b.isWinner('x')) b.mark(6, 'x') print b self.assertTrue(b.isWinner('x'))
def play(): b=Board() ai=AI('o',AI.moveAI) while not b.isFilled(): print str(b) + '\nPlease input a number representing the space '\ 'you want to mark in the range 0-8, then press enter: ' msg = sys.stdin.readline() try: location=int(msg) if b.isMarked(location): print('Please choose a space that has not already been filled in') continue b.mark(location, 'x') if b.isWinner('x'): print('X wins!') return if not b.isFilled(): ai.turn(b) if b.isWinner('o'): print('O wins!') return except: print('Please input a valid number between 0-8') print('Stalemate, please play again!')
def testDetectLine(self): b=Board() [b.mark(l,m) for l,m in ((0,'x'),(4,'o'),(8,'x'))] smartAI=AI('o',AI.moveAI) self.assertEqual(smartAI.moveAI(b), 1)
def testDetectWin(self): b=Board() [b.mark(l,m) for l,m in ((2,'x'),(4,'x'))] smartAI=AI('x',AI.moveAI) self.assertEqual(smartAI.detectWin(b, 'x'), 6)
def testEmptyExcept(self): b=Board() [b.mark(l,m) for l,m in ((2,'x'),(4,'x'))] self.assertTrue(b.isEmptyExcept((2,4)))