Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Site Goodies > Saline's Brain Teasers

Reply
 
LinkBack Thread Tools Display Modes
Old 02-16-2003, 07:59 PM   #1 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
The First Brain Teaser Ever, we're making history here folks!

Hey, my names saline and I'm here to cause problems. Well kind of. This is a new section where each week I'm going to provide a programming problem and then new coders (codenewbies if you will) can get some practice thinking like computer scientists. Then people can ask each other questions and share code snippets and learn how to solve programming problems on their own. It’ll be a big party, a big coding party, trust me they‘re fun.

The problems will probably be limited to the following languages: C++, JavaScript, Perl, Visual Basic and Python because for now, that's all I know. Then through the week people can work on it and ask me and each other questions and who knows where it will all end up?

Anyway, for the first week we're going to draw from the forums for inspiration. Specifically this thread:

http://codenewbie.com/forum/showthre...=&threadid=708

Here's the quick story, toAst, is a newbie but he wants to get going doing something. He wants to make a game, something simple like Pong. That's the first part of our problem of the week. If you think you're up to it, make Pong. Maybe make it like the classic Atari game which you can read all about here http://www.pong-story.com/ or something updated with fancy futuristic things like, um, color.

OK, so I responded in the forums because I've seen the pitfalls (bad old game pun) of people saying pong was simple. It's simplistic and simple compared to now adays, or really anything, however, it's not easy.

Things to consider about pong

1) How are you going to do the graphics? If you don't know how to do graphics in your language(s) it might make things too hard. I've seen pong done as ASCII art but that's something I would consider a rare skill.

2) How are you going to control the computer opponent (if there is one). Are you going to be able to make it good but not too good so that it doesn't always win? If there is no computer opponent you need to set up dual controls somehow.

3) At the very basic level, can you make the "ball" bounce correctly and detect when a point is scored?

If one of these questions gives you pause you might still try and be successful however if more than one seems puzzling you might want to consider the second or third problem and working your way up.

If you choose to do this problem I would recommend C++, Java (or so I'm told in the forum), Python (with pygame), Visual Basic and maybe JavaScript if you like a real challenge. Other languages will work but I can't gauge how difficult it would be as I haven't done graphics in them.

The second part incorporates graphics but they don't move so it avoids a number of the difficulties of Pong.

The "match game" also known as "memory" or "where the hell is it?!" is a classic intro programming game. If you have a Nokia cell phone you can play the match game right now, they call it pairs.

The rules are simple there are cards which are face down. Every card has a picture on it's face down side and there are two of every card picture type. You click on one and get to see its picture. The goal is to find the match for each pair with as few guesses as possible.

Here is an example where you play alone:

http://www.funbrain.com/match/

(I'd like to say that the way they implemented this is kind of ridiculous and I would not recommend it, there are easier ways which look better than this. It's just an example of how the game works.)

And here's a cool variation where you play against the computer:

http://jimworld.com/memory/memory.html

Anyway you get the idea, here are things to consider about doing the match game:

1) Again, can you do graphics, and do you know how to change those graphics from one picture (the back) to another (the front) when the user chooses them?

2) Can you make sure the user doesn't choose the same pair twice, once it's found it should go away somehow?

3) How will you keep score, and how will the user interact with the game board?

If these give you pause you might want to consider the final problem for this week which is geared toward the newest of the coders the few the proud the n00b!

The guessing game.

The guessing game is one of the first things people learn it's got a lot of absolutely fundamental concepts within it. It's a challenge but they're surmountable. It doesn't require graphics so this is a big drop in the difficulty.

It's just a simple guessing game, the computer chooses a number (or a letter but that's a tad more difficult) and the user guesses. Generally the number should be constrained within some reasonable range like 0-20 or something. If you want to get all fancy like you can tell the user whether their guess was too high or too low. Then when they get it just tell them so. Maybe you can keep track of a score or number of guesses versus number of correct answers, kind of like a hit ratio (like counterstrike, only less violent and a guessing game).

This is a basic problem and so you should know or research the following things

1) Getting text input from the user and printing information back to them.

2) "If" statements and the comparison operators (==, >, >=, <, <=).

3) Loops and looping.

4) Generating random numbers.

If you don't think you can do those things you'll probably be able to research them or ask questions about them and still have enough time to get it done. These concepts are the absolute basis of all programming in all languages so even if you don't think you can finish the problem you should try it to get the experience.

So, that's it for this week, good luck to everyone who tries and feel free to ask each other and me questions within the forum. As a final note remember to drink your vegetables, eat all your milk, drugs know best and don't do moms. Or something.
saline is offline   Reply With Quote
Old 02-16-2003, 08:17 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
great idea saline! nice to have you on the team

** goes to ponder pong **
sde is offline   Reply With Quote
Old 02-16-2003, 08:21 PM   #3 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
and they're off!

Alright we've got a taker anybody else entering the fray?
saline is offline   Reply With Quote
Old 02-17-2003, 11:03 PM   #4 (permalink)
Kernel_Killer
Regular Contributor
 
Kernel_Killer's Avatar
 
Join Date: Feb 2003
Location: indisclosed
Posts: 210
Kernel_Killer is on a distinguished road
heh. Pitfall.

*Kernel_Killer goes to play the C64 version
Kernel_Killer is offline   Reply With Quote
Old 02-18-2003, 09:42 AM   #5 (permalink)
Hrqls
Regular Contributor
 
Join Date: May 2002
Location: Alkmaar, the Netherlands
Posts: 167
Hrqls is on a distinguished road
hey saline!

