public static void printActionValues() { TabularQLearningForTwo tq = tabularQLearnings.get(0); if (tq.isPriestessProtectionAddedToState()) { System.out.println("Opponent is protected by priestess"); State state = new State(Card.Soldier, Card.Soldier); state.setOpponentProtectedByPriestess(true); printActionValues(state); System.out.println("Opponent is not protected by priestess"); state = new State(Card.Soldier, Card.Soldier); state.setOpponentProtectedByPriestess(false); printActionValues(state); } else if (tq.isUsedCardsNumAddedToState()) { for (int i = 0; i <= 12; i++) { System.out.println(String.format("Number of used cards is %d", i)); State state = new State(Card.Soldier, Card.Soldier); state.setUsedCardsNum(i); printActionValues(state); } } else if (tq.isOpponentHandByClownAddedToState()) { System.out.println("Opponent hand is unknown"); State state = new State(Card.Soldier, Card.Soldier); state.setOpponentHand(null); printActionValues(state); for (Card opponentHand : Card.values()) { System.out.println(String.format("Opponent hand is %s", opponentHand)); state = new State(Card.Soldier, Card.Soldier); state.setOpponentHand(opponentHand); printActionValues(state); } } else { State state = new State(Card.Soldier, Card.Soldier); printActionValues(state); } }
private static double getAverageValue(State state, Action action) { double sumValue = 0.0; for (TabularQLearningForTwo tq : tabularQLearnings) { sumValue += tq.getActionValue(state, action).getValue(); } return sumValue / tabularQLearnings.size(); }
public static void main(String[] args) { // String csvPathTemplate = "./data/plain/%d.csv"; // String csvPathTemplate = "./data/addPriestessProtectionToState/%d.csv"; // String csvPathTemplate = "./data/addUsedCardsNumToState/%d.csv"; String csvPathTemplate = "./data/addOpponentHandByClownToState/%d.csv"; // String csvPathTemplate = "./data/addTargetCardForSoldierToAction/%d.csv"; // String csvPathTemplate = "./data/addTargetPlayerForWizardToAction/%d.csv"; tabularQLearnings = new ArrayList<TabularQLearningForTwo>(); for (int ti = 0; ti < 10; ti++) { TabularQLearningForTwo tabularQLearning = new TabularQLearningForTwo(); String csvPath = String.format(csvPathTemplate, ti); tabularQLearning.loadActionValuesFromCSV(csvPath); tabularQLearnings.add(tabularQLearning); } printActionValues(); }
private static void printActionValues(State templateState) { TabularQLearningForTwo tq = tabularQLearnings.get(0); System.out.print(String.format("%15s", "")); for (Card hand : Card.values()) { System.out.print(String.format("%15s", hand)); } System.out.println(""); for (Card hand1 : Card.values()) { if (hand1 == Card.Soldier && tq.isTargetCardForSoldierAddedToAction()) { for (Card targetCard : Card.values()) { if (targetCard != Card.Soldier) { System.out.print(String.format("%12s(%d)", hand1, targetCard.getStrength())); for (Card hand2 : Card.values()) { State state = new State(hand1, hand2); state.setOpponentProtectedByPriestess(templateState.isOpponentProtectedByPriestess()); state.setUsedCardsNum(templateState.getUsedCardsNum()); state.setOpponentHand(templateState.getOpponentHand()); Action action = new Action(hand1); action.setTargetCardForSoldier(targetCard); System.out.print(String.format("%15.3f", getAverageValue(state, action))); } System.out.println(""); } } } else if (hand1 == Card.Wizard && tq.isTargetPlayerForWizardAddedToAction()) { System.out.print(String.format("%12s(m)", hand1)); for (Card hand2 : Card.values()) { if (isPossibleHands(hand1, hand2)) { State state = new State(hand1, hand2); state.setOpponentProtectedByPriestess(templateState.isOpponentProtectedByPriestess()); state.setUsedCardsNum(templateState.getUsedCardsNum()); state.setOpponentHand(templateState.getOpponentHand()); Action action = new Action(hand1); action.setTargetMyselfForWizard(true); System.out.print(String.format("%15.3f", getAverageValue(state, action))); } else { System.out.print(String.format("%15s", "-----")); } } System.out.println(""); System.out.print(String.format("%12s(o)", hand1)); for (Card hand2 : Card.values()) { if (isPossibleHands(hand1, hand2)) { State state = new State(hand1, hand2); state.setOpponentProtectedByPriestess(templateState.isOpponentProtectedByPriestess()); state.setUsedCardsNum(templateState.getUsedCardsNum()); state.setOpponentHand(templateState.getOpponentHand()); Action action = new Action(hand1); action.setTargetMyselfForWizard(false); System.out.print(String.format("%15.3f", getAverageValue(state, action))); } else { System.out.print(String.format("%15s", "-----")); } } System.out.println(""); } else { System.out.print(String.format("%15s", hand1)); for (Card hand2 : Card.values()) { if (isPossibleHands(hand1, hand2)) { State state = new State(hand1, hand2); state.setOpponentProtectedByPriestess(templateState.isOpponentProtectedByPriestess()); state.setUsedCardsNum(templateState.getUsedCardsNum()); state.setOpponentHand(templateState.getOpponentHand()); Action action = new Action(hand1); System.out.print(String.format("%15.3f", getAverageValue(state, action))); } else { System.out.print(String.format("%15s", "-----")); } } System.out.println(""); } } }