Exemplo n.º 1
0
 public void TestBlackPawnGetMoves()
 {
     var target = new Pawn(false, "Bd2");
     var board = new Board();
     var tempList = new List<String> {"Cd2", "Bd3"};
     Assert.AreEqual(tempList, target.GetMoves(board));
 }
Exemplo n.º 2
0
        public BoardViewer()
        {
            InitializeComponent();
            _board = new Board();
            _board.NewGame();
            moveWhite = true;
            UpdateBoard();
            lblPlayer1.BackColor = Color.Goldenrod;
            this.menuStrip1.ForeColor = Color.White;

            rm = new ResourceManager("RaumschachForm.Properties.EnglishResources", typeof(BoardViewer).Assembly);

            //Text
            this.quitToolStripMenuItem.Text = rm.GetString("Quit");
            this.fileToolStripMenuItem.Text = rm.GetString("File");
            this.lblPlayer1.Text = rm.GetString("Player1");
            this.lblPlayer2.Text = rm.GetString("Player2");
            this.newGameToolStripMenuItem.Text = rm.GetString("NewGame");
            this.button1.Text = rm.GetString("NewGame");
            this.languageToolStripMenuItem.Text = rm.GetString("Language");
            this.button2.Text = rm.GetString("Checkmate");
            //

            bworker = new BackgroundWorker();
            bworker2 = new BackgroundWorker();
            bworker.DoWork += new DoWorkEventHandler(checkForCheck);
            bworker.DoWork += new DoWorkEventHandler(UpdateMoves);
            bworker2.RunWorkerAsync();
            bworker.RunWorkerAsync();
        }
Exemplo n.º 3
0
        public override List<string> GetBasicMoves(Board board)
        {
            var boardNum = board.GetBoardNumber(CurrentPos);
            var rowNum = board.GetCellRow(CurrentPos);
            var colNum = board.GetCellCol(CurrentPos);
            var moves = new List<String>();

            var directions = White ? _WhiteDirections : _BlackDirections;
            for (var i = 0; i < (directions.Length) / 2; i++)
            {
                var currentCell = board.GetNeighborCell(board.GetCell(CurrentPos), directions[i, 0]);
                if (directions[i, 0] != directions[i, 1])
                {
                    currentCell = board.GetNeighborCell(currentCell, directions[i, 1]);
                    if (currentCell != null && currentCell.HasPiece() && currentCell.GetPiece().White != this.White)
                    {
                        moves.Add(currentCell.GetName());
                    }
                }
                else
                {
                    if (currentCell != null && !currentCell.HasPiece())
                    {
                        moves.Add(currentCell.GetName());
                    }
                }
            }
            return moves;
        }
Exemplo n.º 4
0
        public override List<string> GetMoves(Board board)
        {
            if (movesSet) return movesList;
            var moves = GetBasicMoves(board);
            return validMoves(moves, board);

        }
Exemplo n.º 5
0
 public void TestPieceGetMoves()
 {
     var target = new King(true, "Cc3");
        var board = new Board();
        var tempList = new List<String> { "Cc4", "Bc4", "Dc4", "Cc2", "Bc2", "Dc2", "Cb3", "Bb3", "Db3", "Cd3", "Bd3", "Dd3", "Bc3", "Dc3", "Cd4", "Bd4", "Dd4", "Cb4", "Bb4", "Db4", "Cd2", "Bd2", "Dd2", "Cb2", "Bb2", "Db2" };
     Assert.AreEqual(tempList, target.GetMoves(board));
 }
Exemplo n.º 6
0
        public override List<string> GetMoves(Board board)
        {
           

            return validMoves(this.GetBasicMoves(board),board);

        }
Exemplo n.º 7
0
        public List<string> validMoves(List<string> possibleMoves, Board board)
        {
            if (possibleMoves.Count() == 0) return possibleMoves;
            List<string> finalmoves = new List<string>();
            string origin=this.CurrentPos;

            foreach (var mv in possibleMoves)
            {
                board.MovePiece(this.CurrentPos, mv);
                if (White)
                {
                    if (!board.wCheck())
                    {
                        finalmoves.Add(mv);
                    }
                }
                else
                {
                    if (!board.bCheck())
                    {
                        finalmoves.Add(mv);
                    }

                }
                board.GetCell(origin).RestorePreviousPiece(board);
                board.GetCell(mv).RestorePreviousPiece(board);

            }

            return finalmoves;
        }
