Click here to Skip to main content
15,892,059 members
Home / Discussions / C#
   

C#

 
GeneralRe: Pass connection in a function to another functions... Pin
Christian Graus30-May-07 16:37
protectorChristian Graus30-May-07 16:37 
QuestionProcess Lock Pin
convivial.developer30-May-07 14:44
convivial.developer30-May-07 14:44 
AnswerRe: Process Lock Pin
Luc Pattyn30-May-07 15:34
sitebuilderLuc Pattyn30-May-07 15:34 
QuestionA simple Question Pin
Michel Abi Khalil30-May-07 13:26
Michel Abi Khalil30-May-07 13:26 
AnswerRe: A simple Question Pin
Christian Graus30-May-07 15:50
protectorChristian Graus30-May-07 15:50 
AnswerRe: A simple Question Pin
Not Active30-May-07 17:02
mentorNot Active30-May-07 17:02 
Generaldecision matrix in C# Pin
amatbrewer30-May-07 11:25
amatbrewer30-May-07 11:25 
GeneralRe: decision matrix in C# Pin
Sean Michael Murphy30-May-07 15:11
Sean Michael Murphy30-May-07 15:11 
amatbrewer wrote:
While playing around with a Black Jack program, I got wondering about the best way to do a decision matrix in C#.
What I am thinking of is basically a 2 dimensional matrix with each row/col combination containing a value representing 1 of a number of different options (e.g. Hit, Stand, Double, Split, etc).
Is a 2 dimensional array the best way to implement it, or is there a better method?


That seems pretty elegant to me, but what you're proposing is only good for evaluating the 1st move of the hand. If one axis represents what the dealer is showing, and the other axis represents what you have showing, it's a very fast lookup of what to do.

After the first move, you either need to code a more traditional if {} else {} type code construct, or have another decision matrix, since you don't have options like splitting and doubling-down available to you after the first decision...

The pure decision matrix approach scores higher for me than the if {} else {} construct for your purpose because:
1) Once the array is initialized, evaluating decisions is very, very fast
2) If you structure your code properly, your intentions are perfectly clear. You cannot mess up the logic.

Pseudo-code:
C#
enum Action {
   Hit = 0,
   Stand = 1,
   DD = 2,
   Split = 3
}
 
private static Action[][] _decision = new Action[][] 
// Dealer showing ->      2      3      4       5      6 ...
// You showing    V
{ new Action[] */ 2 */ {  Hit,  Hit,   Stand,   DD,   Hit, ... },
  new Action[] /* 3 */ {  Hit,  Hit,   Stand,   Hit,  DD, ... },
.
.
.
  new Action[] /*21 */ { Stand, Stand, Stand, Stand, ...}
}
 
private static Action Decision(Int32 dealerShow, Int32 meShow) {
   return _decision[meShow - 2][dealerShow - 2];
}


Share and enjoy.
Sean
GeneralRe: decision matrix in C# Pin
amatbrewer31-May-07 4:45
amatbrewer31-May-07 4:45 
GeneralRe: decision matrix in C# Pin
Sean Michael Murphy31-May-07 4:56
Sean Michael Murphy31-May-07 4:56 
QuestionClosing Word Documents Pin
Copper2630-May-07 10:28
Copper2630-May-07 10:28 
AnswerRe: Closing Word Documents [modified] Pin
pnpfriend30-May-07 11:52
pnpfriend30-May-07 11:52 
GeneralRe: Closing Word Documents Pin
Copper2631-May-07 8:33
Copper2631-May-07 8:33 
AnswerRe: how can i remove the "pointer" of datagridview Pin
Not Active30-May-07 8:59
mentorNot Active30-May-07 8:59 
GeneralRe: how can i remove the "pointer" of datagridview Pin
FernandoMartin30-May-07 9:09
FernandoMartin30-May-07 9:09 
QuestionGet list of excel formular/functions for ToDay() from worksheet. [modified] Pin
pnpfriend30-May-07 8:17
pnpfriend30-May-07 8:17 
QuestionWebRequestGet Pin
TAREQ F ABUZUHRI30-May-07 7:55
TAREQ F ABUZUHRI30-May-07 7:55 
AnswerRe: WebRequestGet Pin
kubben30-May-07 8:57
kubben30-May-07 8:57 
QuestionProblem with passing parameter to report through form [modified] Pin
Lucky Hamad30-May-07 7:36
Lucky Hamad30-May-07 7:36 
QuestionHow to sort an array containing values of type DateTime? Pin
Affan Toor30-May-07 6:33
Affan Toor30-May-07 6:33 
AnswerRe: How to sort an array containing values of type DateTime? Pin
Tarakeshwar Reddy30-May-07 6:56
professionalTarakeshwar Reddy30-May-07 6:56 
AnswerRe: How to sort an array containing values of type DateTime? Pin
PIEBALDconsult30-May-07 7:33
mvePIEBALDconsult30-May-07 7:33 
AnswerRe: How to sort an array containing values of type DateTime? Pin
Luc Pattyn30-May-07 7:49
sitebuilderLuc Pattyn30-May-07 7:49 
GeneralRe: How to sort an array containing values of type DateTime? Pin
Martin#30-May-07 9:01
Martin#30-May-07 9:01 
GeneralRe: How to sort an array containing values of type DateTime? Pin
Luc Pattyn30-May-07 9:38
sitebuilderLuc Pattyn30-May-07 9:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.