// Return a full copy of the current game state.
        public override GameState Copy()
        {
            TzaarGameState state = new TzaarGameState((TzaarBoard)this.Board.Copy());

            state.totalMoveCount = this.totalMoveCount;
            state.gameIsOver = this.gameIsOver;
            state.gameOverCondition = GameOverCondition.None;
            state.winningPlayerNumber = this.winningPlayerNumber;
            state.history = new Stack<string>(this.history);

            return state;
        }
 public TzaarLogic(GameState aState)
 {
     this.boardMap = new TzaarBoardMap();
     this.state = (TzaarGameState)aState;
 }
 public TzaarLogic(GameBoard aBoard)
 {
     this.boardMap = new TzaarBoardMap();
     this.state = new TzaarGameState(aBoard);
 }
 // A game can be constructed without a parameter (empty board), with a
 // premade board, with a premade state, or with the bool value 'true'
 // for a randomly generated board.
 public TzaarLogic()
 {
     this.boardMap = new TzaarBoardMap();
     TzaarBoard board = new TzaarBoard();
     this.state = new TzaarGameState(board);
 }
            // The goal is to verify that a change to the board state in the
            // form of a 'capture' or 'stack' operation results in a correct
            // update to the counts for each piece remaining on the board.
            // Throws Exception if a piece count is inconsistent with the actual
            // game state following the specified operation.
            private static void TestUpdatePieceCount()
            {
                TzaarBoard board = new TzaarBoard(true);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.WHITE), 2, 2);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.BLACK), 2, 3);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.BLACK), 3, 4);
                TzaarGameState state = new TzaarGameState(board);
                TzaarLogic game = new TzaarLogic(state);
                int BlackTzaarCount = ((TzaarBoard)game.GetGameState().Board).BlackTzaarCount;

                game.Move(2, 2, 2, 3);

                // A Black Tzaar was 'captured', so the piece count should be
                // decremented by 1.
                if (BlackTzaarCount - ((TzaarBoard)game.GetGameState().Board).BlackTzaarCount != 1)
                    throw new Exception();
            }
            // Test the components which control functionality to 'stack' pieces
            // on one another. Throws Exception if an attempt to 'stack' pieces
            // results in a stack size not equal to the total number of pieces
            // being 'stacked'.
            private static void TestStack()
            {
                TzaarBoard board = new TzaarBoard(true);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.WHITE), 2, 2);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.WHITE), 2, 3);
                TzaarGameState state = new TzaarGameState(board, 4);
                TzaarLogic game = new TzaarLogic(state);

                game.Move(2, 2, 2, 3);

                Stack<TzaarPiece> S = board.Query(2, 3);

                // Stacked a total of 2 pieces, so stack size should be 2.
                if (S.Count() != 2)
                    throw new Exception();

                // Stacked a Tzaar on top of another Tzaar, so the top piece
                // should be a Tzaar.
                if (S.Peek().GetType() != typeof(TzaarPiece.Tzaar))
                    throw new Exception();

                // Stacked a white piece on top of another white piece, so the
                // top piece should be white.
                if (S.Peek().Color != TzaarColor.WHITE)
                    throw new Exception();
            }
            // Test components controlling the logic for one player to 'capture'
            // the piece of another player. Throws Exception if a valid
            // 'capture' results in an inconsistent game state, if an invalid
            // capture is allowed, or if a player is allowed to move the
            // opposite player's game pieces.
            private static void TestCapture()
            {
                // Test a simple, valid capture.
                TzaarBoard board = new TzaarBoard(true);
                TzaarPiece whitePiece = new TzaarPiece.Tzaar(TzaarColor.WHITE);
                board.Add(whitePiece, 2, 2);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.BLACK), 2, 3);
                TzaarGameState state = new TzaarGameState(board);
                TzaarLogic game = new TzaarLogic(state);

                game.Move(2, 2, 2, 3);

                // The destination position should now contain the white piece
                // which captured the black piece.
                if (board.Query(2, 3).Peek() != whitePiece)
                    throw new Exception();

                // The origin position should no longer contain any pieces.
                if (board.Query(2, 2).Count() != 0)
                    throw new Exception();

                // Test an illegal capture.  The capture is illegal because the
                // stack in the target position is more powerful than the stack
                // at the source.
                board = new TzaarBoard(true);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.WHITE), 2, 2);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.BLACK), 2, 3);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.BLACK), 2, 3);
                state = new TzaarGameState(board);
                game = new TzaarLogic(state);

                bool passedTest = false;
                try
                {
                    game.Move(2, 2, 2, 3);
                }
                catch
                {
                    passedTest = true;
                }
                if (!passedTest)
                {
                    throw new Exception();
                }

                // Now try controlling some of the opponent's pieces. The game
                // should not allow it!
                board = new TzaarBoard(true);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.WHITE), 2, 2);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.BLACK), 2, 3);
                board.Add(new TzaarPiece.Tzaar(TzaarColor.BLACK), 2, 3);
                state = new TzaarGameState(board);
                game = new TzaarLogic(state);

                passedTest = false;
                try
                {
                    game.Move(2, 3, 2, 2);
                }
                catch
                {
                    passedTest = true;
                }
                if (!passedTest)
                {
                    throw new Exception();
                }
            }