import java.util.*; public class Player implements Comparable { public int[][] iDecisionMatrix; public int iScore; public int iWins; public int iGameCount; public int iRunningScore; public int iRunningGameCount; public String sShortType = "Default"; public String sName = "Default"; //Default Constructor public Player() { iScore = 0; iWins = 0; iGameCount = 0; iRunningScore = 0; iRunningGameCount = 0; iDecisionMatrix = GenerateDecisionMatrix("Random"); } //Initialized Constructor public Player(String sInitType) { iScore = 0; iWins = 0; iGameCount = 0; iRunningScore = 0; iRunningGameCount = 0; iDecisionMatrix = GenerateDecisionMatrix(sInitType); } //Child Constructor - For when the decision matrix is made via breeding public Player(int[][] DecMatrix) { iScore = 0; iWins = 0; iGameCount = 0; iRunningScore = 0; iRunningGameCount = 0; iDecisionMatrix = DecMatrix; } public int[][] GenerateDecisionMatrix(String sInitType) { int[][] ReturnedMatrix = new int[17][10]; if (sInitType.equals("S17")) { int[][] DecMatrix = { {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 4 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 5 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 6 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 7 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 8 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 9 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 10 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 11 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 12 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 13 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 14 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 15 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 16 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //Score = 17 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //Score = 18 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //Score = 19 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1} //Score = 20 }; ReturnedMatrix = DecMatrix; } else if (sInitType.equals("H17")) { int[][] DecMatrix = { {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 4 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 5 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 6 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 7 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 8 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 9 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 10 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 11 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 12 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 13 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 14 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 15 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 16 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 17 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //Score = 18 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //Score = 19 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1} //Score = 20 }; ReturnedMatrix = DecMatrix; } else if (sInitType.equals("WoO")) { int[][] DecMatrix = { {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 4 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 5 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 6 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 7 {2, 2, 2, 3, 3, 2, 2, 2, 2, 2}, //Score = 8 {3, 3, 3, 3, 3, 2, 2, 2, 2, 2}, //Score = 9 {3, 3, 3, 3, 3, 3, 3, 3, 2, 2}, //Score = 10 {3, 3, 3, 3, 3, 3, 3, 3, 3, 3}, //Score = 11 {1, 1, 1, 1, 1, 2, 2, 2, 2, 2}, //Score = 12 {1, 1, 1, 1, 1, 2, 2, 2, 2, 2}, //Score = 13 {1, 1, 1, 1, 1, 2, 2, 2, 2, 2}, //Score = 14 {1, 1, 1, 1, 1, 2, 2, 2, 2, 2}, //Score = 15 {1, 1, 1, 1, 1, 2, 2, 2, 0, 0}, //Score = 16 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //Score = 17 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //Score = 18 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //Score = 19 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1} //Score = 20 }; ReturnedMatrix = DecMatrix; } else if (sInitType.equals("BB")) { int[][] DecMatrix = { {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 4 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 5 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 6 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 7 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, //Score = 8 {2, 3, 3, 3, 3, 2, 2, 2, 2, 2}, //Score = 9 {3, 3, 3, 3, 3, 3, 3, 3, 2, 2}, //Score = 10 {3, 3, 3, 3, 3, 3, 3, 3, 3, 2}, //Score = 11 {2, 2, 1, 1, 1, 2, 2, 2, 2, 2}, //Score = 12 {1, 1, 1, 1, 1, 2, 2, 2, 2, 2}, //Score = 13 {1, 1, 1, 1, 1, 2, 2, 2, 2, 2}, //Score = 14 {1, 1, 1, 1, 1, 2, 2, 2, 0, 2}, //Score = 15 {1, 1, 1, 1, 1, 2, 2, 0, 0, 0}, //Score = 16 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //Score = 17 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //Score = 18 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //Score = 19 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1} //Score = 20 }; ReturnedMatrix = DecMatrix; } else { Random generator = new Random(); for (int i = 0; i < 17; i++) { for (int j = 0; j < 10; j++) { ReturnedMatrix[i][j] = generator.nextInt(5); } } } return ReturnedMatrix; } public String getShortType() { return sShortType; } public int call(int iPlayerNum, int iPlayers, Hand[] hPlayers) { int iPlayer = hPlayers[iPlayerNum].getScore()-4; int iDealer = hPlayers[0].faceCard()-2; if (iPlayer == 17) return 1; if (iPlayer < 0 || iPlayer > 17 || iDealer < 0 || iDealer > 9) return 0; return iDecisionMatrix[iPlayer][iDealer]; } public String getName() { return sName; } public int getRunningScore() { if (iRunningScore==0) return 0; return (int) 100 * iRunningScore/iRunningGameCount; } public int getWins() { return iWins; } public int getScore() { if (iScore==0) return 0; return (int) 100 * iScore/iGameCount; } public void updateScore(int iProfit) { iScore = iScore + iProfit; iRunningScore = iRunningScore + iProfit; iGameCount++; iRunningGameCount++; if (iProfit > 0) iWins++; } public void reset() { iRunningScore = 0; iRunningGameCount = 0; } public String toString() { String sOutput = sName+":\n"; for (int i = 0; i < 17; i++) { sOutput+="["; for (int j = 0; j < 10; j++) { sOutput+=" "+iDecisionMatrix[i][j]; } sOutput+=" ] Score = "+(i+4)+"\n"; } sOutput+="\n"; return sOutput; } public int compareTo(Object obj) { Player comp = (Player) obj; if (this.getScore() < comp.getScore()) return 1; if (this.getScore() > comp.getScore()) return -1; return 0; } public void run(int iIterations) { Player[] pPlayers = new Player[2]; pPlayers[0]= new Player("S17"); pPlayers[1]= this; pPlayers[1].reset(); Table cTable = new Table(pPlayers); for (int i = 0; i < iIterations; i++) { cTable.play(); } cTable.print(); cTable.record(pPlayers[1].getShortType()+ "-Primary.txt"); cTable.recordSimple(pPlayers[1].getShortType()+"-Simple.txt"); pPlayers[1].reset(); } public void run2(int iIterations) { Player[] pPlayers = new Player[2]; pPlayers[0]= new Player("S17"); pPlayers[1]= this; pPlayers[1].reset(); Table cTable = new Table(pPlayers); for (int i = 0; i < iIterations; i++) { cTable.play(); } cTable.print(); cTable.record2(pPlayers[1].getShortType()+ "-Primary.txt"); cTable.recordSimple2(pPlayers[1].getShortType()+"-Simple.txt"); pPlayers[1].reset(); } public static void main (String[] args) { Player Test = new Player("BB"); System.out.println(Test.toString()); Player Test2 = new Player("WoO"); System.out.println(Test2.toString()); Test.run(1000); Test2.run2(1000); /* Player S17 = new PlayerS17(); Player H17 = new PlayerH17(); Player RoT = new PlayerRuleofThumb(); Player WoO = new PlayerWizardofOdds(); for (int i = 0; i < 75; i++) { System.out.println("Run #"+i+": "+(new Date()).toString()); S17.run(100); S17.run(100); S17.run(100000); S17.run(100000); H17.run(100); H17.run(100); H17.run(100000); H17.run(100000); RoT.run(100); RoT.run(100); RoT.run(100000); RoT.run(100000); WoO.run(100); WoO.run(100); WoO.run(100000); WoO.run(100000); } //*/ } }