Beispiel #1
0
    def put(self, board_id):
        try:
            form = BoardEditNameSchema().load(json.loads(request.data))

            if Board.objects(name=form['name']).first():
                return jsonify(message='이미 존재하는 게시판 이름입니다.'), 409

            find_board = Board.objects(id=board_id).first()
            find_board.update(**form)
        except ValidationError as err:
            return jsonify(err.messages), 422

        return jsonify(message='게시판 이름이 변경되었습니다.'), 200
Beispiel #2
0
class PawnTestCase(unittest.TestCase):
    board = Board()

    def setUp(self):
        self.board.shogi_board[2][8].piece = Pawn(Pawn.BLACK)

    def test_move_possible_initial_board(self):
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][8],
                            self.board.shogi_board[3][8]))

    def test_move_not_possible(self):
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[2][8],
                            self.board.shogi_board[5][8]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[2][8],
                            self.board.shogi_board[1][8]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[2][8],
                            self.board.shogi_board[2][7]))

    def test_promoted_move_possible_initial_board(self):
        self.board.shogi_board[2][8].piece.set_promoted()
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][8],
                            self.board.shogi_board[3][7]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[3][7],
                            self.board.shogi_board[3][6]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[3][6],
                            self.board.shogi_board[4][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[4][5],
                            self.board.shogi_board[3][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[3][5],
                            self.board.shogi_board[4][6]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[4][6],
                            self.board.shogi_board[3][5]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[4][6],
                            self.board.shogi_board[3][7]))

    def tearDown(self):
        self.board.shogi_board = [[Cell(x, y) for x in range(0, 9)]
                                  for y in range(0, 9)]
Beispiel #3
0
class KingTestCase(unittest.TestCase):
    board = Board()

    def setUp(self):
        self.board.shogi_board[0][4].piece = King(King.BLACK)
        self.board.shogi_board[8][4].piece = King(King.WHITE)

    def test_move_possible_initial_board(self):
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][4],
                            self.board.shogi_board[1][4]))

    def test_move_not_possible(self):
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][4],
                            self.board.shogi_board[5][8]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][4],
                            self.board.shogi_board[1][8]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][4],
                            self.board.shogi_board[2][7]))

    def tearDown(self):
        self.board.shogi_board = [[Cell(x, y) for x in range(0, 9)]
                                  for y in range(0, 9)]
Beispiel #4
0
class ReintroduceTestCase(unittest.TestCase):
    board = Board()

    def setUp(self):
        self.board.shogi_board[8][4].piece = King(King.WHITE)
        self.board.shogi_board[3][4].piece = Lance(Lance.WHITE)
        self.board.shogi_board[2][5].piece = Lance(Lance.WHITE)
        self.board.shogi_board[7][7].piece = Knight(Knight.WHITE)
        piece_captured = self.board.shogi_board[2][5].get_piece()
        piece_captured.set_captured()
        self.board.captured_player_black.append(piece_captured)

        piece_captured = self.board.shogi_board[7][7].get_piece()
        piece_captured.set_captured()
        self.board.captured_player_black.append(piece_captured)

        self.board.shogi_board[0][4].piece = King(King.BLACK)
        self.board.shogi_board[0][3].piece = Gold_General(Gold_General.BLACK)
        self.board.shogi_board[6][5].piece = Gold_General(Gold_General.BLACK)
        self.board.shogi_board[7][4].piece = Pawn(Pawn.WHITE)
        self.board.shogi_board[7][5].piece = Pawn(Pawn.BLACK)

        piece_captured = self.board.shogi_board[6][5].get_piece()
        piece_captured.set_captured()
        self.board.captured_player_white.append(piece_captured)

        piece_captured = self.board.shogi_board[7][5].get_piece()
        piece_captured.set_captured()
        self.board.captured_player_white.append(piece_captured)

    def test_reintroduce_piece(self):
        piece = self.board.captured_player_white[0]
        self.assertTrue(
            self.board.re_introduce_piece(piece, self.board.shogi_board[5][4]))
        self.board.captured_player_white.pop(0)

        piece = self.board.captured_player_white[0]
        self.assertFalse(
            self.board.re_introduce_piece(piece, self.board.shogi_board[6][4]))
        self.board.shogi_board[7][4].get_piece().set_promoted()
        self.assertFalse(
            self.board.re_introduce_piece(piece, self.board.shogi_board[0][4]))
        self.assertTrue(
            self.board.re_introduce_piece(piece, self.board.shogi_board[6][4]))

        piece = self.board.captured_player_black[0]
        self.assertFalse(
            self.board.re_introduce_piece(piece, self.board.shogi_board[0][4]))
        self.board.captured_player_black.pop(0)

        piece = self.board.captured_player_black[0]
        self.assertFalse(
            self.board.re_introduce_piece(piece, self.board.shogi_board[1][6]))

    def tearDown(self):
        self.board.captured_player_black = []
        self.board.captured_player_white = []
        self.board.shogi_board = [[Cell(x, y) for x in range(0, 9)]
                                  for y in range(0, 9)]
