whee "turing completness"

Everything todo with programming goes HERE.

Should we force luke-jr to say something nice?

yes
10
91%
no
1
9%
 
Total votes: 11

User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

Tank Program wrote:Yes well. I wrote pong in php a while back.
http://electricpotential.net/temp/pong/
</random>
Great. After some hundreds of mouse clicks (to be faster than the auto reload) and reloads it traveled back and forth once.
ˌɑrməˈɡɛˌtrɑn
User avatar
Tank Program
Forum & Project Admin, PhD
Posts: 6712
Joined: Thu Dec 18, 2003 7:03 pm

Post by Tank Program »

Jonathan wrote:
Tank Program wrote:Yes well. I wrote pong in php a while back.
http://electricpotential.net/temp/pong/
</random>
Great. After some hundreds of mouse clicks (to be faster than the auto reload) and reloads it traveled back and forth once.
Patience...
Image
User avatar
Lucifer
Project Developer
Posts: 8744
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Post by Lucifer »

That pong game is pretty cool, tank. It seems like if you increased the speed of the ball and the paddles (when you press up/down) you could make it work without sigificantly noticing that it's run server-side. :)

Hell, you might be able to make it multi-player too. I don't know how much time you want to spend making a pong game in php, though. It is pretty cool, though.
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

Tank Program wrote:
Jonathan wrote:Great. After some hundreds of mouse clicks (to be faster than the auto reload) and reloads it traveled back and forth once.
Patience...
I'd rather spent my time writing another pong game in C. And I did. :) Maybe I can make a movie of the AI playing against itself.
ˌɑrməˈɡɛˌtrɑn
User avatar
TiTnAsS
Match Winner
Posts: 655
Joined: Sun Jan 23, 2005 2:44 am
Location: Reppin the Bay Area!

Post by TiTnAsS »

Z-Man wrote:Observe that I could happily take all the matches. That should be impossible, and also I should have lost because I took the last one. And when it's player 2's turn, there are 15 matches again. That last error is because there are actually three variables named "a" in the program: the one from the first line, and the ones in func_a and func_b. Variables are local to their definition, and unless you do something aboutof func_b. Also, the "a" of the two functions will be a different "a" for it, writing to func_a's a won't have an effect on the global "a" or the one every time you call the function. There's a way to access global variables from within functions, but it's better style most of the time to pass a function every variable it needs for operation, and let it return the information the caller needs (here, for example, the number of matches left).
Another run:
I didn't realize it was lose if you took last match, ill fix that later and i'm currently working on limiting it to 4 matches per turn..

About the global variable, i havnt had a chance to check it since i made the functipons cuz i couldnt run it cuz the elif thing, i had it close b4 that tho...ill take care of it
Damn, it sure has been a while!
User avatar
Lucifer
Project Developer
Posts: 8744
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Post by Lucifer »

Welcome to the fine art of programming TnA, the area in which you will spend 90% of your time: figuring out why it don't work.

:) (This is where the men get separated from the chimps)
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
User avatar
TiTnAsS
Match Winner
Posts: 655
Joined: Sun Jan 23, 2005 2:44 am
Location: Reppin the Bay Area!

Post by TiTnAsS »

like that quote i posted...and i guess that other thinhg i brought up was true, cuz they changed your rank i just noticed :)
Damn, it sure has been a while!
User avatar
Lucifer
Project Developer
Posts: 8744
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Post by Lucifer »

TiTnAsS wrote:like that quote i posted...and i guess that other thinhg i brought up was true, cuz they changed your rank i just noticed :)
Hurry up, dude. I've got another assignment for you. :)
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
User avatar
TiTnAsS
Match Winner
Posts: 655
Joined: Sun Jan 23, 2005 2:44 am
Location: Reppin the Bay Area!

Post by TiTnAsS »

I've been busy all weekend sry guys :)...
Damn, it sure has been a while!
User avatar
TiTnAsS
Match Winner
Posts: 655
Joined: Sun Jan 23, 2005 2:44 am
Location: Reppin the Bay Area!

Post by TiTnAsS »

Code: Select all

