コード例 #1
0
        public async Task VisualizerTest3BasicUndo()
        {
            ChessLogic              logic      = new ChessLogic();
            MovePlanner             planner    = new MovePlanner(logic.Board);
            MovePerformerVisualizer visualizer = new MovePerformerVisualizer();
            MoveManager             manager    = new MoveManager(planner, visualizer);

            visualizer.ResetBoardRep();
            visualizer.PrintBoardRep();

            List <Position[]> moves = new List <Position[]>();

            Position[] move1 = new Position[2];
            move1[0] = new Position("E", "2");
            move1[1] = new Position("E", "4");
            moves.Add(move1);
            Position[] move2 = new Position[2];
            move2[0] = new Position("D", "7");
            move2[1] = new Position("D", "5");
            moves.Add(move2);
            Position[] move3 = new Position[2];
            move3[0] = new Position("G", "1");
            move3[1] = new Position("F", "3");
            moves.Add(move3);
            Position[] move4 = new Position[2];
            move4[0] = new Position("C", "8");
            move4[1] = new Position("E", "6");
            moves.Add(move4);
            Position[] move5 = new Position[2];
            move5[0] = new Position("F", "1");
            move5[1] = new Position("C", "4");
            moves.Add(move5);
            Position[] move6 = new Position[2];
            move6[0] = new Position("B", "8");
            move6[1] = new Position("C", "6");
            moves.Add(move6);
            Position[] move7 = new Position[2];
            move7[0] = new Position("E", "1");
            move7[1] = new Position("E", "2");
            moves.Add(move7);
            Position[] move8 = new Position[2];
            move8[0] = new Position("D", "5");
            move8[1] = new Position("E", "4");
            moves.Add(move8);
            Position[] move9 = new Position[2];
            move9[0] = new Position("C", "4");
            move9[1] = new Position("E", "6");
            moves.Add(move9);
            Position[] move10 = new Position[2];
            move10[0] = new Position("E", "4");
            move10[1] = new Position("F", "3");
            moves.Add(move10);
            Position[] move11 = new Position[2];
            move11[0] = new Position("A", "2");
            move11[1] = new Position("A", "3");
            moves.Add(move11);
            Position[] move12 = new Position[2];
            move12[0] = new Position("F", "7");
            move12[1] = new Position("E", "6");
            moves.Add(move12);
            Position[] move13 = new Position[2];
            move13[0] = new Position("E", "2");
            move13[1] = new Position("F", "3");
            moves.Add(move13);

            System.Diagnostics.Debug.WriteLine(logic.Board.ToString());

            foreach (var movement in moves)
            {
                System.Diagnostics.Debug.WriteLine(movement[0].ToString() + "\t" + movement[1].ToString());
                Assert.AreEqual(logic.IsMoveValid(movement[0], movement[1]), true);
                await manager.MoveAsync(movement[0], movement[1]);

                logic.MovePiece(movement[0], movement[1]);
                System.Diagnostics.Debug.WriteLine(logic.Board.ToString());
            }

            System.Diagnostics.Debug.WriteLine("Black castles kingside.");
            var rookLocationForBlackCastle = logic.validRookLocationsForCastling();

            Assert.AreEqual(rookLocationForBlackCastle.Count, 1);
            await manager.CastleAsync(rookLocationForBlackCastle[0], logic.Board.GetKingCol());

            logic.Castle(rookLocationForBlackCastle[0]);
            System.Diagnostics.Debug.WriteLine(logic.Board.ToString());

            System.Diagnostics.Debug.WriteLine("White castles queenside.");
            var rookLocationForWhiteCastle = logic.validRookLocationsForCastling();

            Assert.AreEqual(rookLocationForWhiteCastle.Count, 1);
            await manager.CastleAsync(rookLocationForWhiteCastle[0], logic.Board.GetKingCol());

            logic.Castle(rookLocationForWhiteCastle[0]);
            System.Diagnostics.Debug.WriteLine(logic.Board.ToString());

            for (int i = 0; i < moves.Count + 2; i++)                   //+2 for the two castles
            {
                await manager.UndoMoveAsync();

                logic.UndoMove();
                System.Diagnostics.Debug.WriteLine(logic.Board.ToString());
            }
        }