Beispiel #5
0
    def get(self, board_id, post_id):
        board = Board.objects(id=board_id, deleted=False).get_or_404()
        find_post = Post.objects(board=board_id, id=post_id, deleted=False).get_or_404()
        find_post.increase_view_count()

        post_detail = PostSchema().dump(find_post)

        return jsonify(post_detail), 200
Beispiel #6
0
    def delete(self, board_id):
        try:
            find_board = Board.objects(id=board_id).first()
            find_board.soft_delete()
        except ValidationError as err:
            return err

        return jsonify(message='게시판이 삭제되었습니다.'), 200
Beispiel #7
0
class CheckMateTestCase(unittest.TestCase):
    board = Board()

    def setUp(self):
        self.board.shogi_board[8][4].piece = King(King.WHITE)
        self.board.shogi_board[3][4].piece = Lance(Lance.WHITE)
        self.board.shogi_board[2][5].piece = Lance(Lance.WHITE)

        self.board.shogi_board[0][4].piece = King(King.BLACK)
        self.board.shogi_board[0][3].piece = Gold_General(Gold_General.BLACK)
        self.board.shogi_board[6][5].piece = Gold_General(Gold_General.BLACK)
        self.board.shogi_board[7][4].piece = Pawn(Pawn.BLACK)


    def test_check(self):
        self.assertTrue(self.board._check(Pieces.BLACK))
        self.assertTrue(self.board._check(Pieces.WHITE))

    def test_check_mate_white(self):
        if((self.board.shogi_board[0][2].get_piece() is None) | (self.board.shogi_board[0][2].get_piece() is '')):
            self.board.move(self.board.shogi_board[0][3], self.board.shogi_board[0][2])
        self.board.shogi_board[2][3].piece = Pawn(Pawn.WHITE)
        self.board.shogi_board[2][2].piece = Knight(Knight.WHITE)
        self.assertTrue(self.board._check_mate(self.board.shogi_board[3][4]))

    def test_check_mate_black(self):
        self.assertFalse(self.board._check_mate(self.board.shogi_board[7][4]))
        self.assertFalse(self.board._check_mate(self.board.shogi_board[6][5]))

    def test_check_no_mate_white(self):
        if ((self.board.shogi_board[0][2].get_piece() is None) | (self.board.shogi_board[0][2].get_piece() is '')):
            self.board.move(self.board.shogi_board[0][3], self.board.shogi_board[0][2])
        self.board.shogi_board[2][3].piece = ''
        self.board.__str__()
        self.assertFalse(self.board._check_mate(self.board.shogi_board[3][4]))

    def test_check_no_mate_white_corner(self):
        if ((self.board.shogi_board[0][2].get_piece() is None) | (self.board.shogi_board[0][2].get_piece() is '')):
            self.board.move(self.board.shogi_board[0][3], self.board.shogi_board[0][2])
        self.board.shogi_board[2][3].piece = ''
        self.board.shogi_board[1][1].piece = Pawn(Pawn.WHITE)
        self.board.shogi_board[3][0].piece = Lance(Lance.WHITE)
        self.assertFalse(self.board._check_mate(self.board.shogi_board[3][4]))

    def test_check_mate_white_corner(self):
        if ((self.board.shogi_board[0][2].get_piece() is None) | (self.board.shogi_board[0][2].get_piece() is '')):
            self.board.move(self.board.shogi_board[0][3], self.board.shogi_board[0][2])
        self.board.shogi_board[2][3].piece = ''
        self.board.shogi_board[1][1].piece = ''
        self.board.shogi_board[0][4].piece = ''
        self.board.shogi_board[3][0].piece = Lance(Lance.WHITE)
        self.board.shogi_board[2][1].piece = Lance(Lance.WHITE)
        self.board.shogi_board[0][0].piece = King(King.BLACK)
        self.assertTrue(self.board._check_mate(self.board.shogi_board[3][4]))

    def tearDown(self):
        self.board.shogi_board = [[Cell(x, y) for x in range(0, 9)] for y in range(0, 9)]
