Mini project suggestions

N

Nils Petter Vaskinn

But PLEASE, before you ask, there is no way in C++ to clear the screen or
change the colour of the output :)

for (int i = 0; i < MAX_LINES; i++) {
std::cout << "\n";
}
std::cout.flush();

Is the closest i can think of as a way to clear the screen using only the
standard library.

He could do something like:

void Screen::clear()
{
#if defined PLATFORM_1
/* do platform specific clear */
#else
/* Do scroll past the top clear */
#endif
}
 
G

Gene Wirchenko

On Fri, 03 Oct 2003 08:38:58 GMT, "Nils Petter Vaskinn"

[snip]
for (int i = 0; i < MAX_LINES; i++) {
std::cout << "\n";
}
std::cout.flush();

Is the closest i can think of as a way to clear the screen using only the
standard library.

1) MAX_LINES?

2) It will not work if the cursor is positioned other than on the
bottom line.

[snip]

Sincerely,

Gene Wirchenko
 
K

Kevin Goodsell

Nils said:
He could do something like:

void Screen::clear()
{
#if defined PLATFORM_1
/* do platform specific clear */
#else
/* Do scroll past the top clear */
#endif
}

Personally, I'd take a different approach. All that conditional
compilation code could get very ugly. I think I'd have a source file set
aside for platform-dependent screen operations, and a new implementation
of it can be supplied for each platform. Also, a default implementation
could be available.

-Kevin
 
G

Gene Wirchenko

You didn't mention OO, but in addition I found this to be an outstanding
exercise in OO design. It's not complex, but at the same time makes you
think quite about the relationships between the objects involved. Obviously
you need a deck of cards, but who has it? If the dealer has it, then how
much access to it does he have? Do you need a card table? Do you need a
casino? Who gets your chips when you lose, the dealer or the casino? When
you are dealt a hand, where does the hand go? (In a real casino, the hand
is "yours", but you can't touch the cards - only the dealer can. At the
same time, only you can make decisions about changing your hand, and the
dealer can't. So who "owns" or "has" the hand - you or the dealer?) Do you
even need a deck of cards? Can't you just deal a "card" as a random number
"out of thin air", from an "infinite deck"? (Before deciding, note that the
odds of getting a blackjack are higher in real life when using 1 deck of
cards than with 2!!)

You dealt me two ten of diamonds. Hold still while I go get my
gun.

Sincerely,

Gene Wirchenko
 
K

Kevin Goodsell

Gene said:
You dealt me two ten of diamonds. Hold still while I go get my
gun.

Hm? Why would you do that? That's a damn good hand!

(Most if not all casinos use more than one deck of cards in blackjack.
Some use up to 8, I believe.)

-Kevin
 
M

Mike Wahler

Gene Wirchenko said:
You dealt me two ten of diamonds. Hold still while I go get my
gun.

Never played or watched a blackjack game in a casino,
have you?

-Mike
 
C

cheeser

To get to the point, I'm wanting to start a moderately-sized
project that would take a week (working full time on it, which I won't
be :) ) to do reasonably, cover a decent subset of the language, be
interesting to do, and workable under (say) gcc on Linux (without too
much nonstandard code). It'd also be interesting to get some practice
in software design in there.
So, I'd be interested to get some suggestions, because I feel like
doing *something* with all this knowledge (and more importantly,
finding out what I don't know well). Thanks!

One of my all-time favorite projects that I've taken on is to write a
program to solve sliding tile puzzles (8-puzzles). I'm sure you've seen
them - a square grid broken up into 9 tiles, but one of the tiles is
missing, allowing the other tiles to slide around.

If you're feeling really ambitious, you could try to write a generic
implementation that could be used to solve any one-player game for which a
state space search is applicable.

If you choose this project though, be aware of one thing: Not all puzzes are
solvable! For example, if you start in this state:

123
405
678

(0 represents the missing tile)

and make it your goal to get to this state:

132
405
678

it is impossible. Exactly half of all possible board positions are
reachable from a given puzzle configuration.

Here's a good test puzzle that does have a solution:

308
257
146

With this being the goal state:

123
405
678

This project will require some research on your part to find a suitable
algorithm, but the implementation of that algorithm will teach you a lot
about C++. Also, try to use the C++ Standard Library for as much of your
implementation as you can.

Anyway, have fun with whatever you do and good luck!

Dave
 
M

Michael Strorm

Jonathan Mcdougall said:
But PLEASE, before you ask, there is no way in C++ to clear the screen or
change the colour of the output :)

Funny, I was going to make some remark about outputting ANSI codes to
stdout from a standard
std::cout << "Your string here";
which would be well within the ISO standard, right?

