Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A little more about the spirit of the project??? #772

Open
DualBrain opened this issue Jul 14, 2022 · 6 comments
Open

A little more about the spirit of the project??? #772

DualBrain opened this issue Jul 14, 2022 · 6 comments

Comments

@DualBrain
Copy link

DualBrain commented Jul 14, 2022

OK, so I'm looking at (specifically) the VB (.NET) conversion done for Acey Ducey and was left wondering the overall spirit of this project. Certainly, the conversion done is VB, but it also increases the complexity of the program significantly by introducing a lot of extra concepts. It's already bad enough that VB has a lot of "boiler plate" that many could argue is not necessary for some types of projects... literally this one being a perfect example of such. I'm not criticizing the conversion, that is totally not my intention. Rather I'm trying to wrap my head around the overall goal/intent.

One could argue that this is a chance to "show off" VB's capabilities or, to my thinking, this is more of an exercise of simplicity... taking what was, no pun intended, pretty basic and show how that could be done in a more modern implementation / platform.

To that end, I took a stab at a translation that a) attempts to stay VERY TRUE to the original, b) KISS and c) attempt to keep everything in view by either remaining in the same (or smaller) number of total lines of code (without, of course, straying too far from item a).

Imports System.Console

Module Program

  Sub Main()

    Dim Q, M As Single

    Randomize(Timer)

    WriteLine(Space(26) & "ACEY DUCEY CARD GAME")
    WriteLine(Space(15) & "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY")
    WriteLine()
    WriteLine()
    WriteLine("ACEY-DUCEY IS PLAYED IN THE FOLLOWING MANNER ")
    WriteLine("THE DEALER (COMPUTER) DEALS TWO CARDS FACE UP")
    WriteLine("YOU HAVE AN OPTION TO BET OR NOT BET DEPENDING")
    WriteLine("ON WHETHER OR NOT YOU FEEL THE CARD WILL HAVE")
    WriteLine("A VALUE BETWEEN THE FIRST TWO.")
    WriteLine("IF YOU DO NOT WANT TO BET, INPUT A 0")
    'N = 100
Start:
    Q = 100
DisplayPool:
    WriteLine("YOU NOW HAVE " & Q & " DOLLARS.")
    WriteLine()
    GoTo DisplayCards
IncreasePool:
    Q += M
    GoTo DisplayPool
DecreasePool:
    Q -= M
    GoTo DisplayPool
DisplayCards:
    WriteLine("HERE ARE YOUR NEXT TWO CARDS: ")
DetermineFirstCard:
    Dim A = Int(14 * Rnd(1)) + 2
    If A < 2 Then GoTo DetermineFirstCard
    If A > 14 Then GoTo DetermineFirstCard
DetermineSecondCard:
    Dim B = Int(14 * Rnd(1)) + 2
    If B < 2 Then GoTo DetermineSecondCard
    If B > 14 Then GoTo DetermineSecondCard
    If A >= B Then GoTo DetermineFirstCard
    If A < 11 Then WriteLine(A)
    If A = 11 Then WriteLine("JACK")
    If A = 12 Then WriteLine("QUEEN")
    If A = 13 Then WriteLine("KING")
    If A = 14 Then WriteLine("ACE")
    If B < 11 Then WriteLine(B)
    If B = 11 Then WriteLine("JACK")
    If B = 12 Then WriteLine("QUEEN")
    If B = 13 Then WriteLine("KING")
    If B = 14 Then WriteLine("ACE") : WriteLine()
EnterBet:
    WriteLine()
    Write("WHAT IS YOUR BET? ") : Dim valid = Single.TryParse(ReadLine(), M)
    If M <> 0 Then GoTo ValidateBet
    WriteLine("CHICKEN!!")
    WriteLine()
    GoTo DisplayCards
ValidateBet:
    If M <= Q Then GoTo DetermineFinalCard
    WriteLine("SORRY, MY FRIEND, BUT YOU BET TOO MUCH.")
    WriteLine("YOU HAVE ONLY " & Q & " DOLLARS TO BET.")
    GoTo EnterBet
DetermineFinalCard:
    Dim C = Int(14 * Rnd(1)) + 2
    If C < 2 Then GoTo DetermineFinalCard
    If C > 14 Then GoTo DetermineFinalCard
    If C < 11 Then WriteLine(C)
    If C = 11 Then WriteLine("JACK")
    If C = 12 Then WriteLine("QUEEN")
    If C = 13 Then WriteLine("KING")
    If C = 14 Then WriteLine("ACE") : WriteLine()
    If C > A Then GoTo WinCheck
    GoTo Lose
WinCheck:
    If C >= B Then GoTo Lose
    WriteLine("YOU WIN!!!")
    GoTo IncreasePool
