Example #1
0
        public bool MarkScore(string markAs, YatzyRollState rollState)
        {
            int v = this.BestScore(markAs, rollState);

            if (v >= 0)
            {
                this.Score[markAs] = v;
                return(true);
            }
            return(false);
        }
Example #2
0
 public string GetBestBets(YatzyRollState rollState)
 {
     return("{" +
            "\"ones\":" + this.BestScore("ones", rollState) + "," +
            "\"twos\":" + this.BestScore("twos", rollState) + "," +
            "\"threes\":" + this.BestScore("threes", rollState) + "," +
            "\"fours\":" + this.BestScore("fours", rollState) + "," +
            "\"fives\":" + this.BestScore("fives", rollState) + "," +
            "\"sixes\":" + this.BestScore("sixes", rollState) + "," +
            "\"onepair\":" + this.BestScore("onepair", rollState) + "," +
            "\"twopair\":" + this.BestScore("twopair", rollState) + "," +
            "\"tripple\":" + this.BestScore("tripple", rollState) + "," +
            "\"quadruple\":" + this.BestScore("quadruple", rollState) + "," +
            "\"fullhouse\":" + this.BestScore("fullhouse", rollState) + "," +
            "\"smallstrait\":" + this.BestScore("smallstrait", rollState) + "," +
            "\"largestrait\":" + this.BestScore("largestrait", rollState) + "," +
            "\"yatzy\":" + this.BestScore("yatzy", rollState) + "," +
            "\"chance\":" + this.BestScore("chance", rollState) + "}");
 }
Example #3
0
        public int BestScore(string markAs, YatzyRollState rollState)
        {
            bool largestOk = false;

            switch (markAs)
            {
            case "ones":
                if (this.Score["ones"] >= 0)
                {
                    return(-1);
                }
                return(rollState.DiceStates.FindAll(ds => ds.Value == 1).Count);

            case "twos":
                if (this.Score["twos"] >= 0)
                {
                    return(-1);
                }
                return(rollState.DiceStates.FindAll(ds => ds.Value == 2).Count * 2);

            case "threes":
                if (this.Score["threes"] >= 0)
                {
                    return(-1);
                }
                return(rollState.DiceStates.FindAll(ds => ds.Value == 3).Count * 3);

            case "fours":
                if (this.Score["fours"] >= 0)
                {
                    return(-1);
                }
                return(rollState.DiceStates.FindAll(ds => ds.Value == 4).Count * 4);

            case "fives":
                if (this.Score["fives"] >= 0)
                {
                    return(-2);
                }
                return(rollState.DiceStates.FindAll(ds => ds.Value == 5).Count * 5);

            case "sixes":
                if (this.Score["sixes"] >= 0)
                {
                    return(-1);
                }
                return(rollState.DiceStates.FindAll(ds => ds.Value == 6).Count * 6);

            case "onepair":
                if (this.Score["onepair"] >= 0)
                {
                    return(-1);
                }
                for (var largest = 6; largest > 0; largest--)
                {
                    largestOk = rollState.DiceStates.FindAll(ds => ds.Value == largest).Count >= 2;
                    if (largestOk)
                    {
                        return(largest * 2);
                    }
                }
                return(0);

            case "tripple":
                if (this.Score["tripple"] >= 0)
                {
                    return(-1);
                }
                for (var largest = 6; largest > 0; largest--)
                {
                    largestOk = rollState.DiceStates.FindAll(ds => ds.Value == largest).Count >= 3;
                    if (largestOk)
                    {
                        return(largest * 3);
                    }
                }
                return(0);

            case "quadruple":
                if (this.Score["quadruple"] >= 0)
                {
                    return(-2);
                }
                for (var largest = 6; largest > 0; largest--)
                {
                    largestOk = rollState.DiceStates.FindAll(ds => ds.Value == largest).Count >= 4;
                    if (largestOk)
                    {
                        return(largest * 4);
                    }
                }
                return(0);

            case "yatzy":
                if (this.Score["yatzy"] >= 0)
                {
                    return(-1);
                }
                for (var largest = 6; largest > 0; largest--)
                {
                    largestOk = rollState.DiceStates.FindAll(ds => ds.Value == largest).Count >= 5;
                    if (largestOk)
                    {
                        return(50);
                    }
                }
                return(0);

            case "smallstrait":
                if (this.Score["smallstrait"] >= 0)
                {
                    return(-1);
                }
                if (
                    rollState.DiceStates.FindAll(ds => ds.Value == 1).Count == 1 &&
                    rollState.DiceStates.FindAll(ds => ds.Value == 2).Count == 1 &&
                    rollState.DiceStates.FindAll(ds => ds.Value == 3).Count == 1 &&
                    rollState.DiceStates.FindAll(ds => ds.Value == 4).Count == 1 &&
                    rollState.DiceStates.FindAll(ds => ds.Value == 5).Count == 1)
                {
                    return(15);
                }
                return(0);

            case "largestrait":
                if (this.Score["largestrait"] >= 0)
                {
                    return(-1);
                }
                if (
                    rollState.DiceStates.FindAll(ds => ds.Value == 2).Count == 1 &&
                    rollState.DiceStates.FindAll(ds => ds.Value == 3).Count == 1 &&
                    rollState.DiceStates.FindAll(ds => ds.Value == 4).Count == 1 &&
                    rollState.DiceStates.FindAll(ds => ds.Value == 5).Count == 1 &&
                    rollState.DiceStates.FindAll(ds => ds.Value == 6).Count == 1)
                {
                    return(20);
                }
                return(0);

            case "fullhouse":
                if (this.Score["fullhouse"] >= 0)
                {
                    return(-1);
                }
                for (var largest = 6; largest > 0; largest--)
                {
                    largestOk = rollState.DiceStates.FindAll(ds => ds.Value == largest).Count >= 3;
                    if (largestOk)
                    {
                        var largest1 = largest;
                        largestOk = false;
                        for (var largest2 = 6; largest2 > 0; largest2--)
                        {
                            largestOk = rollState.DiceStates.FindAll(ds => ds.Value == largest2 && ds.Value != largest1).Count >= 2;
                            if (largestOk)
                            {
                                return(largest1 * 3 + largest2 * 2);
                            }
                        }
                    }
                }
                return(0);

            case "twopair":
                if (this.Score["twopair"] >= 0)
                {
                    return(-1);
                }
                for (var largest = 6; largest > 0; largest--)
                {
                    largestOk = rollState.DiceStates.FindAll(ds => ds.Value == largest).Count >= 2;
                    if (largestOk)
                    {
                        var largest1 = largest;
                        largestOk = false;
                        for (var largest2 = 6; largest2 > 0; largest2--)
                        {
                            largestOk = rollState.DiceStates.FindAll(ds => ds.Value == largest2 && ds.Value != largest1).Count >= 2;
                            if (largestOk)
                            {
                                return(largest1 * 2 + largest2 * 2);
                            }
                        }
                    }
                }
                return(0);

            case "chance":
                if (this.Score["chance"] >= 0)
                {
                    return(-1);
                }
                return(rollState.DiceStates[0].Value +
                       rollState.DiceStates[1].Value +
                       rollState.DiceStates[2].Value +
                       rollState.DiceStates[3].Value +
                       rollState.DiceStates[4].Value);
            }

            return(0);
        }