[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: =?utf-8?q?=5Bknights=5D_src=3A_Set_the_Move=3A=3ACheck_flag_in_c?=
From: Miha Čančula <miha.cancula () gmail ! com>
Date: 2011-03-06 20:17:30
Message-ID: 20110306201730.33A5AA60C8 () git ! kde ! org
[Download RAW message or body]
Git commit b8117482d3a6401fdcdcfd51ea3306fe8689d4cb by Miha Čančula.
Committed on 06/03/2011 at 20:21.
Pushed by mihac into branch 'master'.
Set the Move::Check flag in checkSpecialMoves()
M +1 -0 src/gamemanager.cpp
M +21 -0 src/rules/chessrules.cpp
http://commits.kde.org/knights/b8117482d3a6401fdcdcfd51ea3306fe8689d4cb
diff --git a/src/gamemanager.cpp b/src/gamemanager.cpp
index 4195f23..c6dd58b 100644
--- a/src/gamemanager.cpp
+++ b/src/gamemanager.cpp
@@ -602,6 +602,7 @@ void Manager::sendPendingMove()
Protocol::byColor ( oppositeColor ( d->activePlayer ) )->move ( pendingMove );
emit pieceMoved ( pendingMove );
rules()->moveMade ( pendingMove );
+
if ( Settings::speakOpponentsMoves()
&& !Protocol::byColor(d->activePlayer)->isLocal()
&& Protocol::byColor(oppositeColor(d->activePlayer))->isLocal() )
diff --git a/src/rules/chessrules.cpp b/src/rules/chessrules.cpp
index d500377..48cabc9 100644
--- a/src/rules/chessrules.cpp
+++ b/src/rules/chessrules.cpp
@@ -496,6 +496,27 @@ void ChessRules::checkSpecialFlags ( Move* move, Color color )
}
}
}
+
+ /**
+ * Check for check after the move has been made
+ */
+ Grid afterMoveGrid = *m_grid;
+ afterMoveGrid.insert(move->to(), afterMoveGrid.take(move->from()));
+
+ Grid::ConstIterator it = afterMoveGrid.constBegin();
+ Grid::ConstIterator end = afterMoveGrid.constEnd();
+
+ const Color kingColor = oppositeColor ( color );
+
+ for ( ; it != end; ++it )
+ {
+
+ if ( it.value()->color() == color &&
+ legalAttackMoves ( it.key(), &afterMoveGrid ).contains ( Move ( \
it.key(), kingPos[kingColor] ) ) ) + {
+ move->setFlag ( Move::Check, true );
+ }
+ }
if ( move->flag(Move::Take) )
{
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic