1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "sci/engine/features.h"
#include "sci/engine/hoyle5poker.h"
#include "sci/engine/kernel.h"
#include "sci/engine/script.h"
#include "sci/engine/selector.h"
#include "sci/engine/vm.h"
namespace Sci {
#ifdef ENABLE_SCI32
// The logic for the poker game in Hoyle Classic Games (Hoyle 5) is hardcoded
// in PENGIN16.DLL, which is then loaded and invoked via the kWinDLL kernel call.
// Note that the first player is the left one.
enum Hoyle5PokerSuits {
kSuitSpades = 0,
kSuitClubs = 1,
kSuitDiamonds = 2,
kSuitHearts = 3
};
enum Hoyle5PokerData {
kTotalChips = 1,
kCurrentPot = 2,
kCurrentBet = 3,
kChipsPlayer1 = 4,
kChipsPlayer2 = 5,
kChipsPlayer3 = 6,
kChipsPlayer4 = 7,
kStatusPlayer1 = 8,
kStatusPlayer2 = 9,
kStatusPlayer3 = 10,
kStatusPlayer4 = 11,
// 12 - 16 seem to be unused?
kCurrentPlayer = 17,
kCurrentStage = 18, // Stage 1: Card changes, 2: Betting
kCard0 = 19,
kSuit0 = 20,
kCard1 = 21,
kSuit1 = 22,
kCard2 = 23,
kSuit2 = 24,
kCard3 = 25,
kSuit3 = 26,
kCard4 = 27,
kSuit4 = 28,
// 19 - 28: current player's cards (number + suit)
// 29 - 38: next clockwise player's cards (number + suit)
// 39 - 48: next clockwise player's cards (number + suit)
// 49 - 58: next clockwise player's cards (number + suit)
// 59 - 60 seem to be unused?
// ---- Return values -----------------------------------
kWhatAmIResult = 61, // bitmask, 0 - 128, checked by PokerHand::whatAmI. Determines what kind of card each player has
kResult = 62, // 1 - 15, checked by localproc_3020
kDiscardCard0 = 63, // flag, checked by PokerHand::think
kDiscardCard1 = 64, // flag, checked by PokerHand::think
kDiscardCard2 = 65, // flag, checked by PokerHand::think
kDiscardCard3 = 66, // flag, checked by PokerHand::think
kDiscardCard4 = 67, // flag, checked by PokerHand::think
// 77 seems to be a bit array?
};
#if 0
Common::String getCardDescription(int16 card, int16 suit) {
Common::String result;
if (card >= 2 && card <= 10)
result += Common::String::format("%d", card);
else if (card == 11)
result = "Jack";
else if (card == 12)
result = "Queen";
else if (card == 13)
result = "King";
else if (card == 14)
result = "Ace";
else
result = "Unknown";
switch (suit) {
case kSuitSpades:
return result + " of spades";
case kSuitClubs:
return result + " of clubs";
case kSuitDiamonds:
return result + " of diamonds";
case kSuitHearts:
return result + " of hearts";
default:
return result + " of unknown";
}
}
void printPlayerCards(int player, SciArray *data) {
debug("Player %d cards:", player);
for (int i = 19 + player * 10; i < 29 + player * 10; i += 2) {
if (data->getAsInt16(i) > 0)
debug("- %s", getCardDescription(data->getAsInt16(i), data->getAsInt16(i + 1)).c_str());
}
}
#endif
// Checks the current player's hand, and returns its type using a bitmask
int checkHand(SciArray *data) {
int cards[5] = {
data->getAsInt16(kCard0),
data->getAsInt16(kCard1),
data->getAsInt16(kCard2),
data->getAsInt16(kCard3),
data->getAsInt16(kCard4),
};
int suits[5] = {
data->getAsInt16(kSuit0),
data->getAsInt16(kSuit1),
data->getAsInt16(kSuit2),
data->getAsInt16(kSuit3),
data->getAsInt16(kSuit4),
};
Common::sort(cards, cards + 5, Common::Less<int>());
int lastCard = -1;
//int lastSuit = -1;
int pairs = 0;
int sameRank = 0;
int sameSuit = 0;
int orderedCards = 0;
for (int i = 0; i < 4; i++) {
if (cards[i] == cards[i + 1] && cards[i] != lastCard)
pairs++;
if (cards[i] == cards[i + 1])
sameRank++;
if (suits[i] == suits[i + 1])
sameSuit++;
if (cards[i] == cards[i + 1] - 1)
orderedCards++;
lastCard = cards[i];
//lastSuit = suits[i];
}
if (pairs == 1)
return 1 << 0; // 1, one pair
else if (pairs == 2)
return 1 << 1; // 2, two pairs
else if (sameRank == 3)
return 1 << 2; // 4, three of a kind
else if (orderedCards == 5 && sameSuit < 5)
return 1 << 7; // 128, straight
else if (sameSuit == 5)
return 1 << 4; // 16, flush
else if (cards[0] == cards[1] && cards[1] == cards[2] && cards[3] == cards[4])
return 1 << 5; // 32, full house
else if (sameRank == 4)
return 1 << 6; // 64, four of a kind
else if (orderedCards == 5 && sameSuit == 5)
return 0; // straight flush // TODO
else if (sameRank == 5)
return 1 << 8; // 256, five of a kind
return 0; // high card
}
reg_t hoyle5PokerEngine(SciArray *data) {
#if 0
debug("Player %d's turn", data->getAsInt16(kCurrentPlayer));
debug("Pot: %d, bet: %d", data->getAsInt16(kCurrentPot), data->getAsInt16(kCurrentBet));
debug("Chips: %d %d %d %d - %d in total",
data->getAsInt16(kChipsPlayer1),
data->getAsInt16(kChipsPlayer2),
data->getAsInt16(kChipsPlayer3),
data->getAsInt16(kChipsPlayer4),
data->getAsInt16(kTotalChips)
);
debug("Player status: %d %d %d %d",
data->getAsInt16(kStatusPlayer1),
data->getAsInt16(kStatusPlayer2),
data->getAsInt16(kStatusPlayer3),
data->getAsInt16(kStatusPlayer4)
);
for (int i = 0; i < 4; i++)
printPlayerCards(i, data);
for (int i = 0; i < data->size(); i++) {
if (i >= kChipsPlayer1 && i <= kChipsPlayer4)
continue;
if (i >= 8 && i <= 11)
continue;
if (i >= 19 && i <= 58)
continue;
if (data->getAsInt16(i) != 0)
debug("%d: %d", i, data->getAsInt16(i));
}
#endif
data->setFromInt16(kWhatAmIResult, checkHand(data));
// Dummy logic
Common::RandomSource &rng = g_sci->getRNG();
data->setFromInt16(kResult, 1 + (int)rng.getRandomNumber(14));
data->setFromInt16(kDiscardCard0, (int)rng.getRandomBit());
data->setFromInt16(kDiscardCard1, (int)rng.getRandomBit());
data->setFromInt16(kDiscardCard2, (int)rng.getRandomBit());
data->setFromInt16(kDiscardCard3, (int)rng.getRandomBit());
data->setFromInt16(kDiscardCard4, (int)rng.getRandomBit());
warning("The Poker game logic has not been implemented yet");
return TRUE_REG;
}
#endif
}
|