
-----------------------------------
aaro4130
Thu Jun 06, 2013 5:04 pm

TuringPong V2.2.1
-----------------------------------
Hey! I'm Aaron, a 16 year old computer programmer with 8 years in programming experience. and I have made TuringPong V2.2.1

"Turing Pong" it's a school project, all the teacher told us to do was make paddles/ball work 
and exit when the ball goes off screen.. I took it to a whole new level.

I wrote 400 + Lines of code (Instead of the 200 or less needed), added AI, difficulty, etc.

FEATURES

-Basic pong gameplay
-3 difficulty levels
-an AI

Enjoy this release!

NOTE : Includes source, binary, instructions

-----------------------------------
Nathan4102
Thu Jun 06, 2013 5:09 pm

RE:TuringPong V2.2.1
-----------------------------------
Has this already been handed in and marked? If not, it's not a good idea to post source code. Took a quick look at it though, it looks pretty good. Nice job.

-----------------------------------
aaro4130
Thu Jun 06, 2013 5:15 pm

RE:TuringPong V2.2.1
-----------------------------------
No not yet, although my class is full of people who do not use the internet to find code and aren't capable of modifying code of this level, I quickly updated the source and will upload V2.2.2 in a moment

I just added menu sounds

EDIT : Hopefully now final. Uploaded now!

-----------------------------------
Raknarg
Thu Jun 06, 2013 5:23 pm

RE:TuringPong V2.2.1
-----------------------------------
with 8 years I hope you try to go above and beyond

-----------------------------------
Tony
Thu Jun 06, 2013 5:31 pm

Re: TuringPong V2.2.1
-----------------------------------
I wrote 400 + Lines of code (Instead of the 200 or less needed)
Or you know... 19 lines. http://compsci.ca/blog/your-computer-science-isu-in-20-lines/

Eventually you might realize that measuring software by lines of code is kind of like measuring aircraft by their weight -- bigger ofter does not mean better.

-----------------------------------
aaro4130
Thu Jun 06, 2013 5:37 pm

Re: TuringPong V2.2.1
-----------------------------------
That is true!

I took out the final prefix, I think this is good for now though, I added a sound toggle because some people find the sound annoying

Enjoy!

-----------------------------------
Nathan4102
Thu Jun 06, 2013 6:40 pm

Re: RE:TuringPong V2.2.1
-----------------------------------
No not yet, although my class is full of people who do not use the internet to find code and aren't capable of modifying code of this level, I quickly updated the source and will upload V2.2.2 in a moment

I just added menu sounds

EDIT : Hopefully now final. Uploaded now!

Students copying the code isn't the only problem. What happens if your teacher googles a snippet of your code, and finds this? I've known teachers who will auto-fail you, no questions asked.  Your choice though!

I took a bit of a closer look at your code, and I noticed a couple things:

1: [code]var text : string := "PAUSED"
        width2 := Font.Width (text, font2)[/code]

What exactly is the point of the variable "text"? Whats wrong with width2 := Font.Width("PAUSED", font2)? Shortening this saves lines, and saves memory.

2: I noticed you're declaring variables all over the place, inside procedures, in the middle of your program, blah blah blah. Its good standards to declare all variables that you can at the top. Also, if you can prevent it, don't declare variables in repeated procedures. I'm pretty sure (Not 100%) that in Turing, this will result in memory leaks.

3: [code]if chars('m') then
exit
end if[/code]

This can be shortened to:

[code]exit when chars('m')[/code]

Not that important, but worth noting.

4. All these procedures for moving the paddle could be shortened into a case statement. Not a huge difference, but much nicer on the eyes.

-----------------------------------
aaro4130
Thu Jun 06, 2013 6:42 pm

RE:TuringPong V2.2.1
-----------------------------------
Well the text variable is there so I don't have to do 
Font.Width("PAUSED"...etc)
Draw.Text("PAUSED"...etc)

And also the teacher told us to do it using procedures, and the exit when is a good idea in that one part

-----------------------------------
Dreadnought
Thu Jun 06, 2013 7:14 pm

Re: TuringPong V2.2.1
-----------------------------------

What exactly is the point of the variable "text"? Whats wrong with width2 := Font.Width("PAUSED", font2)? Shortening this saves lines, and saves memory.
The memory saved is is negligible.

2: I noticed you're declaring variables all over the place, inside procedures, in the middle of your program, blah blah blah. Its good standards to declare all variables that you can at the top. Also, if you can prevent it, don't declare variables in repeated procedures. I'm pretty sure (Not 100%) that in Turing, this will result in memory leaks.
It is good practice to restrict the scope of your variables as much as possible. You should always declare variables in procedures if you intend to use them only in those procedures.
Also, your never going to encounter memory leaks in Turing unless you use [tdoc]new[/tdoc] and [tdoc]free[/tdoc].

-----------------------------------
Nathan4102
Thu Jun 06, 2013 7:21 pm

Re: TuringPong V2.2.1
-----------------------------------

What exactly is the point of the variable "text"? Whats wrong with width2 := Font.Width("PAUSED", font2)? Shortening this saves lines, and saves memory.
The memory saved is is negligible.

2: I noticed you're declaring variables all over the place, inside procedures, in the middle of your program, blah blah blah. Its good standards to declare all variables that you can at the top. Also, if you can prevent it, don't declare variables in repeated procedures. I'm pretty sure (Not 100%) that in Turing, this will result in memory leaks.
It is good practice to restrict the scope of your variables as much as possible. You should always declare variables in procedures if you intend to use them only in those procedures.
Also, your never going to encounter memory leaks in Turing unless you use 

Really?? Well that's interesting, I'll be sure to keep this in mind in future projects.

-----------------------------------
aaro4130
Thu Jun 06, 2013 7:54 pm

Re: TuringPong V2.2.1
-----------------------------------
Yeah variables should be defined in loops if you are going to use them in loops for example

say you have 

var variableExample : int := 0
procedure doSomething
variableExample := 0 %Make sure it's zero
variableExample += 5 %add 5 to it, just for show ,this could be any number
end doSomething

It seems better to do this

procedure doSomething
var variableExample : int := 0
variableExample += 5
end doSomething

Also the memory saved is less! Beause then I am calling it twice, in exe it would have 2 seperate text strings, then in assembly
PUSH TuringPong.
PUSH TuringPong.
CALL TuringPong.

This pushes it onto the stack twice causing more memory use whereas a variable is declared and this happens
PUSH TuringPong.
PUSH TuringPong.
CALL TuringPong.

Not much memory saved with the variable, but less effort required to draw the text this way, as well, memory saved is memory saved. Also the variable is disposed of after use, where as the text strings would always be loaded to memory for any time calling

About variable scopes , he is absolutely right, declaring them all at the top uses more memory because they are always 100% ready to be called, declaring them in procedures means it is made, used, and disposed of.

Trust me on this, I do assembly code as well ,and I know what stacks are and all that. 

Anyways, I am releasing a new version with score limit in it! Enjoy!
EDIT : GAH I PUT SOME WRONG CODE IN AND NOW THE DIFFICULTY SELECTOR DOESNT SHOW! One minute XD
EDIT :Attachment added

-----------------------------------
Zren
Thu Jun 06, 2013 8:15 pm

RE:TuringPong V2.2.1
-----------------------------------
Challenge: Use only one key to toggle between AI (or Music) on/off, without it constantly switching between them while you hold it down.

-----------------------------------
Dreadnought
Thu Jun 06, 2013 9:09 pm

Re: TuringPong V2.2.1
-----------------------------------

Also the memory saved is less! Beause then I am calling it twice, in exe it would have 2 seperate text strings, then in assembly
PUSH TuringPong.
PUSH TuringPong.
CALL TuringPong.

This pushes it onto the stack twice causing more memory use whereas a variable is declared and this happens
PUSH TuringPong.
PUSH TuringPong.
CALL TuringPong.

Or the compiler is smart and optimises both cases to the same assembly code.
Most "good" coding practices are meant to help the programmer, not the machine.

-----------------------------------
aaro4130
Sat Jun 08, 2013 11:39 am

RE:TuringPong V2.2.1
-----------------------------------
Actually the compiler doesn't optimize it, I was looking at the assembly code and it just uses byte code. Basically I tried 

cls

and compiled it,and looked at it, then

cls
cls

and compiled it, looked at it, bigger filesize

P.S. Realized a huge programming error... Turing runs out of ID numbers on older versions because of it!

-----------------------------------
aaro4130
Thu Jun 20, 2013 9:06 pm

RE:TuringPong V2.2.1
-----------------------------------
Btw here is a side note!

I got 100% on my final project and 100% on the exam! :D
