Algorithm to detect no movable pieces in Stratego.
Posted
by maleki
on Stack Overflow
See other posts from Stack Overflow
or by maleki
Published on 2010-04-06T22:05:04Z
Indexed on
2010/04/06
22:23 UTC
Read the original article
Hit count: 498
I am creating a Stratego Game and am having trouble creating an algorithm that can detect when there are no more possible moves because all your pieces are gone or the remaining pieces are unmovable or trapped by forbidden squares, unmovable pieces, or other trapped pieces.
For simplicity you can think of the board as an array of Squares which can contain pieces.
Square[][] gameBoard = new Square[10][10]
Squares have easily checkable state such as hasPiece(), hasEnemyPiece(), hasUnMovablePiece(), hasMoveablePiece(), isBlocked().
It would also probably be nice if this algorithm wasn't run every time a player moved but maybe checked in the beginning and then only certain conditions were checked when the player moved.
© Stack Overflow or respective owner