mirror of
https://github.com/Xevion/unbelievaselfbot.git
synced 2025-12-09 08:09:30 -06:00
implement blackjack prediction into client logging, privatize Blackjack data variables, letter conversion function
This commit is contained in:
@@ -123,20 +123,20 @@ def generate_table_structure(filename: str, column_keys: List[str], row_keys: Li
|
||||
|
||||
class Blackjack(object):
|
||||
# The row and column headers for the hair, soft and pair baseline tables.
|
||||
hard_column = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'A']
|
||||
hard_row = ['20', '19', '18', '17', '16', '15', '14', '13', '12', '11', '10', '9', '8', '7', '6', '5']
|
||||
soft_column = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'A']
|
||||
soft_row = ['A-9', 'A-8', 'A-7', 'A-6', 'A-5', 'A-4', 'A-3', 'A-2']
|
||||
pair_column = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'A']
|
||||
pair_row = ['A-A', 'T-T', '9-9', '8-8', '7-7', '6-6', '5-5', '4-4', '3-3', '2-2']
|
||||
__hard_column = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'A']
|
||||
__hard_row = ['20', '19', '18', '17', '16', '15', '14', '13', '12', '11', '10', '9', '8', '7', '6', '5']
|
||||
__soft_column = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'A']
|
||||
__soft_row = ['A-9', 'A-8', 'A-7', 'A-6', 'A-5', 'A-4', 'A-3', 'A-2']
|
||||
__pair_column = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'A']
|
||||
__pair_row = ['A-A', 'T-T', '9-9', '8-8', '7-7', '6-6', '5-5', '4-4', '3-3', '2-2']
|
||||
|
||||
hard_data = generate_table_structure('baseline_hard.dat', hard_column, hard_row)
|
||||
soft_data = generate_table_structure('baseline_soft.dat', soft_column, soft_row)
|
||||
pair_data = generate_table_structure('baseline_pairs.dat', pair_column, pair_row)
|
||||
__letter_meanings = {'H': 'hit', 'S': 'stand', 'D': 'double down', 'P': 'split'}
|
||||
|
||||
HARD = 0
|
||||
SOFT = 1
|
||||
PAIR = 2
|
||||
__hard_data = generate_table_structure('baseline_hard.dat', __hard_column, __hard_row)
|
||||
__soft_data = generate_table_structure('baseline_soft.dat', __soft_column, __soft_row)
|
||||
__pair_data = generate_table_structure('baseline_pairs.dat', __pair_column, __pair_row)
|
||||
|
||||
HARD, SOFT, PAIR = 0, 1, 2
|
||||
|
||||
@staticmethod
|
||||
def choose(options: constants.PlayOptions, cards: List[Card], dealer: Card) -> str:
|
||||
@@ -172,7 +172,12 @@ class Blackjack(object):
|
||||
logger.warning('No tables were accessed to make a choice. Defaulting to stand.')
|
||||
return Blackjack.convert_letter(choice)
|
||||
|
||||
def options_convert(self, choice: str, options: Tuple[bool, bool, bool, bool]):
|
||||
@classmethod
|
||||
def convert_letter(cls, letter: str) -> str:
|
||||
"""Simple class method for returning the player response to the bot based on the letter given."""
|
||||
return Blackjack.__letter_meanings[letter]
|
||||
|
||||
def options_convert(self, choice: str, options: constants.PlayOptions) -> str:
|
||||
"""Converts the choice to the best possible choice based on the options given by the bot."""
|
||||
|
||||
new_choice = None
|
||||
@@ -208,6 +213,6 @@ class Blackjack(object):
|
||||
:param table:
|
||||
:return:
|
||||
"""
|
||||
if table == cls.HARD: return cls.hard_data[key]
|
||||
if table == cls.SOFT: return cls.soft_data[key]
|
||||
if table == cls.PAIR: return cls.pair_data[key]
|
||||
if table == cls.HARD: return cls.__hard_data[key]
|
||||
if table == cls.SOFT: return cls.__soft_data[key]
|
||||
if table == cls.PAIR: return cls.__pair_data[key]
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import asyncio
|
||||
import ctypes
|
||||
import logging
|
||||
import re
|
||||
from datetime import datetime
|
||||
from typing import Optional, Tuple
|
||||
from typing import Optional
|
||||
|
||||
import discord
|
||||
from discord.ext.tasks import loop
|
||||
|
||||
from bot import constants, parsers, timings, helpers
|
||||
from bot.blackjack import Card
|
||||
from bot.blackjack import Card, Blackjack
|
||||
from bot.constants import PlayOptions
|
||||
|
||||
logger = logging.getLogger(__file__)
|
||||
@@ -31,7 +28,7 @@ class UnbelievaClient(discord.Client):
|
||||
'$crime': timings.Cooldown(20 * 60 + 2),
|
||||
'$dep all': timings.Cooldown(30 * 60)
|
||||
}
|
||||
self.command_cooldown = timings.Cooldown(5)
|
||||
self.command_cooldown = timings.Cooldown(6.5)
|
||||
|
||||
self.money = 0
|
||||
self.last_deposit = -1
|
||||
@@ -73,9 +70,11 @@ class UnbelievaClient(discord.Client):
|
||||
# Handling for blackjack
|
||||
if embed.description.startswith('Type `hit` to draw another card'):
|
||||
options = self.parse_options(embed.description)
|
||||
my_cards = Card.parse_cards(embed.fields[0])
|
||||
dealer_cards = Card.parse_cards(embed.fields[1])
|
||||
print(options, my_cards, dealer_cards)
|
||||
my_cards = Card.parse_cards(embed.fields[0])[1]
|
||||
dealer_card = Card.parse_cards(embed.fields[1])[1][0]
|
||||
|
||||
choice = Blackjack.choose(options, my_cards, dealer_card)
|
||||
logger.info(f'Predicted best choice for Blackjack: {choice}')
|
||||
|
||||
def parse_options(self, options_str: str) -> PlayOptions:
|
||||
"""
|
||||
@@ -86,14 +85,6 @@ class UnbelievaClient(discord.Client):
|
||||
# noinspection PyProtectedMember
|
||||
return PlayOptions._make(options)
|
||||
|
||||
def handle_blackjack(self):
|
||||
embed = self.current_blackjack.embeds[0]
|
||||
options = self.parse_options(embed.description)
|
||||
my_cards = self.parse_cards(embed.fields[0])
|
||||
dealer_cards = self.parse_cards(embed.fields[1])
|
||||
print(options, my_cards, dealer_cards)
|
||||
pass
|
||||
|
||||
@loop(seconds=1)
|
||||
async def check_task_available(self):
|
||||
"""Loop to run tasks as soon as they are available."""
|
||||
|
||||
Reference in New Issue
Block a user