diff --git a/CoupForTelegram/CoupForTelegram/Game.cs b/CoupForTelegram/CoupForTelegram/Game.cs index 48430ba..5448d97 100644 --- a/CoupForTelegram/CoupForTelegram/Game.cs +++ b/CoupForTelegram/CoupForTelegram/Game.cs @@ -165,7 +165,6 @@ public void StartGame() Program.GamesPlayed++; State = GameState.Initializing; Players.Shuffle(); - Players.Shuffle(); //create db entry for game using (var db = new CoupContext()) { @@ -360,7 +359,7 @@ public void StartGame() //Graveyard.Add(target.Cards.First()); target.Cards.Clear(); } - else + else if (target.Cards.Count() > 1) { Send($"{p.Name.ToBold()} was not blocked! {target.Name.ToBold()} please choose a card to lose."); PlayerLoseCard(target); @@ -738,7 +737,7 @@ private bool PlayerMadeBlockableAction(CPlayer p, Action a, CPlayer t = null, st //player has a card! if (bluffer.Cards.Count() == 1) { - Send($"{bluffer.Name.ToBold()}, {p.Name.ToBold()} had {cardUsed.ToBold()}. You are out of cards, and therefore out of the game!"); + Send(msg + $"{bluffer.Name.ToBold()}, {p.Name.ToBold()} had {cardUsed.ToBold()}. You are out of cards, and therefore out of the game!"); PlayerLoseCard(bluffer, bluffer.Cards.First()); //Graveyard.Add(bluffer.Cards.First()); bluffer.Cards.Clear(); @@ -756,7 +755,6 @@ private bool PlayerMadeBlockableAction(CPlayer p, Action a, CPlayer t = null, st Cards.Add(card); p.Cards.Remove(card); Cards.Shuffle(); - Cards.Shuffle(); card = Cards.First(); Cards.Remove(card); p.Cards.Add(card); diff --git a/CoupForTelegram/CoupForTelegram/Handlers/UpdateHandler.cs b/CoupForTelegram/CoupForTelegram/Handlers/UpdateHandler.cs index e29239f..3627ccd 100644 --- a/CoupForTelegram/CoupForTelegram/Handlers/UpdateHandler.cs +++ b/CoupForTelegram/CoupForTelegram/Handlers/UpdateHandler.cs @@ -2,11 +2,8 @@ using CoupForTelegram.Models; using Database; using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading; -using System.Threading.Tasks; using Telegram.Bot.Types; using Telegram.Bot.Types.ReplyMarkups; #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed @@ -82,7 +79,8 @@ internal static void HandleMessage(Message m) var gps = p.GamePlayers.ToList(); stats += $"Games played: {gps.Count()}\n" + $"Games won: {gps.Count(x => x.Won)}\n" + - $"Checks cards on turn: {gps.Average(x => x.LookedAtCardsTurn)}\n" + + $"Win rate: {Math.Round(100 * ((double)(gps.Count(x => x.Won))) / gps.Count(), 5)}%\n" + + $"Checks cards on turn: {Math.Round((double)(gps.Average(x => x.LookedAtCardsTurn)), 5)}\n" + $"Total coins collected: {gps.Sum(x => x.CoinsCollected)}\n" + $"Total coins stolen: {gps.Sum(x => x.CoinsStolen)}\n" + $"Successful blocks: {gps.Sum(x => x.ActionsBlocked)}\n" + diff --git a/CoupForTelegram/CoupForTelegram/Helpers/Extensions.cs b/CoupForTelegram/CoupForTelegram/Helpers/Extensions.cs index 97e108a..dbb2285 100644 --- a/CoupForTelegram/CoupForTelegram/Helpers/Extensions.cs +++ b/CoupForTelegram/CoupForTelegram/Helpers/Extensions.cs @@ -14,15 +14,10 @@ public static class Extensions { public static void Shuffle(this IList list) { - RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider(); int n = list.Count; while (n > 1) { - byte[] box = new byte[1]; - do provider.GetBytes(box); - while (!(box[0] < n * (Byte.MaxValue / n))); - int k = (box[0] % n); - n--; + int k = (new Random()).Next(n--); T value = list[k]; list[k] = list[n]; list[n] = value; diff --git a/CoupForTelegram/CoupForTelegram/Models/Card.cs b/CoupForTelegram/CoupForTelegram/Models/Card.cs index 6ca7668..2adcbbb 100644 --- a/CoupForTelegram/CoupForTelegram/Models/Card.cs +++ b/CoupForTelegram/CoupForTelegram/Models/Card.cs @@ -72,7 +72,6 @@ public static List GenerateCards() new Captain(), new Captain(), new Captain(), new Ambassador(), new Ambassador(), new Ambassador(), new Assassin(), new Assassin(), new Assassin()}; result.Shuffle(); - result.Shuffle(); return result; } } diff --git a/CoupForTelegram/CoupForTelegram/Program.cs b/CoupForTelegram/CoupForTelegram/Program.cs index 69a7cf0..7790e12 100644 --- a/CoupForTelegram/CoupForTelegram/Program.cs +++ b/CoupForTelegram/CoupForTelegram/Program.cs @@ -3,12 +3,7 @@ using System.IO; using System.Linq; using System.Reflection; -using System.Text; using System.Threading; -using System.Threading.Tasks; -using Microsoft.Win32; -using Telegram.Bot; -using Telegram.Bot.Args; using Database; namespace CoupForTelegram diff --git a/CoupForTelegram/Testing/Card.cs b/CoupForTelegram/Testing/Card.cs index b0c7405..f2b8bf1 100644 --- a/CoupForTelegram/Testing/Card.cs +++ b/CoupForTelegram/Testing/Card.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace Testing { @@ -71,7 +67,6 @@ public static List GenerateCards() new Captain(), new Captain(), new Captain(), new Ambassador(), new Ambassador(), new Ambassador(), new Assassin(), new Assassin(), new Assassin()}; result.Shuffle(); - result.Shuffle(); return result; } } diff --git a/CoupForTelegram/Testing/Extensions.cs b/CoupForTelegram/Testing/Extensions.cs index 419ce81..0cca7b7 100644 --- a/CoupForTelegram/Testing/Extensions.cs +++ b/CoupForTelegram/Testing/Extensions.cs @@ -1,9 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Security.Cryptography; -using System.Text; -using System.Threading.Tasks; namespace Testing { @@ -11,15 +7,10 @@ public static class Extensions { public static void Shuffle(this IList list) { - RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider(); int n = list.Count; while (n > 1) { - byte[] box = new byte[1]; - do provider.GetBytes(box); - while (!(box[0] < n * (Byte.MaxValue / n))); - int k = (box[0] % n); - n--; + int k = (new Random()).Next(n--); T value = list[k]; list[k] = list[n]; list[n] = value; diff --git a/CoupForTelegram/Testing/Program.cs b/CoupForTelegram/Testing/Program.cs index a69a829..2485a60 100644 --- a/CoupForTelegram/Testing/Program.cs +++ b/CoupForTelegram/Testing/Program.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Testing { @@ -45,7 +43,6 @@ static bool RunTest(List p1) Cards.Add(card); p1.Remove(card); Cards.Shuffle(); - Cards.Shuffle(); card = Cards.First(); Cards.Remove(card); p1.Add(card);