Exemplo n.º 1
0
        //***Let your strategic brain go nutz here!! All of this below is just **Example** code

        // Example Function - Returns a random safe *ChessMove*
        private ChessMove GetSafeMoves(List <ChessMove> lsMoves)
        {
            List <ChessMove> SafeMoves = new List <ChessMove>();

            // Find the Safe moves
            foreach (ChessMove move in lsMoves)
            {
                // Look in the future
                ChessMove mve         = VirtualBoard.MovePiece(move); // capture possible return of additional information into the move (This MUST be done)
                bool      isPieceSafe = VirtualBoard.IsSafe(mve.PieceMoved.Location, Me);
                VirtualBoard.UndoMovePiece(mve);

                if (isPieceSafe)
                {
                    SafeMoves.Add(mve);
                }
            }

            if (SafeMoves.Count > 0)
            {
                return(SafeMoves[_rando.Next(0, SafeMoves.Count)]); // Return a random safe move
            }
            else // No safe moves
            {
                return(lsMoves[_rando.Next(0, lsMoves.Count)]); // Return a random move
            }
        }
Exemplo n.º 2
0
        // Example Function - Returns a single *ChessMove*
        private ChessMove GetTheSafest(List <ChessMove> lsMoves)
        {
            List <ChessMove> betterMoves = lsMoves.FindAll(m => m.MoveType == Condition.Attack);  // Lambda's for searching Lists are a powerful tool.
            List <ChessMove> bestMoves   = new List <ChessMove>();

            if (betterMoves.Count > 0)
            {
                foreach (ChessMove move in betterMoves)
                {
                    // Look in the future
                    ChessMove mve         = VirtualBoard.MovePiece(move); // capture possible return of additional information into the move (This MUST be done if pawn)
                    bool      isPieceSafe = VirtualBoard.IsSafe(mve.PieceMoved.Location, Me);
                    VirtualBoard.UndoMovePiece(mve);

                    if (isPieceSafe)
                    {
                        bestMoves.Add(move);
                    }
                }
            }
            if (bestMoves.Count < 0)
            {
                foreach (ChessMove move in lsMoves)
                {
                    // Look in the future
                    ChessMove mve         = VirtualBoard.MovePiece(move); // capture possible return of additional information into the move (This MUST be done if pawn)
                    bool      isPieceSafe = VirtualBoard.IsSafe(mve.PieceMoved.Location, Me);
                    VirtualBoard.UndoMovePiece(mve);

                    if (isPieceSafe)
                    {
                        bestMoves.Add(mve);
                    }
                }
            }

            if (bestMoves.Count > 0)
            {
                return(bestMoves[_rando.Next(0, bestMoves.Count)]);
            }
            else
            {
                return(lsMoves[_rando.Next(0, lsMoves.Count)]);
            }
        }