TestXBoardProtocol hasn't changed much. Now it is in a package called test.

NEW FILE: TestMoves -> purpose is to test the Move class

NEW FILE: Move -> this is a first implementation of a simple class that
				  reads a string and converts it to a move or the opposite.

NEW FILE: BitBoard -> this class really doesn't do anything yet.
					  It only has definition of 14 bitboards but they are not
					  created yet.
This commit is contained in:
2006-01-04 19:37:48 +00:00
parent 75d07c5f3f
commit 0b15f1e287
4 changed files with 231 additions and 7 deletions

View File

@ -0,0 +1,86 @@
package suicideChess;
/**
* @author djib
*
* This file contains the board representation.
* The board is represented using bitboards.
*
* $LastChangedDate$
* $LastChangedRev$
* $LastChangedBy$
*/
public class BitBoard {
/*************
* CONSTANTS *
*************/
//Some constants to make code more readable
public static final int NB_OF_SQUARES = 64;
//Some constants used to access the bitboards
//Note that in suicide chess there may be more than one king
public static final int WHITE_PAWNS = 0;
public static final int BLACK_PAWNS = 1;
public static final int WHITE_KINGS = 2;
public static final int BLACK_KINGS = 3;
public static final int WHITE_QUEENS = 4;
public static final int BLACK_QUEENS = 5;
public static final int WHITE_BISHOPS = 6;
public static final int BLACK_BISHOPS = 7;
public static final int WHITE_KNIGHTS = 8;
public static final int BLACK_KNIGHTS = 9;
public static final int WHITE_ROOKS = 10;
public static final int BLACK_ROOKS = 11;
public static final int WHITE_PIECES = 12;
public static final int BLACK_PIECES = 13;
public static final int NB_OF_BITBOARDS = 14;
/********
* DATA *
********/
//The following table is used to map squares to bits
private static long mapSquaresToBits[];
//static function used to initialise data
static {
mapSquaresToBits = new long[NB_OF_SQUARES];
for(int i=0; i<NB_OF_SQUARES; i++) {
mapSquaresToBits[i] = (1L << i);
}
}
//The following table contains all the bit boards
private long bitBoards[];
/***************
* CONSTRUCTOR *
***************/
public BitBoard() {
bitBoards = new long[NB_OF_BITBOARDS];
}
/***********
* METHODS *
***********/
public long getBitboard(int bitboard_number) {
return bitBoards[bitboard_number];
}
/* TODO
public void updateBitboards(String move) {
}
*/
public int squareToBitboardSquare()
}

View File

@ -0,0 +1,96 @@
package suicideChess;
/**
* @author djib
*
* This file contains the moves representation.
*
* $LastChangedDate$
* $LastChangedRev$
* $LastChangedBy$
*/
public class Move {
/********
* DATA *
********/
//integers
private String fromSquare;
private String toSquare;
private String promotionPiece;
private boolean isPromotion;
public class NotAValidMoveException extends Exception {
NotAValidMoveException(String s) { super(s); };
}
/***************
* CONSTRUCTOR *
***************/
//The string is of type e2e4 (4 chars), b7b8q (5 chars) for promotions
public Move(String move) throws NotAValidMoveException {
isPromotion = false;
promotionPiece = "";
switch (move.length()) {
case 5:
isPromotion = true;
promotionPiece = move.substring(4,5);
//no break statement here on purpose
case 4:
fromSquare = move.substring(0,2);
toSquare = move.substring(2,4);
break;
default:
throw new NotAValidMoveException("Invalid Move: "+move);
}
}
/***********
* METHODS *
***********/
public String fromSquare() {
return fromSquare;
}
public String toSquare() {
return toSquare;
}
public boolean isPromotionMove() {
return isPromotion;
}
public void setFromSquare(String square) {
fromSquare = square;
}
public void setToSquare(String square) {
toSquare = square;
}
public void setIsPromotionMove(String piece) {
if (promotionPiece.length()==0) {
isPromotion=false;
} else {
isPromotion=true;
promotionPiece=piece;
}
}
public String toString() {
return fromSquare+toSquare+promotionPiece;
}
public void display() {
System.out.println(" ");
System.out.println("==== Move ====");
System.out.println("From square:"+fromSquare);
System.out.println("To square: "+toSquare);
System.out.println((isPromotion ? "Promotion: "+promotionPiece : "No Promotion"));
System.out.println("===============");
System.out.println(" ");
System.out.println(" ");
}
}

34
src/tests/TestMoves.java Normal file
View File

@ -0,0 +1,34 @@
package tests;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import suicideChess.Move;
/**
* @author djib
*
* The purpose of this file is to test the Moves.java class
*
* $LastChangedDate$
* $LastChangedRev$
* $LastChangedBy$
*/
public class TestMoves {
public static void main(String[] args) {
BufferedReader moveInput = new BufferedReader(new InputStreamReader(System.in));
while (true) {
try {
String move = moveInput.readLine();
(new Move(move)).display();
} catch (Exception err) {
System.out.println(err);
break;
}
}
}
}

View File

@ -1,11 +1,17 @@
package tests;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.logging.*;
/**
* @author djib
*
* This class is used to test the XBoard protocol.
*
* $LastChangedDate$
* $LastChangedRev$
* $LastChangedBy$
*
*/
public class TestXBoardProtocol {
public static void main(String[] args) {
@ -19,23 +25,25 @@ public class TestXBoardProtocol {
BufferedReader xBoardInput = new BufferedReader(new InputStreamReader(System.in));
System.out.println("feature myname=\"djib's Suicide Chess\" sigint=0 sigterm=0 done=1");
//done=1 is here to tell that the program has finish requesting features
System.out.println("feature myname=\"djib's Suicide Chess\" sigint=0 sigterm=0 variant=\"suicide\" done=1");
while (true) {
try {
String xBoardCommand = xBoardInput.readLine();
logger.info(xBoardCommand);
//System.err.println(xBoardCommand);
//if (xBoardCommand.startsWith("quit")) {
// logger.info(">quit;");
// break;
//}
System.err.println(xBoardCommand);
if (xBoardCommand.startsWith("quit")) {
logger.info(">quit;");
break;
}
if (xBoardCommand.startsWith("otim")) {
logger.info(">Error");
System.out.println("Error (unknown command): time");
}
if (xBoardCommand.startsWith("e2e4")) {
logger.info(">move b8c6");
logger.info(">move b8b8");
System.out.println("move b8c6");
}
if (xBoardCommand.startsWith("d2d4")) {