示例#1
0
        /// <summary>
        /// Extracts the row and compares it to the combination
        /// </summary>
        /// <param name="row">The guess by player to compare to combination</param>
        /// <returns>MoveResult struct, which carries some stats based on the guess. Also flags when no more moves are allowed.</returns>
        internal MoveResult doMove(ColoredPegRow row)
        {
            if (row == null)
            {
                throw new MastermindBoardException("Row cannot be null");
            }

            if (row.NumberPegs != this.NumberPegs)
            {
                throw new MastermindBoardException("The row is invalid for this move");
            }

            if (this.curRow >= this.NumberRows)
            {
                throw new MastermindBoardException("There are no more possible moves");
            }

            MoveResult mr = new MoveResult();

            this.CurrentRow               = row;
            mr.TotalRightColor            = this.CurrentRow.EqualColors(this.combination);
            mr.TotalRightColorAndPosition = this.CurrentRow.EqualColorsAndPositions(this.combination);
            mr.TotalMoves = this.curRow + 1;
            this.curRow++;

            if (this.curRow >= this.NumberRows)
            {
                mr.NoMoreMoves = true;
            }

            return(mr);
        }
示例#2
0
        /// <summary>
        /// Setup the board
        /// </summary>
        /// <param name="combination">Secret combination to be guessed by player</param>
        internal void setup(ColoredPegRow combination)
        {
            if (combination == null)
            {
                throw new MastermindBoardException("The combination cannot be null");
            }

            if (combination.NumberPegs != this.NumberPegs)
            {
                throw new MastermindBoardException("The combination doesn't match the size of pegs per row");
            }

            this.combination = combination;
        }