Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions CoupForTelegram/CoupForTelegram/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions CoupForTelegram/CoupForTelegram/Handlers/UpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" +
Expand Down
7 changes: 1 addition & 6 deletions CoupForTelegram/CoupForTelegram/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@ public static class Extensions
{
public static void Shuffle<T>(this IList<T> 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;
Expand Down
1 change: 0 additions & 1 deletion CoupForTelegram/CoupForTelegram/Models/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public static List<Card> 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;
}
}
Expand Down
5 changes: 0 additions & 5 deletions CoupForTelegram/CoupForTelegram/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions CoupForTelegram/Testing/Card.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -71,7 +67,6 @@ public static List<Card> 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;
}
}
Expand Down
11 changes: 1 addition & 10 deletions CoupForTelegram/Testing/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Testing
{
public static class Extensions
{
public static void Shuffle<T>(this IList<T> 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;
Expand Down
3 changes: 0 additions & 3 deletions CoupForTelegram/Testing/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Testing
{
Expand Down Expand Up @@ -45,7 +43,6 @@ static bool RunTest(List<Card> p1)
Cards.Add(card);
p1.Remove(card);
Cards.Shuffle();
Cards.Shuffle();
card = Cards.First();
Cards.Remove(card);
p1.Add(card);
Expand Down