Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8622617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:06:03+00:00 2026-06-12T07:06:03+00:00

I’m attempting to represent the basic strategy of a blackjack game as a map

  • 0

I’m attempting to represent the basic strategy of a blackjack game as a map with integer keys whose values are a fixed length array of strings.
The keys represent the value of the player’s hand, the array index represents the value of the dealers up card (hence the fixed length array of size 10 corresponding to card values 2-11). The string value in the array at the position corresponding to the dealer’s up card contains the ideal play (stay, hit, split, double).

IE) player hand value is a hard 8, dealer up card is a 2. Basic strategy says the player should hit. To determine this using my map, I would get the array whose key is 8(player hand value = 8) and then looking at the string in array index 0 (Dealer up card = 2).

I’ve attempted to define it this way:

val hardHandBasicStrategy = collection.mutable.Map[Int,Array[String](10)]

but Scala doesn’t seem to like this…

Please help me understand what I’ve done wrong, and/or suggest a way to make it work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:06:05+00:00Added an answer on June 12, 2026 at 7:06 am

    Scala doesn’t have a type that represents arrays of a fixed size. You can either simply use arrays of size ten–this is what is normally done–or, if you want stronger guarantees that it really is size ten, you can construct a ten-long-array-class yourself:

    class ArrayTen[T: ClassManifest](zero: T) {
      protected val data = Array.fill(10)(zero)
      def apply(i: Int) = data(i)
      def update(i: Int, t: T) { data(i) = t }
      protected def set(ts: Array[T]) { for (i <- data.indices) data(i) = ts(i) }
      def map[U: ClassManifest](f: T => U) = { 
        val at = new ArrayTen(null.asInstanceOf[U])
        at.set(data.map(f))
        at
      }
      def foreach(f: T => Unit) { data.map(f) }
      override def toString = data.mkString("#10[",",","]")
      override def hashCode = scala.util.MurmurHash.arrayHash(data)
      override def equals(a: Any) = a match {
        case a: ArrayTen[_] => (data,a.data).zipped.forall(_ == _)
        case _ => false
      }
      // Add other methods here if you really need them
    }
    

    Example:

    scala> new ArrayTen("(nothing)")
    res1: ArrayTen[java.lang.String] = 
      #10[(nothing),(nothing),(nothing),(nothing),(nothing),
      (nothing),(nothing),(nothing),(nothing),(nothing)]
    
    scala> res1(3) = "something!!!"
    
    scala> res1
    res3: ArrayTen[java.lang.String] = 
      #10[(nothing),(nothing),(nothing),something!!!,(nothing),
      (nothing),(nothing),(nothing),(nothing),(nothing)]
    

    If you need the the fixed-length array to take a parameter that determines the length, then you should

    trait Size { size: Int }
    class ArraySize[S <: Size, T: ClassManifest](zero: T, s: Size) {
      protected val data = Array.fill(s.size)(zero)
      ...
    }
    

    You won’t have all the collections goodies unless you reimplement them, but then again you don’t want most of the goodies, since most of them can change the length of the array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
I have an array which has BIG numbers and small numbers in it. I
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.