// TT4DStats.java /** * * @author Sean Bridges * @version 1.0 * * The TT4DStats keeps track of how well each player is doing. * Keeps track of the number of rows each player has 1,2 and 3 makers in * while their opponent has 0 markers in. * * Can return an evaluation of how each player is doing based on these stats. */ public class TT4DStats implements BoardStats { //---------------------------------------- //class variables private static final int rowPoints = 100; private static final int with2Points = 20; private static final int with1Points = 1; //---------------------------------------- //instance variables private int xRows, oRows, xWith2, oWith2, xWith1, oWith1; //---------------------------------------- //instance methods public final void incXRows() { xRows++; } public final void incORows() { oRows++; } public final void incXWith1() { xWith1++; } public final void incXWith2() { xWith2++; } public final void incOWith1() { oWith1++; } public final void incOWith2() { oWith2++; } public final void decXRows() { xRows--; } public final void decORows() { oRows--; } public final void decXWith1() { xWith1--; } public final void decXWith2() { xWith2--; } public final void decOWith1() { oWith1--; } public final void decOWith2() { oWith2--; } public TT4DStats copy() { TT4DStats t = new TT4DStats(); t.xRows = xRows; t.oRows = oRows; t.xWith1 = xWith1; t.xWith2 = xWith2; t.oWith1 = oWith1; t.oWith2 = oWith2; return t; } private int xPoints() { return (xRows * rowPoints) + (xWith2 * with2Points) + (xWith1 * with1Points); } private int oPoints() { return (oRows * rowPoints) + (oWith2 * with2Points) + (oWith1 * with1Points); } //------------------------------------ //BoardStat methods /** * Get the score for the given player. * A score is an indisputable thing, such as the number of hits in battleship. */ public int getScore(Player aPlayer) { if(aPlayer.getNumber() == TT4DBoard.X_PLAYER_NUMBER) { return xRows; } if(aPlayer.getNumber() == TT4DBoard.O_PLAYER_NUMBER) { return oRows; } System.err.println("Invalid player"); Thread.dumpStack(); return 0; } /** * Get an evaluation of how well a player is doing. * The number returned could b debabtable, such as a measure * of how strong a chess players position is */ public int getStrength(Player aPlayer) { if(aPlayer.getNumber() == TT4DBoard.X_PLAYER_NUMBER) { return xPoints() - oPoints(); } if(aPlayer.getNumber() == TT4DBoard.O_PLAYER_NUMBER) { return oPoints() - xPoints(); } System.err.println("Invalid player"); Thread.dumpStack(); return 0; } /** * Returns the maximum possible hueristic. */ public int getMaxStrength() { return Integer.MAX_VALUE; } /** * Returns the minimum possible hueristic. */ public int getMinStrength() { return Integer.MIN_VALUE; } public String toString() { return "TT4dStats: X Score:" + xRows + " OScore:" + oRows + " xStrength:" + (xPoints() - oPoints()) + "\n" + "xWith2:" + xWith2 + " xWith1:" + xWith1 + "\n" + "oWith2:" + oWith2 + " oWith1:" + oWith1; } }//end TT4DStats