Beispiel #8
0
    def post(self):
        try:
            form = BoardCreateSchema().load(json.loads(request.data))

            if Board.objects(name=form['name']).first():
                return jsonify(message='이미 존재하는 게시판 이름입니다.'), 409

            form.save()
        except ValidationError as err:
            return jsonify(err.messages), 422

        return jsonify(message='게시판이 생성되었습니다.'), 200
Beispiel #9
0
    def post(self, board_id):
        try:
            if not Board.objects(id=board_id, deleted=False).first():
                return jsonify(message="존재하지 않는 게시판입니다"), 404

            form = PostCreateSchema().load(json.loads(request.data))
            form.board = ObjectId(board_id)
            form.writer = ObjectId(g.member_id)

            form.save()
        except ValidationError as err:
            return jsonify(err.messages), 422

        return jsonify(message='게시글이 작성되었습니다.'), 200
Beispiel #10
0
    def put(self, board_id, post_id):
        try:
            if not Board.objects(id=board_id, deleted=False).first():
                return jsonify(message="존재하지 않는 게시판입니다"), 404

            form = PostEditSchema().load(json.loads(request.data))

            find_post = Post.objects(id=post_id).first()
            find_post.update_post_modified_time()
            post = Post(**form)
            find_post.update(post)
        except ValidationError as err:
            return jsonify(err.messages), 422

        return jsonify(message='게시판 이름이 변경되었습니다.'), 200
Beispiel #11
0
def add():
    form = request.form
    u = current_user()
    name = form.get('name', '')
    title = form.get('title', '')
    if Board.query.filter_by(name=name).first() is not None:
        flash("该板块名已存在", 'danger')
        return redirect(url_for('.index'))
    if Board.query.filter_by(title=title).first() is not None:
        flash("该tag已存在", 'danger')
        return redirect(url_for('.index'))
    board = Board(form)
    db.session.add(board)
    db.session.commit()
    flash('添加板块成功', 'success')
    return redirect(url_for('.index'))
Beispiel #12
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    bootstrap.init_app(app)
    db.init_app(app)

    with app.app_context():
        db.create_all()

        from app.models.board import Board
        from app.models.user import User
        bs = Board.query.all()
        if bs == []:
            init_boards = [{'title': 'news', 'name': '新闻'},
                           {'title': 'games', 'name': '游戏'},
                           {'title': 'books', 'name': '好书'},
                           {'title': 'bala', 'name': '闲聊'}]

            User.register(dict(username=CF.FLASKY_ADMIN, email='*****@*****.**',
                               password=CF.FLASKY_PWD))

            for b in init_boards:
                db.session.add(Board(b))
            try:
                db.session.commit()
            except Exception as e:
                print('init_board err:', e)

    # url_prefix 路由前缀
    from app.routes.index import main as index_routes
    from app.routes.post import main as post_routes
    from app.routes.comment import main as comment_routes
    from app.routes.board import main as board_routes

    app.register_blueprint(index_routes)
    app.register_blueprint(post_routes, url_prefix='/post')
    app.register_blueprint(comment_routes, url_prefmderix='/comment')
    app.register_blueprint(board_routes, url_prefix='/board')

    return app
