Compare commits

...

4 Commits

Author SHA1 Message Date
jandrews
ce69c6b474 fykfyk 2026-01-16 13:00:39 -05:00
jandrews
72928df0cc Merge branch 'main' of https://git.makingwithcode.org/jandrews/project_game 2026-01-14 09:09:14 -05:00
jandrews
39695c2d92 updated 2026-01-13 12:57:09 -05:00
jandrews
5399ffd008 updated card mapping 2026-01-05 09:55:00 -05:00
9 changed files with 155 additions and 21 deletions

Binary file not shown.

View File

@@ -1,5 +1,5 @@
#module defines the value of the card.
#the cards in blackjack have a range in value from 1-10 with a face card being worth 10 and an ace being worth 1 or 11 depending on what you choose it to be worth.
#module defines the value of the card. 1-13 display and value are defined outside of this class.
from random import randint
class Card:
@@ -10,10 +10,7 @@ class Card:
return str(self.face)
def deal(self):
self.face = randint(1, 11)
#I think here we should return 1-13 to include ace and face cards.
#This will make checking if 4 of a kind have been dealt easier.
#THEN when it comes to scoring we can use the value to calculate face cards as 10 points.
self.face = randint(1, 13)
return self.face

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -44,6 +44,7 @@ class Dealer:
self.deal_card_to_player()
game.state["score"] = self.get_player_score()
def set_up_new_round(self, game):
self.deck = Deck(self.position)
for agent in self.deck.get_agents():
@@ -81,6 +82,8 @@ class Dealer:
return (x + 4 * len(self.dealer_cards), y)
def get_player_score(self):
"""if score >21 set A va """
return sum([card.value() for card in self.player_cards])
def end_round(self, game):

View File

@@ -1,11 +1,20 @@
from retro.game import Game
from dealer import Dealer
import json
dealer = Dealer((1, 1))
state = {
def play():
dealer = Dealer((1, 1))
state = {
"score": 0,
"options": "h to hit or s to stay",
}
game = Game([dealer], state)
game.play()
"options": "H to hit or F to stay",
}
game = Game([dealer], state)
game.play()
with open("result.json") as result_file:
json.dump(game.state)
if __name__ == '__main__':
play()

130
dealer.py
View File

@@ -14,9 +14,13 @@ def deal_first():
dealer_show = Card()
if dealer_show == 1:
print("dealer shown card:"+ "Ace")
if dealer_show == 10:
if dealer_show == 11:
print("dealer shown card:"+ "Jack")
#continue code here to show the correct face based on what was drawn
if dealer_show == 12:
print("dealer shown code:"+ "Queen")
if dealer_show == 13:
print("dealer shown card:"+ "King")
print("dealer shown card:"+ str(dealer_show))
@@ -31,13 +35,125 @@ def deal_first():
def is_card_valid(card):
cards_dealt = []
for card_face in cards_dealt:
if card_face == card:
return False
else:
cards_dealt.append(card)
counts = card_count(cards_dealt)
if card == 1:
if card_ones.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 2:
if card_twos.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 3:
if card_threes.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 4:
if card_fours.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 5:
if card_fives.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 6:
if card_sixes.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 7:
if card_sevens.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 8:
if card_eights.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 9:
if card_nines.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 10:
if card_tens.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 11:
if card_jacks.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 12:
if card_queens.value <= 3:
cards_dealt.append = [card]
return True
return False
if card == 13:
if card_kings.value <= 3:
cards_dealt.append = [card]
return True
return False
def card_count(cards_dealt):
cards_ones = 0
cards_twos = 0
cards_threes = 0
cards_fours = 0
cards_fives = 0
cards_sixes = 0
cards_sevens = 0
cards_eights = 0
cards_nines = 0
cards_tens = 0
cards_aces = 0
cards_jacks = 0
cards_queens = 0
cards_kings = 0
for face in self.face():
if face == 1:
cards_ones+=1
if face == 2:
cards_twos+=1
if face == 3:
cards_threes+=1
if face == 4:
cards_fours+=1
if face == 5:
cards_fives+=1
if face == 6:
cards_sixes+=1
if face == 7:
cards_sevens+=1
if face == 8:
cards_eights+=1
if face == 9:
cards_nines+=1
if face == 10:
cards_tens+=1
if face == 11:
cards_jacks+=1
if face == 12:
cards_queens+=1
if face == 13:
cards_kings+=1
deal_first()

View File

@@ -1,7 +1,7 @@
[project]
name = "project-game"
name = "blackjack"
version = "0.1.0"
description = ""
description = "draw cards or "hit" and see if you have a more points than the dealer hand. "
authors = [
{name = "Chris Proctor",email = "chris@chrisproctor.net"}
]
@@ -12,6 +12,14 @@ dependencies = [
"retro-games (>=1.1.0,<2.0.0)"
]
[project.scripts]
play = "game:play"
[tool.retro]
author = "jacob"
description = "draw cards or "hit" and see if you have more points than the dealer hand."
instructions = "draw cards and make sure not to have more than 21 points or a lower total amount of points than the dealer."hit" when you are cofident with your cards to see if you win the round"
result_file = "result.json"
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
@@ -19,3 +27,4 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
package-mode = false