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:
47
src/suicideChess/ComputerPlayer.java
Normal file
47
src/suicideChess/ComputerPlayer.java
Normal 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();
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user