Exemplo n.º 8
0
        public override List<string> GetBasicMoves(Board board)
        {
            var moves = new List<string>();

            foreach (var mainDirc in smallList)
            {

                for (var i = 0; i < (_directions.Length) / 2; i++)
                {
                    var currentCell = board.GetNeighborCell(board.GetCell(CurrentPos), mainDirc);
                    currentCell = board.GetNeighborCell(currentCell, _directions[i, 0]);
                    currentCell = board.GetNeighborCell(currentCell, _directions[i, 1]);

                    while (currentCell != null &&
                           (currentCell.GetPiece() == null || currentCell.GetPiece().White != White))
                    {
                        moves.Add(currentCell.GetName());
                        if (currentCell.HasPiece()) break;
                        currentCell = board.GetNeighborCell(currentCell, mainDirc);
                        currentCell = board.GetNeighborCell(currentCell, _directions[i, 0]);
                        currentCell = board.GetNeighborCell(currentCell, _directions[i, 1]);
                    }
                }
            }
            return moves;
        }
Exemplo n.º 9
0
 public void TestBlackPawnTakeForwardRight()
 {
     var target = new Pawn(false, "Bd2");
     var board = new Board();
     board.GetCell("Be3").AddPiece(new Pawn(true, "Be3"));
     var tempList = new List<String> {"Cd2", "Bd3", "Be3"};
     Assert.AreEqual(tempList, target.GetMoves(board));
 }
Exemplo n.º 10
0
 public void SetMoves(Board board)
 {
     movesList = new List<string>();
     movesList.AddRange((new Rook(this.White, this.CurrentPos)).GetMoves(board));
     movesList.AddRange((new Bishop(this.White, this.CurrentPos)).GetMoves(board));
     movesList.AddRange((new Unicorn(this.White, this.CurrentPos)).GetMoves(board));
     movesSet = true;
 }
Exemplo n.º 11
0
        public override List<string> GetBasicMoves(Board board)
        {
            var moves = new List<string>();

            moves.AddRange((new Rook(this.White, this.CurrentPos)).GetBasicMoves(board));
            moves.AddRange((new Bishop(this.White, this.CurrentPos)).GetBasicMoves(board));
            moves.AddRange((new Unicorn(this.White, this.CurrentPos)).GetBasicMoves(board));

            return moves;
        }
Exemplo n.º 12
0
 public void TestPieceGetMovesWithTakeable()
 {
     var target = new King(true, "Cc3");
     var board = new Board();
     board.GetCell("Cb4").AddPiece(new Pawn(false, "Cb4"));
     board.GetCell("Dc4").AddPiece(new Pawn(false, "Dc4"));
     board.GetCell("Cc4").AddPiece(new Pawn(false, "Cc4"));
     board._blackPieces.Add(board.GetCell("Cb4").GetPiece());
     board._blackPieces.Add(board.GetCell("Dc4").GetPiece());
     board._blackPieces.Add(board.GetCell("Cc4").GetPiece());
     var tempList = new List<String> { "Cc4", "Bc4", "Cc2", "Bc2", "Dc2", "Cb3", "Bb3", "Db3", "Cd3", "Bd3", "Dd3", "Bc3", "Dc3", "Cd4", "Bd4", "Cb4", "Bb4", "Cd2", "Bd2", "Dd2", "Cb2", "Bb2", "Db2" };
     Assert.AreEqual(tempList, target.GetMoves(board));
 }
Exemplo n.º 13
0
        public override List<string> GetBasicMoves(Board board)
        {
            var moves = new List<string>();

            foreach (var direction in Enum.GetValues(typeof(Board.CellNeighbor)))
            {
                var currentCell = board.GetNeighborCell(board.GetCell(CurrentPos), (Board.CellNeighbor)direction);

                while (currentCell != null && (currentCell.GetPiece() == null || currentCell.GetPiece().White != White))
                {
                    moves.Add(currentCell.GetName());
                    if (currentCell.HasPiece()) break;
                    currentCell = board.GetNeighborCell(currentCell, (Board.CellNeighbor)direction);
                }
            }
            return moves;
        }
