Example #1
0
        //public bool MakeMove(Move move)
        //{
        //PieceColor thisColor = move.Piece.Owner;
        //if (!GetLegalMoves(thisColor).Contains(move))
        //    return false;

        //var tempBoard = (move.Piece.Owner == PieceColor.White) ? FlipBoard() : boardState;
        //var opposingColor = Piece.GetOppositeColor(move.Piece.Owner);
        //int rowMove = GetRowMoveAmount(move.Direction);
        //int colMove = GetColMoveAmount(move.Direction);

        //if (TileCanBeJumped(move.Piece.Row + rowMove, move.Piece.Col + colMove, opposingColor, boardState, move.Direction))
        //{
        //    // move piece two times further
        //    // capture opposing piece
        //    // check that piece can't jump again
        //    if (PieceCanJump(move.Piece, opposingColor, boardState))
        //    {
        //        // get move from player to jump
        //    }
        //}
        //else
        //{
        //    // move piece
        //}
        //return true;
        //}

        public List <Move> GetLegalMoves(PieceColor player)
        {
            PieceColor   opposingColor = CheckerPiece.GetOppositeColor(player);
            CheckerBoard boardToCheck  = this;
            var          legalMoves    = new List <Move>();

            for (int i = 0; i < SIZE; i++)
            {
                for (int j = 0; j < SIZE; j++)
                {
                    var piece = boardToCheck.GetPiece(i, j);
                    if ((piece == null) || (piece.Owner == opposingColor))
                    {
                        continue;
                    }
                    var moves = new BoardMoveGenerator(boardToCheck, piece.Row, piece.Col).Moves;
                    legalMoves.AddRange(moves);
                }
            }
            return(legalMoves);
        }
Example #2
0
        private bool IsValidMove(Move move)
        {
            var moveGenerator = new BoardMoveGenerator(_board, move.Piece.Row, move.Piece.Col);

            return(moveGenerator.Moves.Contains(move));
        }