Beispiel #13
0
class LanceTestCase(unittest.TestCase):
    board = Board()

    def setUp(self):
        self.board.shogi_board[0][4].piece = King(King.BLACK)
        self.board.shogi_board[8][4].piece = King(King.WHITE)
        self.board.shogi_board[0][0].piece = Lance(Lance.BLACK)
        self.board.shogi_board[0][8].piece = Lance(Lance.BLACK)
        self.board.shogi_board[8][0].piece = Lance(Lance.WHITE)
        self.board.shogi_board[8][8].piece = Lance(Lance.WHITE)

    def test_move_possible_initial_board(self):
        # Black Lance
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][0],
                            self.board.shogi_board[2][0]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][0],
                            self.board.shogi_board[7][0]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[7][0],
                            self.board.shogi_board[0][0]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][8],
                            self.board.shogi_board[1][8]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][8],
                            self.board.shogi_board[3][8]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[3][8],
                            self.board.shogi_board[7][8]))

        # White Lance
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][0],
                            self.board.shogi_board[7][0]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][0],
                            self.board.shogi_board[2][0]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][0],
                            self.board.shogi_board[1][0]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][8],
                            self.board.shogi_board[5][8]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[5][8],
                            self.board.shogi_board[2][8]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][8],
                            self.board.shogi_board[1][8]))

    def test_promoted_move_possible_initial_board(self):
        self.board.shogi_board[0][0].piece.set_promoted()
        self.board.shogi_board[0][8].piece.set_promoted()
        self.board.shogi_board[8][0].piece.set_promoted()
        self.board.shogi_board[8][8].piece.set_promoted()

        self.assertTrue(self.board.shogi_board[0][0].piece.promoted)
        self.assertTrue(self.board.shogi_board[0][8].piece.promoted)
        self.assertTrue(self.board.shogi_board[8][0].piece.promoted)
        self.assertTrue(self.board.shogi_board[8][8].piece.promoted)

        # Black Lance
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][0],
                            self.board.shogi_board[1][0]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][0],
                            self.board.shogi_board[2][1]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][1],
                            self.board.shogi_board[1][1]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][1],
                            self.board.shogi_board[0][1]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][1],
                            self.board.shogi_board[0][0]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][8],
                            self.board.shogi_board[1][8]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][8],
                            self.board.shogi_board[1][7]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][7],
                            self.board.shogi_board[0][7]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][7],
                            self.board.shogi_board[1][6]))

        # White Lance
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][0],
                            self.board.shogi_board[8][1]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][1],
                            self.board.shogi_board[8][2]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][2],
                            self.board.shogi_board[7][2]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][8],
                            self.board.shogi_board[7][7]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][7],
                            self.board.shogi_board[6][6]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[6][6],
                            self.board.shogi_board[5][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[5][5],
                            self.board.shogi_board[4][4]))

    def test_move_not_possible(self):
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][0],
                            self.board.shogi_board[5][8]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][8],
                            self.board.shogi_board[4][4]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][0],
                            self.board.shogi_board[7][1]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][8],
                            self.board.shogi_board[5][8]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[5][8],
                            self.board.shogi_board[8][8]))

    def tearDown(self):
        self.board.shogi_board = [[Cell(x, y) for x in range(0, 9)]
                                  for y in range(0, 9)]
Beispiel #14
0
class Gold_GeneralTestCase(unittest.TestCase):
    board = Board()

    def setUp(self):
        self.board.shogi_board[0][4].piece = King(King.BLACK)
        self.board.shogi_board[8][4].piece = King(King.WHITE)
        self.board.shogi_board[0][5].piece = Gold_General(Gold_General.BLACK)
        self.board.shogi_board[0][3].piece = Gold_General(Gold_General.BLACK)
        self.board.shogi_board[8][5].piece = Gold_General(Gold_General.WHITE)
        self.board.shogi_board[8][3].piece = Gold_General(Gold_General.WHITE)

    def test_move_possible_initial_board(self):
        # Black Gold General
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][3],
                            self.board.shogi_board[1][3]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][3],
                            self.board.shogi_board[1][2]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][2],
                            self.board.shogi_board[1][3]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][3],
                            self.board.shogi_board[0][3]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][5],
                            self.board.shogi_board[1][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][5],
                            self.board.shogi_board[1][6]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][6],
                            self.board.shogi_board[1][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][5],
                            self.board.shogi_board[0][5]))

        # White Gold General
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][3],
                            self.board.shogi_board[8][3]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][3],
                            self.board.shogi_board[7][3]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][3],
                            self.board.shogi_board[7][2]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][2],
                            self.board.shogi_board[7][3]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][3],
                            self.board.shogi_board[8][3]))

        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][5],
                            self.board.shogi_board[8][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][5],
                            self.board.shogi_board[7][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][5],
                            self.board.shogi_board[7][6]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][6],
                            self.board.shogi_board[7][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][5],
                            self.board.shogi_board[8][5]))

    def test_move_not_possible(self):
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][3],
                            self.board.shogi_board[0][5]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][3],
                            self.board.shogi_board[1][8]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][3],
                            self.board.shogi_board[2][7]))

        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][5],
                            self.board.shogi_board[0][7]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][5],
                            self.board.shogi_board[1][8]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][5],
                            self.board.shogi_board[0][8]))

        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][3],
                            self.board.shogi_board[8][1]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][3],
                            self.board.shogi_board[6][4]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][3],
                            self.board.shogi_board[3][2]))

        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][5],
                            self.board.shogi_board[8][7]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][5],
                            self.board.shogi_board[0][6]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][5],
                            self.board.shogi_board[8][3]))

    def tearDown(self):
        self.board.shogi_board = [[Cell(x, y) for x in range(0, 9)]
                                  for y in range(0, 9)]
