public void GetAction(HandHistory history, out holdem_engine.Action.ActionTypes action, out double amount) { var xml = history.ToXmlHand(); int rIdx = (int)history.CurrentRound - 1; int aIdx = xml.Rounds[rIdx].Actions.Length; var features = _featureGen.GenerateMonolithicNeuralNetworkFeatures(xml, rIdx, aIdx, false); for(int i = 0; i < features.Length; i++) { var feature = features[i]; if(feature < 0 || feature > 1) { _featureGen.PrintFeatureList(); throw new Exception(string.Format("Feature {0}: {1}", i, feature)); } } // Console.WriteLine("{0} features", features.Length); // Console.WriteLine("Features: {0}", features.Flatten()); var probs = _network.Activate(features); //Console.WriteLine("Raw Probs: {0}", probs.Flatten()); probs.Normalize(); //Console.WriteLine("Normalized: {0}", probs.Flatten()); int result = _rand.SampleFromDistribution(probs); if (result == 0) action = holdem_engine.Action.ActionTypes.Fold; else if (result == 1) action = holdem_engine.Action.ActionTypes.Call; else if (result == 2) action = holdem_engine.Action.ActionTypes.Raise; else throw new Exception("Unknown class: " + result); amount = 0; }
public void GetAction(HandHistory history, out holdem_engine.Action.ActionTypes type, out double amount) { PokerHandHistory.PokerHand xml = history.ToXmlHand(); PokerHandHistory.PokerHandXML hands = new PokerHandHistory.PokerHandXML(){ Hands = new PokerHandHistory.PokerHand[] { xml } }; StringBuilder sb = new StringBuilder(); using(TextWriter writer = new StringWriter(sb)) { XmlSerializer ser = new XmlSerializer(typeof(PokerHandHistory.PokerHandXML)); ser.Serialize(writer, hands); } Console.WriteLine(sb.ToString()); if (actions != null && curAction < actions.Length) { holdem_engine.Action action = actions[curAction++]; type = action.ActionType; amount = action.Amount; } else { type = holdem_engine.Action.ActionTypes.Fold; amount = 0; } }
public void GetAction(HandHistory history, out holdem_engine.Action.ActionTypes action, out double amount) { var xml = history.ToXmlHand(); int rIdx = (int)history.CurrentRound - 1; int aIdx = xml.Rounds[rIdx].Actions.Length; var features = _featureGen.GenerateFeatures(xml, rIdx, aIdx, _instances[rIdx], false); var classifier = _models[rIdx]; int result; // Mixed policies take a randomized action based on a probability distribution. if (MixedPolicy) { double[] dist = classifier.distributionForInstance(features); result = _rand.SampleFromDistribution(dist); } else { // Otherwise, the policy is a pure strategy taking deterministic actions. result = (int)classifier.classifyInstance(features); } if (result == 0) action = holdem_engine.Action.ActionTypes.Fold; else if (result == 1) action = holdem_engine.Action.ActionTypes.Call; else if (result == 2) action = holdem_engine.Action.ActionTypes.Raise; else throw new Exception("Unknown class: " + result); amount = 0; }
public void GetAction(HandHistory history, out holdem_engine.Action.ActionTypes action, out double amount) { // Console.WriteLine(history.ToString()); // Console.WriteLine(); // Console.WriteLine(); var xml = history.ToXmlHand(); int rIdx = (int)history.CurrentRound - 1; int aIdx = xml.Rounds[rIdx].Actions.Length; // Console.WriteLine("rIdx: {0} aIdx: {1}", rIdx, aIdx); // StringBuilder sb = new StringBuilder(); // using(TextWriter writer = new StringWriter(sb)) // { // XmlSerializer ser = new XmlSerializer(typeof(PokerHandHistory.PokerHand)); // ser.Serialize(writer, xml); // } // Console.WriteLine(sb.ToString()); var features = _featureGen.GenerateFeatures(xml, rIdx, aIdx, _instances[rIdx], false); var classifier = _models[rIdx]; int result; // Mixed policies take a randomized action based on a probability distribution. if(MixedPolicy) { double[] dist = classifier.distributionForInstance(features); double prev = 0; double sample = _rand.NextDouble(); result = -1; for(int i = 0; i < dist.Length; i++) { double val = prev + dist[i]; if(val < sample) { result = i; break; } } } else { // Otherwise, the policy is a pure strategy taking deterministic actions. result = (int)classifier.classifyInstance(features); } if(result == 0) action = holdem_engine.Action.ActionTypes.Fold; else if(result == 1) action = holdem_engine.Action.ActionTypes.Call; else if (result == 2) action = holdem_engine.Action.ActionTypes.Raise; else throw new Exception("Unknown class: " + result); amount = 0; }
public void GetAction(HandHistory history, out holdem_engine.Action.ActionTypes action, out double amount) { Console.WriteLine(history.ToString()); action = getAction(); amount = 0; }