mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-16 02:52:44 -04:00
@@ -30,40 +30,76 @@ public class PlinkoCommand : ICommand
|
|||||||
Window = TimeSpan.FromSeconds(10)
|
Window = TimeSpan.FromSeconds(10)
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly string NULLSPACE = "⚫";
|
private const string NULLSPACE = "⚫";
|
||||||
private readonly string EMPTYSPACE = "⚪";
|
private const string EMPTYSPACE = "⚪";
|
||||||
private readonly string BALL = "🟠";
|
private const string BALL = "🟠";
|
||||||
private readonly int DIFFICULTY = 7;//maybe plan to allow user to change difficulty of plinko in future updates, would need to change the payout logic though
|
private const string LOSESPACE = "🔻";
|
||||||
private static readonly double VACUUM = 0.02;
|
private const string SMALLWINSPACE = "🟢";
|
||||||
|
private const string MIDWINSPACE = "🍀";
|
||||||
|
private const string BIGWINSPACE = "💲";
|
||||||
|
|
||||||
|
private const int DIFFICULTY = 8;//maybe plan to allow user to change difficulty of plinko in future updates, would need to change the payout logic though
|
||||||
|
private static readonly double VACUUM = 0.27;
|
||||||
|
|
||||||
|
private static Dictionary<decimal, string> PAYOUTSTOSTRING = new Dictionary<decimal, string>()
|
||||||
|
{
|
||||||
|
{69, BIGWINSPACE},
|
||||||
|
{(decimal)42.069, MIDWINSPACE},
|
||||||
|
{9, SMALLWINSPACE},
|
||||||
|
{(decimal)0.1, LOSESPACE}
|
||||||
|
};
|
||||||
|
|
||||||
private static readonly Dictionary<int, decimal> PlinkoPayoutBoard = new()
|
private static readonly Dictionary<int, decimal> PlinkoPayoutBoard = new()
|
||||||
{
|
{
|
||||||
{0, 8},
|
{0, 69},
|
||||||
{1, (decimal)0.5},
|
{2, (decimal)42.069},
|
||||||
{2, (decimal)0.25},
|
{4, 9},
|
||||||
{3, (decimal)0.25},
|
{6, (decimal)0.1},
|
||||||
{4, (decimal)0.25},
|
{8, (decimal)0.1},
|
||||||
{5, (decimal)0.5},
|
{10, 9},
|
||||||
{6, 8},
|
{12, (decimal)42.069},
|
||||||
|
{14, 69}
|
||||||
|
|
||||||
};
|
};
|
||||||
private static readonly List<(int row, int col)> validPositions = new() //would need to come up with a formula to make this to have user defined difficulty, good luck
|
|
||||||
{
|
private static List<(int row, int col)> validPositions;
|
||||||
(0, 3),
|
|
||||||
(1, 2), (1, 4),
|
private static Dictionary<int, List<int>> validColumnsForRow;
|
||||||
(2, 2), (2, 3), (2, 4),
|
|
||||||
(3, 1),(3, 2), (3, 4), (3, 5),
|
|
||||||
(4, 1),(4, 2), (4, 3), (4, 4), (4, 5),
|
|
||||||
(5, 0), (5, 1),(5, 2), (5, 4), (5, 5), (5, 6),
|
|
||||||
(6, 0), (6, 1),(6, 2), (6, 3), (6, 4), (6, 5), (6, 6)
|
|
||||||
};
|
|
||||||
// 1 1 1 1 1 1 1
|
|
||||||
// 2 1 0.5 1 0.5 1 2
|
|
||||||
// 4 0.5 0.5 0.25 0.5 0.5 4
|
|
||||||
// 8 0.5 0.25 0.25 0.25 0.5 8
|
|
||||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
|
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
|
||||||
CancellationToken ctx)
|
CancellationToken ctx)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
validPositions = new List<(int row, int col)>() { (0, DIFFICULTY-1) };
|
||||||
|
validColumnsForRow = new Dictionary<int, List<int>>(){{0, new List<int>(){DIFFICULTY-1}}};
|
||||||
|
|
||||||
|
//calculate all the valid positions for the difficulty
|
||||||
|
for (int i = 1; i < DIFFICULTY; i++)
|
||||||
|
{
|
||||||
|
// Find all positions from the row we just finished (i-1)
|
||||||
|
var previousRowPositions = validPositions.Where(p => p.row == i - 1).ToList();
|
||||||
|
|
||||||
|
foreach (var pos in previousRowPositions)
|
||||||
|
{
|
||||||
|
var leftChild = (i, pos.col - 1);
|
||||||
|
var rightChild = (i, pos.col + 1);
|
||||||
|
|
||||||
|
// Use a hash-set or check Contains to avoid adding duplicate nodes
|
||||||
|
if (!validPositions.Contains(leftChild)) validPositions.Add(leftChild);
|
||||||
|
if (!validPositions.Contains(rightChild)) validPositions.Add(rightChild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//calculate all the valid columns for any particular row
|
||||||
|
foreach (var position in validPositions)
|
||||||
|
{
|
||||||
|
if (!validColumnsForRow.ContainsKey(position.row)) validColumnsForRow.Add(position.row, new List<int>(){position.col});
|
||||||
|
else validColumnsForRow[position.row].Add(position.col);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
decimal payout = 0;
|
decimal payout = 0;
|
||||||
decimal currentPayout = 0;
|
decimal currentPayout = 0;
|
||||||
var settings = await SettingsProvider.GetMultipleValuesAsync([
|
var settings = await SettingsProvider.GetMultipleValuesAsync([
|
||||||
@@ -199,7 +235,15 @@ public class PlinkoCommand : ICommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spaceIsBall) board += EMPTYSPACE;
|
if (!spaceIsBall)
|
||||||
|
{
|
||||||
|
if (row == DIFFICULTY - 1)
|
||||||
|
{
|
||||||
|
foreach (var num in new List<int>(){0,2,4,6,8,10,12,14})
|
||||||
|
if (col == num) board += PAYOUTSTOSTRING[PlinkoPayoutBoard[num]];
|
||||||
|
}
|
||||||
|
else board += EMPTYSPACE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,39 +260,31 @@ public class PlinkoCommand : ICommand
|
|||||||
{
|
{
|
||||||
private RandomShim<StandardRng> RAND = RandomShim.Create(StandardRng.Create());
|
private RandomShim<StandardRng> RAND = RandomShim.Create(StandardRng.Create());
|
||||||
public (int row, int col) POSITION;
|
public (int row, int col) POSITION;
|
||||||
private Dictionary<int, List<int>> validColumnsForRow;
|
|
||||||
public PlinkoBall()
|
public PlinkoBall()
|
||||||
{
|
{
|
||||||
POSITION = (0, 3);
|
POSITION = (0, 3);
|
||||||
validColumnsForRow = new Dictionary<int, List<int>>();
|
|
||||||
foreach (var position in validPositions){
|
|
||||||
if (!validColumnsForRow.ContainsKey(position.row)) validColumnsForRow.Add(position.row, new List<int>()
|
|
||||||
{
|
|
||||||
position.col
|
|
||||||
}); //if no current key for that row add it
|
|
||||||
else validColumnsForRow[position.row].Add(position.col);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public void Iterate()
|
public void Iterate()
|
||||||
{
|
{
|
||||||
double rng = RAND.NextDouble();
|
double rng = RAND.NextDouble();
|
||||||
bool evenrow = POSITION.row % 2 == 0;
|
bool evenrow = POSITION.row % 2 == 0;
|
||||||
if (POSITION.col < 2)
|
if (POSITION.col < DIFFICULTY-1)
|
||||||
{
|
{
|
||||||
rng -= VACUUM;
|
rng -= VACUUM;
|
||||||
}
|
}
|
||||||
else if (POSITION.col > 4)
|
else if (POSITION.col > DIFFICULTY+1)
|
||||||
{
|
{
|
||||||
rng += VACUUM;
|
rng += VACUUM;
|
||||||
}
|
}
|
||||||
switch (rng)
|
switch (rng)
|
||||||
{
|
{
|
||||||
case >= 0.5:
|
case >= 0.5:
|
||||||
if (validColumnsForRow[POSITION.row+1].Contains(POSITION.col-1)) POSITION.col--;
|
POSITION.col--;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case < 0.5:
|
case < 0.5:
|
||||||
if (validColumnsForRow[POSITION.row+1].Contains(POSITION.col+1)) POSITION.col++;
|
POSITION.col++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception("generated an incorrect number");
|
throw new Exception("generated an incorrect number");
|
||||||
|
|||||||
Reference in New Issue
Block a user