Compare commits

...

10 Commits

Author SHA1 Message Date
d743e5610a Implemented card counting. Refactored blackjack code a bit.
Removed gamepicker references
2025-08-13 14:45:57 +10:00
48f9389100 Moved shit to recycle bin etc etc 2025-08-11 21:58:43 +10:00
686e5d6617 Main addition: Russian Roulette 2024-02-18 10:00:21 +10:00
bdf4c32e70 Merge branch 'Game-Pick-Bot' 2023-11-30 16:37:22 +10:00
b18f0ae688 master pre merge commit 2023-11-30 16:37:11 +10:00
9501737b43 Fixed multiple session bug for blackjack 2023-11-30 16:35:37 +10:00
a6bc671231 Updated gitignore 2023-11-23 09:48:26 +10:00
f9785f0e8a BlackJack Finished 2023-11-23 09:46:08 +10:00
a7fc6da2cb Preperations for setting up game picker 1.0 2023-11-22 12:06:58 +10:00
c2ea96445d Added dice roller 2023-09-12 11:09:27 +10:00
25 changed files with 253 additions and 80 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
ledger.db
__pycache__/*
src/py/__pycache__/*
*.drawio

View File

@@ -1,11 +0,0 @@
FROM python:3
RUN pip install discord
WORKDIR /usr/app/src
COPY Acronymbot.py ./
COPY BlackJack.py ./
COPY Ledger.py ./
CMD [ "python", "./Acronymbot.py" ]

View File

@@ -1,31 +0,0 @@
import discord
import random
# Temporary List
games = ["Left 4 Dead 2",
"Aragami",
"Astroneer",
"Factorio",
"Borderlands",
"Stardew Valley",
"Viscera Cleanup Detail",
"SCP",
"Satisfactory",
"Backrooms (Alternate Ending)",
"Ghost Recon Wildlands"
]
def add_game(game: str):
games.append(game)
def pick_game():
randomIndex = random.randrange(0, len(games))
coinFlip = random.randrange(0, 2)
if coinFlip:
return f"Valorant ({games[randomIndex]})"
else:
return games[randomIndex]

34
Recycle Bin/Gamepicker.py Normal file
View File

@@ -0,0 +1,34 @@
import discord
import random
# Temporary List
# games = ["Left 4 Dead 2",
# "Aragami",
# "Astroneer",
# "Factorio",
# "Borderlands",
# "Stardew Valley",
# "Viscera Cleanup Detail",
# "SCP",
# "Satisfactory",
# "Ghost Recon Wildlands"
# ]
games = ["Plate Up",
"Terraria",
"Ghost Recon"]
def add_game(game: str):
games.append(game)
def pick_game():
randomIndex = random.randrange(0, len(games))
coinFlip = random.randrange(0, 2)
if coinFlip:
return f"Valorant ({games[randomIndex]})"
else:
return games[randomIndex]

View File

@@ -0,0 +1,20 @@
version: "3.3"
networks:
net:
driver: bridge
services:
acronymbot:
build: ./src/py
volumes:
- "./src/py:/usr/app/src"
networks:
- "net"
depends_on:
- database
database:
image: mariadb:latest
networks:
- "net"

View File

@@ -3,7 +3,7 @@ GAMEINFO:
ID, NAME, GENRE, GAMEPASS
WHOOWNSIT (bitmap index):
ID, MARCUS, BENSON, ALEX, TIM
ID, MARCUS, BENSON, ALEX, TIM, AIDAN
GAMEFACTORS:
ID, BRAINLEVEL, TIMETOPLAY, CAMPAIGN

5
Recycle Bin/plan.txt Normal file
View File

@@ -0,0 +1,5 @@
Microservices:
- Some sort of database for storing the data
- Image for the python code that runs the bot
- Something to interface the two, like sparkSQL for interacting with the database

BIN
ledger.db

Binary file not shown.

View File

@@ -1,9 +1,9 @@
import random
import discord
import sqlite3
from discord import app_commands
from BlackJack import BlackJack
from Calculator import Calculator
from Gamepicker import pick_game
botIntents = discord.Intents.all()
@@ -112,16 +112,110 @@ async def calculator(interaction: discord.Interaction):
calculator = Calculator()
await interaction.followup.send(content="`" + " " * calculator.MAXIMUMBARSIZE + "0`", view=calculator)
@tree.command(description="Roll a Dice")
@app_commands.choices(dice = [
app_commands.Choice(name = 'd4', value=4),
app_commands.Choice(name = 'd6', value=6),
app_commands.Choice(name = 'd8', value=8),
app_commands.Choice(name = 'd10', value=10),
app_commands.Choice(name = 'd12', value=12),
app_commands.Choice(name = 'd20', value=20),
app_commands.Choice(name = 'd100', value=100),
])
async def roll(interaction: discord.Interaction, dice:app_commands.Choice[int]):
roll = random.randint(1, dice.value)
await interaction.response.send_message(f"{dice.name}: {roll}")
"""
#### Game Picker ####
#### Russian Roulette ####
"""
@tree.command(description="Pick a game")
async def gg(interaction: discord.Interaction):
MAXLINELENGTH = 12
tooLong = lambda x: len(x) > MAXLINELENGTH
tooShort = lambda x: len(x) < MAXLINELENGTH
difference = lambda x: MAXLINELENGTH - len(x)
sidePad = lambda x: " " * (difference(x) // 2)
evenPad = lambda x: sidePad(x) + x + sidePad(x)
oddPad = lambda x: evenPad(x) + " "
game = pick_game()
await interaction.response.send_message("Barotrauma")
def demon_text_helper(line):
if tooShort(line):
if difference(line) % 2 == 0:
return evenPad(line)
else:
return oddPad(line)
return line
def demon_text(lineOne="", lineTwo="", lineThree=""):
if tooLong(lineOne) or tooLong(lineTwo) or tooLong(lineThree):
print("Line too long lol")
lineOne = demon_text_helper(lineOne)
lineTwo = demon_text_helper(lineTwo)
lineThree = demon_text_helper(lineThree)
demon = f"``` , , /\ /\ \n\
/( /\ )\ _\ \_/ /_ ____________\n\
|\_||_/| < \_ _/ > / \ \n\
\______/ \|0 0|/ | {lineOne} |\n\
_\/_ _(_ ^ _)_ | {lineTwo} |\n\
( () ) /`\|V\"\"\"V|/`\ | {lineThree} |\n\
{{}} \ \_____/ / <______________/\n\
() /\ )=( /\ \n\
{{}} / \_/\=/\_/ \ \n```"
return demon
class ShootOrNoShoot(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)
self.bullets = 6
@discord.ui.button(label="Shoot", style=discord.ButtonStyle.red)
async def shoot(self, interaction: discord.Interaction, button: discord.ui.Button):
if self.bullets == 0:
for child in self.children:
child.disabled = True
await interaction.response.edit_message(content=f"What?", view=self)
if random.randrange(0,self.bullets) == 0:
for child in self.children:
child.disabled = True
demonDeath = demon_text(lineOne="You died!", lineTwo="Bahahahah!", lineThree=f"Score: {6 - self.bullets}")
await interaction.response.edit_message(content=f"{demonDeath}", view=self)
else:
self.bullets -= 1
button.label = f"Shoot again"
demonLife = demon_text(lineOne="You live", lineTwo="This time!!",
lineThree=f"({6 - self.bullets}/5) blanks")
await interaction.response.edit_message(content=f"{demonLife}", view=self)
@discord.ui.button(label="PussyOut", style=discord.ButtonStyle.blurple)
async def noshoot(self, interaction: discord.Interaction, button: discord.ui.Button):
for child in self.children:
child.disabled = True
demonPussy = demon_text(lineOne="You are such", lineTwo="a huge pussy", lineThree= "0 bitches 4u")
await interaction.response.edit_message(content=f"{demonPussy}", view=self)
@tree.command(description="????")
async def rr(interaction: discord.Interaction):
await interaction.response.defer()
buttons = ShootOrNoShoot()
demon = demon_text(lineTwo="Shoot urself")
await interaction.followup.send(content=f"{demon}", view=buttons)
"""
#### Fin ####

View File

@@ -1,10 +1,10 @@
import random
from Ledger import Ledger
#TODO Starting a game with 21 fucks with hidden cards
#TODO Look into 5card jack thingo that Tim mentioned
#TODO Insurance - If dealer starts with 21, you can bet against it and win your money back
#TODO Make each game session more distinct (Embeds?)
#TODO Card counting.
# Game States
INIT = 0
@@ -30,9 +30,22 @@ class Card():
self.suit = suit
self.hidden = False
def turn_card(self):
# XOR to flip hidden element
self.hidden = self.hidden != True
if self.value in range(2,7):
self.count_value = 1
elif self.value in range(7,10):
self.count_value = 0
else:
self.count_value = -1
def hide_card(self):
self.hidden = True
def show_card(self):
self.hidden = False
def get_value(self):
return self.value
@@ -51,7 +64,7 @@ class Card():
strValue = str(self.value)
string = ""
string = f"{suits[self.suit]}{strValue}"
string = f"{suits[self.suit]}{strValue}: ({self.count_value})"
if self.hidden:
string = "??"
return string
@@ -67,11 +80,11 @@ class Deck():
self.discard = []
self.joker = joker
self.deck.extend([Card(x, Card.HEARTS) for x in range(1, 13)])
self.deck.extend([Card(x, Card.DIAMONDS) for x in range(1, 13)])
self.deck.extend([Card(x, Card.SPADES) for x in range(1, 13)])
self.deck.extend([Card(x, Card.CLUBS) for x in range(1, 13)])
self.deck.extend([Card(x, Card.HEARTS) for x in range(1, 14)])
self.deck.extend([Card(x, Card.DIAMONDS) for x in range(1, 14)])
self.deck.extend([Card(x, Card.SPADES) for x in range(1, 14)])
self.deck.extend([Card(x, Card.CLUBS) for x in range(1, 14)])
print(len(self.deck))
if joker:
self.deck.append(Card(0, 0))
@@ -113,6 +126,7 @@ class Deck():
class Hand():
def __init__(self) -> None:
self.hand = []
self.hidden_cards = []
def sortHand(self):
self.hand.sort()
@@ -130,10 +144,25 @@ class Hand():
return self.hand[index]
def hide_card(self, index):
self.peek_card(index).turn_card()
card = self.peek_card(index)
card.hide_card()
self.hidden_cards.append(card)
def __len__(self):
return len(self.hand)
def show_card(self, index):
card = self.peek_card(index)
card.show_card()
try:
self.hidden_cards.remove(card)
except ValueError:
print("Card not hidden")
def show_hand(self):
extra_count = 0
for card in self.hidden_cards:
card.show_card()
extra_count += card.count_value
self.hidden_cards.remove(card)
return extra_count
def __str__(self) -> str:
string = ""
@@ -147,11 +176,14 @@ class Hand():
aces = 0
# Add static values
for card in self.hand:
if card.hidden:
continue
if card.value == 1:
aces += 1
continue
if card.value > 10:
card.value = 10
value += 10
continue
value += card.value
# Dynamically add ace value based on ideal rules
@@ -174,6 +206,8 @@ class Hand():
def __next__(self):
return next(self.iter)
def __len__(self):
return len(self.hand)
class BlackJack:
def __init__(self) -> None:
@@ -181,34 +215,49 @@ class BlackJack:
self.playerHand = Hand()
self.dealerHand = Hand()
self.ledger = Ledger()
self.playing = False
self.count = 0
def deal_card(self, hand):
card = self.deck.take_from_deck()
hand.add_to_hand(card)
self.count += card.count_value
def deal_hidden_card(self, hand):
hand.add_to_hand(self.deck.take_from_deck())
# Hide one of the dealers cards
self.dealerHand.hide_card(1)
def game_setup(self):
# Deal cards in alternate order
self.deck.shuffle()
for _ in range(2):
for i in range(2):
self.deal_card(self.playerHand)
self.deal_card(self.dealerHand)
if i == 0:
self.deal_card(self.dealerHand)
else:
self.deal_hidden_card(self.dealerHand)
# Hide one of the dealers cards
self.dealerHand.hide_card(1)
def discard_hand(self, hand):
hand.show_hand()
for _ in range(len(hand)):
card = hand.remove_from_hand(0)
self.deck.addToDiscard(card)
async def show_cards(self, send, displayDealerScore=False):
async def show_cards(self, send):
# Show Cards to player
string = f"Player Hand = {repr(self.playerHand)}: {self.playerHand}\nDealer Hand = ??: {self.dealerHand}"
if displayDealerScore:
string = f"Player Hand = {repr(self.playerHand)}: {self.playerHand}\nDealer Hand = {repr(self.dealerHand)}: {self.dealerHand}"
string = f"Player Hand = {repr(self.playerHand)}: {self.playerHand}\nDealer Hand = {repr(self.dealerHand)}: {self.dealerHand}\nCount = {self.count}"
await send(string)
async def play_game(self, ID, bet, recv, send):
if self.playing:
await send("Game in Progress")
return
else:
self.playing = True
gameState = INIT
while gameState != OVER:
@@ -220,6 +269,9 @@ class BlackJack:
self.game_setup()
gameState = PLAYERTURN
if int(repr(self.playerHand)) >= 21:
gameState = FINISHED
if gameState == PLAYERTURN:
await self.show_cards(send)
@@ -227,17 +279,15 @@ class BlackJack:
if playerHit:
self.deal_card(self.playerHand)
else:
#TODO Rename hide_card function
self.dealerHand.hide_card(1)
gameState = DEALERTURN
if int(repr(self.playerHand)) >= 21:
self.dealerHand.hide_card(1)
gameState = FINISHED
if gameState == DEALERTURN:
extra_count = self.dealerHand.show_hand()
self.count += extra_count
if int(repr(self.dealerHand)) > int(repr(self.playerHand)):
gameState = FINISHED
continue
@@ -256,7 +306,7 @@ class BlackJack:
tie = False
playerScore = int(repr(self.playerHand))
dealerScore = int(repr(self.dealerHand))
await self.show_cards(send, True)
await self.show_cards(send)
if playerScore == 21:
playerBlackJack = True
if dealerScore == 21:
@@ -308,8 +358,10 @@ class BlackJack:
if len(self.deck) < 0.25 * 51:
self.deck.return_all_from_discard()
self.deck.shuffle()
self.count = 0
await send("Everyday I'm shuffling")
gameState = OVER
self.playing = False
def main():
game = BlackJack()
@@ -320,5 +372,3 @@ def main():
if __name__ == "__main__":
main()

11
src/py/Dockerfile Normal file
View File

@@ -0,0 +1,11 @@
FROM python:3
RUN pip install discord \
&& pip install mariadb
WORKDIR /usr/app/src
VOLUME /usr/app/src
# -v flag to mount to this volume. -v [from]:/usr/app/src
CMD [ "python", "./Acronymbot.py" ]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.