senadityasingh commited on
Commit
d2ba577
·
verified ·
1 Parent(s): ae7a494

added Blackjack strategy tool

Browse files
Files changed (1) hide show
  1. app.py +41 -7
app.py CHANGED
@@ -9,14 +9,48 @@ from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -55,7 +89,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def blackjack_strategy(player_cards: list[str], dealer_card:str)-> str:
13
+ """A tool that determines optimal Blackjack strategy based on player's cards and dealer's face-up card.
 
14
  Args:
15
+ player_cards: A list of strings representing the player's cards.
16
+ Each card is represented as two character string (ex: 'AH' for Ace of hearts, '10S' for 10 of Spades).
17
+ dealer_card_rank: A string representing delaler's face-up card
18
+
19
+ Returns: Recommended action ("Hit", "Stand", or "Double Down").
20
  """
21
+ def card_value(card: str) -> int:
22
+ if card[0] == 'A': return 11
23
+ elif card[0] in 'KQJ': return 10
24
+ else: return int(card[:-1])
25
+
26
+ player_values = [card_value(card) for card in player_cards]
27
+ player_total = sum(player_values)
28
+ dealer_total = card_value(dealer_card)
29
+
30
+ if 11 in player_values and player_total > 21:
31
+ player_total -= 10
32
+
33
+ if player_total >= 17:
34
+ return 'Stand'
35
+ elif player_total >= 13 and player_total <= 16:
36
+ if dealer_total >= 7:
37
+ return 'Hit'
38
+ else:
39
+ return 'Stand'
40
+ elif player_total == 12:
41
+ if dealer_total >= 4 and dealer_total <= 6:
42
+ return 'Stand'
43
+ else:
44
+ return 'Hit'
45
+ elif player_total <= 11:
46
+ # Double down condition (9, 10, or 11) - Only allowed if it's the first two cards
47
+ if len(player_cards) == 2 and (player_total in [9,10,11]):
48
+ if dealer_total >= 2 and dealer_total <= 9: # Typical condition for doubling down
49
+ return 'Double Down'
50
+ else:
51
+ return 'Hit'
52
+ else:
53
+ return 'Hit'
54
 
55
  @tool
56
  def get_current_time_in_timezone(timezone: str) -> str:
 
89
 
90
  agent = CodeAgent(
91
  model=model,
92
+ tools=[final_answer, blackjack_strategy], ## add your tools here (don't remove final answer)
93
  max_steps=6,
94
  verbosity_level=1,
95
  grammar=None,