Lose:
    WriteLine("SORRY, YOU LOSE")
    If M < Q Then GoTo DecreasePool
    WriteLine() : WriteLine()
    WriteLine("SORRY, FRIEND, BUT YOU BLEW YOUR WAD.")
    WriteLine() : WriteLine()
    Write("TRY AGAIN (YES OR NO)? ") : Dim yesNo$ = ReadLine()
    WriteLine() : WriteLine()
    If yesNo$?.ToUpper = "YES" Then GoTo Start
    WriteLine("O.K., HOPE YOU HAD FUN!")

  End Sub

End Module

Now with an actual example to illustrate more of what I'm asking (wondering), what is the goal (or goals) related to conversions - most likely a very specific set of question(s) for VB as there are a lot of things VB is capable of doing that still harkens back to the early days of MBASIC?

Thanks.

(Also, if there are any errors in this posted example - please understand that I threw this together in about 20 minutes.)

@aldrinm
Copy link
Contributor

aldrinm commented Jul 14, 2022

The posted example is definitely simpler and easier to read. However, all the GoTos may make it harder to debug or follow the program flow. One of the goals is to use good, modern coding practices and the Gotos don't fit there. Other programs are longer and more complex and may not fit in a single screen view. Not a VB expert, so can't comment on the other points.

@pricerc
Copy link

pricerc commented Jul 14, 2022

In the main project guidelines:

Project goals

Feel free to begin converting these classic games into the above list of modern, memory safe languages.
...

  • Please DO update for modern coding conventions. Support uppercase and lowercase. Use structured programming. Use subroutines. Try to be an example of good, modern coding practices!

  • Use lots of comments to explain what is going on. Comment liberally! If there were clever tricks in the original code, decompose those tricks into simpler (even if more verbose) code, and use comments to explain what’s happening and why. If there is something particularly tricky about a program, edit the Porting Notes section of the readme.md to let everyone know. Those GOTOs can be very pesky..

  • Please don’t get too fancy. Definitely use the most recent versions and features of the target language, but also try to keep the code samples simple and explainable – the goal is to teach programming in the target language, not necessarily demonstrate the cleverest one-line tricks, or big system "enterprise" coding techniques designed for thousands of lines of code.

Note in that last bullet: the goal is to teach programming in the target language .

Which I interpret as: the conversion should demonstrate the practices that you would like your students to follow.

@coding-horror
Copy link
Owner

I would say we want the project to reflect modern coding practices, so essentially convert the gotos to subroutines would be preferable versus a "straight" port.

@shayneoneill
Copy link

shayneoneill commented Nov 11, 2022

There is a few things in the python one that could do with some simplification. The mugwump one for instance uses map(). I mean, cool and all, but as a 30+ year coder, this one had me paused for a bit, since its a very unstandard way of doing things.

m, n = map(int, input(f"Turn {turns} - what is your guess? ").split())

Like, ok we're splitting a string into two strings with a space, then kinda hack casting those both into integers.

But that map(int) thing introduces function passing, casting, string splitting and finally returning tuples. Thats a lot of lesson for a single line of code, and its worth keeping in mind that map()'s use can be controversial in some sectors of python, with Guido Van Rossen being a fan of removing it from the list of reserved word commands, although it never was. Its recent more common use is mostly a product of JS coders migrating to python. Its not a bad command (I use it a lot), but its a weird command that never felt quite at home in python due to the fact you tend to need to stop for a moment and figure out what the heck its trying to do.

Personally I would have had that thing replaced by something like

try:
     x= int(input(f"Turn {turns} - what is your guess for X?"))
except ValueError:
    x = -1
    print ("X Must be a number")
try:
    y= int(input(f"Turn {turns} - what is your guess for Y?"))
except ValueError:
    y = -1
    print ("Y Must be a number")

Sure, its longer, but every line expresses one concept (or two in the. case of int(input()) which can be explained to a child easily. Honestly I would also probably have used string concatenation instead of interpolation too, but thats a pretty easy to explain thing.

Also x,y is the standard for coordinates in cartesian geometry, not m,n. Generally we ought teach to use words for variables (Or even things like word_word , wordWord etc, but hey KISS) except when that single letter abreviation is well understood. x,y is common enough that most people know what it means (and you can explain it to a kid pretty easily) but with m, n I had to scan over the code a couple of times to grok what these letters meant.

@AnthonyMichaelTDM
Copy link
Contributor

I'd just make a pull request for that

@coding-horror
Copy link
Owner

Sure @shayneoneill if you are up for it a pull request is very welcome! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants
@aldrinm @shayneoneill @coding-horror @DualBrain @pricerc @AnthonyMichaelTDM and others