Referencing a match statement when populating an array [closed]Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?PHP: Delete an element from an arrayHow to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?How to use foreach with array in JavaScript?

How to source a part of a file

Revoked SSL certificate

Horror movie about a virus at the prom; beginning and end are stylized as a cartoon

Paid for article while in US on F-1 visa?

dbcc cleantable batch size explanation

Does detail obscure or enhance action?

How is it possible to have an ability score that is less than 3?

What's that red-plus icon near a text?

I'm flying to France today and my passport expires in less than 2 months

What does it mean to describe someone as a butt steak?

Can I make popcorn with any corn?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

Why is 150k or 200k jobs considered good when there's 300k+ births a month?

Perform and show arithmetic with LuaLaTeX

How does one intimidate enemies without having the capacity for violence?

What would happen to a modern skyscraper if it rains micro blackholes?

Java Casting: Java 11 throws LambdaConversionException while 1.8 does not

What is the word for reserving something for yourself before others do?

Modeling an IP Address

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

What defenses are there against being summoned by the Gate spell?

How does quantile regression compare to logistic regression with the variable split at the quantile?

What doth I be?

Important Resources for Dark Age Civilizations?



Referencing a match statement when populating an array [closed]


Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?PHP: Delete an element from an arrayHow to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?How to use foreach with array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have been set a simple task to create a TicTacToe game, using arrays.
I have a class 'Player' with the objects 'X' and 'O'



I have the following Match statement:



def optPlayerToChar(p: Option[Player]): Char = p match 
case None => ' '
case Some(O) => 'O'
case Some(X) => 'X'



I have the following declaration for the grid:



private var grid: Array[Array[Option[Player]]] = ofDim[Option[Player]](3,3)


I need to be able to populate the grid at (x)(y) using the match statement. I have tried many things but can't seem to get it to work for some reason. Apologies if it is just a simple solution I am overlooking.



it needs to be in a format like the following but obviously functioning:



grid(x)(y) = optPlayerToChar(p: Option[Player])



the code I am using to show the grid (in case you need it):



def showGrid() 
println()
for(j <- 0 to 2) " + optPlayerToChar(grid(2)(j)))
println()
if (j<2) println(" --- --- --- ")

println()










share|improve this question













closed as unclear what you're asking by Dima, Shaido, Tiw, Dale Burrell, Matteo Baldi Mar 8 at 8:52


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.













  • 2





    So, what's the actual problem?

    – Dima
    Mar 8 at 1:57

















0















I have been set a simple task to create a TicTacToe game, using arrays.
I have a class 'Player' with the objects 'X' and 'O'



I have the following Match statement:



def optPlayerToChar(p: Option[Player]): Char = p match 
case None => ' '
case Some(O) => 'O'
case Some(X) => 'X'



I have the following declaration for the grid:



private var grid: Array[Array[Option[Player]]] = ofDim[Option[Player]](3,3)


I need to be able to populate the grid at (x)(y) using the match statement. I have tried many things but can't seem to get it to work for some reason. Apologies if it is just a simple solution I am overlooking.



it needs to be in a format like the following but obviously functioning:



grid(x)(y) = optPlayerToChar(p: Option[Player])



the code I am using to show the grid (in case you need it):



def showGrid() 
println()
for(j <- 0 to 2) " + optPlayerToChar(grid(2)(j)))
println()
if (j<2) println(" --- --- --- ")

println()










share|improve this question













closed as unclear what you're asking by Dima, Shaido, Tiw, Dale Burrell, Matteo Baldi Mar 8 at 8:52


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.













  • 2





    So, what's the actual problem?

    – Dima
    Mar 8 at 1:57













0












0








0








I have been set a simple task to create a TicTacToe game, using arrays.
I have a class 'Player' with the objects 'X' and 'O'



I have the following Match statement:



def optPlayerToChar(p: Option[Player]): Char = p match 
case None => ' '
case Some(O) => 'O'
case Some(X) => 'X'



I have the following declaration for the grid:



private var grid: Array[Array[Option[Player]]] = ofDim[Option[Player]](3,3)


I need to be able to populate the grid at (x)(y) using the match statement. I have tried many things but can't seem to get it to work for some reason. Apologies if it is just a simple solution I am overlooking.



it needs to be in a format like the following but obviously functioning:



grid(x)(y) = optPlayerToChar(p: Option[Player])



the code I am using to show the grid (in case you need it):



def showGrid() 
println()
for(j <- 0 to 2) " + optPlayerToChar(grid(2)(j)))
println()
if (j<2) println(" --- --- --- ")

println()










share|improve this question














I have been set a simple task to create a TicTacToe game, using arrays.
I have a class 'Player' with the objects 'X' and 'O'



I have the following Match statement:



def optPlayerToChar(p: Option[Player]): Char = p match 
case None => ' '
case Some(O) => 'O'
case Some(X) => 'X'



I have the following declaration for the grid:



private var grid: Array[Array[Option[Player]]] = ofDim[Option[Player]](3,3)


I need to be able to populate the grid at (x)(y) using the match statement. I have tried many things but can't seem to get it to work for some reason. Apologies if it is just a simple solution I am overlooking.



it needs to be in a format like the following but obviously functioning:



grid(x)(y) = optPlayerToChar(p: Option[Player])



the code I am using to show the grid (in case you need it):



def showGrid() 
println()
for(j <- 0 to 2) " + optPlayerToChar(grid(2)(j)))
println()
if (j<2) println(" --- --- --- ")

println()







arrays scala






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 1:47









Frazer EastmanFrazer Eastman

365




365




closed as unclear what you're asking by Dima, Shaido, Tiw, Dale Burrell, Matteo Baldi Mar 8 at 8:52


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Dima, Shaido, Tiw, Dale Burrell, Matteo Baldi Mar 8 at 8:52


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2





    So, what's the actual problem?

    – Dima
    Mar 8 at 1:57












  • 2





    So, what's the actual problem?

    – Dima
    Mar 8 at 1:57







2




2





So, what's the actual problem?

– Dima
Mar 8 at 1:57





So, what's the actual problem?

– Dima
Mar 8 at 1:57












1 Answer
1






active

oldest

votes


















2














You define your grid but you don't populate it, so it is populated with null by default. null isn't the same thing as None.



val grid: Array[Array[Option[Player]]] = 
Array.fill[Option[Player]](3,3)(None)


With this, optPlayerToChar() and showGrid() should work as planned.



This won't work grid(x)(y) = optPlayerToChar(p: Option[Player]) because each grid element is an Option[Player] but optPlayerToChar() returns a Char. Those are, of course, unrelated and incompatible types.



Note: There's no reason to make grid a var. Arrays are mutable. The variable usually doesn't need to be mutable as well.






share|improve this answer































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You define your grid but you don't populate it, so it is populated with null by default. null isn't the same thing as None.



    val grid: Array[Array[Option[Player]]] = 
    Array.fill[Option[Player]](3,3)(None)


    With this, optPlayerToChar() and showGrid() should work as planned.



    This won't work grid(x)(y) = optPlayerToChar(p: Option[Player]) because each grid element is an Option[Player] but optPlayerToChar() returns a Char. Those are, of course, unrelated and incompatible types.



    Note: There's no reason to make grid a var. Arrays are mutable. The variable usually doesn't need to be mutable as well.






    share|improve this answer





























      2














      You define your grid but you don't populate it, so it is populated with null by default. null isn't the same thing as None.



      val grid: Array[Array[Option[Player]]] = 
      Array.fill[Option[Player]](3,3)(None)


      With this, optPlayerToChar() and showGrid() should work as planned.



      This won't work grid(x)(y) = optPlayerToChar(p: Option[Player]) because each grid element is an Option[Player] but optPlayerToChar() returns a Char. Those are, of course, unrelated and incompatible types.



      Note: There's no reason to make grid a var. Arrays are mutable. The variable usually doesn't need to be mutable as well.






      share|improve this answer



























        2












        2








        2







        You define your grid but you don't populate it, so it is populated with null by default. null isn't the same thing as None.



        val grid: Array[Array[Option[Player]]] = 
        Array.fill[Option[Player]](3,3)(None)


        With this, optPlayerToChar() and showGrid() should work as planned.



        This won't work grid(x)(y) = optPlayerToChar(p: Option[Player]) because each grid element is an Option[Player] but optPlayerToChar() returns a Char. Those are, of course, unrelated and incompatible types.



        Note: There's no reason to make grid a var. Arrays are mutable. The variable usually doesn't need to be mutable as well.






        share|improve this answer















        You define your grid but you don't populate it, so it is populated with null by default. null isn't the same thing as None.



        val grid: Array[Array[Option[Player]]] = 
        Array.fill[Option[Player]](3,3)(None)


        With this, optPlayerToChar() and showGrid() should work as planned.



        This won't work grid(x)(y) = optPlayerToChar(p: Option[Player]) because each grid element is an Option[Player] but optPlayerToChar() returns a Char. Those are, of course, unrelated and incompatible types.



        Note: There's no reason to make grid a var. Arrays are mutable. The variable usually doesn't need to be mutable as well.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 8 at 8:14

























        answered Mar 8 at 7:06









        jwvhjwvh

        28.5k52141




        28.5k52141















            Popular posts from this blog

            AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

            Алба-Юлія

            Захаров Федір Захарович