none
Challenge of the Month - September 2011 RRS feed

  • General discussion

  • Welcome to the monthly SmallBASIC Challenge!

    We have changed from weekly to monthly to allow everyone enough time to code their entries. It would be good if people could post their problems with these challenges so that a discussion can start so that everyone can learn from each other.

    These challenges are intended for people who are learning to program or for more experienced programmers who want to start using SmallBASIC after using a different language. Some will be easy, some will be hard - but they will all make you think, and more importantly be GREAT FUN!

    Please post your solutions / partial solutions / questions / feedback etc. into this thread that will remain 'sticky' for the month. The only rule is that your solution must use standard SmallBASIC methods (no extensions).

    Easy Challenge
    Use the SmallBASIC Turtle to write your name (or anything else) on the screen.

    Intermediate Challenge
    Use the SmallBASIC Turtle to draw a regular polygon with the number of sides selected by the user. For example if the user enters 5 then the Turtle should draw a regular pentagon.

    Advanced Challenge
    Write a program (text or graphical) that allows the user to play the game "Last One Loses" against the computer.
    The game starts off with a row of 15 matchsticks. The player and the computer take it in turns to remove 1, 2 or 3 of the matchsticks. The game is over when there are no more matchsticks. The player who took the last matchstick loses.

    Your program should allow for either the player or the computer to go first (maybe with the toss of a coin?)

    You might like to start by making the computer player just choose 1, 2 or 3 at random - but this would not make for a very intelligent opponent. Have a look at this site for a better way for the computer to play.

    If done correctly you will have a game that will nearly always win against your friends and family! What a Prize!



    Do you have an idea for a future challenge? Please post it here!




    • Edited by rubikWizard Friday, September 2, 2011 2:08 PM
    Thursday, September 1, 2011 10:00 PM

