Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 TuringPong V2.2.1
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aaro4130




PostPosted: Thu Jun 06, 2013 5:04 pm   Post subject: 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



turingPong_v2.2.1_full.zip
 Description:

Download
 Filename:  turingPong_v2.2.1_full.zip
 Filesize:  681.77 KB
 Downloaded:  689 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Nathan4102




PostPosted: Thu Jun 06, 2013 5:09 pm   Post subject: 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




PostPosted: Thu Jun 06, 2013 5:15 pm   Post subject: 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!



turingPong_v2.2.2_full.zip
 Description:

Download
 Filename:  turingPong_v2.2.2_full.zip
 Filesize:  681.84 KB
 Downloaded:  345 Time(s)

Raknarg




PostPosted: Thu Jun 06, 2013 5:23 pm   Post subject: RE:TuringPong V2.2.1

with 8 years I hope you try to go above and beyond
Tony




PostPosted: Thu Jun 06, 2013 5:31 pm   Post subject: Re: TuringPong V2.2.1

aaro4130 @ Thu Jun 06, 2013 5:04 pm wrote:
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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
aaro4130




PostPosted: Thu Jun 06, 2013 5:37 pm   Post subject: 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!



turingPong_v2.3_full.zip
 Description:

Download
 Filename:  turingPong_v2.3_full.zip
 Filesize:  682.04 KB
 Downloaded:  275 Time(s)

Nathan4102




PostPosted: Thu Jun 06, 2013 6:40 pm   Post subject: Re: RE:TuringPong V2.2.1

aaro4130 @ Thu Jun 06, 2013 6:15 pm wrote:
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)


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


This can be shortened to:

code:
exit when chars('m')


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




PostPosted: Thu Jun 06, 2013 6:42 pm   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Thu Jun 06, 2013 7:14 pm   Post subject: Re: TuringPong V2.2.1

Nathan4102 wrote:

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.
Nathan4102 wrote:

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 new and free.
Nathan4102




PostPosted: Thu Jun 06, 2013 7:21 pm   Post subject: Re: TuringPong V2.2.1

Dreadnought @ Thu Jun 06, 2013 8:14 pm wrote:
Nathan4102 wrote:

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.
Nathan4102 wrote:

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 new and free.


Really?? Well that's interesting, I'll be sure to keep this in mind in future projects.
aaro4130




PostPosted: Thu Jun 06, 2013 7:54 pm   Post subject: 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.<address for 1st>
PUSH TuringPong.<address for 2nd>
CALL TuringPong.<address for draw>

This pushes it onto the stack twice causing more memory use whereas a variable is declared and this happens
PUSH TuringPong.<varAddress>
PUSH TuringPong.<varAddress>
CALL TuringPong.<address for draw>

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



turingPong_v2.3.1_full.zip
 Description:

Download
 Filename:  turingPong_v2.3.1_full.zip
 Filesize:  682.5 KB
 Downloaded:  279 Time(s)

Zren




PostPosted: Thu Jun 06, 2013 8:15 pm   Post subject: 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




PostPosted: Thu Jun 06, 2013 9:09 pm   Post subject: Re: TuringPong V2.2.1

aaro4130 wrote:

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.<address for 1st>
PUSH TuringPong.<address for 2nd>
CALL TuringPong.<address for draw>

This pushes it onto the stack twice causing more memory use whereas a variable is declared and this happens
PUSH TuringPong.<varAddress>
PUSH TuringPong.<varAddress>
CALL TuringPong.<address for draw>

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




PostPosted: Sat Jun 08, 2013 11:39 am   Post subject: 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




PostPosted: Thu Jun 20, 2013 9:06 pm   Post subject: RE:TuringPong V2.2.1

Btw here is a side note!

I got 100% on my final project and 100% on the exam! Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: