public async Task <decimal> Run(AnalysisConfiguration analysisConfiguration, IUpdateProgress updateProgress) { decimal currentBet = analysisConfiguration.StartingAnte; _logger.LogInformation($"Run: Start currentBet: {currentBet}"); // Create the dealer var dealer = new Dealer() { Money = 9999999999 // House has infinite funds }; // Create the table var table = new Table(dealer); // Create and shuffle the shoe var shoe = new Shoe(4); shoe.Cards.Shuffle(); // Create the player and sit at the table var player = new Player() { Money = analysisConfiguration.PlayerFunds, Ante = analysisConfiguration.StartingAnte, Strategy = BuildStrategy( analysisConfiguration.AvailableActions, Deck.CreateDeck().Cards) }; table.SitPlayer(player); // Play each hand _playHand.Init(shoe.Cards, table); while (player.Money > 0 && player.Money < analysisConfiguration.TargetFunds && currentBet <= player.Money) { await updateProgress.Update(player.Money, analysisConfiguration.TargetFunds); _playHand.PlayerAnte(player, currentBet); _playHand.Deal(); _logger.LogInformation($"Run: Dealt Players {string.Join(", ", _playHand.Table.Players.SelectMany(a => a.Hand.Cards).Select(a => a.Description))}"); _logger.LogInformation($"Run: Dealt Dealer {string.Join(", ", _playHand.Table.Dealer.Hand.Cards.Select(a => a.Description))}"); while (_playHand.GameInProgress) { _playHand.Play(); } _logger.LogInformation($"Run: Play Finished Players {string.Join(", ", _playHand.Table.Players.SelectMany(a => a.Hand.Cards).Select(a => a.Description))}"); _logger.LogInformation($"Run: Play Finished Dealer {string.Join(", ", _playHand.Table.Dealer.Hand.Cards.Select(a => a.Description))}"); bool playerWins = _playHand.Payout(); currentBet = BettingStrategyHelper.DetermineBet( currentBet, analysisConfiguration.BettingStrategy, playerWins, analysisConfiguration.TargetFunds, player.Money); _logger.LogInformation($"Run: Player Funds {string.Join(", ", _playHand.Table.Players.Select(a => a.Money))}"); } return(player.Money); }
public void CalcMotionSimilarity(IUpdateProgress updater) { frames_ = IndexMotionSeg(); updater.Update("collect frames info", 0.0f); string[] jointName = new string[] { "Bip01 L Thigh", "Bip01 R Thigh", "Bip01 L Calf", "Bip01 R Calf", "Bip01 L UpperArm", "Bip01 R UpperArm", "Bip01 L Forearm", "Bip01 R Forearm", }; quat_ = new Quaternion[totalBeats_, NumSamplesPerBeat, jointName.Length]; int beatIndex = 0; foreach (var frame in frames_) { var resName = string.Format("Assets/DanceMotion/resource/{0}/{0}.prefab", frame.name); Debug.Log("load " + resName); var res = (GameObject)AssetDatabase.LoadAssetAtPath(resName, typeof(GameObject)); Debug.Log("load " + resName); var inst = GameObject.Instantiate(res); Transform[] joints = new Transform[jointName.Length]; for (int i = 0; i < jointName.Length; i++) { GameObject o = Utility.FindGameObjectByName_r(inst, jointName[i]); if (o == null) { Debug.LogFormat("can not found gameobject {0}", jointName[i]); } else { joints[i] = o.transform; } } Animation animation = inst.GetComponent <Animation>(); AnimationState state = animation["Take 001"]; state.weight = 1.0f; state.enabled = true; float dt = frame.beatTime / (float)NumSamplesPerBeat; float invdt = 1.0f / dt; for (int i = 0; i < frame.numBeats; i++) { for (int j = 0; j < NumSamplesPerBeat; j++) { float time = frame.startTime + dt * (i * NumSamplesPerBeat + j); state.time = time; animation.Sample(); for (int k = 0; k < joints.Length; k++) { quat_[beatIndex, j, k] = joints[k].localRotation; } } beatIndex++; } GameObject.DestroyImmediate(inst); } int numCost = EstimateCostCount(); cost_esti_ = new List <float>(); for (int i = 0; i < totalBeats_; i++) { for (int j = i + 1; j < totalBeats_; j++) { float cost = MotionSeqCost(quat_, i, j); cost_esti_.Add(cost); } float progress = cost_esti_.Count / (float)numCost; updater.Update("calculate cost", progress); } if (cost_esti_.Count != numCost) { Debug.LogFormat("cost {0} estimate {1}", cost_esti_.Count, numCost); throw new Exception("value count invalid"); } updater.Update("save to file", 1.0f); FileStream fs = new FileStream("MotionCost.bin", FileMode.Create, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs); bw.Write(frames_.Count); foreach (var f in frames_) { var chars = f.name.ToCharArray(); bw.Write(chars.Length); bw.Write(chars); bw.Write(f.numBeats); Debug.LogFormat("chars {0} {1} {2}", chars.Length, f.name, f.numBeats); } bw.Write(cost_esti_.Count); foreach (var v in cost_esti_) { bw.Write(v); } bw.Close(); fs.Close(); Debug.Log("Done!"); }