Beispiel #15
0
 def make_board(self, data, **kwargs):
     return Board(**data)
Beispiel #16
0
 def run(self):
     """This method is used to start the game. """
     board = Board()
     board.initialize_board()
     tablero = board.__str__()
     print(tablero)
Beispiel #17
0
    def index(self, board_id, page=1):
        board = Board.objects(id=board_id, deleted=False).get_or_404()
        find_posts = Post.objects(board=board_id, deleted=False).paginate(page=page, per_page=10)
        posts = PaginatedPostSchema().dump(find_posts)

        return jsonify(posts), 200
Beispiel #18
0
 def test_name이_변경된다(self, subject, target_board_id, form):
     board = Board.objects(id=target_board_id).get()
     assert board.name == form['name']
Beispiel #19
0
class KnightTestCase(unittest.TestCase):
    board = Board()

    def setUp(self):
        self.board.shogi_board[0][7].piece = Knight(Knight.BLACK)
        self.board.shogi_board[0][1].piece = Knight(Knight.BLACK)
        self.board.shogi_board[8][7].piece = Knight(Knight.WHITE)
        self.board.shogi_board[8][1].piece = Knight(Knight.WHITE)
        self.board.shogi_board[0][4].piece = King(King.BLACK)
        self.board.shogi_board[8][8].piece = King(King.WHITE)

    def test_move_possible_initial_board(self):
        self.assertFalse(self.board.shogi_board[0][7].piece.captured)
        self.assertFalse(self.board.shogi_board[0][1].piece.captured)
        self.assertFalse(self.board.shogi_board[8][7].piece.captured)
        self.assertFalse(self.board.shogi_board[8][1].piece.captured)
        # Black Knights
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][1],
                            self.board.shogi_board[2][0]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][0],
                            self.board.shogi_board[4][1]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][7],
                            self.board.shogi_board[2][6]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][6],
                            self.board.shogi_board[4][5]))

        # White Silver General
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][1],
                            self.board.shogi_board[6][2]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[6][2],
                            self.board.shogi_board[4][1]))
        #TODO aquí ha comido una pieza

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][7],
                            self.board.shogi_board[6][6]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[6][6],
                            self.board.shogi_board[4][5]))
        #TODO aquí ha comido al otro caballo

    # def test_promoted_move_possible_initial_board(self):
    #     self.board.shogi_board[0][7].piece.set_promoted()
    #     self.board.shogi_board[0][1].piece.set_promoted()
    #     self.board.shogi_board[8][7].piece.set_promoted()
    #     self.board.shogi_board[8][1].piece.set_promoted()
    #
    #     self.assertTrue(self.board.shogi_board[0][1].piece.promoted)
    #     self.assertTrue(self.board.shogi_board[0][7].piece.promoted)
    #     self.assertTrue(self.board.shogi_board[8][1].piece.promoted)
    #     self.assertTrue(self.board.shogi_board[8][7].piece.promoted)
    #
    #     # Black Knights
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[0][1], self.board.shogi_board[1][1]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[1][1], self.board.shogi_board[2][2]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[2][2], self.board.shogi_board[2][1]))
    #     self.assertEqual(0, self.board.move(self.board.shogi_board[2][1], self.board.shogi_board[1][2]))
    #
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[0][7], self.board.shogi_board[0][6]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[0][6], self.board.shogi_board[1][5]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[1][5], self.board.shogi_board[2][4]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[2][4], self.board.shogi_board[1][4]))
    #
    #
    #     # White Knights
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[8][1], self.board.shogi_board[8][2]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[8][2], self.board.shogi_board[8][3]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[8][3], self.board.shogi_board[7][3]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[7][3], self.board.shogi_board[6][4]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[6][4], self.board.shogi_board[6][5]))
    #
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[8][7], self.board.shogi_board[8][6]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[8][6], self.board.shogi_board[8][5]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[8][5], self.board.shogi_board[7][4]))
    #     self.assertEqual(0, self.board.move(self.board.shogi_board[7][4], self.board.shogi_board[8][3]))
    #     self.assertEqual(1, self.board.move(self.board.shogi_board[7][4], self.board.shogi_board[8][4]))

    def test_move_not_possible(self):
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][1],
                            self.board.shogi_board[5][8]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][1],
                            self.board.shogi_board[2][2]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[2][2],
                            self.board.shogi_board[0][1]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][7],
                            self.board.shogi_board[4][4]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][1],
                            self.board.shogi_board[7][5]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][7],
                            self.board.shogi_board[5][8]))

    def tearDown(self):
        self.board.shogi_board = [[Cell(x, y) for x in range(0, 9)]
                                  for y in range(0, 9)]
