Skip to content

Commit 346e2d8

Browse files
committed
e
1 parent e445bc8 commit 346e2d8

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

source/archipelago/traps/games/APUnoTrapState.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class APUnoTrapState extends UnoTestState {
6565
var unoColors = APItem.unoColorsUnlocked;
6666

6767
var unoColorsWithInt = [for (colorInfo in unoColors) {
68-
var colorInt = FlxColor.fromString(colorInfo.color);
68+
var colorInt = FlxColor.fromString('#${colorInfo.color}');
6969
{name: colorInfo.name, color: colorInt};
7070
}];
7171
var usableColors:Array<UnoColor> = [];

source/games/uno/backend/UnoCPU.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class UnoCPU extends UnoPlayer {
243243
}
244244

245245
// Return the color with the most cards, or a random standard color if no cards
246-
return colorCounts.length > 0 ? colorCounts[0].color : UnoColor.RED;
246+
return colorCounts.length > 0 ? colorCounts[0].color : colorCounts[Math.floor(Math.random() * colorCounts.length)].color;
247247
}
248248

249249
/**

source/games/uno/backend/UnoDeck.hx

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
package games.uno.backend;
22

3-
using Math;
4-
import games.uno.backend.UnoCard;
5-
import games.uno.backend.UnoCard.UnoColor;
63
import games.uno.backend.UnoCard.UnoCardType;
4+
import games.uno.backend.UnoCard.UnoColor;
5+
import games.uno.backend.UnoCard;
6+
7+
using Math;
78

89
/**
910
* Represents a deck of UNO cards with shuffling and dealing capabilities
1011
*/
1112
class UnoDeck {
1213
public var cards:Array<UnoCard>;
1314
public var discardPile:Array<UnoCard>;
14-
15+
1516
public function new() {
1617
cards = [];
1718
discardPile = [];
1819
initializeDeck();
1920
shuffle();
2021
}
21-
22+
2223
/**
2324
* Initialize a standard UNO deck
2425
*/
2526
private function initializeDeck():Void {
2627
initializeDeckWithColors(UnoCard.getStandardColors(), null);
2728
}
28-
29+
2930
/**
3031
* Initialize deck with custom colors and custom cards
3132
*/
3233
public function initializeDeckWithColors(colors:Array<UnoColor>, ?customCards:Array<UnoCard>):Void {
3334
cards = [];
34-
35+
3536
// Add number cards (0-9 for each color, with 0 appearing once and 1-9 appearing twice)
3637
for (color in colors) {
3738
// Add one 0 card for each color
3839
cards.push(new UnoCard(color, NUMBER, 0));
39-
40-
// Add two of each number card 1-9 for each color
40+
4141
for (i in 1...10) {
4242
cards.push(new UnoCard(color, NUMBER, i));
4343
cards.push(new UnoCard(color, NUMBER, i));
4444
}
45-
45+
4646
// Add two of each action card for each color
4747
cards.push(new UnoCard(color, SKIP));
4848
cards.push(new UnoCard(color, SKIP));
@@ -51,22 +51,29 @@ class UnoDeck {
5151
cards.push(new UnoCard(color, DRAW_TWO));
5252
cards.push(new UnoCard(color, DRAW_TWO));
5353
}
54-
54+
5555
// Add wild cards (4 of each)
5656
for (i in 0...4) {
5757
cards.push(new UnoCard(WILD, WILD));
5858
cards.push(new UnoCard(WILD, WILD_DRAW_FOUR));
5959
}
60-
60+
61+
while (cards.length < 108) {
62+
for (i in 1...10) {
63+
cards.push(new UnoCard(color, NUMBER, i));
64+
cards.push(new UnoCard(color, NUMBER, i));
65+
}
66+
}
67+
6168
// Add custom cards if provided
6269
if (customCards != null) {
6370
for (customCard in customCards) {
6471
cards.push(customCard.clone()); // Clone to avoid reference issues
6572
}
6673
}
6774
}
68-
69-
75+
76+
7077
/**
7178
* Shuffle the deck using Fisher-Yates algorithm
7279
*/
@@ -78,22 +85,22 @@ class UnoDeck {
7885
cards[j] = temp;
7986
}
8087
}
81-
88+
8289
/**
8390
* Draw a card from the deck
8491
*/
8592
public function drawCard():UnoCard {
8693
if (cards.length == 0) {
8794
reshuffleFromDiscard();
8895
}
89-
96+
9097
if (cards.length == 0) {
9198
throw "No cards available to draw!";
9299
}
93-
100+
94101
return cards.pop();
95102
}
96-
103+
97104
/**
98105
* Draw multiple cards from the deck
99106
*/
@@ -104,14 +111,14 @@ class UnoDeck {
104111
}
105112
return drawnCards;
106113
}
107-
114+
108115
/**
109116
* Add a card to the discard pile
110117
*/
111118
public function discard(card:UnoCard):Void {
112119
discardPile.push(card);
113120
}
114-
121+
115122
/**
116123
* Get the top card of the discard pile without removing it
117124
*/
@@ -121,46 +128,46 @@ class UnoDeck {
121128
}
122129
return discardPile[discardPile.length - 1];
123130
}
124-
131+
125132
/**
126133
* Reshuffle the discard pile back into the deck (keeping the top card)
127134
*/
128135
private function reshuffleFromDiscard():Void {
129136
if (discardPile.length <= 1) {
130137
return; // Can't reshuffle if there's only the top card or no cards
131138
}
132-
139+
133140
// Keep the top card in the discard pile
134141
var topCard = discardPile.pop();
135-
142+
136143
// Move all other cards back to the deck
137144
cards = cards.concat(discardPile);
138145
discardPile = [topCard];
139-
146+
140147
// Reset wild card colors in the deck
141148
for (card in cards) {
142149
if (card.isWildCard()) {
143150
card.color = WILD;
144151
}
145152
}
146-
153+
147154
shuffle();
148155
}
149-
156+
150157
/**
151158
* Get the number of cards remaining in the deck
152159
*/
153160
public function getRemainingCards():Int {
154161
return cards.length;
155162
}
156-
163+
157164
/**
158165
* Get the number of cards in the discard pile
159166
*/
160167
public function getDiscardPileSize():Int {
161168
return discardPile.length;
162169
}
163-
170+
164171
/**
165172
* Reset the deck to its initial state
166173
*/

0 commit comments

Comments
 (0)