Skip to content

Commit 7654ea4

Browse files
committed
Fix blackjack values and use new card to calculate
1 parent 554d092 commit 7654ea4

File tree

7 files changed

+330
-354
lines changed

7 files changed

+330
-354
lines changed

api/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ packages:
1313
dependency: transitive
1414
description:
1515
name: analyzer
16-
sha256: a40a0cee526a7e1f387c6847bd8a5ccbf510a75952ef8a28338e989558072cb0
16+
sha256: f51c8499b35f9b26820cfe914828a6a98a94efd5cc78b37bb7d03debae3a1d08
1717
url: "https://pub.dev"
1818
source: hosted
19-
version: "8.4.0"
19+
version: "8.4.1"
2020
ansicolor:
2121
dependency: transitive
2222
description:

app/pack/scripts/blackjack.luau

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ local Colors = {
1717
"spade"
1818
}
1919
local Values = {
20-
"1",
2120
"2",
2221
"3",
2322
"4",
@@ -87,7 +86,6 @@ function RemoveStack()
8786
}, true)
8887
end
8988
local VariationsScores : {[string]: {number}} = {
90-
["1"] = {1},
9189
["2"] = {2},
9290
["3"] = {3},
9391
["4"] = {4},
@@ -122,16 +120,19 @@ function GetCellObjects(position)
122120
end
123121
return cell.objects or {}
124122
end
125-
function CalculateStack() : number
123+
function CalculateStack(optionalCardId : string?) : number
126124
-- Gather identifiers of cards currently in the stack cell.
127125
-- Assuming an API like GetCellObjects(cell) -> { { identifier = "..." }, ... }
128126
local objects = GetCellObjects(StackPosition)
127+
if optionalCardId then
128+
table.insert(objects, { identifier = optionalCardId })
129+
end
129130

130131
-- Start with a single possible sum: 0
131132
local sums = {0}
132133

133134
for _, obj in pairs(objects) do
134-
local id = obj.identifier or obj.id or obj.cardId
135+
local id = obj.identifier
135136
if id then
136137
local values = CalculateCard(id) or {0}
137138
local newSums = {}
@@ -211,8 +212,16 @@ function FinishRound()
211212
end
212213
Reset()
213214
end
214-
function OnNewCard()
215-
local score = CalculateStack()
215+
function GetTopCardFromDeck() : string?
216+
local cell = State.Table.cells["("..DeckPosition.x..", "..DeckPosition.y..")"]
217+
if not cell or not cell.objects or #cell.objects == 0 then
218+
return nil
219+
end
220+
return cell.objects[1].identifier
221+
end
222+
function OnNewCard(from, objectId)
223+
local topCardId = GetTopCardFromDeck()
224+
local score = CalculateStack(topCardId)
216225
print("Current score: "..score)
217226
if score > MaxScore then
218227
print("Player "..CurrentPlayer.." busted!")
@@ -234,7 +243,8 @@ end)
234243
Events.ObjectMoved.Connect(function(event, details)
235244
local isFromDeck = event.from.table == DeckPosition.table and event.from.x == DeckPosition.x and event.from.y == DeckPosition.y
236245
local isToStack = event.to.table == StackPosition.table and event.to.x == StackPosition.x and event.to.y == StackPosition.y
237-
if(not isFromDeck or not isToStack) then
246+
local isOneObject = #event.objects == 1 and event.objects[1] == 0
247+
if(not isFromDeck or not isToStack or not isOneObject) then
238248
details.cancelled = true
239249
return
240250
end

app/pubspec.lock

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,10 @@ packages:
564564
dependency: transitive
565565
description:
566566
name: get_it
567-
sha256: a4292e7cf67193f8e7c1258203104eb2a51ec8b3a04baa14695f4064c144297b
567+
sha256: ae78de7c3f2304b8d81f2bb6e320833e5e81de942188542328f074978cc0efa9
568568
url: "https://pub.dev"
569569
source: hosted
570-
version: "8.2.0"
570+
version: "8.3.0"
571571
glob:
572572
dependency: transitive
573573
description:
@@ -1240,14 +1240,6 @@ packages:
12401240
url: "https://pub.dev"
12411241
source: hosted
12421242
version: "1.10.1"
1243-
sprintf:
1244-
dependency: transitive
1245-
description:
1246-
name: sprintf
1247-
sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23"
1248-
url: "https://pub.dev"
1249-
source: hosted
1250-
version: "7.0.0"
12511243
stack_trace:
12521244
dependency: transitive
12531245
description:
@@ -1413,10 +1405,10 @@ packages:
14131405
dependency: transitive
14141406
description:
14151407
name: uuid
1416-
sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff
1408+
sha256: a11b666489b1954e01d992f3d601b1804a33937b5a8fe677bd26b8a9f96f96e8
14171409
url: "https://pub.dev"
14181410
source: hosted
1419-
version: "4.5.1"
1411+
version: "4.5.2"
14201412
vector_graphics:
14211413
dependency: transitive
14221414
description:

docs/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
},
1212
"dependencies": {
1313
"@astrojs/check": "^0.9.5",
14-
"@astrojs/react": "^4.4.0",
15-
"@astrojs/starlight": "^0.36.1",
14+
"@astrojs/react": "^4.4.1",
15+
"@astrojs/starlight": "^0.36.2",
1616
"@phosphor-icons/react": "^2.1.10",
1717
"@types/react": "^19.2.2",
1818
"@types/react-dom": "^19.2.2",
19-
"astro": "^5.15.1",
19+
"astro": "^5.15.3",
2020
"react": "^19.2.0",
2121
"react-dom": "^19.2.0",
2222
"remark-gemoji": "^8.0.0",
@@ -26,7 +26,7 @@
2626
"packageManager": "[email protected]",
2727
"devDependencies": {
2828
"@vite-pwa/astro": "^1.1.1",
29-
"sass": "^1.93.2",
29+
"sass": "^1.93.3",
3030
"sharp": "^0.34.4",
3131
"vite-plugin-pwa": "^1.1.0",
3232
"workbox-window": "^7.3.0"

0 commit comments

Comments
 (0)