Example #1
0
        private PieceSet FindPieces()
        {
            PieceSet pieces = new PieceSet();


            PointSet unsorted = new PointSet();

            for (Int32 x = 0; x < width; x++)
            {
                for (Int32 y = 0; y < height; y++)
                {
                    if (matrix[x, y])
                    {
                        unsorted.Add(new Point(x, y));
                    }
                }
            }

            while (unsorted.Count > 0)
            {
                pieces.Add(CreatePiece(unsorted));
            }

            return(pieces);
        }
Example #2
0
        public bool undoMove(Move m)
        {
            // undo the movement
            m.movingPiece.pos = m.FromCoord;
            this.PiecesLayout[m.ToCoord.X, m.ToCoord.Y]     = m.opponentPiece; // remember, can be null
            this.PiecesLayout[m.FromCoord.X, m.FromCoord.Y] = m.movingPiece;

            // re-hide the pieces if they were just revealed
            if (m.movingPiece.turnRevealed == this.TurnNumber)
            {
                m.movingPiece.turnRevealed = null;
            }

            if (m.opponentPiece.turnRevealed == this.TurnNumber)
            {
                m.opponentPiece.turnRevealed = null;
            }



            // only add the moving piece back into the piece set IF it was removed previously
            if (m.outcome == GameRules.MoveOutcomes.Lose || m.outcome == GameRules.MoveOutcomes.Tie)
            {
                PieceSet.Add(m.movingPiece);
            }

            m.movingPiece.pos = m.FromCoord;
            if (m.opponentPiece != null)
            {
                m.opponentPiece.pos = m.ToCoord;

                // only add the opponent piece back into the piece set IF it was removed previously
                if (m.outcome == GameRules.MoveOutcomes.Win || m.outcome == GameRules.MoveOutcomes.Tie)
                {
                    PieceSet.Add(m.opponentPiece);
                }
            }

            return(true);
        }