All replies

  • If i will use turtle im not gona get only my name, but anything :).
    I love game design and game programing.
    Friday, September 2, 2011 1:58 PM
  • intermediate: ZNJ579
    Saturday, September 3, 2011 11:58 AM
  • I tried your intermediate Luquitas94... it's horrible ;( i put 500 sides and 100 length and it just flies away.
    I love game design and game programing.
    Saturday, September 3, 2011 12:54 PM
  • I tried your intermediate Luquitas94... it's horrible ;( i put 500 sides and 100 length and it just flies away.

    I think it's great. It does exactly what it is meant to do. Well done Luquitas94.

    @Primox128: 500 sides of length 100 would be a very large shape (almost a circle) - so the program is behaving properly. Try 500 sides with a length of 1.


    • Edited by rubikWizard Saturday, September 3, 2011 9:45 PM
    Saturday, September 3, 2011 1:59 PM
  • Here is my game  for advanced : NZB428

    It doesn't work though and i need help with it. any ideas what is wrong with it? Its main problem is that when i tell it to take away 2 match sticks the computer player takes all but one! ITS MADDENING. im kind of new to programming so theres probably a reasonable explanation to this problem.



    Saturday, September 3, 2011 7:54 PM
  • Here is my game  for advanced : NZB428

    It doesn't work though and i need help with it. any ideas what is wrong with it? Its main problem is that when i tell it to take away 2 match sticks the computer player takes all but one! ITS MADDENING. im kind of new to programming so theres probably a reasonable explanation to this problem.

    A good start. I have made a slight modification which at least stops the program from crashing. The computer turn now just picks 1, 2 or 3 at random for its move. See here NZB428-0. I have not added much, just commented out lines. Good work so far for a beginner! Keep at it!

    If you are a beginner then it might be easier to use the text window for your first attempt so that you do not get bogged down with buttons and events which distract from the logic of the game. Have a look at the text output below from a version of the game I made with VisualBasic.


    • Edited by rubikWizard Saturday, September 3, 2011 9:44 PM
    Saturday, September 3, 2011 9:37 PM
  • I've done the matchstick game so its impossible to beat the computer but it has some bugs in it... You have to wait some time before clicking the button or it becomes crazy ;(((

    Also if someone could tell me how to make it shorter and simpler cuz it drives me nuts XD

    PHT405

    Thanks

    Monday, September 5, 2011 11:37 AM
  • easy: NXF657

    intermediate: XVS889

    Monday, September 5, 2011 2:27 PM
  • easy: NXF657

    Nice use of subroutines to re-use code.
    Monday, September 5, 2011 7:41 PM
  • intermediate: XVS889

    Great work! Would be good if you could also enter the size of each side so that the turtle does not run off the edge of the screen when drawing shapes with lots of sides.
    Monday, September 5, 2011 7:43 PM
  • I've done the matchstick game so its impossible to beat the computer but it has some bugs in it... You have to wait some time before clicking the button or it becomes crazy ;(((

    PHT405

    Good work. Would be good if the computer waited before taking its turn as it can be a little difficult to understand what exactly is going on.
    Monday, September 5, 2011 7:46 PM
  • Thank you! Im currently working on a text based version
    You just wasted 2 seconds reading this.
    Monday, September 5, 2011 9:06 PM
  • Thank you! Im currently working on a text based version
    You just wasted 2 seconds reading this.

    Here is my new version that still doesn't work!!!: DLT451

    For some unknown reason it keeps skipping the "comturn" subroutine and the the check to see if youve lost or won.


    You just wasted 2 seconds reading this.
    Monday, September 5, 2011 9:25 PM
  • Thank you! Im currently working on a text based version
    You just wasted 2 seconds reading this.

    Here is my new version that still doesn't work!!!: DLT451

    For some unknown reason it keeps skipping the "comturn" subroutine and the the check to see if youve lost or won.


    You just wasted 2 seconds reading this.

    Nevermind, I fixed it! My game works(i think) here it is: NGB820
    I am an unknown person from an unknown place. My age is between 1 and 100000000 and if you guess it right you won't win anything so there's no point in guessing it right or wrong or both.
    Monday, September 5, 2011 9:48 PM
  • Nice one! Seems to work well!

    Now try to make the matchsticks look like matchsticks (like my image above). Also allow the user to decide who goes first...

    Maybe you would like to suggest a Challenge for next month?

    Monday, September 5, 2011 10:46 PM
  • I am brand new to learning programing.

    This is my first post.

    Here is my version of the matchstick game. JZF087

    It allows the user to beat the computer, but only if they pay very close attention to what they are doing. Otherwise the computer is a very good player.

    It seems like it is working fine.

    Any feedback is appreciated. Like I said, I am learning right now.

    Tuesday, September 6, 2011 2:32 AM
  • Some suggestions on your code, LightHouse9:

    Instead of 

    If (taken <> 1) And (taken <> 2) And (taken <> 3) Then

    You can use

    If (taken > 0) and (taken < 4) Then

     

    Also, you can use TextWindow.ReadNumber() instead of TextWindow.Read()


    ~~AirWaves!!~~
    Tuesday, September 6, 2011 4:01 AM
  • I wrote GWM744.

    Turtle shows words and figure.

    Tuesday, September 6, 2011 6:10 AM
    Answerer
  • Maybe a program that puts a set of words (that you tell it) in alphabetical order.

    Or an extremely simple collision physics demo for expert challenge.


    I am an unknown person from an unknown place. My age is between 1 and 100000000 and if you guess it right you won't win anything so there's no point in guessing it right or wrong or both.
    Tuesday, September 6, 2011 6:29 PM
  • I tested your program and found it to work perfectly!
    I am an unknown person from an unknown place. My age is between 1 and 100000000 and if you guess it right you won't win anything so there's no point in guessing it right or wrong or both.
    Tuesday, September 6, 2011 6:31 PM
  • I wrote GWM744.

    Turtle shows words and figure.

    Very nice!

    Great use of maths for the curves and spirals.

    Tuesday, September 6, 2011 8:42 PM
  • Maybe a program that puts a set of words (that you tell it) in alphabetical order.

    Or an extremely simple collision physics demo for expert challenge.


    I am an unknown person from an unknown place. My age is between 1 and 100000000 and if you guess it right you won't win anything so there's no point in guessing it right or wrong or both.

    Many thanks for this. I will make a note to use it in the future.
    Tuesday, September 6, 2011 8:43 PM
  • I am brand new to learning programing.

    This is my first post.

    Here is my version of the matchstick game. JZF087

    It allows the user to beat the computer, but only if they pay very close attention to what they are doing. Otherwise the computer is a very good player.

    It seems like it is working fine.

    Any feedback is appreciated. Like I said, I am learning right now.


    Nice game, seems to work well. Maybe you could add some simple text graphics to illustrate the matches like in the picture further up. Great messages to inform the player what is going on. Well done as you are new to programming.
    Tuesday, September 6, 2011 8:48 PM
  • Thanks for the tips. I will give those a try.
    Tuesday, September 6, 2011 9:45 PM
  • Thanks. I have never made text graphics like above before, but I will give it a shot. I think it would help add something to the game for sure.
    Tuesday, September 6, 2011 9:52 PM
  • Thanks for the ideas.

    I have updated the game with some new features. Now the user can select to go first or  let the computer go first.

    Also the user can select a difficulty rating from 1 to 5 with each level making it harder to beat the computer.

    I also added in the text graphics that you suggested rubikWizard.

    AirWaves I also made the modifications you suggested. Changing to "readnumber" instead of just "read" fixed the problem I was having.

     

    Here is the new program:     ZZL103

    Thursday, September 8, 2011 2:29 AM
  • I have updated the game with some new features.

    Excellent work. Love the computer level feature and the graphics make it much more appealing.
    Thursday, September 8, 2011 9:01 PM
  • I wrote matchstick game. HVB446

    I unfortunately don't have game sence.

    So this program does not include selecting PC level. 

    If program.delay added after shapes.animate,

    program looks like 'stopped'.

    So I used turtle moving to delay. 


    Friday, September 9, 2011 12:14 AM
    Answerer
  • I wrote matchstick game. HVB446

    I unfortunately don't have game sence.


    I love the graphics and animation. Maybe you could combine your program with the computer player logic of Lighthouse's program to make the game play better.
    Friday, September 9, 2011 5:00 PM
  • I wrote matchstick game. HVB446

    I unfortunately don't have game sence.


    I love the graphics and animation. Maybe you could combine your program with the computer player logic of Lighthouse's program to make the game play better.


    I wrote NWM421. PC level is added.

    I reffered  Lighthouse's program.

     Thank you Lighthouse9.

     

    Saturday, September 10, 2011 8:16 AM
    Answerer
  • Nice! I could only beat it on levels 1-3!
    ~~AirWaves!!~~
    Saturday, September 10, 2011 8:54 AM
  • Intermediate: JRK517

    First I tried to get the user input from a TextBox in the GraphicWindow, but I just don't know how to read them. Does anyone know where I can find that information?

    Tuesday, September 20, 2011 12:11 PM
  • Use this:

    tbox = Controls.AddTextBox(0,0)

    return = Controls.GetTextBoxText(tbox) 'This gets the text from the textbox

     


    ~~AirWaves!!~~
    Tuesday, September 20, 2011 4:21 PM
  • easy: DWX529

    It's supposed to let you input your own name(or anything else) but it doesn't seem to work after I uploaded it, you can see the code though. It's pretty glitchy anyway, but, I was able to get it to write my own name at least.


    Thursday, September 22, 2011 6:11 AM
  • easy: DWX529

    It's supposed to let you input your own name(or anything else) but it doesn't seem to work after I uploaded it, you can see the code though. It's pretty glitchy anyway, but, I was able to get it to write my own name at least.



    Very nice - a lot of work went into this.  You could check out the Hershey font format as a shorthand method to describe vector fonts - there are plenty of web downloads of fonts using this format - you just need to write a program to decode the font to instructions for the turtle.
    Thursday, September 22, 2011 7:20 PM
    Moderator
  • Very nice - a lot of work went into this.  You could check out the Hershey font format as a shorthand method to describe vector fonts - there are plenty of web downloads of fonts using this format - you just need to write a program to decode the font to instructions for the turtle.

    Thanks for the reply I have started looking into outline and stroke fonts, but I don't know what you mean by "decoding" a font, could you explain?  In the meantime here's an update to the old program:

    ZZG580

    I've managed to fix the main glitch that was causing the crashes, although it still won't work with silverlight so you'll have to import it to run... also you can't write "net". I've managed to make it so pressing enter will skip to the next line and the text is now more visually appealing. Any advice on how to improve on this program or my code in general would be appreciated, this is a learning experience for me after all!




    Friday, September 23, 2011 3:58 AM
  • I cannot see anything wrong with your code - looks like some sort of bug with the turtle - perhaps add it to the sticky thread "Bugs to fix for version 1.1" with the code you wrote and instructions that entering NET fails.

    The vector description for Hershey vector fonts are contained in strings of characters - a code if you like.  A sample is like this:

        1  9MWRMNV RRMVV RPSTS
        2 16MWOMOV ROMSMUNUPSQ ROQSQURUUSVOV
        3 11MXVNTMRMPNOPOSPURVTVVU
        4 12MWOMOV ROMRMTNUPUSTURVOV
        5 12MWOMOV ROMUM ROQSQ ROVUV

    The net has plenty of explanations of what this means and how it can be decoded into pen (or turtle) movements - a bit of work with string manipulation and character codes UNICODE, but its all there in the SmallBasic Text method - here is an example output, the first small letters (A,B,C,D,E) are the 5 above.

     

    Friday, September 23, 2011 6:37 PM
    Moderator
  • OK so here mine for the advanced challenge: CQH022

    Enjoy and let me know what you think.


    31337 - everything can be solved... the impossible just takes longer.
    • Edited by DaCodeDude Saturday, September 24, 2011 1:37 AM Forgot to remove dialogs...
    Saturday, September 24, 2011 1:20 AM
  • Works well, a couple of suggestions:

    1] Download the image once and store it using ImageList

    2] Use shapes for the images rather than drawing directly on the GraphicsWindow background.  This means we can show/hide or even move the image shapes without a GraphicsWindow.Clear() that creates a break in the display (especially if we are downloading the image for each match added).

    Simple example showing how - no game, just matches being shown and hidden.

    matchURL = "https://byfiles.storage.live.com/y1pf2eEsI2qMbTnoxSOsXGbYqfXK1A1YuTSBLw4qbHiSDXYV41bXdJLppy2ZOLfgEDBofvTCWNbnC4/matchNorm.JPG?psid=1"
    matchImage = ImageList.LoadImage(matchURL)
    GraphicsWindow.BackgroundColor = "Black"

    For i = 1 To 10
      matchNorm[i] = Shapes.AddImage(matchImage)
      matchDisplay[i] = 1
      Shapes.Move(matchNorm[i],50*i,50)
      Shapes.Zoom(matchNorm[i],0.4,0.4)
    EndFor

    While ("True")
      i = Math.GetRandomNumber(10)
      If (matchDisplay[i] = 1) Then
        Shapes.HideShape(matchNorm[i])
        matchDisplay[i] = 0
      Else
        Shapes.ShowShape(matchNorm[i])
        matchDisplay[i] = 1
      EndIf
      Program.Delay(1000)
    EndWhile

     


    Saturday, September 24, 2011 12:03 PM
    Moderator
  • Thanks for the help litdev. I had originally used a download function for the image, but due to security features on my computer, it doesnt want to let the download work properly and since I know others who load the silverlight version probably dont want to change security settings just to view a game i figured i would do it this way instead.

    The shapes idea is definatly a good idea though, truth be told i havent once used the shapes commands... lol most of the time my programs create the art and manage most functions manualy with my own code, i like the challenge... but this was just a quick code for this challenge of the month :D


    31337 - everything can be solved... the impossible just takes longer.
    Monday, September 26, 2011 3:29 PM
  • QRW395 - ADVANCE CHALLENGE SEP11
    Best Regards..
    Wednesday, September 28, 2011 2:58 AM
  • Hi rockstar111

    Your program looks good, but unfortunately it does not display the matches as they are linked to a file on your local disk (C:). You should upload it somewhere and then link to that.

    Thursday, September 29, 2011 9:27 PM
  • It's almost the end of the September Challenge. There have been loads of fantastic entries for all of the challenges which we have all learnt from. Hopefully you have all found them to be useful and FUN! I have certainly had great fun trying out everyone's solutions and there have been some very interesting and creative solutions posted.

    Now let's move to the new October Challenges and see what everyone can create!

    Happy Coding!

    ... and don't forget that if you have an idea for a future challenge then let us know.

    Thursday, September 29, 2011 9:32 PM
  • Simple advanced: QNL136

    I know i could made it shorter...

    • Edited by HBK12 Sunday, November 20, 2011 12:26 AM
    Sunday, November 20, 2011 12:24 AM
  • Nice program!

    Would be great if you could make the computer player "more intelligent" - see above posts.

     

    Keep up the good work!

    Wednesday, November 23, 2011 11:26 PM
  • Intermediate Challenge

    Advanced Challenge

    I'm working on a graphical version for the Advanced challenge.

    Tuesday, March 13, 2012 12:43 AM