public Variant.Type SelectBestAvailableChoice() { int highestValue = 0; Variant.Type highVariant = 0; int[] getValueByVariants = new int[variant.Length()]; // NullReferenceException here when resuming game foreach (Variant.Type vari in variant.GetList()) { int i = variant.GetValue(vari); getValueByVariants[i] = rules.GetValueByVariant(vari); if (vari != variant.Chance() && !GetPickedChoice(vari) && getValueByVariants[i] >= highestValue) { highestValue = getValueByVariants[i]; highVariant = vari; } } getValueByVariants[12] = rules.GetValueByVariant(variant.Chance()); if (!GetPickedChoice(variant.Chance()) && getValueByVariants[12] > highestValue && highestValue <10 && highVariant> variant.Threes() && highVariant < variant.Yahtzee()) { highVariant = variant.Chance(); } return(highVariant); }
public Variant.Type type() { Variant.Type result = (Variant.Type)AppUtilPINVOKE.Variant_type(this.swigCPtr); if (AppUtilPINVOKE.SWIGPendingException.Pending) { throw AppUtilPINVOKE.SWIGPendingException.Retrieve(); } return(result); }
public bool GetPickedChoice(Variant.Type variant) { Score score = scoreList.Find(scoreObj => scoreObj.TakenChoice == variant); if (score != null) { return(true); } return(false); }
public List <Player> GetPlayersFromFile(InterfaceRules rules, string fileName, out DateTime date, out int roundNumber) { string line; this.playersfromfile = new List <Player>(); List <string> items = new List <string>(); var savingDirectory = Path.Combine(path + "/" + gameType.ToString() + "/" + fileName); StreamReader file = new StreamReader(savingDirectory); while ((line = file.ReadLine()) != null) { items.Add(line); } file.Close(); date = Convert.ToDateTime(items[0]); roundNumber = int.Parse(items[1]); string name = ""; bool isAI = false; int rowsForPlayer = roundNumber + 2; int noOfPlayers = (items.Count - 2) / (roundNumber + 2); int indexStartPlayer = 2; for (int i = 0; i < noOfPlayers; i++) { indexStartPlayer = 2 + i * rowsForPlayer; List <Score> scoreList = new List <Score>(); name = items[indexStartPlayer]; isAI = bool.Parse(items[indexStartPlayer + 1]); string[] scoreItems; for (int j = 0; j < roundNumber; j++) { scoreItems = items[indexStartPlayer + 2 + j].Split('|'); int point = Int32.Parse(scoreItems[0]); Variant.Type vari = (Variant.Type)Enum.Parse(typeof(Variant.Type), (scoreItems[1])); Score score = new Score(vari, point); scoreList.Add(score); } if (isAI) { Ai ai = new Ai(name, rules, variant, scoreList, gameType); playersfromfile.Add(ai); } else { Player player = new Player(name, scoreList); playersfromfile.Add(player); } } return(playersfromfile); }
private void AddingScoreToList(Player player, Variant.Type choiceToPick) { player.AddScoreToList(choiceToPick, rules.GetValueByVariant(choiceToPick)); bool exist = false; int roundScore = player.GetScoreFromList(choiceToPick, out exist); if (exist) { renderer.RenderScoreOfRound(roundScore, choiceToPick); } }
public int GetScoreFromList(Variant.Type variant, out bool exist) { Score score = scoreList.Find(scoreObj => scoreObj.TakenChoice == variant); if (score != null) { exist = true; return(score.Points); } else { exist = false; return(0); } }
private static void AddSetting(string title, Variant.Type type, object value) { title = SettingPath(title); if (ProjectSettings.HasSetting(title)) { return; } ProjectSettings.SetSetting(title, value); var info = new Dictionary { ["name"] = title, ["type"] = type }; ProjectSettings.AddPropertyInfo(info); }
private void PlayRound(Player player) { Ai ai = player as Ai; Variant.Type choiceToPick = variant.Chance(); renderer.RenderRound(player.Name); for (int rollNumber = 1; rollNumber <= 3; rollNumber++) { RolledDice(rollNumber, player, ai); } if (player.IsAI) { choiceToPick = ai.SelectBestAvailableChoice(); } else { choiceToPick = renderer.RenderChoices(player.GetTakenChoices(variant)); } AddingScoreToList(player, choiceToPick); }
public override int GetValue(Variant.Type type) { return((int)type); }
public override string GetName(Variant.Type i) { return(Enum.GetName(typeof(Type), i)); }
/// <summary> /// Converts from a <c>Variant</c> type to another in the best way possible. /// The <paramref name="type"/> parameter uses the <see cref="Variant.Type"/> values. /// </summary> /// <example> /// <code> /// var a = new Vector2(1, 0); /// // Prints 1 /// GD.Print(a.Length()); /// var b = GD.Convert(a, Variant.Type.String) /// // Prints 6 as "(1, 0)" is 6 characters /// GD.Print(b.Length); /// </code> /// </example> /// <returns>The <c>Variant</c> converted to the given <paramref name="type"/>.</returns> public static object Convert(object what, Variant.Type type) { return(godot_icall_GD_convert(what, type)); }
public int GetValueByVariant(Variant.Type variant) { VariantYatzy.Type variantYatzy = (VariantYatzy.Type)variant; int retValueForVariant = 0; switch (variantYatzy) { case VariantYatzy.Type.Aces: case VariantYatzy.Type.Twos: case VariantYatzy.Type.Threes: case VariantYatzy.Type.Fours: case VariantYatzy.Type.Fives: case VariantYatzy.Type.Sixes: retValueForVariant = SumOfSameVariant(variantYatzy); break; case VariantYatzy.Type.Pair: if (BasicRules.HasPair()) { retValueForVariant = Pair(); } break; case VariantYatzy.Type.TwoPair: if (BasicRules.HasTwoPair()) { retValueForVariant = TwoPair(); } break; case VariantYatzy.Type.ThreeOfAKind: if (BasicRules.HasThreeOfAKind()) { retValueForVariant = ThreeOfAKind(); } break; case VariantYatzy.Type.FourOfAKind: if (BasicRules.HasFourOfAKind()) { retValueForVariant = FourOfAKind(); } break; case VariantYatzy.Type.FullHouse: if (BasicRules.HasFullHouse()) { retValueForVariant = FullHouse(); } break; case VariantYatzy.Type.SmallStraight: if (HasSmallStraight()) { retValueForVariant = SmallStraight(); } break; case VariantYatzy.Type.LargeStraight: if (HasLargeStraight()) { retValueForVariant = LargeStraight(); } break; case VariantYatzy.Type.Yahtzee: if (BasicRules.HasYahtzee()) { retValueForVariant = Yahtzee(); } break; case VariantYatzy.Type.Chance: retValueForVariant = diceCollection.GetSumOfDice(); break; } return(retValueForVariant); }
public void RenderScoreOfRound(int roundScore, Variant.Type chosenVariant) { scoreView.RenderScoreOfRound(roundScore, chosenVariant); }
public void RenderScoreOfRound(int roundScore, Variant.Type chosenVariant) { PrintMessage("Received " + roundScore + " points for type " + variant.GetName(chosenVariant) + "\n"); }
public CommandBuilder AddArgument(string argumentName, Variant.Type argumentType) { _commandObject.Call("add_argument", argumentName, argumentType); return(this); }
public Score(Variant.Type variant, int points) { TakenChoice = variant; Points = points; }
public void AddScoreToList(Variant.Type variant, int point) { scoreList.Add(new Score(variant, point)); }
internal static extern object godot_icall_GD_convert(object what, Variant.Type type);
/// <summary> /// Converts from a <c>Variant</c> type to another in the best way possible. /// The <paramref name="type"/> parameter uses the <see cref="Variant.Type"/> values. /// </summary> /// <example> /// <code> /// var a = new Vector2(1, 0); /// // Prints 1 /// GD.Print(a.Length()); /// var b = GD.Convert(a, Variant.Type.String) /// // Prints 6 as "(1, 0)" is 6 characters /// GD.Print(b.Length); /// </code> /// </example> /// <returns>The <c>Variant</c> converted to the given <paramref name="type"/>.</returns> public static Variant Convert(Variant what, Variant.Type type) { NativeFuncs.godotsharp_convert((godot_variant)what.NativeVar, (int)type, out godot_variant ret); return(Variant.CreateTakingOwnershipOfDisposableValue(ret)); }