예제 #1
0
        protected void FindFieldsInRow(ChessBoard board, FieldStatus ownStatus)
        {
            int  row    = CurrentField.Row;
            char column = (char)((int)CurrentField.Column - 1);

            while ((int)column >= (int)'A')
            {
                ChessField field = board.GetField(row, column);
                if (field.Status != ownStatus)
                {
                    FieldsToMove.Add(field);
                }
                if (field.Status != FieldStatus.EMPTY)
                {
                    break;
                }
                column--;
            }
            column = (char)((int)CurrentField.Column + 1);
            while ((int)column <= (int)'H')
            {
                ChessField field = board.GetField(row, column);
                if (field.Status != ownStatus)
                {
                    FieldsToMove.Add(field);
                }
                if (field.Status != FieldStatus.EMPTY)
                {
                    break;
                }
                column++;
            }
        }
예제 #2
0
        protected void FindFieldsInColumn(ChessBoard board, FieldStatus ownStatus)
        {
            char column = CurrentField.Column;
            int  row    = CurrentField.Row - 1;

            while (row > 0)
            {
                ChessField field = board.GetField(row, column);
                if (field.Status != ownStatus)
                {
                    FieldsToMove.Add(field);
                }
                if (field.Status != FieldStatus.EMPTY)
                {
                    break;
                }
                row--;
            }
            row = CurrentField.Row + 1;
            while (row <= 8)
            {
                ChessField field = board.GetField(row, column);
                if (field.Status != ownStatus)
                {
                    FieldsToMove.Add(field);
                }
                if (field.Status != FieldStatus.EMPTY)
                {
                    break;
                }
                row++;
            }
        }
예제 #3
0
        public override void FindFieldsToMove(ChessBoard board)
        {
            if (IsKilled)
            {
                return;
            }
            FieldsToMove.Clear();
            FieldStatus enemyStatus = Color == Color.WHITE
                ? FieldStatus.OCCUPIED_WITH_BLACK
                : FieldStatus.OCCUPIED_WITH_WHITE;
            int row = Color == Color.WHITE ? CurrentField.Row + 1 : CurrentField.Row - 1;

            if (row < 1 || row > 8)
            {
                return;
            }
            ChessField field = board.GetField(row, CurrentField.Column);

            if (field.Status == FieldStatus.EMPTY)
            {
                FieldsToMove.Add(field);
            }

            char column = (char)(CurrentField.Column - 1);

            field = board.GetField(row, column);
            if (field.Status == enemyStatus)
            {
                FieldsToMove.Add(field);
            }
            column = (char)(CurrentField.Column + 1);
            field  = board.GetField(row, column);
            if (field.Status == enemyStatus)
            {
                FieldsToMove.Add(field);
            }

            if (PreviousMoves.Count == 0)
            {
                row   = Color == Color.WHITE ? CurrentField.Row + 2 : CurrentField.Row - 2;
                field = board.GetField(row, CurrentField.Column);
                if (field.Status == FieldStatus.EMPTY)
                {
                    FieldsToMove.Add(field);
                }
            }
        }
예제 #4
0
        public override void FindFieldsToMove(ChessBoard board)
        {
            if (IsKilled)
            {
                return;
            }
            FieldsToMove.Clear();
            FieldStatus ownStatus = Color == Color.WHITE
                ? FieldStatus.OCCUPIED_WITH_WHITE
                : FieldStatus.OCCUPIED_WITH_BLACK;
            int  row;
            char column = '\0';

            for (int i = 0; i < 8; i++)
            {
                if (i < 2)
                {
                    row = CurrentField.Row + 2;
                }
                else if (i < 4)
                {
                    row = CurrentField.Row + 1;
                }
                else if (i < 6)
                {
                    row = CurrentField.Row - 1;
                }
                else
                {
                    row = CurrentField.Row - 2;
                }
                if (i == 2 || i == 4)
                {
                    column = (char)(CurrentField.Column - 2);
                }
                else if (i == 0 || i == 6)
                {
                    column = (char)(CurrentField.Column - 1);
                }
                else if (i == 1 || i == 7)
                {
                    column = (char)(CurrentField.Column + 1);
                }
                else if (i == 3 || i == 5)
                {
                    column = (char)(CurrentField.Column + 2);
                }
                if (row < 1 || row > 8 || column < 'A' || column > 'H')
                {
                    continue;
                }

                ChessField field = board.GetField(row, column);
                if (field.Status != ownStatus)
                {
                    FieldsToMove.Add(field);
                }
            }
        }
예제 #5
0
        public override void FindFieldsToMove(ChessBoard board)
        {
            FieldsToMove.Clear();
            FieldStatus ownStatus = Color == Color.WHITE
                ? FieldStatus.OCCUPIED_WITH_WHITE
                : FieldStatus.OCCUPIED_WITH_BLACK;

            List <int> potentialRows = new List <int>();

            if (CurrentField.Row != 1)
            {
                potentialRows.Add(CurrentField.Row - 1);
            }
            potentialRows.Add(CurrentField.Row);
            if (CurrentField.Row != 8)
            {
                potentialRows.Add(CurrentField.Row + 1);
            }
            List <char> potentialColumns = new List <char>();

            if (CurrentField.Column != 'A')
            {
                potentialColumns.Add((char)((int)CurrentField.Column - 1));
            }
            potentialColumns.Add(CurrentField.Column);
            if (CurrentField.Column != 'H')
            {
                potentialColumns.Add((char)((int)CurrentField.Column + 1));
            }

            foreach (int row in potentialRows)
            {
                foreach (char column in potentialColumns)
                {
                    ChessField field = board.GetField(row, column);
                    if (field.Status != ownStatus)
                    {
                        FieldsToMove.Add(field);
                    }
                }
            }
        }