Beispiel #1
0
        /// <summary>
        /// Returns the move specified by the given information.
        /// </summary>
        /// <param name="position">The position the move is to be played on.</param>
        /// <param name="from">The initial square of the move.</param>
        /// <param name="to">The final square of the move.</param>
        /// <returns>The move specified by the given information.</returns>
        private Int32 CreateMove(Position position, Int32 from, Int32 to)
        {
            foreach (Int32 move in position.LegalMoves())
            {
                if (from == Move.From(move) && to == Move.To(move))
                {
                    Int32 special = Move.Special(move);
                    if (Move.IsPromotion(move))
                    {
                        switch (SelectionBox.Show("What piece would you like to promote to?", "Queen", "Rook", "Bishop", "Knight"))
                        {
                        case "Queen":
                            special = position.SideToMove | Piece.Queen;
                            break;

                        case "Rook":
                            special = position.SideToMove | Piece.Rook;
                            break;

                        case "Bishop":
                            special = position.SideToMove | Piece.Bishop;
                            break;

                        case "Knight":
                            special = position.SideToMove | Piece.Knight;
                            break;
                        }
                    }
                    return(Move.Create(position, from, to, special));
                }
            }
            return(Move.Invalid);
        }
Beispiel #2
0
 /// <summary>
 /// Displays a SelectionBox and returns the option chosen by the user.
 /// </summary>
 /// <param name="message">The message to display.</param>
 /// <param name="options">The default input.</param>
 /// <returns>The option choosen by the user.</returns>
 public static String Show(String message, params String[] options)
 {
     while (true)
     {
         using (SelectionBox a = new SelectionBox()) {
             if (a.ShowDialog(message, options) == DialogResult.OK)
             {
                 return(a.responseBox.Text);
             }
         }
     }
 }