public void update_history_Test() { var options = new Dictionary <string, string>(); options["ct-depth"] = "4"; options["agent-horizon"] = "6"; options["mc-simulations"] = "1"; //original value=300 options["random-seed"] = "5"; CoinFlip env = new CoinFlip(options); MC_AIXI_CTW agent = new MC_AIXI_CTW(env, options); IModel ct = agent.ContextTree; ct.update_tree_history(5); int[] ints = { 10, 11, 12 }; ct.update_tree_history(ints); Assert.AreEqual(4, ct.History.Count); Assert.AreEqual(5, ct.History[0]); Assert.AreEqual(10, ct.History[1]); Assert.AreEqual(11, ct.History[2]); Assert.AreEqual(12, ct.History[3]); }
public void setExpectedToZeroTest() { CoinFlip CF = new CoinFlip(); CF.setExpected(0); Assert.AreEqual(0, CF.getExpected()); }
static void Main(string[] args) { using (var sim = new QuantumSimulator()) { var count = 10000; var res = QBitRead.Run(sim, count).Result; var(numZeros, numOnes) = res; System.Console.WriteLine($"QBitRead \t\t 0s={numZeros,0} \t 1s={numOnes,0}"); res = CoinFlip.Run(sim, count).Result; (numZeros, numOnes) = res; System.Console.WriteLine($"CoinFlip \t\t 0s={numZeros,0} \t 1s={numOnes,0}"); res = DoubleCoinFlip.Run(sim, count).Result; (numZeros, numOnes) = res; System.Console.WriteLine($"DoubleCoinFlip \t\t 0s={numZeros,0} \t 1s={numOnes,0}"); res = BlindDoubleCoinFlip.Run(sim, count).Result; (numZeros, numOnes) = res; System.Console.WriteLine($"BlindDoubleCoinFlip \t 0s={numZeros,0} \t 1s={numOnes,0}"); } System.Console.WriteLine("Press any key to continue..."); System.Console.ReadKey(); }
public void setExpectedToOneTest() { CoinFlip CF = new CoinFlip(); CF.setExpected(1); Assert.AreEqual(1, CF.getExpected()); }
public void CheckCoinflipExceptedStartsAsOneTest() { CoinFlip CF = new CoinFlip(); //Check origonal Value Assert.AreEqual(1, CF.getExpected()); }
private void CreateBillboardIfEliglible(IBillboardBuilder builder, Vector3 position, Vector2 area) { if (builder.HasBillboards()) { var northSouthSideLength = area.X; var eastWestSideLength = area.Y; if (northSouthSideLength > eastWestSideLength) { if (northSouthSideLength >= builder.CalculateBillboardWidth(3)) { var billboard = CoinFlip.Flip() ? builder.CreateNorthFacingBillboard(position, area, 3) : builder.CreateSouthFacingBillboard(position, area, 3); _meshes.AddRange(billboard.Meshes); } } else { if (eastWestSideLength >= builder.CalculateBillboardWidth(3)) { var billboard = CoinFlip.Flip() ? builder.CreateWestFacingBillboard(position, area, 3) : builder.CreateEastFacingBillboard(position, area, 3); _meshes.AddRange(billboard.Meshes); } } } }
public void ReturnsCoinFlipLoss() { var expectedGameResult = GameResult.Lost; var coinFlip = new CoinFlip(); var actualGameResult = coinFlip.GetGameResult(SideOfCoin.Heads, SideOfCoin.Tails); Assert.AreEqual(expectedGameResult, actualGameResult); }
static void Main(string[] args) { using (var qsim = new QuantumSimulator()) { var res = CoinFlip.Run(qsim, 1000).Result; var(numZeros, numOnes) = res; System.Console.WriteLine( $"0s={numZeros} 1s={numOnes}"); } }
public AgentTest() { this.Options = new Dictionary <string, string>(); Options["ct-depth"] = "4"; Options["agent-horizon"] = "6"; Options["mc-simulations"] = "200"; this.Env = new CoinFlip(Options); this.Agent = new MC_AIXI_CTW(Env, Options); }
public void setExpectedToWrongValuesTest() { CoinFlip CF = new CoinFlip(); //If the coin flip is set to a number other than 1 or 0 it will do nothing CF.setExpected(2); Assert.AreNotEqual(2, CF.getExpected()); Assert.AreEqual(1, CF.getExpected()); CF.setExpected(-1); Assert.AreNotEqual(-1, CF.getExpected()); Assert.AreEqual(1, CF.getExpected()); }
// Use this for initialization void Start() { m_playerManagers = new List <Manager>(); Manager player1Manager = GameObject.FindGameObjectWithTag("ManagerP1").GetComponent <Manager>(); m_playerAmount = player1Manager.Controllers; for (int i = 0; i < m_playerAmount; i++) { m_playerManagers.Add(GameObject.FindGameObjectWithTag("ManagerP" + (i + 1)).GetComponent <Manager>()); } CoinSpawn = GetComponentInParent <CoinSpawn>(); flip = GetComponentInParent <CoinFlip>(); }
public void revert_history_Test() { var options = new Dictionary <string, string>(); options["ct-depth"] = "4"; options["agent-horizon"] = "6"; options["mc-simulations"] = "1"; //original value=300 options["random-seed"] = "5"; CoinFlip env = new CoinFlip(options); MC_AIXI_CTW agent = new MC_AIXI_CTW(env, options); agent.ModelUpdatePercept(1, 1); var ct = agent.ContextTree; Assert.AreEqual(2, ct.History.Count); ct.revert_tree_history(1); Assert.AreEqual(1, ct.History.Count); }
// Update is called once per frame void Update() { value1 = randomize.value1; seconds = timer.seconds; minutes = timer.minutes; environmentTilt = outsideInfluence.environmentTilt; if (d2 != null) { preserved = d2.preserved; } if (GameObject.FindGameObjectWithTag("coin") != null) { coinFlip = GameObject.FindGameObjectWithTag("coin").GetComponent <CoinFlip> (); } if (coinFlip != null) { decision4 = coinFlip.face; } }
public static void Example(CoinFlip coinFlip) { #region snippet // ERROR Enum value not handled by switch: Tails switch (coinFlip) { default: throw ExhaustiveMatch.Failed(coinFlip); case CoinFlip.Heads: Console.WriteLine("Heads!"); break; } // ERROR Enum value not handled by switch: Tails _ = coinFlip switch { CoinFlip.Heads => "Heads!", _ => throw ExhaustiveMatch.Failed(coinFlip), }; #endregion }
/// <summary> /// Initializes all variables needed to run the script. /// </summary> void Start () { GameObject GameController = GameObject.FindGameObjectWithTag("GameController"); BR = GameController.GetComponent<BallReset>(); GT = GameController.GetComponent<GameTimer>(); CF = new CoinFlip(); if (CF.Flip()) { // Red team won toss, blue will get ball next half ball.GetComponent<Possession>().SetNextHalfPossession(Possession.Team.blue); // Give the ball to the red team BR.placeBallRSC(); } else { // Blue team won toss, red will get the ball next half ball.GetComponent<Possession>().SetNextHalfPossession(Possession.Team.red); // Give the ball to the blue team BR.placeBallBSC(); } setupDone = true; }
public void EnvironmentClassTest() { var options = new Dictionary <string, string>(); CoinFlip e = new CoinFlip(options); Assert.AreEqual(false, e.IsFinished); if (!(e.Observation == e.OHead || e.Observation == e.OTail)) { Assert.Fail("invalid observation: {0}", e.Observation); } if (e.Reward != e.RLose && e.Reward != e.RWin) { Assert.Fail("invalid reward"); } int [] correctEnum = { 0, 1 }; //correct for actions, observations and rewards if (!e.ValidActions.SequenceEqual(correctEnum)) { Assert.Fail("valid actions are wrong"); } if (!e.ValidObservations.SequenceEqual(correctEnum)) { Assert.Fail("valid actions are wrong"); } if (!e.ValidRewards.SequenceEqual(correctEnum)) { Assert.Fail("valid actions are wrong"); } Assert.AreEqual(1, e.actionBits()); Assert.AreEqual(1, e.observationBits()); Assert.AreEqual(2, e.perceptBits()); Assert.AreEqual(1, e.rewardBits()); Assert.AreEqual(false, e.IsValidAction(-1)); Assert.AreEqual(true, e.IsValidAction(1)); Assert.AreEqual(true, e.IsValidAction(0)); Assert.AreEqual(false, e.IsValidAction(2)); Assert.AreEqual(false, e.IsValidObservation(-1)); Assert.AreEqual(true, e.IsValidObservation(1)); Assert.AreEqual(true, e.IsValidObservation(0)); Assert.AreEqual(false, e.IsValidObservation(2)); Assert.AreEqual(false, e.IsValidReward(-1)); Assert.AreEqual(true, e.IsValidReward(1)); Assert.AreEqual(true, e.IsValidReward(0)); Assert.AreEqual(false, e.IsValidReward(2)); Assert.AreEqual(1, e.maximum_action()); Assert.AreEqual(1, e.maximum_observation()); Assert.AreEqual(1, e.maximum_reward()); Assert.AreEqual(0, e.minimum_action()); Assert.AreEqual(0, e.minimum_observation()); Assert.AreEqual(0, e.minimum_reward()); //doing all possible actions e.PerformAction(0); Tuple <int, int> res = e.PerformAction(1); Assert.AreEqual(1, e.Action);//TODO: test other state vars if (e.Reward != e.RLose && e.Reward != e.RWin) { Assert.Fail("invalid reward"); } if (e.Observation != e.OHead && e.Observation != e.OTail) { Assert.Fail("invalid reward"); } Assert.AreEqual(res.Item1, e.Observation); Assert.AreEqual(res.Item2, e.Reward); }
public async Task coin([Summary("The id of your opponent, playing against yourself is supported if you put your own id")] string recipitantid, [Summary("A string of bits (0 or 1) seperated by $")] string bits, [Summary("Type of encoding used, rectilinear or diagonal. ('rect' or 'diag')")] string encoding) { var recipitant = Context.Client.GetUser(ulong.Parse(recipitantid)); if (usersInGame.Keys.Any(a => a.Contains(recipitant.Id.ToString()))) { await ReplyAsync("person is already in a game"); return; } IUser sender = Context.User; if (usersInGame.Keys.Any(a => a.Contains(sender.Id.ToString()))) { await ReplyAsync("cannot start a new game while in a game"); return; } usersInGame.Add(recipitant.Id.ToString() + "$" + sender.Id.ToString(), ""); if (encoding != "rect" && encoding != "diag") { await ReplyAsync("use arguments 'rect' and 'diag' only for the encryption field"); return; } using var sim = new QuantumSimulator(); if (bits.Split("$").Any(a => a != "1" && a != "0")) { await ReplyAsync("make sure bits only consist of 1s and 0s and seperators ($)"); return; } var elements = bits.Split("$").Select(a => a == "1"); if (elements.Count() != 5) { await ReplyAsync("please enter exactly 5 bits"); return; } Random rng = new Random(); bool[] decoding = new bool[5]; for (int i = 0; i < rng.Next((int)Round((double)5 / 2, MidpointRounding.ToZero), (int)Round((double)5 / 2, MidpointRounding.AwayFromZero) + 1); i++) { decoding[i] = true; } int n = decoding.Length; for (int i = 0; i < (n - 1); i++) { int r = i + rng.Next(n - i); var t = decoding[r]; decoding[r] = decoding[i]; decoding[i] = t; } var result = await CoinFlip.Run(sim, new QArray <bool>(elements), encoding == "rect", new QArray <bool>(decoding)); string[] final = new string[5]; for (int i = 0; i < 5; i++) { if (decoding[i]) { final[i] = $"{(result[i] == Result.One ? "1" : "0")}| "; } else { final[i] = $" |{(result[i] == Result.One ? "1" : "0")}"; } } usersInGame.Remove(recipitant.Id.ToString() + "$" + sender.Id.ToString()); usersInGame.Add(recipitant.Id.ToString() + "$" + sender.Id.ToString(), encoding + "%" + bits + "%" + string.Join("\n", final)); await recipitant.SendMessageAsync("decoding results from " + sender.ToString() + ":\n```R|D\n" + string.Join("\n", final) + "``` Use '\\`guess [rect/diag]' to guess the type of encryption used."); await Context.Message.AddReactionAsync(new Emoji("✅")); }