Of course, it wouldn't be portable, but it would still be within the
standard >;-)

In all seriousness, point taken, I knew ANSI C (89) didn't support
such stuff, and I wasn't expecting ISO C++ to do that either.

<troll>but id like to know how to do that in visual c++ anyway</troll>

- Michael S
 
M

Michael Strorm

Gene Wirchenko said:
Quite. There are OO languages for writing these games. See
rec.art.int-fiction.

I'm going for the "text adventure" suggestion.... although it's going
to be more like a framework than an actual text adventure. And the
text adventure I'm designing to go round it will probably be quite
strange- more an opportunity to implement some ideas I had (for
example, multiple characters in the game acting independently, all
represented by concrete implementations of some abstract base class.
And then I noticed how 'rooms', 'objects' and 'characters' all have
some common characteristics which suggest an inheritance
relationship... and so on.

Oh, and I agree with the comment elsewhere in the thread about this
being an excuse to learn C++ better as opposed to the optimal choice
to design a text adventure. The former is *definitely* what I'm after.

I think I'd have trouble making it fit into 16KB if I was using C++
;-)

- Michael S
 
M

Michael Strorm

jeffc said:
I thought writing a Blackjack (21) simulator was a great exercise.

Hey, I already wrote a Connect-4 simulator with pruning blah-blah for
university... that's quite enough Artificial Intelligence for one
year. ;-)

Seriously, good idea- I'll look at it after having a stab at the text
adventure.

- Michael S
 
M

Michael Strorm

Mike Wahler said:
Yes, as your knowledge grows, I think you'll find this
book quite valuable. Make sure it's the 3rd or 'special'
edition though. Previous additions are essentially
obsolete.

It's the Special... BTW, what is the difference between that and the
vanilla 3rd ed? It doesn't seem to be mentioned anywhere.
Another very good book, especially for those who have
previous experience with other languages, is Koenig
& Moo's "Accelerated C++". www.acceleratedcpp.com

Yeah, I keep hearing about this. I'm giving serious consideration to
buying it.
Short exercises are good start, especially to prove to
yourself you understand a particular concept(s).

The concepts I'm usually fine with, but actually applying them is usu.
a different kettle of fish.
Don't be too optimistic with your time estimates.

I've learned not to be :-/
Don't
worry if something takes far longer than you expect. Even
for professionals, one of the most difficult tasks is making
(and meeting!) time estimates.

Reminds me of a Dilbert cartoon where the pointy-haired boss is asking
for a time estimate, then giving that to *his* boss and so on...

Only practice and experience
will help with this. And having built up a 'code base' of
useful functions helps a lot toward 'speed of development'.
The concept of code reuse. When writing a function, keep
in mind "can this be 'generalized' to be useful in other
contexts?"

That's a good point... though I guess spending too long generalising a
problem is a good/bad hacker trait depending on who you ask. ;-)
This project has some scope for generalisation via base-classes for a
start...
Design isn't really topical here, but we can help you
organize your code to best take advantage of the
language's power, prevent common errors etc. Software
design itself would be better discussed in groups such
as comp.programming and/or comp.algorithms, etc.
Often specific algorithm categories have their own
groups, e.g. cryptography.

I was thinking more in terms of software design, rather than at the
algorithm level...
Hint: Use the standard library. [snip]
Which reminds me: A very good book to have is
Josuttis' "The C++ Standard Library" www.josuttis.com/libbook

Anything comparable online, in the same way that Sun have the Java
documentation online?

Thanks,

- Michael S
 
J

Jonathan Mcdougall

