A fully working version of the game.

Works with XBoard only (not eboard).

The program plays the first legal move.
This commit is contained in:
2006-01-17 15:18:53 +00:00
parent 42e56fde4f
commit dbfd428710
6 changed files with 356 additions and 139 deletions

View File

@ -0,0 +1,47 @@
package suicideChess;
import java.util.ArrayList;
import suicideChess.Square.NotAValidSquare;
/**
* This class will contain all the AI.
* @author Jean-Baptiste Hétier
* @version $LastChangedRevision: 33 $, $LastChangedDate: 2006-01-13 17:03:06 +0000 (Fri, 13 Jan 2006) $
*/
public class ComputerPlayer {
private int color;
/**
* This constructor creates a computer that plays with the given color
* @param color An integer representing the color. (See {@link Piece})
* @see Piece
*/
public ComputerPlayer(int color) {
this.color = color;
}
/**
* This asks the computer to compute a move
* @param bitboard The current status of the {@link Board}
* @return move A {@link Move}
* @throws NotAValidSquare
* @see Board
* @see Move
*/
public Move doMove(Board bitboard) throws NotAValidSquare {
Rules.legalMovesForPlayer(bitboard,color);
ArrayList<Move> allLegalMoves = Rules.getLegalMovesCapture();
if (allLegalMoves.size()==0) {
allLegalMoves = Rules.getLegalMovesNonCapture();
}
if (allLegalMoves.size()!=0) {
return allLegalMoves.get(0);
}
throw new RuntimeException();
}
}