Beispiel #20
0
class Silver_GeneralTestCase(unittest.TestCase):
    board = Board()

    def setUp(self):
        self.board.shogi_board[0][2].piece = Silver_General(
            Silver_General.BLACK)
        self.board.shogi_board[0][6].piece = Silver_General(
            Silver_General.BLACK)
        self.board.shogi_board[8][2].piece = Silver_General(
            Silver_General.WHITE)
        self.board.shogi_board[8][6].piece = Silver_General(
            Silver_General.WHITE)
        self.board.shogi_board[0][4].piece = King(King.BLACK)
        self.board.shogi_board[8][8].piece = King(King.WHITE)

    def test_move_possible_initial_board(self):
        self.assertFalse(self.board.shogi_board[0][2].piece.captured)
        self.assertFalse(self.board.shogi_board[0][6].piece.captured)
        self.assertFalse(self.board.shogi_board[8][2].piece.captured)
        self.assertFalse(self.board.shogi_board[8][6].piece.captured)
        # Black Silver General
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][2],
                            self.board.shogi_board[1][2]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][2],
                            self.board.shogi_board[2][1]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][1],
                            self.board.shogi_board[1][0]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][0],
                            self.board.shogi_board[2][1]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][1],
                            self.board.shogi_board[1][2]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][6],
                            self.board.shogi_board[1][6]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][6],
                            self.board.shogi_board[2][7]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][7],
                            self.board.shogi_board[1][8]))

        # White Silver General
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][2],
                            self.board.shogi_board[7][1]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][1],
                            self.board.shogi_board[6][0]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[6][0],
                            self.board.shogi_board[5][1]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[5][1],
                            self.board.shogi_board[6][2]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][6],
                            self.board.shogi_board[7][7]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][7],
                            self.board.shogi_board[6][6]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[6][6],
                            self.board.shogi_board[7][5]))

    def test_promoted_move_possible_initial_board(self):
        self.board.shogi_board[0][2].piece.set_promoted()
        self.board.shogi_board[0][6].piece.set_promoted()
        self.board.shogi_board[8][2].piece.set_promoted()
        self.board.shogi_board[8][6].piece.set_promoted()

        self.assertTrue(self.board.shogi_board[0][2].piece.promoted)
        self.assertTrue(self.board.shogi_board[0][6].piece.promoted)
        self.assertTrue(self.board.shogi_board[8][2].piece.promoted)
        self.assertTrue(self.board.shogi_board[8][6].piece.promoted)

        # Black Silver General
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][2],
                            self.board.shogi_board[1][1]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][1],
                            self.board.shogi_board[2][2]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][2],
                            self.board.shogi_board[2][1]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[2][1],
                            self.board.shogi_board[1][2]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][6],
                            self.board.shogi_board[0][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][5],
                            self.board.shogi_board[1][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][5],
                            self.board.shogi_board[2][4]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][4],
                            self.board.shogi_board[1][4]))

        # White Silver General
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][2],
                            self.board.shogi_board[8][3]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][3],
                            self.board.shogi_board[7][3]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][3],
                            self.board.shogi_board[6][4]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[6][4],
                            self.board.shogi_board[6][5]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][6],
                            self.board.shogi_board[8][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][5],
                            self.board.shogi_board[7][4]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[7][4],
                            self.board.shogi_board[8][3]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][4],
                            self.board.shogi_board[8][4]))

    def test_move_not_possible(self):
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][2],
                            self.board.shogi_board[5][8]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[0][6],
                            self.board.shogi_board[4][4]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][2],
                            self.board.shogi_board[7][5]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[8][6],
                            self.board.shogi_board[5][8]))

    def tearDown(self):
        self.board.shogi_board = [[Cell(x, y) for x in range(0, 9)]
                                  for y in range(0, 9)]