great post .. iloved the post as much as the idea

i might be working on pong or the memory game ... but i dont know if i will be having some spare time this week

quite curious as to what other will come up with as well
(especially because they will probably code it in java ... while i will do it in vb )
__________________
The specialty of the house? thats me (cheap as always)
Hrqls is offline   Reply With Quote
Old 02-18-2003, 12:26 PM   #6 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
yeah, lack of time sucks

I was going to and am still going to try and do all of them. I finished the number guessing one but I need to try and learn pygame with a quickness if I'm going to get either of the other ones finished. Stupid graphics and their stinkin' trickyness.

Thanks for the feedback on the post and the idea!
saline is offline   Reply With Quote
Old 02-20-2003, 06:04 AM   #7 (permalink)
nadadogg
Registered User
 
Join Date: Feb 2003
Posts: 4
nadadogg is on a distinguished road
Send a message via AIM to nadadogg
i did pong in qbasic a loooong time ago, that count?
nadadogg is offline   Reply With Quote
Old 02-20-2003, 07:44 AM   #8 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
sure...

We're not running a contest here, everything you do is for your own education and enjoyment. I have to say I never much liked QBasic and am rather impressed that you could get it to do something more process numbers. The langauges I listed were recommendations not edicts, you can do any of the brain teasers in any language you want, whenever you want we're going to keep the old ones posted long after we've introduced new ones.
saline is offline   Reply With Quote
Old 02-20-2003, 09:21 AM   #9 (permalink)
nadadogg
Registered User
 
Join Date: Feb 2003
Posts: 4
nadadogg is on a distinguished road
Send a message via AIM to nadadogg
heck, i'd have to get the 386 out of the closet at my parent's house and see if it would still even boot up
nadadogg is offline   Reply With Quote
Old 02-20-2003, 09:34 AM   #10 (permalink)
Travis Dane
Code Monkey
 
Travis Dane's Avatar
 
Join Date: Feb 2003
Location: Netherlands
Posts: 89
Travis Dane is on a distinguished road
Send a message via ICQ to Travis Dane
Quote:
Originally posted by nadadogg
heck, i'd have to get the 386 out of the closet at my parent's house and see if it would still even boot up
You shouldn't be underestimating old computers you know,
NASA uses pentium1's in their mainframes, and you know why?
Because they are S-T-A-B-L-E, and because they won't break in
a hundred years. Same goes with your 386, I wouldn't be
surprised if it still worked.
__________________
OpenGL, DirectX
Travis Dane is offline   Reply With Quote
Old 02-20-2003, 09:59 AM   #11 (permalink)
Travis Dane
Code Monkey
 
Travis Dane's Avatar
 
Join Date: Feb 2003
Location: Netherlands
Posts: 89
Travis Dane is on a distinguished road
Send a message via ICQ to Travis Dane
Oke, I took a quick shot at it even though i never program
Console Applications anymore so don't go to harsh on me .

I took the number guessing game.

Hmm, I just noticed i can't place attachments? Well i'l post it on
my FTP when i have time.
__________________
OpenGL, DirectX
Travis Dane is offline   Reply With Quote
Old 02-20-2003, 10:27 AM   #12 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
travis.. what type of attachment were you trying to attach? you should see a link at the bottom of the 'reply' page. if you don't see it or it won't let you post, give me more details so i can fix it.

thanks!
sde is offline   Reply With Quote
Old 02-20-2003, 10:29 AM   #13 (permalink)
nadadogg
Registered User
 
Join Date: Feb 2003
Posts: 4
nadadogg is on a distinguished road
Send a message via AIM to nadadogg
guessing game in perl

I did the guessing game as a perl script. I recently had to start learning perl for work, so I picked up a couple new things
The forum rules say I'm not allowed to attach things, so here is the url to my script.

This right here is the script in text format.
http://www.bolda.com/nadadogg.txt
nadadogg is offline   Reply With Quote
Old 02-21-2003, 05:32 AM   #14 (permalink)
MrMark
Registered User
 
Join Date: Feb 2003
Location: Washington, DC, USA
Posts: 2
MrMark is on a distinguished road
These challenges are a great idea! Lots of things seem easy to do until you actually try to do them...

For those who are daunted by graphics (myself included), you can do Memory in JavaScript without knowing anything about graphics... use your favorite paint program to create images of the fronts & backs of cards, then change the image source as needed. That's a good way to just learn the "logic" part of the game.
MrMark is offline   Reply With Quote
Old 02-21-2003, 07:44 AM   #15 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
well I wasn't gonna say it, but...

You're very right! I didn't want to give people really specific information off the bat because I wanted to get the people participating talking to one another. He's also specifically right about how javascript lends itself to memory. It's just a simple image swap also commonly known as a roll-over if you want to look it up.

Personally, I love javascript, a lot of people think I'm crazy because it's a little inconsistant across browsers. But it gets better and better with every release and it's absolutely free and really easy to get started because everything is pre-configured and installed.

It's very similar to C and C++ (and therefor Java) in syntax and graphics are a snap if you know a little bit of HTML and a little bit about the Document Object Model (DOM). I feel this is because graphics are handled somewhat differently as they're a more integral part of web pages than console applications (generally). So if you want to try it out, there's a bunch of keywords in here all of which can be checked out in depth here:

http://www.webmonkey.com

Or more specific questions can and should be posed on this and other codenewbie forums.

Thanks for the post MrMark.
saline is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 08:43 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting