Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. decision matrix in C#

decision matrix in C#

Scheduled Pinned Locked Moved C#
csharpdata-structuresquestiondiscussion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amatbrewer
    wrote on last edited by
    #1

    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? Any opinions?

    David Wilkes

    S 1 Reply Last reply
    0
    • A amatbrewer

      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? Any opinions?

      David Wilkes

      S Offline
      S Offline
      Sean Michael Murphy
      wrote on last edited by
      #2

      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:

      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

      A 1 Reply Last reply
      0
      • S Sean Michael Murphy

        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:

        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

        A Offline
        A Offline
        amatbrewer
        wrote on last edited by
        #3

        Thanks for the reply! Blackjack got me thinking about it, but I can think of a number of projects (current and proposed) that this could be useful for. I appreciate your example; it is much more elegant then what I was originally thinking of. Not sure I understand the syntax of “Action[][] _decision” and “private static Action Decision(Int32 dealerShow, Int32 meShow)” but it gives me something to research. Thanks again!

        David Wilkes

        S 1 Reply Last reply
        0
        • A amatbrewer

          Thanks for the reply! Blackjack got me thinking about it, but I can think of a number of projects (current and proposed) that this could be useful for. I appreciate your example; it is much more elegant then what I was originally thinking of. Not sure I understand the syntax of “Action[][] _decision” and “private static Action Decision(Int32 dealerShow, Int32 meShow)” but it gives me something to research. Thanks again!

          David Wilkes

          S Offline
          S Offline
          Sean Michael Murphy
          wrote on last edited by
          #4

          amatbrewer wrote:

          Thanks for the reply!

          No prob. Evaluating card hands with multi-dimensional arrays[^] is sort of a hobby of mine. :) Share and enjoy. Sean

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups