Esempio n. 1
0
        private void getValidMoves()
        {
            ValidMoves.Clear();
            Point start     = new Point();
            Size  direction = new Size();
            bool  nextMove;

            for (start.X = 0; start.X < Board.GetLength(0); ++start.X)
            {
                for (start.Y = 0; start.Y < Board.GetLength(1); ++start.Y)
                {
                    nextMove = (Board[start.X, start.Y] != GameState.player.NONE);
                    for (direction.Width = -1; !nextMove && direction.Width < 2; ++direction.Width)
                    {
                        for (direction.Height = -1; !nextMove && direction.Height < 2; ++direction.Height)
                        {
                            if (direction != new Size(0, 0) && checkDirection(start, direction))
                            {
                                ValidMoves.Add(start);
                                nextMove = true;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /*
         * Gets all valid move for the selected piece and updates the ViewModel
         */
        private void ShowValidMoves(Square FromSquare)
        {
            //var color = Game.CurrentPlayer.Color == ChessColor.Black ? ChessColor.White : ChessColor.Black;
            var color = Game.CurrentPlayer.Color;

            ValidMoves.Clear();
            GetAllValidMoves.AllValidMoves.Clear();
            GetAllValidMoves.GetMoves(Game.ml, FromSquare, color, false);

            for (int i = 0; i < GetAllValidMoves.AllValidMoves.Count; i++)
            {
                ValidMoves.Add(ConvertCordToIndex(GetAllValidMoves.AllValidMoves[i]));
                ChessBoard[ValidMoves[i]].ValidMove = Visibility.Visible;
            }
        }
Esempio n. 3
0
 private void swapTurn()
 {
     Current_player = (GameState.player)getOpponent();
     ValidMoves.Clear();
     getValidMoves();
     if (ValidMoves.Count == 0)
     {
         Current_player = getOpponent();
         ValidMoves.Clear();
         getValidMoves();
         if (ValidMoves.Count == 0)
         {
             Current_player = GameState.player.GAME_OVER;
         }
     }
 }
Esempio n. 4
0
        // Save possible valid moves for the current player
        public void GetValidMoves(Player i_CurrentPlayer)
        {
            ValidMoves.Clear();

            for (int i = 0; i < m_BoardGame.ScreenBoard.GetLength(0); i++)
            {
                for (int j = 0; j < m_BoardGame.ScreenBoard.GetLength(0); j++)
                {
                    if (m_BoardGame.IsValidMove(i_CurrentPlayer, i, j))
                    {
                        string RowToConcat    = (i + 1).ToString();
                        string ColToConcat    = ((char)(j + 'A')).ToString();
                        string ValidMoveToAdd = string.Concat(ColToConcat, RowToConcat);
                        ValidMoves.Add(ValidMoveToAdd);
                    }
                }
            }
        }
Esempio n. 5
0
        public override bool ValidMovement(BoardLogic.ChessCoordinates startLocation, BoardLogic.ChessCoordinates endLocation)
        {
            ValidMoves.Clear();

            int column = FileLogic.GetColumnFromChar(startLocation.Column).GetHashCode();
            int row    = startLocation.Row;

            if (row - 1 >= 0)
            {
                int goingDown = row;
                while (true)
                {
                    if (goingDown - 1 >= 0)
                    {
                        BoardLogic.ChessCoordinates maybeGood = CheckSpaces(Program.board[column, goingDown - 1], startLocation);
                        if (maybeGood == new BoardLogic.ChessCoordinates('0', -1, null))
                        {
                            break;
                        }
                        else
                        {
                            ValidMoves.Add(maybeGood);
                            goingDown = goingDown - 1;
                            if (shouldStop)
                            {
                                shouldStop = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (row + 1 <= 7)
            {
                int goingUp = row;
                while (true)
                {
                    if (goingUp + 1 <= 7)
                    {
                        BoardLogic.ChessCoordinates maybeGood = CheckSpaces(Program.board[column, goingUp + 1], startLocation);
                        if (maybeGood == new BoardLogic.ChessCoordinates('0', -1, null))
                        {
                            break;
                        }
                        else
                        {
                            ValidMoves.Add(maybeGood);
                            goingUp = goingUp + 1;
                            if (shouldStop)
                            {
                                shouldStop = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (column - 1 >= 0)
            {
                int goingLeft = column;
                while (true)
                {
                    if (goingLeft - 1 >= 0)
                    {
                        BoardLogic.ChessCoordinates maybeGood = CheckSpaces(Program.board[goingLeft - 1, row], startLocation);
                        Console.WriteLine(maybeGood);
                        if (maybeGood == new BoardLogic.ChessCoordinates('0', -1, null))
                        {
                            break;
                        }
                        else
                        {
                            ValidMoves.Add(maybeGood);
                            goingLeft = goingLeft - 1;
                            if (shouldStop)
                            {
                                shouldStop = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (column + 1 <= 7)
            {
                int goingRight = column;
                while (true)
                {
                    if (goingRight + 1 <= 7)
                    {
                        BoardLogic.ChessCoordinates maybeGood = CheckSpaces(Program.board[goingRight + 1, row], startLocation);
                        if (maybeGood == new BoardLogic.ChessCoordinates('0', -1, null))
                        {
                            break;
                        }
                        else
                        {
                            ValidMoves.Add(maybeGood);
                            goingRight = goingRight + 1;
                            if (shouldStop)
                            {
                                shouldStop = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            BoardLogic.ChessCoordinates lookingFor = new BoardLogic.ChessCoordinates(BoardLogic.GetCharFromNumber(FileLogic.GetColumnFromChar(endLocation.Column).GetHashCode()), endLocation.Row, null);

            foreach (var space in ValidMoves)
            {
                if (space == lookingFor)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 6
0
        public override bool ValidMovement(BoardLogic.ChessCoordinates startLocation, BoardLogic.ChessCoordinates endLocation)
        {
            //validate movement eventually
            ValidMoves.Clear();

            int column = FileLogic.GetColumnFromChar(startLocation.Column).GetHashCode();
            int row    = startLocation.Row;

            if (Program.board[column, row].Piece.IsLight)
            {
                if (column - 1 >= 0)
                {
                    if (Program.board[column - 1, row].Piece == null)
                    {
                        ValidMoves.Add(Program.board[column - 1, row]);
                        if (column == 6)
                        {
                            if (Program.board[column - 2, row].Piece == null)
                            {
                                ValidMoves.Add(Program.board[column - 2, row]);
                            }
                        }
                    }
                    if (row - 1 >= 0 && Program.board[column - 1, row - 1].Piece != null && Program.board[column - 1, row - 1].Piece.IsLight != Program.board[column, row].Piece.IsLight)
                    {
                        ValidMoves.Add(Program.board[column - 1, row - 1]);
                    }
                    if (row + 1 <= 7 && Program.board[column - 1, row + 1].Piece != null && Program.board[column - 1, row + 1].Piece.IsLight != Program.board[column, row].Piece.IsLight)
                    {
                        ValidMoves.Add(Program.board[column - 1, row + 1]);
                    }
                }
            }
            else if (!Program.board[column, row].Piece.IsLight)
            {
                if (column + 1 <= 7)
                {
                    if (Program.board[column + 1, row].Piece == null)
                    {
                        ValidMoves.Add(Program.board[column + 1, row]);
                        if (column == 1)
                        {
                            if (Program.board[column + 2, row].Piece == null)
                            {
                                ValidMoves.Add(Program.board[column + 2, row]);
                            }
                        }
                    }
                    if (row - 1 >= 0 && Program.board[column + 1, row - 1].Piece != null && Program.board[column + 1, row - 1].Piece.IsLight != Program.board[column, row].Piece.IsLight)
                    {
                        ValidMoves.Add(Program.board[column + 1, row - 1]);
                    }
                    if (row + 1 <= 7 && Program.board[column + 1, row + 1].Piece != null && Program.board[column + 1, row + 1].Piece.IsLight != Program.board[column, row].Piece.IsLight)
                    {
                        ValidMoves.Add(Program.board[column + 1, row + 1]);
                    }
                }
            }
            BoardLogic.ChessCoordinates lookingFor = new BoardLogic.ChessCoordinates(BoardLogic.GetCharFromNumber(FileLogic.GetColumnFromChar(endLocation.Column).GetHashCode()), endLocation.Row, null);
            //BoardLogic.ChessCoordinates lookingFor2 = new BoardLogic.ChessCoordinates(BoardLogic.GetCharFromNumber(endLocation.Row), FileLogic.GetColumnFromChar(endLocation.Column).GetHashCode(), null);

            foreach (var space in ValidMoves)
            {
                if (space == lookingFor)
                {
                    return(true);
                }
            }
            return(false);
        }