#Homework from Z-Man
#I finally finished it so be amazed!
numMatches = 15
player1 = raw_input("Player 1's name: ")
player2 = raw_input("Player 2's name: ")
players = (player1,player2)
currentPlayer = 0
print "The rules to this game are simple."
print "You can't take more then 3 matches."
print "The person to take the last match is the loser."
print "Good luck! :)"
while numMatches > 0:
    print " "
    print "It's",players[currentPlayer] + "'s","turn."
    print "There are",numMatches,"matches left."
    numTaken = input("How many matches do you want to take? ")
    numMatches = numMatches - numTaken
    if numTaken > 3:
        numMatches = numMatches + numTaken
        print "You can't take that many matches."
        currentPlayer = 1 - currentPlayer
    currentPlayer = 1 - currentPlayer
print players[currentPlayer],"is the winner!"
Whoo!! Down with functions (especially when you don't need em yet you don't realize that you dont...)!!

*Waits for applause...* lol :)
Damn, it sure has been a while!
User avatar
Lucifer
Project Developer
Posts: 8744
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Post by Lucifer »

You should do your input validation before subtracting num matches. Something like:

Code: Select all

if input > 3 or input < 1:
    pass
else:
    numMatches = numMatches - input
Or something like that. Or you can wrap the input getter into a while loop that only exits when the input is valid.

Code: Select all

isValid = False
while isValid:
    input = input("Whateverblahblah")
    if input < 3 and input > 0:
        isValid = True
Under no circumstances do you ever want to apply input to variables without validating it somehow! Which is exactly what you did. ;) Ideally, you would structure your input getting so that there is no such thing as invalid input, but that's not something that happens very often.
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
User avatar
TiTnAsS
Match Winner
Posts: 655
Joined: Sun Jan 23, 2005 2:44 am
Location: Reppin the Bay Area!

Post by TiTnAsS »

If it works as is why bother.. But i'll keep that in mind for the second it dosnt work the way i do it :) thx for the help :wink:
Damn, it sure has been a while!
User avatar
Lucifer
Project Developer
Posts: 8744
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Post by Lucifer »

TiTnAsS wrote:If it works as is why bother.. But i'll keep that in mind for the second it dosnt work the way i do it :) thx for the help :wink:
It doesn't work. Type in -1 for matches and see what happens. Type in 0 and watch your turn be skipped. :) Type in 34000000000 and see what happens.
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
User avatar
TiTnAsS
Match Winner
Posts: 655
Joined: Sun Jan 23, 2005 2:44 am
Location: Reppin the Bay Area!

Post by TiTnAsS »

Code: Select all

## lucifer taught me how to validate my input :)

#Homework from Z-Man
#I finally finished it so be amazed!
numMatches = 15
player1 = raw_input("Player 1's name: ")
player2 = raw_input("Player 2's name: ")
players = (player1,player2)
currentPlayer = 0
print "The rules to this game are simple."
print "You can't take more then 3 matches."
print "The person to take the last match is the loser."
print "Good luck! :)"
while numMatches > 0:
    print " "
    print "It's",players[currentPlayer] + "'s","turn."
    print "There are",numMatches,"matches left."
    inputValid = False
    while inputValid is not True:
        numTaken = str(raw_input("How many matches do you want to take? ") )
        if numTaken.isdigit():
            numTaken = int(numTaken)
            if numTaken > 3 or numTaken <= 0:
                print "You must pick 1-3 matches.  You picked " + str(numTaken)
            else:
                inputValid = True
        else:
            print "You must enter a number from 1 to 3."
    numMatches = numMatches - numTaken
    currentPlayer = 1 - currentPlayer
print players[currentPlayer],"is the winner!" 
Fixed code up after lucifer taught me to validate the input....
Damn, it sure has been a while!
User avatar
Z-Man
God & Project Admin
Posts: 11710
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Post by Z-Man »

Applause! It works fine, and it's even good style. A minor glitch (minor because it does not lead to undesired behavior): it does not check anymore whether you took more matches than are there:

Code: Select all

...
It's blubb's turn.
There are 2 matches left.
How many matches do you want to take? 3
bla is the winner!
Post Reply