Version 0.3 beta 3:

Computer can now play black and white
For some reason the computer cannot play against himself.
I think it must be because of force that is not understood.
This commit is contained in:
2006-01-24 16:16:04 +00:00
parent dbfd428710
commit 6cf9f27892
4 changed files with 61 additions and 31 deletions

View File

@ -1,6 +1,7 @@
package suicideChess;
import java.util.ArrayList;
import java.util.Random;
import suicideChess.Square.NotAValidSquare;
@ -12,17 +13,13 @@ import suicideChess.Square.NotAValidSquare;
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
* This constructor creates a computer.
*/
public ComputerPlayer(int color) {
this.color = color;
public ComputerPlayer() {
//this.color = color;
}
/**
* This asks the computer to compute a move
* @param bitboard The current status of the {@link Board}
@ -31,17 +28,19 @@ public class ComputerPlayer {
* @see Board
* @see Move
*/
public Move doMove(Board bitboard) throws NotAValidSquare {
public Move doMove(Board bitboard, int color) throws NotAValidSquare {
Random generator = new Random();
Rules.legalMovesForPlayer(bitboard,color);
ArrayList<Move> allLegalMoves = Rules.getLegalMovesCapture();
if (allLegalMoves.size()==0) {
allLegalMoves = Rules.getLegalMovesNonCapture();
}
if (allLegalMoves.size()!=0) {
return allLegalMoves.get(0);
return allLegalMoves.get(generator.nextInt(allLegalMoves.size()));
}
throw new RuntimeException();
}
}
}