Пример #1
0
        /*
         * Returns the move specified by the AI
         */
        public Move GetMove(Board b)
        {
            List <Piece> pieces = GetBlackPieces(b);

            List <Move> moves = GetAllMoves(b, pieces);

            //if we're out of pieces, we lose (reset the game)
            if (pieces.Count == 0)
            {
                return(null);
            }
            else
            {
                Random rand = new Random();

                //select a move to take a piece (if able)
                bool canTake = false;

                List <Move> takeMoves = new List <Move>(0);

                List <Piece> oppPieces = GetWhitePieces(b);
                for (int i = 0; i < moves.Count; i++)
                {
                    for (int j = 0; j < oppPieces.Count; j++)
                    {
                        if (moves[i].End == b.GetPiecePosition(oppPieces[j]))
                        {
                            //then I can take it
                            System.Console.WriteLine("I can take a piece");
                            canTake = true;
                            takeMoves.Add(moves[i]);
                        }
                    }
                }

                if (canTake) //take it
                {
                    return(takeMoves[rand.Next(takeMoves.Count())]);
                }
                else //do a random move
                {
                    return(moves[rand.Next(moves.Count())]);
                }
            }
        }