def test_board(self): blank_board = {0: {0: " ", 1: " ", 2: " "}, 1: {0: " ", 1: " ", 2: " "}, 2: {0: " ", 1: " ", 2: " "} } test_board = {0: {0: "X", 1: " ", 2: "O"}, 1: {0: " ", 1: "X", 2: "O"}, 2: {0: "O", 1: " ", 2: "X"} } board = Board() self.assertEqual(board.board(), blank_board) board = Board(setup=test_board) self.assertEqual(board.board(), test_board) for x in range(0, 3): for y in range(0, 3): self.assertEqual(board.square((x, y)), board.board()[x][y]) test_board2 = Board(setup=copy(blank_board)) for i in range(0, 3): test_board2.square((i, i), set_to="X") for coords in ((0, 2), (1, 2), (2, 0)): test_board2.square(coords, set_to="O") self.assertEqual(test_board2.board(), test_board) self.assertEqual(board.check_requirements( [[0, 0], [1, 1], [2, 2]], {"X": 3}), True) self.assertEqual(board.check_requirements( [[0, 2], [1, 2], [2, 2]], {"O": 3}), False) self.assertEqual(board.traverse(requires={"O": 3}), []) self.assertEqual(board.traverse(requires={"O": 2}), [ [(0, 2), (1, 2), (2, 2)], [(0, 2), (1, 1), (2, 0)]])
def ai_move(): layout = request.args.get('layout') layout = json.loads(layout) board = Board(setup=layout) ai.move(board) layout = board.board() layout = json.dumps(layout) return layout