From 4785dde648c2688611ffc4045ff9e131ee38576d Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Sun, 10 Feb 2008 23:04:07 +0100 Subject: [PATCH] push dba7844810ccf5dada78def48e30e1669c45d321 --- TODO_shogi | 33 ------- debian/.gitignore | 1 - debian/control | 9 -- debian/tagua-variant-chess.files | 1 - debian/tagua-variant-shogi.files | 2 - src/core/baseanimator.cpp | 14 +-- src/core/board.cpp | 21 +--- src/core/board.h | 5 +- src/core/defaultpolicy.cpp | 6 +- src/graphicalsystem.cpp | 21 ++-- src/variants/CMakeLists.txt | 1 - src/variants/chess/CMakeLists.txt | 27 ++---- src/variants/chess/animator.cpp | 22 ++--- src/variants/chess/behaviour.cpp | 2 +- src/variants/chess/castlingrules.cpp | 17 ++-- src/variants/chess/moveserializer.cpp | 32 +++--- src/variants/chess/pawn.cpp | 3 +- src/variants/chess/state.cpp | 8 +- src/variants/chess/validator.cpp | 31 +++--- src/variants/crazyhouse/behaviour.cpp | 10 +- src/variants/crazyhouse/state.cpp | 18 ++-- src/variants/crazyhouse/validator.cpp | 3 +- src/variants/shogi/CMakeLists.txt | 32 ------ src/variants/shogi/behaviour.cpp | 38 -------- src/variants/shogi/behaviour.h | 26 ----- src/variants/shogi/bishop.cpp | 36 ------- src/variants/shogi/bishop.h | 32 ------ src/variants/shogi/colors.cpp | 17 ---- src/variants/shogi/colors.h | 22 ----- src/variants/shogi/gold.cpp | 38 -------- src/variants/shogi/gold.h | 34 ------- src/variants/shogi/king.cpp | 33 ------- src/variants/shogi/king.h | 32 ------ src/variants/shogi/knight.cpp | 39 -------- src/variants/shogi/knight.h | 32 ------ src/variants/shogi/lance.cpp | 41 -------- src/variants/shogi/lance.h | 34 ------- src/variants/shogi/moveserializer.cpp | 43 --------- src/variants/shogi/moveserializer.h | 16 --- src/variants/shogi/pawn.cpp | 40 -------- src/variants/shogi/pawn.h | 32 ------ src/variants/shogi/rook.cpp | 36 ------- src/variants/shogi/rook.h | 32 ------ src/variants/shogi/shogi.cpp | 64 ------------ src/variants/shogi/silver.cpp | 37 ------- src/variants/shogi/silver.h | 34 ------- src/variants/shogi/state.cpp | 171 --------------------------------- src/variants/shogi/state.h | 73 -------------- src/variants/shogi/tagua-shogi.desktop | 20 ---- src/variants/shogi/types.h | 24 ----- src/variants/shogi/validator.cpp | 159 ------------------------------ src/variants/shogi/validator.h | 43 --------- 52 files changed, 102 insertions(+), 1495 deletions(-) delete mode 100644 debian/tagua-variant-shogi.files delete mode 100644 src/variants/shogi/CMakeLists.txt delete mode 100644 src/variants/shogi/behaviour.cpp delete mode 100644 src/variants/shogi/behaviour.h delete mode 100644 src/variants/shogi/bishop.cpp delete mode 100644 src/variants/shogi/bishop.h delete mode 100644 src/variants/shogi/colors.cpp delete mode 100644 src/variants/shogi/colors.h delete mode 100644 src/variants/shogi/gold.cpp delete mode 100644 src/variants/shogi/gold.h delete mode 100644 src/variants/shogi/king.cpp delete mode 100644 src/variants/shogi/king.h delete mode 100644 src/variants/shogi/knight.cpp delete mode 100644 src/variants/shogi/knight.h delete mode 100644 src/variants/shogi/lance.cpp delete mode 100644 src/variants/shogi/lance.h delete mode 100644 src/variants/shogi/moveserializer.cpp delete mode 100644 src/variants/shogi/moveserializer.h delete mode 100644 src/variants/shogi/pawn.cpp delete mode 100644 src/variants/shogi/pawn.h delete mode 100644 src/variants/shogi/rook.cpp delete mode 100644 src/variants/shogi/rook.h delete mode 100644 src/variants/shogi/shogi.cpp delete mode 100644 src/variants/shogi/silver.cpp delete mode 100644 src/variants/shogi/silver.h delete mode 100644 src/variants/shogi/state.cpp delete mode 100644 src/variants/shogi/state.h delete mode 100644 src/variants/shogi/tagua-shogi.desktop delete mode 100644 src/variants/shogi/types.h delete mode 100644 src/variants/shogi/validator.cpp delete mode 100644 src/variants/shogi/validator.h diff --git a/TODO_shogi b/TODO_shogi index 4ad2526..988d1ad 100644 --- a/TODO_shogi +++ b/TODO_shogi @@ -1,34 +1,3 @@ -component-api port: -- finalize shogi functionnality: - - promoting moves - legalitycheck.h pseudolegal() -> validator.cpp - gamestate.h promotionZone() -> ? - gamestate.h canPromote() -> ? - shogiactions.* -> ? - ? -> state.cpp move() - - mimic Chess::Pawn::setPromotion() into a common ancestor for - shogi pieces - - moves of promoted pieces (legalitycheck.h getMoveType() -> ?) - - drops - - pieces do not appear in pool - ? -> moveserializer.* serialize() - - dropped pawn cannot checkmate (not in master ?!) - - piece orientation - - japanese digits on shogiban (shogiban.h borderCoords() -> move to theme ?) -- put correct credits in variants/shogi/* -- generalize required chess components to get rid of libtaguachesslib.so - - caracterize jump moves instead of hardcoding Knight in animations - - Pawn::setPromotion - - caracterize royal status (maybe policy-driven to account for Prince in Sho) - instead of hardcoding King - -other general non-shogi-related things to do quickly: -- find out how to use uninstalled plugins, document running from source tree -- use git-describe for debian package versionning -- solve missing icons ("View" menu) -- shlib versionning scheme -- engines do not work any more (No such slot EngineInfo::playAsWhite) - tagua core: - gnushogi engine gets confused when moving through history => generic pb ? - tooltips for figurines, for people who can't read kanji @@ -36,8 +5,6 @@ tagua core: -> maybe by splitting target square, so the piece gets all different moves in one click, depending on which part of the square is hit ? - allow to setup and play problems (tsume shogi) -- loading a saved shogi game from PGN does notwork => probable generic issue -- install engine declarations system-wide engines/core: - engine options (eg. select difficulty level) diff --git a/debian/.gitignore b/debian/.gitignore index 659968e..b354d86 100644 --- a/debian/.gitignore +++ b/debian/.gitignore @@ -6,4 +6,3 @@ tagua-data tagua-variant-chess tagua-variant-chess5x5 tagua-variant-crazyhouse -tagua-variant-shogi diff --git a/debian/control b/debian/control index 6258bdf..fcffa8b 100644 --- a/debian/control +++ b/debian/control @@ -51,12 +51,3 @@ Provides: tagua-variant Description: Chess 5x5 support for the tagua board-game frontend This package allows to play "chess 5x5", a chess variant on a 5x5 board, from tagua. - -Package: tagua-variant-shogi -Architecture: any -Depends: tagua, tagua-variant-chess, tagua-variant-crazyhouse -Suggests: gnushogi, gpsshogi -Provides: tagua-variant -Description: Shogi support for the tagua board-game frontend - This package allows to play Shogi, a japanese chess-like game, from - tagua. diff --git a/debian/tagua-variant-chess.files b/debian/tagua-variant-chess.files index 7a7a68f..a2426a5 100644 --- a/debian/tagua-variant-chess.files +++ b/debian/tagua-variant-chess.files @@ -1,3 +1,2 @@ usr/lib/kde4/taguachess.so -usr/lib/libtaguachess* usr/share/kde4/services/tagua-chess.desktop diff --git a/debian/tagua-variant-shogi.files b/debian/tagua-variant-shogi.files deleted file mode 100644 index 67667f1..0000000 --- a/debian/tagua-variant-shogi.files +++ /dev/null @@ -1,2 +0,0 @@ -usr/lib/kde4/taguashogi.so -usr/share/kde4/services/tagua-shogi.desktop diff --git a/src/core/baseanimator.cpp b/src/core/baseanimator.cpp index 4c068f7..abbc8c9 100644 --- a/src/core/baseanimator.cpp +++ b/src/core/baseanimator.cpp @@ -29,23 +29,23 @@ AnimationPtr BaseAnimator::warp(const IState* state) { Point p(i, j); NamedSprite sprite = m_api->getSprite(p); - const Piece* piece = state->board()->get(p); + Piece piece = state->board()->get(p); AnimationPtr anim; - if (!sprite && piece != NULL && *piece != Piece()) { - anim = m_api->appear(m_api->setPiece(p, *piece, false), "instant"); + if (!sprite && piece != Piece()) { + anim = m_api->appear(m_api->setPiece(p, piece, false), "instant"); } - else if (sprite && (piece == NULL || *piece == Piece())) { + else if (sprite && piece == Piece()) { m_api->takeSprite(p); anim = m_api->disappear(sprite, "instant"); } // sprite and piece differ - else if (sprite && piece != NULL && *piece != Piece() && - m_namer->name(*piece) != sprite.name()) { + else if (sprite && piece != Piece() && + m_namer->name(piece) != sprite.name()) { m_api->takeSprite(p); - anim = m_api->morph(sprite, m_api->setPiece(p, *piece, false), "instant"); + anim = m_api->morph(sprite, m_api->setPiece(p, piece, false), "instant"); } res->addPreAnimation(anim); diff --git a/src/core/board.cpp b/src/core/board.cpp index fd827ae..28ca58e 100644 --- a/src/core/board.cpp +++ b/src/core/board.cpp @@ -35,22 +35,12 @@ bool Board::equals(const Board* other) const { Point Board::size() const { return m_size; } -const Piece* Board::get(const Point& p) const { +Piece Board::get(const Point& p) const { if (valid(p)) { - return &m_data[p.x + p.y * m_size.x]; + return m_data[p.x + p.y * m_size.x]; } else { - return NULL; - } -} - -// FIXME: solve this code duplication -Piece* Board::get(const Point& p) { - if (valid(p)) { - return &m_data[p.x + p.y * m_size.x]; - } - else { - return NULL; + return Piece(); } } @@ -90,8 +80,7 @@ PathInfo Board::path(const Point& from, const Point& to) const { Point step = delta.normalizeInfinity(); Point position = from; while ((position += step) != to) { - if (get(position) == NULL || - *get(position) == Piece()) + if (get(position) == Piece()) continue; num_obs++; } @@ -104,7 +93,7 @@ Point Board::find(const Piece& piece) const { for (int i = 0; i < m_size.x; i++) { for (int j = 0; j < m_size.y; j++) { Point p(i, j); - if (*get(p) == piece) + if (get(p) == piece) return p; } } diff --git a/src/core/board.h b/src/core/board.h index 10caf39..d2377a8 100644 --- a/src/core/board.h +++ b/src/core/board.h @@ -54,10 +54,9 @@ public: /** * Retrieve a piece from the board. * @param p Coordinates of the piece. - * @return Pointer to the piece at that square, or NULL, if the square is out of the board. + * @return The piece at that square, or an invalid piece, if the square is out of the board. */ - Piece* get(const Point& p); - const Piece* get(const Point& p) const; + Piece get(const Point& p) const; /** * Add a piece to the board. diff --git a/src/core/defaultpolicy.cpp b/src/core/defaultpolicy.cpp index c40b2d0..a57e835 100644 --- a/src/core/defaultpolicy.cpp +++ b/src/core/defaultpolicy.cpp @@ -15,11 +15,11 @@ InteractionType DefaultPolicy::movable(const IState* state, const TurnTest& test, const Point& p) const { - const Piece* piece = state->board()->get(p); - if (piece == NULL || *piece == Piece() || !test(piece->color())) + Piece piece = state->board()->get(p); + if (piece == Piece() || !test(piece.color())) return NoAction; - return piece->color() == state->turn() ? Moving : Premoving; + return piece.color() == state->turn() ? Moving : Premoving; } InteractionType DefaultPolicy::droppable(const IState* state, diff --git a/src/graphicalsystem.cpp b/src/graphicalsystem.cpp index 862c030..8d8eadf 100644 --- a/src/graphicalsystem.cpp +++ b/src/graphicalsystem.cpp @@ -180,7 +180,7 @@ std::pair GraphicalSystem::droppedPoolPiece() { void GraphicalSystem::forward(const Move& move, const StatePtr& pos, const SpritePtr& /*movingSprite*/) { - const Piece* sel1 = m_state->board()->get(m_board->selection); + Piece sel1 = m_state->board()->get(m_board->selection); if (move != Move()) { AnimationPtr animation = m_animator->forward(move, pos.get()); @@ -192,9 +192,8 @@ void GraphicalSystem::forward(const Move& move, else warp(Move(), pos); - const Piece* sel2 = m_state->board()->get(m_board->selection); - if(!(sel1 != NULL && sel2 != NULL && - *sel1 != Piece() && *sel2 != Piece() && *sel1 == *sel2)) + Piece sel2 = m_state->board()->get(m_board->selection); + if(!(sel1 != Piece() && sel2 != Piece() && sel1 == sel2)) m_board->cancelSelection(); m_board->cancelPremove(); @@ -205,7 +204,7 @@ void GraphicalSystem::forward(const Move& move, void GraphicalSystem::back(const Move& lastMove, const Move& move, const StatePtr& state) { - const Piece* sel1 = m_state->board()->get(m_board->selection); + Piece sel1 = m_state->board()->get(m_board->selection); if (move != Move()) { AnimationPtr animation = m_animator->back(move, state.get()); @@ -222,9 +221,8 @@ void GraphicalSystem::back(const Move& lastMove, else m_board->clearTags("highlighting"); - const Piece* sel2 = m_state->board()->get(m_board->selection); - if(!(sel1 != NULL && sel2 != NULL && - *sel1 != Piece() && *sel2 != Piece() && *sel1 == *sel2)) + Piece sel2 = m_state->board()->get(m_board->selection); + if(!(sel1 != Piece() && sel2 != Piece() && sel1 == sel2)) m_board->cancelSelection(); m_board->cancelPremove(); m_view->updateTurn(state->turn()->index()); @@ -234,7 +232,7 @@ void GraphicalSystem::back(const Move& lastMove, void GraphicalSystem::warp(const Move& lastMove, const StatePtr& state) { - const Piece* sel1 = m_state->board()->get(m_board->selection); + Piece sel1 = m_state->board()->get(m_board->selection); AnimationPtr animation = m_animator->warp(state.get()); //??? animation->setChainAbortions(false); @@ -249,9 +247,8 @@ void GraphicalSystem::warp(const Move& lastMove, else m_board->clearTags("highlighting"); - const Piece* sel2 = m_state->board()->get(m_board->selection); - if(!(sel1 != NULL && sel2 != NULL && - *sel1 != Piece() && *sel2 != Piece() && *sel1 == *sel2)) + Piece sel2 = m_state->board()->get(m_board->selection); + if(!(sel1 != Piece() && sel2 != Piece() && sel1 == sel2)) m_board->cancelSelection(); m_view->updateTurn(state->turn()->index()); m_board->onPositionChanged(); diff --git a/src/variants/CMakeLists.txt b/src/variants/CMakeLists.txt index 0183858..f45132e 100644 --- a/src/variants/CMakeLists.txt +++ b/src/variants/CMakeLists.txt @@ -2,4 +2,3 @@ add_subdirectory(chess) add_subdirectory(chess5x5) add_subdirectory(crazyhouse) -add_subdirectory(shogi) diff --git a/src/variants/chess/CMakeLists.txt b/src/variants/chess/CMakeLists.txt index a7b33fd..6fc9485 100644 --- a/src/variants/chess/CMakeLists.txt +++ b/src/variants/chess/CMakeLists.txt @@ -1,42 +1,31 @@ -set(taguachesslib_SRCS - castlingrules.cpp - icsverbose.cpp - king.cpp - knight.cpp - moveserializer.cpp - pawn.cpp - queen.cpp - san.cpp -) set(taguachess_SRCS animator.cpp behaviour.cpp bishop.cpp + castlingrules.cpp chess.cpp colors.cpp + icsverbose.cpp + king.cpp + knight.cpp + moveserializer.cpp namer.cpp + pawn.cpp rook.cpp + queen.cpp + san.cpp state.cpp validator.cpp ) include_directories(${CMAKE_SOURCE_DIR}/src/) -kde4_add_library(taguachesslib SHARED ${taguachesslib_SRCS}) - -target_link_libraries(taguachesslib - taguacore - ${KDE4_KDECORE_LIBS} -) - kde4_add_plugin(taguachess ${taguachess_SRCS}) target_link_libraries(taguachess taguacore - taguachesslib ${KDE4_KDECORE_LIBS} ) -install(TARGETS taguachesslib DESTINATION ${LIB_INSTALL_DIR}) install(TARGETS taguachess DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES tagua-chess.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/src/variants/chess/animator.cpp b/src/variants/chess/animator.cpp index 2e23306..7a61d59 100644 --- a/src/variants/chess/animator.cpp +++ b/src/variants/chess/animator.cpp @@ -46,11 +46,11 @@ AnimationPtr Animator::forward(const Move& move, const IState* state) { res->addPostAnimation(m_api->disappear(captured, "destroy")); if (move.promotion() && move.type() == "promotion") { - const Piece* promoted = state->board()->get(move.dst()); + Piece promoted = state->board()->get(move.dst()); - if (promoted != NULL && *promoted != Piece()) { + if (promoted != Piece()) { NamedSprite old_sprite = m_api->getSprite(move.dst()); - NamedSprite new_sprite = m_api->setPiece(move.dst(), *promoted, false); + NamedSprite new_sprite = m_api->setPiece(move.dst(), promoted, false); res->addPostAnimation(m_api->morph(old_sprite, new_sprite, "default")); } @@ -84,23 +84,23 @@ AnimationPtr Animator::back(const Move& move, const IState* state) { Point captureSquare = move.dst(); if (const IBehaviour* behaviour = state->behaviour()) captureSquare = behaviour->captureSquare(state, move); - const Piece* captured_piece = state->board()->get(captureSquare); - if (captured_piece != NULL && *captured_piece != Piece()) { - captured = m_api->setPiece(captureSquare, *captured_piece, false); + Piece captured_piece = state->board()->get(captureSquare); + if (captured_piece != Piece()) { + captured = m_api->setPiece(captureSquare, captured_piece, false); res->addPreAnimation(m_api->appear(captured, "default")); } if (!piece) { - piece = m_api->createPiece(move.dst(), *state->board()->get(move.src()), false); + piece = m_api->createPiece(move.dst(), state->board()->get(move.src()), false); res->addPreAnimation(m_api->appear(piece, "default")); } m_api->setSprite(move.src(), piece); if (move.promotion() && move.type() == "promotion") { - const Piece* pawn_piece = state->board()->get(move.src()); - if (pawn_piece != NULL && *pawn_piece != Piece()) { - NamedSprite pawn = m_api->createPiece(move.dst(), *pawn_piece, false); + Piece pawn_piece = state->board()->get(move.src()); + if (pawn_piece != Piece()) { + NamedSprite pawn = m_api->createPiece(move.dst(), pawn_piece, false); res->addPreAnimation(m_api->morph(piece, pawn, "default")); // replace piece with pawn @@ -135,7 +135,7 @@ AnimationPtr Animator::back(const Move& move, const IState* state) { } AnimationPtr Animator::movement(const NamedSprite& sprite, const Move& move) const { - bool knight = m_api->state()->board()->get(move.src())->type() == Knight::self(); + bool knight = m_api->state()->board()->get(move.src()).type() == Knight::self(); QString flags = knight ? "lshaped rotating" : "straight"; return m_api->move(sprite, move.dst(), flags); } diff --git a/src/variants/chess/behaviour.cpp b/src/variants/chess/behaviour.cpp index 9880b32..4c60f7f 100644 --- a/src/variants/chess/behaviour.cpp +++ b/src/variants/chess/behaviour.cpp @@ -22,7 +22,7 @@ void Behaviour::captureOn(IState* state, const Point& square) const { void Behaviour::move(IState* state, const Move& m) const { if (m.dst() != m.src()) { - state->board()->set(m.dst(), *state->board()->get(m.src())); + state->board()->set(m.dst(), state->board()->get(m.src())); state->board()->set(m.src(), Piece()); } } diff --git a/src/variants/chess/castlingrules.cpp b/src/variants/chess/castlingrules.cpp index 03783a9..c13a192 100644 --- a/src/variants/chess/castlingrules.cpp +++ b/src/variants/chess/castlingrules.cpp @@ -31,22 +31,17 @@ bool CastlingRules::canCastle(const Piece& piece, Move& move, const IState* stat if (move.src() != m_delegator->kingStartingPosition(state, piece.color())) return false; if (move.delta() == Point(2,0)) { - if ((state->board()->get(move.src() + Point(1,0)) == NULL || - *state->board()->get(move.src() + Point(1,0)) == Piece()) && - (state->board()->get(move.dst()) == NULL || - *state->board()->get(move.dst()) == Piece()) && - state->flags()->get(piece.color()->name() + "_king_castling").toBool()) { + if (state->board()->get(move.src() + Point(1,0)) == Piece() && + state->board()->get(move.dst()) == Piece() && + state->flags()->get(piece.color()->name() + "_king_castling").toBool()) { move.setType("king_castling"); return true; } } else if (move.delta() == Point(-2,0)) { - if ((state->board()->get(move.src() - Point(1, 0)) == NULL || - *state->board()->get(move.src() - Point(1, 0)) == Piece()) && - (state->board()->get(move.dst() + Point(1, 0)) == NULL || - *state->board()->get(move.dst() + Point(1, 0)) == Piece()) && - (state->board()->get(move.dst()) == NULL || - *state->board()->get(move.dst()) == Piece()) && + if (state->board()->get(move.src() - Point(1, 0)) == Piece() && + state->board()->get(move.dst() + Point(1, 0)) == Piece() && + state->board()->get(move.dst()) == Piece() && state->flags()->get(piece.color()->name() + "_queen_castling").toBool()) { move.setType("queen_castling"); return true; diff --git a/src/variants/chess/moveserializer.cpp b/src/variants/chess/moveserializer.cpp index e4669e2..5c443c2 100644 --- a/src/variants/chess/moveserializer.cpp +++ b/src/variants/chess/moveserializer.cpp @@ -34,10 +34,10 @@ QString MoveSerializer::san(const Move& move, const IState* ref) const { if (const IBehaviour* behaviour = ref->behaviour()) captureSquare = behaviour->captureSquare(ref, move); - const Piece* piece = ref->board()->get(move.src()); - const Piece* captured = ref->board()->get(captureSquare); + Piece piece = ref->board()->get(move.src()); + Piece captured = ref->board()->get(captureSquare); - if (piece == NULL || *piece == Piece()) + if (piece == Piece()) return ""; // no piece in the initial square if (move.type() == "king_side_castling") { @@ -46,25 +46,25 @@ QString MoveSerializer::san(const Move& move, const IState* ref) const { else if (move.type() == "queen_side_castling") { res = "O-O-O"; } - else if (piece->type() == Pawn::self()) { - if (captured != NULL && *captured != Piece()) + else if (piece.type() == Pawn::self()) { + if (captured != Piece()) res = move.src().col() + "x"; res += move.dst().toString(ref->board()->size().y); } else { - if (piece->type() != Pawn::self()) - res = symbol(piece->type()).toUpper(); + if (piece.type() != Pawn::self()) + res = symbol(piece.type()).toUpper(); SAN tmp; tmp.src = move.src(); tmp.dst = move.dst(); - tmp.type = piece->type(); + tmp.type = piece.type(); tmp.castling = SAN::NoCastling; minimal_notation(tmp, ref); res += tmp.src.toString(ref->board()->size().y); - if (captured != NULL && *captured != Piece()) + if (captured != Piece()) res += "x"; res += tmp.dst.toString(ref->board()->size().y); } @@ -138,8 +138,8 @@ Move MoveSerializer::get_san(const SAN& san, const IState* ref) const { // find king starting position Point from(ref->board()->size().x / 2, ref->rank(0, ref->turn())); Point to = from + (san.castling == SAN::KingSide? Point(2,0) : Point(-2,0)); - const Piece* king = ref->board()->get(from); - if (king->type() != King::self()) + Piece king = ref->board()->get(from); + if (king.type() != King::self()) return candidate; else { candidate = Move(from, to); @@ -157,14 +157,12 @@ Move MoveSerializer::get_san(const SAN& san, const IState* ref) const { for (int i = 0; i < ref->board()->size().x; i++) { for (int j = 0; j < ref->board()->size().y; j++) { Point p(i, j); - const Piece* piece = ref->board()->get(p); + Piece piece = ref->board()->get(p); Move mv(p, san.dst, san.promotion); - if (p.resembles(san.src) && - piece != NULL && - *piece != Piece() && - piece->type() == san.type && - piece->color() == ref->turn()) { + if (p.resembles(san.src) && + piece.type() == san.type && + piece.color() == ref->turn()) { if (m_validator->legal(ref, mv)) { if (candidate != Move()) { // ambiguous! diff --git a/src/variants/chess/pawn.cpp b/src/variants/chess/pawn.cpp index 78856ce..e0c845b 100644 --- a/src/variants/chess/pawn.cpp +++ b/src/variants/chess/pawn.cpp @@ -40,8 +40,7 @@ bool Pawn::canMove(const Piece& piece, const Piece& target, if (move.src().y == state->rank(1, piece.color()) && move.delta() == behaviour->direction(piece.color()) * 2 && - (state->board()->get(move.src() + behaviour->direction(piece.color())) == NULL || - *state->board()->get(move.src() + behaviour->direction(piece.color())) == Piece())) { + state->board()->get(move.src() + behaviour->direction(piece.color())) == Piece()) { move.setType("en_passant_trigger"); return true; } diff --git a/src/variants/chess/state.cpp b/src/variants/chess/state.cpp index 27fbe12..7065a21 100644 --- a/src/variants/chess/state.cpp +++ b/src/variants/chess/state.cpp @@ -96,8 +96,8 @@ void State::assign(const IState* other) { } void State::move(const Move& m) { - const Piece* piece = m_board.get(m.src()); - if (piece == NULL || *piece == Piece()) return; + Piece piece = m_board.get(m.src()); + if (piece == Piece()) return; Point captureSquare = behaviour()->captureSquare(this, m); behaviour()->captureOn(m_delegator, captureSquare); @@ -107,11 +107,11 @@ void State::move(const Move& m) { const IType* promotion_type = m.promotion(); if (promotion_type != 0) { - m_board.set(m.dst(), Piece(piece->color(), promotion_type)); + m_board.set(m.dst(), Piece(piece.color(), promotion_type)); } if (m_castling_rules) - m_castling_rules->handleCastling(*piece, m, m_delegator); + m_castling_rules->handleCastling(piece, m, m_delegator); behaviour()->advanceTurn(m_delegator); } diff --git a/src/variants/chess/validator.cpp b/src/variants/chess/validator.cpp index e2c7011..fdadb0b 100644 --- a/src/variants/chess/validator.cpp +++ b/src/variants/chess/validator.cpp @@ -16,21 +16,21 @@ bool Validator::pseudolegal(const IState* state, Move& move) const { if (!state->board()->valid(move.src())) return false; if (!state->board()->valid(move.dst())) return false; - const Piece* piece = state->board()->get(move.src()); - if (piece == NULL || *piece == Piece()) return false; + Piece piece = state->board()->get(move.src()); + if (piece == Piece()) return false; const IBehaviour* behaviour = state->behaviour(); if (!behaviour) return false; - const IColor* thisTurn = piece->color(); + const IColor* thisTurn = piece.color(); const IColor* otherTurn = behaviour->opponent(thisTurn); if (state->turn() != thisTurn) return false; - const Piece* target = state->board()->get(move.dst()); - if (target->color() == piece->color()) + Piece target = state->board()->get(move.dst()); + if (target.color() == piece.color()) return false; - if (!piece->type()->canMove(*piece, *target, move, state)) + if (!piece.type()->canMove(piece, target, move, state)) return false; if (move.type() == "promotion") { @@ -43,12 +43,12 @@ bool Validator::pseudolegal(const IState* state, Move& move) const { if (move.type() == "king_side_castling") { if (m_delegator->attacks(state, otherTurn, move.src()) || - m_delegator->attacks(state, otherTurn, move.src() + Point(1, 0), *piece)) + m_delegator->attacks(state, otherTurn, move.src() + Point(1, 0), piece)) return false; } if (move.type() == "queen_side_castling") { if (m_delegator->attacks(state, otherTurn, move.src()) || - m_delegator->attacks(state, otherTurn, move.src() + Point(-1, 0), *piece)) + m_delegator->attacks(state, otherTurn, move.src() + Point(-1, 0), piece)) return false; } @@ -85,21 +85,20 @@ bool Validator::legal(const IState* state, Move& move) const { bool Validator::attacks(const IState* state, const IColor* player, const Point& square, const Piece& target_) const { - const Piece* target; + Piece target; if (target_ != Piece()) - target = &target_; + target = target_; else target = state->board()->get(square); for (int i = 0; i < state->board()->size().x; i++) { for (int j = 0; j < state->board()->size().y; j++) { Point p(i, j); - const Piece* piece = state->board()->get(p); + Piece piece = state->board()->get(p); Move move(p, square); - if (piece != NULL && - *piece != Piece() && - piece->color() == player && - piece->type()->canMove(*piece, *target, move, state)) + if (piece != Piece() && + piece.color() == player && + piece.type()->canMove(piece, target, move, state)) return true; } } @@ -107,7 +106,7 @@ bool Validator::attacks(const IState* state, const IColor* player, } const IColor* Validator::mover(const IState* state, const Move& move) const { - return state->board()->get(move.src())->color(); + return state->board()->get(move.src()).color(); } void Validator::setDelegator(IValidator* delegator) { diff --git a/src/variants/crazyhouse/behaviour.cpp b/src/variants/crazyhouse/behaviour.cpp index 0dd43f6..6cd2058 100644 --- a/src/variants/crazyhouse/behaviour.cpp +++ b/src/variants/crazyhouse/behaviour.cpp @@ -22,12 +22,12 @@ Behaviour::Behaviour(const IBehaviour* behaviour) : Delegators::Behaviour(behaviour) { } void Behaviour::captureOn(IState* state, const Point& square) const { - Piece* captured = state->board()->get(square); - if (captured != NULL && *captured != Piece()) { - if (captured->get("promoted").toBool()) { - captured->setType(pawn); + Piece captured = state->board()->get(square); + if (captured != Piece()) { + if (captured.get("promoted").toBool()) { + captured.setType(pawn); } - state->pools()->pool(opponent(captured->color()))->insert(-1, *captured); + state->pools()->pool(opponent(captured.color()))->insert(-1, captured); } m_behaviour->captureOn(state, square); } diff --git a/src/variants/crazyhouse/state.cpp b/src/variants/crazyhouse/state.cpp index 765c853..af2ae84 100644 --- a/src/variants/crazyhouse/state.cpp +++ b/src/variants/crazyhouse/state.cpp @@ -48,17 +48,17 @@ void State::assign(const IState* other) { void State::move(const Move& m) { if (m.drop() != Piece()) { - Piece* captured = board()->get(m.dst()); + Piece captured = board()->get(m.dst()); board()->set(m.dst(), m.drop()); pools()->pool(m.drop().color())->take(m.drop()); // handle capturing by drop: some variants could use it - if (captured != NULL && *captured != Piece()) { - if (captured->get("promoted").toBool()) { - captured->setType(pawn); + if (captured != Piece()) { + if (captured.get("promoted").toBool()) { + captured.setType(pawn); } - pools()->pool(behaviour()->opponent(captured->color())) - ->insert(-1, *captured); + pools()->pool(behaviour()->opponent(captured.color())) + ->insert(-1, captured); } behaviour()->advanceTurn(this); @@ -66,9 +66,9 @@ void State::move(const Move& m) { else { m_state->move(m); if (m.promotion()) { - Piece* promoted = board()->get(m.dst()); - promoted->set("promoted", true); - board()->set(m.dst(), *promoted); + Piece promoted = board()->get(m.dst()); + promoted.set("promoted", true); + board()->set(m.dst(), promoted); } } } diff --git a/src/variants/crazyhouse/validator.cpp b/src/variants/crazyhouse/validator.cpp index e25193e..b416123 100644 --- a/src/variants/crazyhouse/validator.cpp +++ b/src/variants/crazyhouse/validator.cpp @@ -43,8 +43,7 @@ bool Validator::pseudolegal(const IState* state, Move& move) const { return false; // cannot drop on occupied squares - if (state->board()->get(move.dst()) != NULL && - *state->board()->get(move.dst()) != Piece()) + if (state->board()->get(move.dst()) != Piece()) return false; // cannot drop pawns in first or eighth rank diff --git a/src/variants/shogi/CMakeLists.txt b/src/variants/shogi/CMakeLists.txt deleted file mode 100644 index b43dd45..0000000 --- a/src/variants/shogi/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -set(taguashogi_SRCS - shogi.cpp - - king.cpp - gold.cpp - silver.cpp - knight.cpp - lance.cpp - pawn.cpp - rook.cpp - bishop.cpp - - behaviour.cpp - colors.cpp - moveserializer.cpp -# san.cpp - state.cpp - validator.cpp -) - -include_directories(${CMAKE_SOURCE_DIR}/src/) - -kde4_add_plugin(taguashogi ${taguashogi_SRCS}) - -target_link_libraries(taguashogi - taguacore - taguachesslib - ${KDE4_KDECORE_LIBS} -) - -install(TARGETS taguashogi DESTINATION ${PLUGIN_INSTALL_DIR}) -install(FILES tagua-shogi.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/src/variants/shogi/behaviour.cpp b/src/variants/shogi/behaviour.cpp deleted file mode 100644 index 3b29d49..0000000 --- a/src/variants/shogi/behaviour.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#include "behaviour.h" - -#include -#include -#include -#include -#include - -namespace Shogi { - -Behaviour::Behaviour(const IBehaviour* behaviour) -: Delegators::Behaviour(behaviour) { } - -void Behaviour::captureOn(IState* state, const Point& square) const { - const Piece* captured = state->board()->get(square); - if (captured != NULL && *captured != Piece()) { - if (captured->get("promoted").toBool()) { -#warning un-promote - // FIXME: generalize this, and use Crazyhouse::Behaviour instead ? - //captured->setType(pawn); - } - state->pools()->pool(opponent(captured->color()))->insert(-1, *captured); - } - m_behaviour->captureOn(state, square); -} - -} // namespace Shogi - - diff --git a/src/variants/shogi/behaviour.h b/src/variants/shogi/behaviour.h deleted file mode 100644 index 8f43c4c..0000000 --- a/src/variants/shogi/behaviour.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__BEHAVIOUR_H -#define SHOGI__BEHAVIOUR_H - -#include - -namespace Shogi { - -class Behaviour : public Delegators::Behaviour { -public: - Behaviour(const IBehaviour* behaviour); - - virtual void captureOn(IState* state, const Point& square) const; -}; - -} // namespace Shogi - -#endif // SHOGI__BEHAVIOUR_H diff --git a/src/variants/shogi/bishop.cpp b/src/variants/shogi/bishop.cpp deleted file mode 100644 index d16b786..0000000 --- a/src/variants/shogi/bishop.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#include "bishop.h" -#include -#include -#include -#include - -namespace Shogi { - -Bishop::Bishop() { } - -QString Bishop::name() const { return "bishop"; } - -bool Bishop::canMove(const Piece& piece, const Piece& target, - Move& move, const IState* state) const { - PathInfo path = state->board()->path(move.src(), move.dst()); - return path.diagonal() && path.clear() && target.color() != piece.color(); -} - -int Bishop::index() const { return 35; } - -Bishop* Bishop::self() { - static Bishop s_instance; - return &s_instance; -} - -} diff --git a/src/variants/shogi/bishop.h b/src/variants/shogi/bishop.h deleted file mode 100644 index 2a7de19..0000000 --- a/src/variants/shogi/bishop.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__TYPES__BISHOP_H -#define SHOGI__TYPES__BISHOP_H - -#include -#include - -namespace Shogi { - -class TAGUA_EXPORT Bishop : public Component, public IType { -Q_OBJECT - Bishop(); -public: - virtual QString name() const; - virtual bool canMove(const Piece& piece, const Piece& target, - Move& move, const IState* state) const; - virtual int index() const; - static Bishop* self(); -}; - -} - -#endif // SHOGI__TYPES__BISHOP_H diff --git a/src/variants/shogi/colors.cpp b/src/variants/shogi/colors.cpp deleted file mode 100644 index 420b67e..0000000 --- a/src/variants/shogi/colors.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#include "colors.h" - -namespace Shogi { - -IColor* COLORS[] = { Black::self(), White::self() }; - -} diff --git a/src/variants/shogi/colors.h b/src/variants/shogi/colors.h deleted file mode 100644 index 45e24f3..0000000 --- a/src/variants/shogi/colors.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__COLORS_H -#define SHOGI__COLORS_H - -#include - -namespace Shogi { - -extern IColor* COLORS[2]; - -} - -#endif // SHOGI__COLORS_H diff --git a/src/variants/shogi/gold.cpp b/src/variants/shogi/gold.cpp deleted file mode 100644 index a3414cf..0000000 --- a/src/variants/shogi/gold.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#include "gold.h" -#include -#include -#include - -namespace Shogi { - -Gold::Gold() { } - -QString Gold::name() const { return "gold"; } - -bool Gold::canMove(const Piece& piece, const Piece&, - Move& move, const IState* state) const { - const IBehaviour* behaviour = state->behaviour(); - if (!behaviour) return false; - return ((move.delta().x == 0 && abs(move.delta().y) == 1) - || (move.delta().y == 0 && abs(move.delta().x) == 1) - || (move.delta().y == behaviour->direction(piece.color()).y && abs(move.delta().x) <= 1)); -} - -int Gold::index() const { return 10000; } - -Gold* Gold::self() { - static Gold s_instance; - return &s_instance; -} - -} diff --git a/src/variants/shogi/gold.h b/src/variants/shogi/gold.h deleted file mode 100644 index 59feb8d..0000000 --- a/src/variants/shogi/gold.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__TYPES__GOLD_H -#define SHOGI__TYPES__GOLD_H - -#include -#include - -namespace Shogi { - -class ICastlingRules; - -class TAGUA_EXPORT Gold : public Component, public IType { -Q_OBJECT - Gold(); -public: - virtual QString name() const; - virtual bool canMove(const Piece& piece, const Piece& target, - Move& move, const IState* state) const; - virtual int index() const; - static Gold* self(); -}; - -} - -#endif // SHOGI__TYPES__GOLD_H diff --git a/src/variants/shogi/king.cpp b/src/variants/shogi/king.cpp deleted file mode 100644 index 8a6da22..0000000 --- a/src/variants/shogi/king.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#include "king.h" -#include - -namespace Shogi { - -King::King() { } - -QString King::name() const { return "king"; } - -bool King::canMove(const Piece& piece, const Piece&, - Move& move, const IState* state) const { - if (abs(move.delta().x) <= 1 && abs(move.delta().y) <= 1) return true; - return false; -} - -int King::index() const { return 10000; } - -King* King::self() { - static King s_instance; - return &s_instance; -} - -} diff --git a/src/variants/shogi/king.h b/src/variants/shogi/king.h deleted file mode 100644 index 9059f9d..0000000 --- a/src/variants/shogi/king.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__TYPES__KING_H -#define SHOGI__TYPES__KING_H - -#include -#include - -namespace Shogi { - -class TAGUA_EXPORT King : public Component, public IType { -Q_OBJECT - King(); -public: - virtual QString name() const; - virtual bool canMove(const Piece& piece, const Piece& target, - Move& move, const IState* state) const; - virtual int index() const; - static King* self(); -}; - -} - -#endif // SHOGI__TYPES__KING_H diff --git a/src/variants/shogi/knight.cpp b/src/variants/shogi/knight.cpp deleted file mode 100644 index 3a4a6b8..0000000 --- a/src/variants/shogi/knight.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#include "knight.h" -#include -#include -#include -#include -#include - -namespace Shogi { - -Knight::Knight() { } - -QString Knight::name() const { return "knight"; } - -bool Knight::canMove(const Piece& piece, const Piece&, - Move& move, const IState* state) const { - const IBehaviour* behaviour = state->behaviour(); - if (!behaviour) return false; - return abs(move.delta().x) == 1 && - move.delta().y == behaviour->direction(piece.color()).y * 2; -} - -int Knight::index() const { return 30; } - -Knight* Knight::self() { - static Knight s_instance; - return &s_instance; -} - -} diff --git a/src/variants/shogi/knight.h b/src/variants/shogi/knight.h deleted file mode 100644 index 3167d08..0000000 --- a/src/variants/shogi/knight.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__TYPES__KNIGHT_H -#define SHOGI__TYPES__KNIGHT_H - -#include -#include - -namespace Shogi { - -class TAGUA_EXPORT Knight : public Component, public IType { -Q_OBJECT - Knight(); -public: - virtual QString name() const; - virtual bool canMove(const Piece& piece, const Piece& target, - Move& move, const IState* state) const; - virtual int index() const; - static Knight* self(); -}; - -} - -#endif // SHOGI__TYPES__KNIGHT_H diff --git a/src/variants/shogi/lance.cpp b/src/variants/shogi/lance.cpp deleted file mode 100644 index 7a99430..0000000 --- a/src/variants/shogi/lance.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#include "lance.h" -#include -#include -#include -#include -#include - -namespace Shogi { - -Lance::Lance() { } - -QString Lance::name() const { return "lance"; } - -bool Lance::canMove(const Piece& piece, const Piece&, - Move& move, const IState* state) const { - const IBehaviour* behaviour = state->behaviour(); - if (!behaviour) return false; - PathInfo path = state->board()->path(move.src(), move.dst()); - return move.delta().x == 0 && - path.clear() && - (move.delta().y * behaviour->direction(piece.color()).y > 0); -} - -int Lance::index() const { return 10000; } - -Lance* Lance::self() { - static Lance s_instance; - return &s_instance; -} - -} diff --git a/src/variants/shogi/lance.h b/src/variants/shogi/lance.h deleted file mode 100644 index 9f9d249..0000000 --- a/src/variants/shogi/lance.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__TYPES__LANCE_H -#define SHOGI__TYPES__LANCE_H - -#include -#include - -namespace Shogi { - -class ICastlingRules; - -class TAGUA_EXPORT Lance : public Component, public IType { -Q_OBJECT - Lance(); -public: - virtual QString name() const; - virtual bool canMove(const Piece& piece, const Piece& target, - Move& move, const IState* state) const; - virtual int index() const; - static Lance* self(); -}; - -} - -#endif // SHOGI__TYPES__LANCE_H diff --git a/src/variants/shogi/moveserializer.cpp b/src/variants/shogi/moveserializer.cpp deleted file mode 100644 index fb6e17c..0000000 --- a/src/variants/shogi/moveserializer.cpp +++ /dev/null @@ -1,43 +0,0 @@ - -#include "moveserializer.h" - -#include -#include - -namespace Shogi { - -MoveSerializer::MoveSerializer(const QString& rep, IValidator* validator) - : Chess::MoveSerializer(rep, validator) { } - -QString MoveSerializer::serialize(const Move& move, const IState* ref) const { - if (m_rep == "simple") { - int ysize = ref->board()->size().y; - QString res = move.src().toString(ysize) + move.dst().toString(ysize); - if (move.promotion()) - res = res + "=" + - symbol( - move.promotion() - ).toUpper(); - return res; - } - else if (m_rep == "compact") { - return san(move, ref); - } - else if (m_rep == "decorated") { - QString res = san(move, ref); - res.replace('K', "{king}"); - res.replace('G', "{gold}"); - res.replace('S', "{silver}"); - res.replace('N', "{knight}"); - res.replace('L', "{lance}"); - res.replace('B', "{bishop}"); - res.replace('R', "{rook}"); - res.replace('P', "{pawn}"); - return res; - } - else { - return ""; - } -} - -} // namespace Shogi diff --git a/src/variants/shogi/moveserializer.h b/src/variants/shogi/moveserializer.h deleted file mode 100644 index 43f46e6..0000000 --- a/src/variants/shogi/moveserializer.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SHOGI__MOVESERIALIZER_H -#define SHOGI__MOVESERIALIZER_H - -#include "../chess/moveserializer.h" - -namespace Shogi { -class TAGUA_EXPORT MoveSerializer : public Chess::MoveSerializer { -public: - MoveSerializer(const QString& rep, IValidator* validator); - virtual QString serialize(const Move& move, const IState* ref) const; -}; - -} // namespace Shogi - -#endif // SHOGI__MOVESERIALIZER_H - diff --git a/src/variants/shogi/pawn.cpp b/src/variants/shogi/pawn.cpp deleted file mode 100644 index 5c3776b..0000000 --- a/src/variants/shogi/pawn.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#include "pawn.h" -#include -#include -#include -#include -#include -#include - -namespace Shogi { - -Pawn::Pawn() { } - -QString Pawn::name() const { return "pawn"; } - -bool Pawn::canMove(const Piece& piece, const Piece&, - Move& move, const IState* state) const { - const IBehaviour* behaviour = state->behaviour(); - if (!behaviour) return false; - - return move.delta() == behaviour->direction(piece.color()); -} - -int Pawn::index() const { return 10; } - -Pawn* Pawn::self() { - static Pawn s_instance; - return &s_instance; -} - -} diff --git a/src/variants/shogi/pawn.h b/src/variants/shogi/pawn.h deleted file mode 100644 index 9304103..0000000 --- a/src/variants/shogi/pawn.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__TYPES__PAWN_H -#define SHOGI__TYPES__PAWN_H - -#include -#include - -namespace Shogi { - -class TAGUA_EXPORT Pawn : public Component, public IType { -Q_OBJECT - Pawn(); -public: - virtual QString name() const; - virtual bool canMove(const Piece& piece, const Piece& target, - Move& move, const IState* state) const; - virtual int index() const; - static Pawn* self(); -}; - -} - -#endif // SHOGI__TYPES__PAWN_H diff --git a/src/variants/shogi/rook.cpp b/src/variants/shogi/rook.cpp deleted file mode 100644 index c0ec689..0000000 --- a/src/variants/shogi/rook.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#include "rook.h" -#include -#include -#include -#include - -namespace Shogi { - -Rook::Rook() { } - -QString Rook::name() const { return "rook"; } - -bool Rook::canMove(const Piece& piece, const Piece& target, - Move& move, const IState* state) const { - PathInfo path = state->board()->path(move.src(), move.dst()); - return path.parallel() && path.clear() && target.color() != piece.color(); -} - -int Rook::index() const { return 50; } - -Rook* Rook::self() { - static Rook s_instance; - return &s_instance; -} - -} diff --git a/src/variants/shogi/rook.h b/src/variants/shogi/rook.h deleted file mode 100644 index 1d978f3..0000000 --- a/src/variants/shogi/rook.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__TYPES__ROOK_H -#define SHOGI__TYPES__ROOK_H - -#include -#include - -namespace Shogi { - -class TAGUA_EXPORT Rook : public Component, public IType { -Q_OBJECT - Rook(); -public: - virtual QString name() const; - virtual bool canMove(const Piece& piece, const Piece& target, - Move& move, const IState* state) const; - virtual int index() const; - static Rook* self(); -}; - -} - -#endif // SHOGI__TYPES__ROOK_H diff --git a/src/variants/shogi/shogi.cpp b/src/variants/shogi/shogi.cpp deleted file mode 100644 index 0097040..0000000 --- a/src/variants/shogi/shogi.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include - -#include "behaviour.h" -#include "colors.h" -#include "moveserializer.h" -#include "types.h" -#include "state.h" -#include "validator.h" - -using namespace Shogi; - -extern "C" KDE_EXPORT Repository* -taguashogi_initrepo(IVariantLoader* loader) { - Repository* repo = new Repository; - Repository* chess = loader->getRepository("chess"); - if (!chess) - // bail out if there is no chess variant - return 0; -#if 0 - Repository* crazyhouse = loader->getRepository("crazyhouse"); - if (!crazyhouse) - // bail out if there is no crazyhouse variant - return 0; -#endif - - repo->addComponent("player/0", dynamic_cast(COLORS[0])); - repo->addComponent("player/1", dynamic_cast(COLORS[1])); - - repo->addComponent("type/king", King::self()); - repo->addComponent("type/gold", Gold::self()); - repo->addComponent("type/silver", Silver::self()); - repo->addComponent("type/knight", Knight::self()); - repo->addComponent("type/lance", Lance::self()); - repo->addComponent("type/rook", Rook::self()); - repo->addComponent("type/bishop", Bishop::self()); - repo->addComponent("type/pawn", Pawn::self()); - -#if 0 - // create crazyhouse behaviour - IState* crazyhouse_state = requestInterface(crazyhouse->getComponent("state")); - repo->addComponent("state", new State(crazyhouse_state->behaviour(), Point(9, 9))); -#else - IState* chess_state = requestInterface(chess->getComponent("state")); - repo->addComponent("state", new State(new Behaviour(chess_state->behaviour()), Point(9, 9))); -#endif - - Validator* validator = new Validator; - repo->addComponent("validator", validator); - repo->addComponent("animator_factory", chess->getComponent("animator_factory")); - repo->addComponent("namer", chess->getComponent("namer")); - repo->addComponent("policy", chess->getComponent("policy")); - - repo->addComponent("move_serializer/simple", - new MoveSerializer("simple", validator)); - repo->addComponent("move_serializer/decorated", - new MoveSerializer("decorated", validator)); - MoveSerializer* san = new MoveSerializer("compact", validator); - repo->addComponent("move_serializer/san", san); - repo->addComponent("move_serializer/compact", san); - - return repo; -} - diff --git a/src/variants/shogi/silver.cpp b/src/variants/shogi/silver.cpp deleted file mode 100644 index 8b3a99b..0000000 --- a/src/variants/shogi/silver.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#include "silver.h" -#include -#include -#include - -namespace Shogi { - -Silver::Silver() { } - -QString Silver::name() const { return "silver"; } - -bool Silver::canMove(const Piece& piece, const Piece&, - Move& move, const IState* state) const { - const IBehaviour* behaviour = state->behaviour(); - if (!behaviour) return false; - return (abs(move.delta().x) == abs(move.delta().y) && abs(move.delta().x) == 1) - || (move.delta().y == behaviour->direction(piece.color()).y && abs(move.delta().x) <= 1); -} - -int Silver::index() const { return 10000; } - -Silver* Silver::self() { - static Silver s_instance; - return &s_instance; -} - -} diff --git a/src/variants/shogi/silver.h b/src/variants/shogi/silver.h deleted file mode 100644 index 3d3dd3a..0000000 --- a/src/variants/shogi/silver.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__TYPES__SILVER_H -#define SHOGI__TYPES__SILVER_H - -#include -#include - -namespace Shogi { - -class ICastlingRules; - -class TAGUA_EXPORT Silver : public Component, public IType { -Q_OBJECT - Silver(); -public: - virtual QString name() const; - virtual bool canMove(const Piece& piece, const Piece& target, - Move& move, const IState* state) const; - virtual int index() const; - static Silver* self(); -}; - -} - -#endif // SHOGI__TYPES__SILVER_H diff --git a/src/variants/shogi/state.cpp b/src/variants/shogi/state.cpp deleted file mode 100644 index d910f22..0000000 --- a/src/variants/shogi/state.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#include "state.h" - -#include -#include -#include -#include - -#include "colors.h" -#include "types.h" - -namespace Shogi { - -State::State(const IBehaviour* behaviour, - const Point& size) -: m_board(size) -, m_behaviour(behaviour) -, m_delegator(this) { - DefaultPoolCollection* c = new DefaultPoolCollection; - for (int i = 0; i < 2; i++) - c->addPool(COLORS[i], new DefaultPool(COLORS[i])); - m_pools = c; -} - -State::State(const State& other) -: Component() -, IState() -, m_board(other.m_board) -, m_flags(other.m_flags) -, m_turn(other.m_turn) -, m_behaviour(other.m_behaviour) -, m_pools(other.m_pools) -, m_delegator(this) { } - -State::~State() { delete m_pools; } - -IState* State::clone() const { - State* s = new State(*this); - s->m_pools = m_pools->clone(); - return s; -} - -#define COL(i, c) c == Black::self() ? (i) : (m_board.size().x - i - 1) -void State::setup() { - for (int c = 0; c < 2; c++) { - IColor* color = COLORS[c]; - int r0 = rank(0, color); - int r1 = rank(1, color); - int r2 = rank(2, color); - - for (int i = 0; i < m_board.size().x; i++) { - m_board.set(Point(i, r2), Piece(color, Pawn::self())); - } - m_board.set(Point(0, r0), Piece(color, Lance::self())); - m_board.set(Point(1, r0), Piece(color, Knight::self())); - m_board.set(Point(2, r0), Piece(color, Silver::self())); - m_board.set(Point(3, r0), Piece(color, Gold::self())); - m_board.set(Point(4, r0), Piece(color, King::self())); - m_board.set(Point(5, r0), Piece(color, Gold::self())); - m_board.set(Point(6, r0), Piece(color, Silver::self())); - m_board.set(Point(7, r0), Piece(color, Knight::self())); - m_board.set(Point(8, r0), Piece(color, Lance::self())); - - m_board.set(Point(COL(1, color), r1), Piece(color, Bishop::self())); - m_board.set(Point(COL(7, color), r1), Piece(color, Rook::self())); - } - - m_turn = White::self(); -} -#undef COL - -const Board* State::board() const { - return &m_board; -} - -Board* State::board() { - return &m_board; -} - -const IColor* State::turn() const { - return m_turn; -} - -void State::setTurn(const IColor* turn) { - m_turn = turn; -} - -bool State::equals(IState* other) const { - return m_board.equals(other->board()) && - m_turn == other->turn() && - m_flags == *other->flags(); -} - -void State::assign(const IState* other) { - m_board = *other->board(); - m_turn = other->turn(); - m_flags = *other->flags(); - - const IPoolCollection* pools = other->pools(); - if (pools) { - delete m_pools; - m_pools = pools->clone(); - } -} - -void State::move(const Move& m) { - if (m.drop() != Piece()) { - const Piece* captured = board()->get(m.dst()); - board()->set(m.dst(), m.drop()); - pools()->pool(m.drop().color())->take(m.drop()); - -#if 0 - // handle capturing by drop: some variants could use it - if (captured != NULL && *captured != Piece()) { - if (captured->get("promoted").toBool()) { - captured->setType(pawn); - } - pools()->pool(behaviour()->opponent(captured->color())) - ->insert(-1, *captured); - } -#endif - } else { - const Piece* piece = m_board.get(m.src()); - if (piece == NULL || *piece == Piece()) return; - - Point captureSquare = behaviour()->captureSquare(this, m); - behaviour()->captureOn(m_delegator, captureSquare); - behaviour()->move(m_delegator, m); - - const IType* promotion_type = m.promotion(); - - if (promotion_type != 0) { - m_board.set(m.dst(), Piece(piece->color(), promotion_type)); - } - } - - behaviour()->advanceTurn(m_delegator); -} - -const TaguaObject* State::flags() const { return &m_flags; } -TaguaObject* State::flags() { return &m_flags; } - -int State::rank(int n, const IColor* turn) const { - if (turn == White::self()) - return m_board.size().y - n - 1; - else - return n; -} - -IPoolCollection* State::pools() { return m_pools; } -const IPoolCollection* State::pools() const { return m_pools; } - -const IBehaviour* State::behaviour() const { return m_behaviour; } - -void State::setDelegator(IState* delegator) { m_delegator = delegator; } - -Component* State::clone(const IBehaviour* behaviour, - const Point& size) const { - return new State(behaviour, size); -} - -} // namespace Shogi diff --git a/src/variants/shogi/state.h b/src/variants/shogi/state.h deleted file mode 100644 index 8a46912..0000000 --- a/src/variants/shogi/state.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__STATE_H -#define SHOGI__STATE_H - -#include -#include -#include -#include -#include - -namespace Shogi { - -class State : public Component, public IState { -Q_OBJECT - Board m_board; - TaguaObject m_flags; - const IColor* m_turn; - const IBehaviour* m_behaviour; - IState* m_delegator; - IPoolCollection* m_pools; -protected: - State(const State&); -public: - State(const IBehaviour* behaviour, - const Point& size); - virtual ~State(); -public: - virtual IState* clone() const; - - virtual void setup(); - - virtual const Board* board() const; - virtual Board* board(); - - virtual const IColor* turn() const; - - virtual void setTurn(const IColor* turn); - - virtual bool equals(IState* other) const; - - virtual void assign(const IState* other); - - virtual void move(const Move& move); - - virtual TaguaObject* flags(); - virtual const TaguaObject* flags() const; - - virtual int rank(int n, const IColor* turn) const; - - virtual const IPoolCollection* pools() const; - virtual IPoolCollection* pools(); - - virtual const IBehaviour* behaviour() const; - - virtual void setDelegator(IState* delegator); -public Q_SLOTS: - virtual Component* clone(const IBehaviour* behaviour, - const Point& size) const; -}; - -} // namespace Shogi - -#endif // SHOGI__STATE_H - diff --git a/src/variants/shogi/tagua-shogi.desktop b/src/variants/shogi/tagua-shogi.desktop deleted file mode 100644 index 6d61ae8..0000000 --- a/src/variants/shogi/tagua-shogi.desktop +++ /dev/null @@ -1,20 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Name=Shogi -Comment=The Game of Shogi (Japanese Chess) -Icon=tagua -Type=Service -ServiceTypes=Tagua/Variant - -X-KDE-Library=taguashogi -X-KDE-PluginInfo-Author=Paolo Capriotti -X-KDE-PluginInfo-Email=p.capriotti@gmail.com -X-KDE-PluginInfo-Name=shogi -X-KDE-PluginInfo-Version=0.5.1 -X-KDE-PluginInfo-Website=http://www.tagua-project.org -X-KDE-PluginInfo-Depends= -X-KDE-PluginInfo-License=GPL -X-KDE-PluginInfo-EnabledByDefault=true - -X-Tagua-Proxy=Shogi -X-Tagua-Hidden=false diff --git a/src/variants/shogi/types.h b/src/variants/shogi/types.h deleted file mode 100644 index 8b05033..0000000 --- a/src/variants/shogi/types.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__TYPES_H -#define SHOGI__TYPES_H - -// include all shogi types -#include "king.h" -#include "gold.h" -#include "silver.h" -#include "knight.h" -#include "lance.h" -#include "rook.h" -#include "bishop.h" -#include "pawn.h" - -#endif // SHOGI__TYPES_H diff --git a/src/variants/shogi/validator.cpp b/src/variants/shogi/validator.cpp deleted file mode 100644 index bee9171..0000000 --- a/src/variants/shogi/validator.cpp +++ /dev/null @@ -1,159 +0,0 @@ -#include "validator.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "colors.h" -#include "types.h" - -namespace Shogi { - -Validator::Validator() : m_delegator(this) { } - -bool Validator::pseudolegal(const IState* state, Move& move) const { - // add drop information to move, if missing - if (move.drop() == Piece() && - move.pool() && move.index() != -1) { - move.setDrop(state->pools()->pool(move.pool())->get(move.index())); - } - - Piece dropped = move.drop(); - if (dropped == Piece()) { - if (!state->board()->valid(move.src())) return false; - if (!state->board()->valid(move.dst())) return false; - - const Piece* piece = state->board()->get(move.src()); - if (piece == NULL || *piece == Piece()) return false; - - const IBehaviour* behaviour = state->behaviour(); - if (!behaviour) return false; - - const IColor* thisTurn = piece->color(); - if (state->turn() != thisTurn) return false; - - const Piece* target = state->board()->get(move.dst()); - if (target->color() == piece->color()) - return false; - if (!piece->type()->canMove(*piece, *target, move, state)) - return false; - -#if 0 - if (move.type() == "promotion") { - const IType* promotionType = move.promotion(); - if (promotionType != Queen::self() && - promotionType != Bishop::self() && - promotionType != Rook::self() && - promotionType != Knight::self()) return false; - } -#endif - } else { - // dropping on a valid square - if (!state->board()->valid(move.dst())) - return false; - - // cannot drop on occupied squares - if (state->board()->get(move.dst()) != NULL && - *state->board()->get(move.dst()) != Piece()) - return false; - - // cannot drop on a place where piece would be stuck - if (stuckPiece(state, dropped, move.dst())) - return false; - - // cannot drop a pawn in a column with already a pawn of same color - if (dropped.type() == Pawn::self()) { - for (int i = 0; i < state->board()->size().y; i++) { - const Piece* other = state->board()->get(Point(move.dst().x, i)); - if (other->type() == Pawn::self() && - other->color() == state->turn() && - !other->get("promoted").toBool()) - return false; - } - } - } - - return true; -} - -bool Validator::legal(const IState* state, Move& move) const { - // do not check a move more than once - if (!move.type().isEmpty()) return true; - - if (!m_delegator->pseudolegal(state, move)) - return false; - - const IBehaviour* behaviour = state->behaviour(); - if (!behaviour) return false; - - const IColor* turn = m_delegator->mover(state, move); - - std::auto_ptr tmp(state->clone()); - tmp->move(move); - - Point kingPos = tmp->board()->find(Piece(turn, King::self())); - - if (kingPos == Point::invalid()) - return false; - - if (m_delegator->attacks(tmp.get(), behaviour->opponent(turn), kingPos)) - return false; - - // set move type as normal, if not already set - if (move.type().isEmpty()) move.setType("normal"); - return true; -} - -// FIXME: move this logic into Piece classes ? -bool Validator::stuckPiece(const IState* state, - const Piece& piece, const Point& p) const { - const IBehaviour* behaviour = state->behaviour(); - - if (piece.type() == Pawn::self() || piece.type() == Lance::self()) { - return p.y == state->rank(0, behaviour->opponent(piece.color())); - } - else if (piece.type() == Knight::self()) { - int rank = state->rank(0, behaviour->opponent(piece.color())); - return p.y == rank || p.y == rank - behaviour->direction(piece.color()).y; - } - else { - return false; - } -} - -bool Validator::attacks(const IState* state, const IColor* player, - const Point& square, const Piece& target_) const { - const Piece* target; - if (target_ != Piece()) - target = &target_; - else - target = state->board()->get(square); - - for (int i = 0; i < state->board()->size().x; i++) { - for (int j = 0; j < state->board()->size().y; j++) { - Point p(i, j); - const Piece* piece = state->board()->get(p); - Move move(p, square); - if (piece != NULL && - *piece != Piece() && - piece->color() == player && - piece->type()->canMove(*piece, *target, move, state)) - return true; - } - } - return false; -} - -const IColor* Validator::mover(const IState* state, const Move& move) const { - return state->board()->get(move.src())->color(); -} - -void Validator::setDelegator(IValidator* delegator) { - m_delegator = delegator; -} - -} - diff --git a/src/variants/shogi/validator.h b/src/variants/shogi/validator.h deleted file mode 100644 index 6281cd8..0000000 --- a/src/variants/shogi/validator.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright (c) 2007 Paolo Capriotti - (c) 2007 Maurizio Monge - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef SHOGI__VALIDATOR_H -#define SHOGI__VALIDATOR_H - -#include -#include - -namespace Shogi { - -class Validator : public Component, public IValidator { -Q_OBJECT - IValidator* m_delegator; -protected: - virtual bool stuckPiece(const IState* state, - const Piece& piece, const Point& p) const; -public: - Validator(); - - virtual bool pseudolegal(const IState* state, Move& move) const; - - virtual bool legal(const IState* state, Move& move) const; - - virtual bool attacks(const IState* state, const IColor* player, - const Point& square, const Piece& target = Piece()) const; - - virtual const IColor* mover(const IState* state, const Move& move) const; - - virtual void setDelegator(IValidator* validator); -}; - -} - -#endif // SHOGI__VALIDATOR_H - -- 2.11.4.GIT