You could write a small text adventure.
I'm going for the "text adventure" suggestion.... although it's going
to be more like a framework than an actual text adventure. And the
text adventure I'm designing to go round it will probably be quite
strange- more an opportunity to implement some ideas I had (for
example, multiple characters in the game acting independently, all
represented by concrete implementations of some abstract base class.

That is what small projects are for. You don`t have to write a story
or a full-fledge design document. Just try and learn. I worked on
a game for some time and I think I must have throw it away and start
again like 20 times, just to apply new things from the start.
And then I noticed how 'rooms', 'objects' and 'characters' all have
some common characteristics which suggest an inheritance
relationship... and so on.

And what 'rooms', 'objects' and 'characters' have in common?


Jonathan
 
M

Mike Wahler

Michael Strorm said:
"Mike Wahler" <[email protected]> wrote in message

It's the Special... BTW, what is the difference between that and the
vanilla 3rd ed? It doesn't seem to be mentioned anywhere.

See http://www.research.att.com/~bs/3rd.html
Yeah, I keep hearing about this. I'm giving serious consideration to
buying it.

I bought it quite a while ago, and am certainly glad I did.
The concepts I'm usually fine with, but actually applying them is usu.
a different kettle of fish.

Yes, choosing the right 'pieces' (concepts) for constructing
the 'puzzle' (application). This simply takes practice, lots
of it. Be prepared to throw away much code from false starts.
The code itself isn't what's really valuable, but the lessons
learned.
I've learned not to be :-/


Reminds me of a Dilbert cartoon where the pointy-haired boss is asking
for a time estimate, then giving that to *his* boss and so on...

Only practice and experience

That's a good point... though I guess spending too long generalising a
problem is a good/bad hacker trait depending on who you ask. ;-)
This project has some scope for generalisation via base-classes for a
start...

Yes, anything can be 'overdone'.
I was thinking more in terms of software design, rather than at the
algorithm level...

Look for newsgroups, web resource, books etc. about that.
No particular one comes to mind at the moment.
Hint: Use the standard library. [snip]
Which reminds me: A very good book to have is
Josuttis' "The C++ Standard Library" www.josuttis.com/libbook

Anything comparable online, in the same way that Sun have the Java
documentation online?

There are several places online which document the standard library,
e.g. www.dinkumware.com , but they only *document it*, the
Josuttis book *explains* how it works and gives advice how
to use it effectively. Another similar book which is more
oriented toward application of the library rather than
dissecting it, is Austern's "Generic Programming and the
"STL".

-Mike
 
M

Michael Strorm

Jonathan Mcdougall said:
And what 'rooms', 'objects' and 'characters' have in common?

<action> <room | object | character> [ <preposition> <room | object |
character> ]

Where action could be "look", "examine"... implying appearance... and
some other stuff I haven't thought of yet. ;-)

- Michael S
 
J

jeffc

Gene Wirchenko said:
You dealt me two ten of diamonds. Hold still while I go get my
gun.

First, I'd play out the hand and take the money, and second I'd make sure I
was playing in a one deck game (rare) before I did that......
 
J

jeffc

Michael Strorm said:
"jeffc" <[email protected]> wrote in message

Hey, I already wrote a Connect-4 simulator with pruning blah-blah for
university... that's quite enough Artificial Intelligence for one
year. ;-)

Seriously, good idea- I'll look at it after having a stab at the text
adventure.

Just to clarify, it wasn't a "game" that required "AI", it was a simulator
that played many hands and reported the results, given different tables with
the rule set (for player and dealer) and decisions (on what to do with any
given hand).
 
G

Gene Wirchenko

[snip]
First, I'd play out the hand and take the money, and second I'd make sure I
was playing in a one deck game (rare) before I did that......
^^^^^^^^^^^^^^^^^^^^
Shoot! (or rather, not shoot) I do not remember reading that in
the spec.

Sincerely,

Gene "Putting the Gun Down Slowly and Backing Away" Wirchenko
 
M

Martijn Lievaart

Hm? Why would you do that? That's a damn good hand!

(Most if not all casinos use more than one deck of cards in blackjack.
Some use up to 8, I believe.)

They do. The reason is that it makes it harder to remember what cards are
dealt, and therefore which cards have a higher probability of showing up.

HTH,
M4
 
J

jeffc

Martijn Lievaart said:
They do. The reason is that it makes it harder to remember what cards are
dealt, and therefore which cards have a higher probability of showing up.

No, not really. It really isn't any harder to count cards in multiple decks
than one deck. The reason is that you are not literally keeping track of
every card. You're just keeping a running tab. Imagine a stream of +1
and -1 going by. You want to know if the total is negative or positive at
any given time. This really is the same whether there are 10 cards or 1,000
cards. The reasons more decks are used are:
a) The probabilities of the game change with more decks. For example,
getting a blackjack, which is extremely favorable to the player and
disadvantageous to the casino, is more likely with 1 deck than with 8.
b) The less shuffling and more dealing the casinos do, the more money they
make.
 
N

Nils Petter Vaskinn

On Fri, 03 Oct 2003 08:38:58 GMT, "Nils Petter Vaskinn"

[snip]
for (int i = 0; i < MAX_LINES; i++) {
std::cout << "\n";
}
std::cout.flush();

Is the closest i can think of as a way to clear the screen using only the
standard library.

1) MAX_LINES?

The whole point beeing to choose MAX_LINES large enough to clear the
screen on any platform (that you know about) So in case the cursor starts
at the upper left, and the biggest screen you can think of has 200 lines
MAX lines could be 200.
2) It will not work if the cursor is positioned other than on the
bottom line.

Unless you have used some implementation specific way to move the cursor
around it will.


It's not a pretty solution, but the whole point is to have something that
does the job, and then you can replace it with a pretty but
platform/library dependent solution later.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top