Beispiel #1
0
        public Board UnmakeMove(Move move)
        {
            int row = (int)move.Row;
            int column = (int)move.Column;
            if (_BoardValues[column, row] == Values.None)
                throw new ArgumentException();

            _BoardValues[column, row] = Values.None;
            int bit = ~((int)move.Value);
            _RowValues[row] = (Values) ((int)_RowValues[row] & bit);
            _ColumnValues[column] = (Values)((int)_ColumnValues[column] & bit);
            _RegionValues[column / 3, row / 3] = (Values) ((int) _RegionValues[column / 3, row / 3] & bit);
            _EmptySquaresCount++;

            return this;
        }
Beispiel #2
0
        public Board MakeMove(Move move)
        {
            int row = (int)move.Row;
            int column = (int)move.Column;

            _BoardValues[column, row] = move.Value;
            //int bit = (int) move.Value;

            if ((_RowValues[row] & move.Value) == move.Value)
                throw new ArgumentException(
                    string.Format("Invalid move {2}.\nNumber {0}. \nAlready present in row {1}\n{3}",
                    move.Value,
                    move.Row,
                    move.ToString(),
                    this.ToString()
                    ));

            if ((_ColumnValues[column] & move.Value) == move.Value)
                throw new ArgumentException(
                    string.Format("Invalid move {2}.\nNumber {0} already present in column {1}\n{3}",
                    move.Value,
                    move.Column,
                    move.ToString(),
                    this.ToString()
                    ));

            if ((_RegionValues[column / 3, row / 3] & move.Value) == move.Value)
                throw new ArgumentException(
                    string.Format("Invalid move {1}.\nNumber {0} already present in this region\n{2}",
                    move.Value,
                    move.ToString(),
                    this.ToString()
                    ));

            _RowValues[row] |= move.Value;
            _ColumnValues[column] |= move.Value;
            _RegionValues[column / 3, row / 3] |= move.Value;
            _EmptySquaresCount--;

            return this;
        }