/*
 * Copyright (C) 2015 Matthew Seal
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.mseal.chess.ai;

import java.util.Random;
import org.mseal.chess.GameAppState;
import org.mseal.chess.logic.Board;
import org.mseal.chess.logic.ChessMove;
import org.mseal.chess.logic.Moves;
import org.mseal.chess.logic.Player;
import org.mseal.chess.logic.pieces.ChessPiece;

/**
 *
 * @author Matthew Seal
 */
public class BasicAIModule implements AIModule {

    private static final Random ran = new Random();

    @Override
    public boolean doMove(GameAppState gameState, Player player, Board board) {
        // do simple ai that moves a pawn each turn
        ChessPiece[] pieces = player.getPieces();
        // first eight are pawns
        int n = ran.nextInt(8);

        ChessPiece piece = pieces[n];

        ChessMove[] moves = Moves.getMovesFor(piece);
        if (moves.length > 0) {
            ChessMove move = moves[0];

            // make move
            return gameState.makeMove(piece, move);
        } else {
            return false;
        }

    }

    @Override
    public void initialize(GameAppState gameState, Board board) {
    }
}
