From 429e099f323774c9676669bb9dc68f407c437615 Mon Sep 17 00:00:00 2001 From: Kuvam Date: Thu, 16 Feb 2017 09:00:00 +0530 Subject: [PATCH 1/7] Add files via upload Testing. --- CoupForTelegram/CoupForTelegram/Game.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CoupForTelegram/CoupForTelegram/Game.cs b/CoupForTelegram/CoupForTelegram/Game.cs index 48430ba..e922ae8 100644 --- a/CoupForTelegram/CoupForTelegram/Game.cs +++ b/CoupForTelegram/CoupForTelegram/Game.cs @@ -360,7 +360,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 +738,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(); From e1d328718f8cd5ec492511a6f815e5e3f24c938f Mon Sep 17 00:00:00 2001 From: Kuvam Date: Tue, 21 Feb 2017 07:52:00 +0530 Subject: [PATCH 2/7] Add files via upload --- CoupForTelegram/CoupForTelegram/Game.cs | 2 -- CoupForTelegram/CoupForTelegram/Program.cs | 5 ----- 2 files changed, 7 deletions(-) diff --git a/CoupForTelegram/CoupForTelegram/Game.cs b/CoupForTelegram/CoupForTelegram/Game.cs index e922ae8..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()) { @@ -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/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 From 6a74bb7da7a37fffbf66ee66e5ea2445f56a1941 Mon Sep 17 00:00:00 2001 From: Kuvam Date: Tue, 21 Feb 2017 07:54:21 +0530 Subject: [PATCH 3/7] Add files via upload --- CoupForTelegram/Testing/Card.cs | 7 +------ CoupForTelegram/Testing/Extensions.cs | 11 +---------- CoupForTelegram/Testing/Program.cs | 3 --- 3 files changed, 2 insertions(+), 19 deletions(-) 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); From 9ec230d5497639179ab80491c1dae07320dc9d5a Mon Sep 17 00:00:00 2001 From: Kuvam Date: Tue, 21 Feb 2017 08:06:32 +0530 Subject: [PATCH 4/7] Add files via upload From f0b41664683032bbd29330684dd3405b0e29b361 Mon Sep 17 00:00:00 2001 From: Kuvam Date: Tue, 21 Feb 2017 08:07:34 +0530 Subject: [PATCH 5/7] Add files via upload --- CoupForTelegram/CoupForTelegram/Helpers/Extensions.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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; From 82b5128d368cb1d13907a150225fd4fea7914b54 Mon Sep 17 00:00:00 2001 From: Kuvam Date: Tue, 21 Feb 2017 08:09:24 +0530 Subject: [PATCH 6/7] Add files via upload --- CoupForTelegram/CoupForTelegram/Models/Card.cs | 1 - 1 file changed, 1 deletion(-) 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; } } From 36fc31528b900741846d98bacabd5e32a8b2f28b Mon Sep 17 00:00:00 2001 From: Kuvam Date: Tue, 21 Feb 2017 08:44:02 +0530 Subject: [PATCH 7/7] Add files via upload --- CoupForTelegram/CoupForTelegram/Handlers/UpdateHandler.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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" +