Exemplo n.º 14
0
        public override List<string> GetBasicMoves(Board board)
        {
            var moves = new List<String>();
            foreach (var direction in Enum.GetValues(typeof(Board.CellNeighbor)))
            {
                var currentCell = board.GetNeighborCell(board.GetCell(CurrentPos), (Board.CellNeighbor)direction);
                if (currentCell != null && (!currentCell.HasPiece() || (currentCell.HasPiece() && currentCell.GetPiece().White != this.White)))
                {
                    moves.Add(currentCell.GetName());
                }

                if (!smallList.Contains((Board.CellNeighbor)direction))
                {
                    foreach (var dirc in smallList)
                    {
                        var tempCell = board.GetNeighborCell(currentCell, dirc);
                        if (tempCell != null && (!tempCell.HasPiece() || (tempCell.HasPiece() && tempCell.GetPiece().White != this.White)))
                        {
                            moves.Add(tempCell.GetName());
                        }
                    }
                }
            }

            for (var i = 0; i < (_directions.Length) / 2; i++)
            {
                var currentCell = board.GetNeighborCell(board.GetCell(CurrentPos), _directions[i, 0]);
                currentCell = board.GetNeighborCell(currentCell, _directions[i, 1]);
                if (currentCell != null && (!currentCell.HasPiece() || (currentCell.HasPiece() && currentCell.GetPiece().White != this.White)))
                {
                    moves.Add(currentCell.GetName());
                }

                foreach (var dirc in smallList)
                {
                    var tempCell = board.GetNeighborCell(currentCell, dirc);
                    if (tempCell != null && (!tempCell.HasPiece() || (tempCell.HasPiece() && tempCell.GetPiece().White != this.White)))
                    {
                        moves.Add(tempCell.GetName());
                    }
                }
            }
            return moves;
        }
Exemplo n.º 15
0
        public override List<string> GetBasicMoves(Board board)
        {
            var moves = new List<string>();

            foreach (var mainDirc in Enum.GetValues(typeof(Board.CellNeighbor)))
            {
                var mainCell = board.GetNeighborCell(board.GetCell(CurrentPos), (Board.CellNeighbor)mainDirc);
                if (mainCell == null) continue;
                mainCell = board.GetNeighborCell(mainCell, (Board.CellNeighbor)mainDirc);
                if (mainCell == null) continue;
                foreach(var secondaryDirc in Enum.GetValues(typeof(Board.CellNeighbor)))
                {
                    var checkCell = board.GetNeighborCell(mainCell, (Board.CellNeighbor)secondaryDirc);

                    if (board.IsSameOrOpposite((Board.CellNeighbor)mainDirc, (Board.CellNeighbor)secondaryDirc) ||
                        checkCell == null || (checkCell.GetPiece() != null && checkCell.GetPiece().White == this.White)) continue;
                    moves.Add(checkCell.GetName());

                }
            }

            return moves;
        }
Exemplo n.º 16
0
 public void TestSetup()
 {
     _board = new Board();
 }