Beispiel #21
0
 def index(self):
     find_boards = Board.objects(deleted=False).order_by('name').paginate(
         1, 10)
     boards = SimpleBoardSchema().dump(find_boards, many=True)
     return jsonify(boards), 200
Beispiel #22
0
 def get(self, board_id):
     find_board = Board.objects(id=board_id).first()
     board_detail = BoardSchema().dump(find_board)
     return jsonify(board_detail), 200
Beispiel #23
0
class PromotedPiecesTestCase(unittest.TestCase):
    board = Board()

    def setUp(self):
        self.board.shogi_board[1][7].piece = Rook(Rook.BLACK)
        self.board.shogi_board[7][1].piece = Rook(Rook.WHITE)
        self.board.shogi_board[0][7].piece = Knight(Knight.BLACK)
        self.board.shogi_board[0][1].piece = Knight(Knight.BLACK)
        self.board.shogi_board[8][7].piece = Knight(Knight.WHITE)
        self.board.shogi_board[8][1].piece = Knight(Knight.WHITE)
        self.board.shogi_board[0][4].piece = King(King.BLACK)
        self.board.shogi_board[8][8].piece = King(King.WHITE)

    def test_promoted_rook(self):
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][7],
                            self.board.shogi_board[6][7]))
        self.assertTrue(self.board.shogi_board[6][7].piece.promoted)
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[6][7],
                            self.board.shogi_board[7][6]))

    def test_promoted_move_possible_initial_board(self):
        self.board.shogi_board[0][7].piece.set_promoted()
        self.board.shogi_board[0][1].piece.set_promoted()
        self.board.shogi_board[8][7].piece.set_promoted()
        self.board.shogi_board[8][1].piece.set_promoted()

        self.assertTrue(self.board.shogi_board[0][1].piece.promoted)
        self.assertTrue(self.board.shogi_board[0][7].piece.promoted)
        self.assertTrue(self.board.shogi_board[8][1].piece.promoted)
        self.assertTrue(self.board.shogi_board[8][7].piece.promoted)

        # Black Knights
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][1],
                            self.board.shogi_board[1][1]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][1],
                            self.board.shogi_board[2][2]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][2],
                            self.board.shogi_board[2][1]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[2][1],
                            self.board.shogi_board[1][2]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][7],
                            self.board.shogi_board[0][6]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[0][6],
                            self.board.shogi_board[1][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[1][5],
                            self.board.shogi_board[2][4]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[2][4],
                            self.board.shogi_board[1][4]))

        # White Knights
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][1],
                            self.board.shogi_board[8][2]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][2],
                            self.board.shogi_board[8][3]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][3],
                            self.board.shogi_board[7][3]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][3],
                            self.board.shogi_board[6][4]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[6][4],
                            self.board.shogi_board[6][5]))

        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][7],
                            self.board.shogi_board[8][6]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][6],
                            self.board.shogi_board[8][5]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[8][5],
                            self.board.shogi_board[7][4]))
        self.assertEqual(
            0,
            self.board.move(self.board.shogi_board[7][4],
                            self.board.shogi_board[8][3]))
        self.assertEqual(
            1,
            self.board.move(self.board.shogi_board[7][4],
                            self.board.shogi_board[8][4]))

    def tearDown(self):
        self.board.shogi_board = [[Cell(x, y) for x in range(0, 9)]
                                  for y in range(0, 9)]
Beispiel #24
0
 def test_db에_저장된다(self, subject, form):
     board = Board.objects(name=form['name']).get()
     assert board.name == form['name']