Esempio n. 1
0
        /// <summary>
        /// Gets the <see cref="BoardRow"/> with the specified zero based row index.
        /// </summary>
        /// <value>
        /// The <see cref="BoardRow"/> at index <paramref name="zeroBasedRowIndex"/>.
        /// </value>
        /// <param name="zeroBasedRowIndex">Index of the row.</param>
        public BoardRow this[int zeroBasedRowIndex]
        {
            get
            {
                ContractExtensions.IsNotDisposed(this, this.IsDisposed);
                ContractExtensions.IsValidIndex(zeroBasedRowIndex, "zeroBasedRowIndex");
                Contract.EndContractBlock();

                return(this.rows[zeroBasedRowIndex]);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets or sets the value of the cell at the specified column index.
        /// </summary>
        /// <value>
        /// The value of the cell.
        /// </value>
        /// <param name="zeroBasedColumnIndex">Index of the column.</param>
        public byte this[int zeroBasedColumnIndex]
        {
            get
            {
                ContractExtensions.IsValidIndex(zeroBasedColumnIndex, "zeroBasedColumnIndex");
                return(this.getter(zeroBasedColumnIndex));
            }

            set
            {
                ContractExtensions.IsValidIndex(zeroBasedColumnIndex, "zeroBasedColumnIndex");
                this.setter(zeroBasedColumnIndex, value);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Resets a cell's value to unset.
        /// </summary>
        /// <param name="zeroBasedRowIndex">Index of the row.</param>
        /// <param name="zeroBasedColumnIndex">Index of the column.</param>
        public void ResetCell(int zeroBasedRowIndex, int zeroBasedColumnIndex)
        {
            ContractExtensions.IsNotDisposed(this, this.IsDisposed);
            ContractExtensions.IsValidIndex(zeroBasedRowIndex, "zeroBasedRowIndex");
            ContractExtensions.IsValidIndex(zeroBasedColumnIndex, "zeroBasedColumnIndex");
            Contract.EndContractBlock();

            this.contentLock.EnterWriteLock();
            try
            {
                this.content[Board.CalculateIndexFromRowAndColumn(zeroBasedRowIndex, zeroBasedColumnIndex)] = 0;
            }
            finally
            {
                this.contentLock.ExitWriteLock();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the value of a cell.
        /// </summary>
        /// <param name="zeroBasedRowIndex">Index of the row.</param>
        /// <param name="zeroBasedColumnIndex">Index of the column.</param>
        /// <returns>Value of the cell at the specified row and column index.</returns>
        /// <remarks>
        /// Zero is returned for an unset cell.
        /// </remarks>
        public byte GetCell(int zeroBasedRowIndex, int zeroBasedColumnIndex)
        {
            ContractExtensions.IsNotDisposed(this, this.IsDisposed);
            ContractExtensions.IsValidIndex(zeroBasedRowIndex, "zeroBasedRowIndex");
            ContractExtensions.IsValidIndex(zeroBasedColumnIndex, "zeroBasedColumnIndex");
            Contract.EndContractBlock();

            // Note that we use a read lock this time. This makes sure that many threads
            // can read the board's content at the same time.
            this.contentLock.EnterReadLock();
            try
            {
                return(this.content[Board.CalculateIndexFromRowAndColumn(zeroBasedRowIndex, zeroBasedColumnIndex)]);
            }
            finally
            {
                this.contentLock.ExitReadLock();
            }
        }
Esempio n. 5
0
        public byte[] GetCopyOfRow(int zeroBasedRowIndex)
        {
            ContractExtensions.IsNotDisposed(this, this.IsDisposed);
            ContractExtensions.IsValidIndex(zeroBasedRowIndex, "zeroBasedRowIndex");
            Contract.EndContractBlock();

            var result = new byte[9];

            this.contentLock.EnterReadLock();
            try
            {
                Array.Copy(this.content, zeroBasedRowIndex * 9, result, 0, 9);
            }
            finally
            {
                this.contentLock.ExitReadLock();
            }

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Tries the set the value of a cell.
        /// </summary>
        /// <param name="zeroBasedRowIndex">Index of the row.</param>
        /// <param name="zeroBasedColumnIndex">Index of the column.</param>
        /// <param name="value">The new value.</param>
        /// <returns><c>True</c> if the value could be set successfully, otherwise <c>false</c>.</returns>
        /// <remarks>
        /// <para>
        /// Note that <paramref name="value"/> must not be zero. If you want to unset a cell,
        /// use <see cref="ResetCell"/> instead.
        /// </para>
        /// <para>
        /// Note the TryXXX naming pattern. <see cref="TrySetCell"/> does the same as <see cref="SetCell"/>
        /// except that it does not throw an exception if the value could not be set.
        /// </para>
        /// </remarks>
        public bool TrySetCell(int zeroBasedRowIndex, int zeroBasedColumnIndex, byte value)
        {
            ContractExtensions.IsNotDisposed(this, this.IsDisposed);
            ContractExtensions.IsValidIndex(zeroBasedRowIndex, "zeroBasedRowIndex");
            ContractExtensions.IsValidIndex(zeroBasedColumnIndex, "zeroBasedColumnIndex");
            ContractExtensions.IsValidValue(value, "value");
            Contract.EndContractBlock();

            // Note that we use a write lock this time. This makes sure that only one thread
            // can write to the board bytes at the same time.
            this.contentLock.EnterWriteLock();
            try
            {
                // Call internal implementation.
                return(Board.TrySetCellInternal(this.content, zeroBasedRowIndex, zeroBasedColumnIndex, value));
            }
            finally
            {
                this.contentLock.ExitWriteLock();
            }
        }