Exemplo n.º 17
0
        public object Clone()
        {
            var board = new Board();
            try
            {
                foreach (var p in this._blackPieces)
                {
                    if (p.GetType() == typeof(Pawn)) board._blackPieces.Add(new Pawn(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(King)) board._blackPieces.Add(new King(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(Queen)) board._blackPieces.Add(new Queen(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(Unicorn)) board._blackPieces.Add(new Unicorn(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(Bishop)) board._blackPieces.Add(new Bishop(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(Knight)) board._blackPieces.Add(new Knight(p.White, p.CurrentPos));
                    if (p.GetType() == typeof(Rook)) board._blackPieces.Add(new Rook(p.White, p.CurrentPos));

                }
                foreach (var q in this._whitePieces)
                {
                    if (q.GetType() == typeof(Pawn)) board._whitePieces.Add(new Pawn(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(King)) board._whitePieces.Add(new King(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(Queen)) board._whitePieces.Add(new Queen(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(Unicorn)) board._whitePieces.Add(new Unicorn(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(Bishop)) board._whitePieces.Add(new Bishop(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(Knight)) board._whitePieces.Add(new Knight(q.White, q.CurrentPos));
                    if (q.GetType() == typeof(Rook)) board._whitePieces.Add(new Rook(q.White, q.CurrentPos));
                }
            }
            catch {
                return null;
            }

                board._board = (new Board())._board;

                board._whitePieces.ForEach(e => board.GetCell(e.CurrentPos).AddPiece(e));
                board._blackPieces.ForEach(e => board.GetCell(e.CurrentPos).AddPiece(e));

            board.state = this.state;
            return board;
        }
Exemplo n.º 18
0
 public void SetMoves(Board board)
 {
     movesList = new List<string>();
     movesList = GetBasicMoves(board);
     movesList = IsCheck(movesList, board);
     movesSet = true;
 }
Exemplo n.º 19
0
 private void NewGame_Click(object sender, EventArgs e)
 {
     _board = new Board();
     _board.NewGame();
     UpdateBoard();
     moveWhite = true;
     lblPlayer1.BackColor = Color.Goldenrod;
     lblPlayer2.BackColor = WhitePlayerTaken.BackColor;
     WhitePlayerTaken.Controls.Clear();
     BlackPlayerTaken.Controls.Clear();
     moveNextClick = false;
     if (panelToClear != null)
     {
         currentMoves.Add(panelToClear.Name);
         fixColors(currentMoves);
     }
 }
Exemplo n.º 20
0
        public List<string> IsCheck(List<string> moves, Board board)
        {
            //var pieces = White ? board._blackPieces : board._whitePieces;
            var pieces = new List<Piece>();
            pieces.AddRange(White ? board._blackPieces : board._whitePieces);
            List<Piece> origPieces = new List<Piece>();
            List<Cell> origCells = new List<Cell>();
            foreach (var piece in pieces)
            {
                List<string> piecemoves;
                 piecemoves = piece.GetBasicMoves(board);
                if (piece.GetType() == typeof(Pawn))
                {                    
                    foreach (var mv in moves)
                    {
                        origPieces.Add(board.GetCell(mv).GetPiece());
                        origCells.Add(board.GetCell(mv));
                        board.GetCell(mv).AddPiece(new Pawn(White, mv));
                    }
                    piecemoves.AddRange(piece.GetMoves(board));
                }
               
                foreach (var move in piecemoves)
                {
                    moves.Remove(move);
                }

                for(var i = 0; i< origCells.Count; i++){
                    board.GetCell((origCells[i]).GetName()).AddPiece(origPieces[i]);
                }

            }
            return moves;
        }
Exemplo n.º 21
0
 public abstract List<string> GetMoves(Board board);
Exemplo n.º 22
0
 public override List<string> GetMoves(Board board)
 {
     if ( movesSet) return movesList;
     SetMoves(board);
     return movesList;
 }
Exemplo n.º 23
0
 public void TestPiecegetMoves()
 {
     var target = new Pawn(true, "Ee4");
        var board = new Board();
     var tempList = new List<String> {"De4", "Ee3"};
     Assert.AreEqual(tempList, target.GetMoves(board));
 }
Exemplo n.º 24
0
 public void TestwhitePawnTakeForwardLeft()
 {
     var target = new Pawn(true, "Dc4");
     var board = new Board();
     board.GetCell("Dd3").AddPiece(new Pawn(false, "Dd3"));
     var tempList = new List<String> {"Cc4", "Dc3", "Dd3"};
     Assert.AreEqual(tempList, target.GetMoves(board));
 }
Exemplo n.º 25
0
 public void addInitialPiece()
 {
     target = new Board();
     target.GetCell("Aa1").AddPiece(new Pawn(true,"Aa1"));
     target._whitePieces.Add(target.GetCell("Aa1").GetPiece());
 }