chessai

college code for ai playing chess in java

git clone https://9o.is/git/chessai.git

commit e5e38257c31d68071f11fac092205f2f92704377
parent 6a93c2399388dd3ad9a93c29f98134ff9ddee68f
Author: Jul <jul@9o.is>
Date:   Sat,  1 Dec 2012 18:17:14 -0500

ChessCoordinate does not throw exceptions anymore.

Diffstat:
Msrc/chess/ChessCoordinate.java | 20+++-----------------
1 file changed, 3 insertions(+), 17 deletions(-)

diff --git a/src/chess/ChessCoordinate.java b/src/chess/ChessCoordinate.java @@ -6,29 +6,21 @@ package chess; public class ChessCoordinate { public static final int MAX = 8; - private static final String ERROR_MSG = - ChessCoordinate.class+": Invalid coordinate."; private char file; private int rank; - public ChessCoordinate(char file, int rank) throws Exception { - if(isInvalid(file, rank)) - throw new Exception(ERROR_MSG); - + public ChessCoordinate(char file, int rank) { this.file = file; this.rank = rank; } - public ChessCoordinate(int file, int rank) throws Exception { + public ChessCoordinate(int file, int rank) { this((char) (file-1+97), rank); // 97 = 'a' } - public void set(char x, int y) throws Exception { - if(isInvalid(x,y)) - throw new Exception(ERROR_MSG); - + public void set(char x, int y) { this.file = x; this.rank = y-1; } @@ -45,12 +37,6 @@ public class ChessCoordinate { return file - 96; // 97 = 'a' } - private boolean isInvalid(char x, int y) { - if(x > 'h' || x < 'a' || y > 8 || y < 1) - return true; - return false; - } - public String toString() { return ""+file+rank; }