Version 0.1.99

==============
Everything seems to work fine for a two player game.
This commit is contained in:
2006-01-13 16:48:21 +00:00
parent c62bdacb9f
commit 651ed576bd
6 changed files with 242 additions and 100 deletions

View File

@ -46,13 +46,14 @@ public class SuicideChess {
Board bitboard = new Board();
bitboard.display();
/*int playerColor = Piece.WHITE;
System.out.println("White: ");*/
int playerColor = Piece.WHITE;
System.out.println("White: ");
while (true) {
try {
String whatMove= moveInput.readLine();
boolean playedALegalMove = false;
if (whatMove.startsWith("quit")) {
System.out.println("Goodbye!");
@ -61,10 +62,21 @@ public class SuicideChess {
if (whatMove.startsWith("hint")) {
Rules rules = new Rules();
ArrayList<Move> allLegalMoves =
rules.legalMovesFromSquare(new Square(whatMove.substring(5,7)),bitboard);
rules.legalMovesForPlayer(bitboard,playerColor);
ArrayList<Move> allLegalMoves = rules.getLegalMovesCapture();
if (allLegalMoves.size()==0) {
allLegalMoves = rules.getLegalMovesNonCapture();
}
for(int i = 0; i<allLegalMoves.size(); i++) {
allLegalMoves.get(i).display();
if(allLegalMoves.get(i).isPromotionMove()) {
System.out.println(allLegalMoves.get(i).fromSquare().toString() +
allLegalMoves.get(i).toSquare().toString() +
allLegalMoves.get(i).getPromotionPiece().toString());
} else {
System.out.println(allLegalMoves.get(i).fromSquare().toString() +
allLegalMoves.get(i).toSquare().toString());
}
}
continue;
}
@ -79,32 +91,50 @@ public class SuicideChess {
Move theMove = new Move(whatMove, bitboard);
Rules rules = new Rules();
ArrayList<Move> allLegalMoves =
rules.legalMovesFromSquare(new Square(whatMove.substring(0,2)),bitboard);
int foundMoveIndex = -1;
for (int moveIndex = 0; moveIndex < allLegalMoves.size(); moveIndex++) {
if (allLegalMoves.get(moveIndex).toSquare().isEqual(theMove.toSquare())) {
foundMoveIndex=moveIndex;
break;
}
}
if (foundMoveIndex == -1) {
System.out.println("This move is not valid. Please type 'hint "+whatMove.substring(0,2)
+"' to see available moves.");
} else {
allLegalMoves.get(foundMoveIndex).display();
bitboard.doMove(allLegalMoves.get(foundMoveIndex));
bitboard.display();
}
boolean needToCapture = false;
int foundMoveIndex = -1;
if(theMove.getMovingPiece().getColor() == playerColor) {
rules.legalMovesForPlayer(bitboard,playerColor);
ArrayList<Move> allLegalMoves = rules.getLegalMovesCapture();
if (allLegalMoves.size()==0) {
allLegalMoves = rules.getLegalMovesNonCapture();
} else {
needToCapture = true;
}
for (int moveIndex = 0; moveIndex < allLegalMoves.size(); moveIndex++) {
if (allLegalMoves.get(moveIndex).isSimpleEqual(theMove)) {
if(theMove.isPromotionMove()&&
theMove.getPromotionPiece().getPieceNumber()!=allLegalMoves.get(moveIndex).getPromotionPiece().getPieceNumber()) {
continue;
}
foundMoveIndex=moveIndex;
break;
}
}
if (foundMoveIndex == -1) {
if (needToCapture) {
System.out.println("Capturing is mandatory.");
}
System.out.println("This move is not valid. Please type 'hint' to see list of legal moves.");
} else {
allLegalMoves.get(foundMoveIndex).display();
bitboard.doMove(allLegalMoves.get(foundMoveIndex));
bitboard.display();
playedALegalMove=true;
}
} else {
System.out.println("Please play a piece of the right color.");
}
/*if (playerColor == Piece.WHITE) {
playerColor = Piece.BLACK;
System.out.println("Black: ");
} else {
playerColor = Piece.WHITE;
System.out.println("White: ");
}*/
if (playedALegalMove) {
if (playerColor == Piece.WHITE) {
playerColor = Piece.BLACK;
System.out.println("Black: ");
} else {
playerColor = Piece.WHITE;
System.out.println("White: ");
}
}
} catch (NotAValidMoveException err) {
System.out.println(err);