Murtan 317 Practically a Master Poster

There are several possibilities for 'getting between'.

In the end, you will end up providing an interface to the program that must act as it expects the 'LPT' to act.

To better understand the problem:

Does the program think that a printer is attached to the LPT or is it some other device?

What Operating System does the program run under?

Does the program have any configuration to select the LPT or printer?

I doubt this is an option, but is it possible for you to modify and re-build the program?

The source code you included appears to be for Windows. Almost all Windows applications allow you to select the printer to print to.

The stream of bytes that Windows sends to the printer very rarely reflects the characters that are being printed. For example, if you put "Hello, World" in notepad and print it, the resulting byte stream to the printer will far exceed the 12 characters you typed.

Are you trying to catch the byte-stream or the characters?

Murtan 317 Practically a Master Poster

Short answer:

Move the do { from line 23/24 in front of the random stuff starting on line 15.

Longer answer:
If you were to break each problem type out into a function, you could call it from the if (choice == stuff. The function could then generate the random values for the problem.

This second method would have the added advantage of having everything about the problem all in one place. (The random parameters, the display, the input and the validation.) Also, your code wouldn't be bothering to generate random problems that will never be used.

Sample add method:

void add()
{
   int add1 = (rand()%500)+1;
   int add2 = (rand()%500)+1;
   int addAnswer = add1 + add2;

   cout << setw (6) << add1 << "\n";
   cout << "+ ";
   cout << setw (4) << add2 << "\n";
   cout << "------";
   cout << "\n";
   cin >> input;
   cout << "\n";
   if (input == addAnswer)
      cout << "Congratulations\n";
   else
      cout << "That is incorrect,\nThe correct answer is: " << addAnswer;
   cout << "\n";
   cout << "\n";
}
Murtan 317 Practically a Master Poster

When I was testing the deck, I put in a couple of helper functions and just put the play in main.

You should probably have one method to play a hand or round, which will include dealing, hit/stay, dealer hit/stay and scoring. Whether you put those directly in the method or in other methods called from there is mostly a matter of preference. (Unless something gets really big, then you're almost always better of breaking it up.)

Another method might 'sequence' the hands and determine if the user wanted to keep playing, but that's just my take on it; there is no 'One True Way' to write it.

The class should probably also keep track of the number of hands won vs the number of hands lost.

Murtan 317 Practically a Master Poster

You entered tried_good = ( ) did you mean tried_good = 0 ?

Repeat above comment for tried_bad as well.

You have 2 while loops with neither while really meeting your goal. I think you'd be better off with a for loop, prompting for letter guesses. Then use an if to display whether or not the letter guess was in the word.

When the for loop runs out, they have used all of their letter guesses and will have to guess at the word.

for guesscount in range(1,6):
        lguess = raw_input("Enter your letter guess #%d" % guesscount)
        # put an if test here along with the 'yes' or 'no' display
    # They've run out of letter guesses
    guess_word = raw_input("What do you think the word is? ")
    # test and output here
Murtan 317 Practically a Master Poster

Multiple exit points means there is more than one way out of the function. (Each 'return' statement is an exit point.)

I think you want to have the BlackJack class create a DeckOfCards; something like [/icode]self.deck = DeckOfCards()[/icode] then you can do things like self.deck.mix()

Murtan 317 Practically a Master Poster

LPT1 is a device, you are unable to open it to read what someone else has written (or will write) to it, it just doesn't work that way.

To do what you are proposing, you would need to somehow 'get between' the other application and the output device. You could then log the characters the other application sends and forward them to the device.

Murtan 317 Practically a Master Poster

Your loop starting on line 129 is only one line long (130)

You should probably also indent lines 131 to 147 to the same level as 130 to make them part of the loop.

Murtan 317 Practically a Master Poster

You don't want the for in the cardValue method.

You also can't compare against 3 string values with elif c[:-1] == "J" or "K" or "Q": you either need to change it to elif c[:-1] == "J" or c[:-1] == "Q" or c[:-1] == "K": or to elif c[:-1] in ["J","Q","K"]: cardValue is only trying to get the value for a single card.
handValue uses it to help calculate the value for the hand.

Here's a version without the for loop and just returning the card value when it knows what it is. (Note this has multiple exit points, which can be bad form, but in this case I would do it anyway.)

def cardValue(card):
    if card[:-1] == "A":
        return 11
    if card[:-1] in ["J", "Q", "K"]:
        return 10
    return int(card[:-1])

Once you get it working, the handValue method will call cardValue to get the value for each card.

Murtan 317 Practically a Master Poster

Your approach to getting the card number is pretty good, but it will fail for the 10 card (you'll get the value 1). You could fix what you have by doing int(card[:-1]) . The code also doesn't handle the ace yet either.

Another option to using the slice (that's what the card[:-1] is) would be to change the representation of the cards in the deck. When making the cards in the deck of cards, instead of making a single string with the card and the suit, you could split them into a tuple. Where we have card + suit in the DeckOfCards. __init__ you could put (card,suit) . Each card then would be a tuple (sort of like a list, but you can't modify it) where card[0] would be the card's face value and card[1] would be the suit. If you do this, you would have to merge them when you display the cards with either card[0]+card[1] or ''.join(card) {I love how there is always more than one way way to do something, don't you} use the way that makes the most sense to you.

Ok having said the above, the way I would address the hand value would be something like the following. (I'll leave the writing of cardValue(card) to you.)

def handValue(hand):
    cardValues = []
    for card in hand:
        cardValues.append(cardValue(card))
    while sum(cardValues) > 21 and 11 in cardValues:
        cardValues.remove(11)
        cardValues.append(1)
    return sum(cardValues)

Note that this was written, expecting cardValue and handValue to be stand alone …

Murtan 317 Practically a Master Poster

Sorry it took so long to reply, but it would have been longer if I could sleep (grin).

Your current problem is that you can't create a DeckOfCards with a = DeckOfCards you need to a = DeckOfCards() If you want, you can stop reading here and go try that, it will make a world of difference.

Here's the little test app I wrote up to build the deck with more of what I had in mind. You seem to keep thinking of the cards in terms of their value to blackjack. What if you wanted to use the deck to play poker, or cribbage? This implementation will be slightly harder to score, but if I can score my hand in my head, why can't the computer?

import random

class DeckOfCards:
    def __init__(self):
        self._cards = []
        for suit in ["S","C","H","D"]:
            for card in ["A","2","3","4","5","6","7","8","9","10","J","Q","K"]:
                self._cards.append(card+suit)
        self._drawIndex = 0

    def mix(self):
        random.shuffle(self._cards)
        self._drawIndex = 0

    def draw(self):
        rval = self._cards[self._drawIndex]
        self._drawIndex += 1
        return rval

if __name__ == "__main__":
    thedeck = DeckOfCards()
    thedeck.mix()

    playercards = []
    dealercards = []

    playercards.append(thedeck.draw())
    dealercards.append(thedeck.draw())
    playercards.append(thedeck.draw())
    dealercards.append(thedeck.draw())

    print playercards
    print dealercards

The if __name__ == "__main__" is how I'm currently adding test code to modules. This expression will be true if this file is the 'main' file, but it will be false if this file was included due to an import command.

You may also note that I didn't use the same style of import for random that you did. You …

Murtan 317 Practically a Master Poster

This program appears to be a merge of the 'have the computer pick a word and have the user guess it' and your 'number guessing' program.

As written, the user doesn't have any interface to ask if the word contains a letter. You let them guess at the word and tell them if the word is what they guessed, or if it comes alphabetically before or after their guess.

The message 'Lower Letter' which means the computer's word would appear before the word the player guessed in the dictionary and the message 'Higher Letter' which means the computer's word would appear after the word the player guessed are not very intuitive.

Before you go writing a bunch of code, plan how you think the user might interact with a program that worked like what you describe.

How does the user specifiy they are guessing a letter or if they are guessing the word?

How does the program tell them whether or not the letter is in the word?

How does the program tell them how many more letter guesses the player has?

Can the player make more than one guess at the word?

Does the game play more than once, or does it quit and the user has to re-start it to play again?

If you better define how the user will interact (which in turn describes how your program must behave) you'll have a much better idea of where to …

Murtan 317 Practically a Master Poster

Yes the code can all be in one file, but you still have to end up defining the objects (classes) and how they interact. The multi-file method would make more sense if you planned to re-use some of the classes.

For example, the 'deck of cards' would probably populate itself when you make it, support a 'shuffle' or 'mix' method to mix all the cards up. It would probably have a 'deal' method that would return the next card from the deck and maybe a counter to tell you how many cards are left in the deck. You could then re-mix the cards every hand or every few hands without having to worry about the deck anymore.

The game would interact with the deck by calling mix and then deal to get a card for the player. Then deal for the 'down card' for the dealer. Then calling deal twice more to get the player's second card and the 'up card' for the dealer.

Is this how you think of the problem, or do you think about it some other way?

NOTE: this is the key part of the problem (or assignment) how do YOU think about the problem? How do you think about breaking the problem up into smaller, more-managable pieces?

What else would be required to complete a round of play?

How does the user (player) decide to keep playing or to quit?

I am intentionally asking leading questions to help …

Murtan 317 Practically a Master Poster

You're using 'choice' from the random module. This selects a random member of the list. This part is ok, but if you were to give the cards actual display values (like 5S for 5 of Spaces or 2H for the 2 of Hearts) nothing in choice prevents you from dealing the same card twice, its always picking a card from a new deck, regardless of the cards that have already been drawn.

I like the concept of a deck of cards as a class, but the deck of cards shouldn't know anything about the player or the computer or the score or anything besides the cards. That data should live in another class or as global data, depending on your design.

(Side note: if you build a list of cards you could use random.shuffle to mix up the order of the cards in the list. Then you could 'walk through' the list from head to tail to get cards which would guarantee you didn't deal the same card twice.)

Why do you limit the user to only being able to hit when the total is 18 or less? Granted it wouldn't be very common to hit at or above 18, but I think it is the player's decision to make.

You might consider a 'card' class that has a display (like AD, 7C, JS) and a value. (Right now your deck is only values.) This might make it easier to 'score' a hand. The problem being …

Murtan 317 Practically a Master Poster

What's your objective?

What kind of interface do you need? Should the game play fully automated, or does the user interact with the game? If fully automated, where/how do you define the 'rules' for the player?

Do you need to shuffle the deck?

What keeps 'choice' from re-picking the same card that was picked previously?

When dealing Blackjack, don't you normally deal one to each player and then one to the dealer. Then repeat for the second card?

Murtan 317 Practically a Master Poster

Is this game supposed to be like the card game memory?

Where you turn over two cards and if they match you count the pair (usually removing the cards) and if not flip them back over?

So for each user turn:
the user should pick a first card
you 'turn face up' the first card
(display the grid)
the user should pick a second card
you 'turn face up' the second card
(display the grid)
if the cards match, remove the cards from play
if the cards do not match, turn then back 'face down'
(display the grid)

until the user has either matched all of the cards or quit

This means that each location in the grid has one of 3 states: face down, face up, empty

If you would like further assistance, please implement more of the code. It would also be nice if your posted code would at least compile, and if you want to use an external file, a sample of what that file was intended to contain would also be useful.

PS- As an alternative design to the 'scrolling text' method you are using, if you are at least passing familiar with the python graphic support, this application would lend itself well to a grid of buttons. Although it would be a very different approach from what you have, I think the result would be more user friendly.

Murtan 317 Practically a Master Poster

If you want the program to ask for multiple inputs, you need to re-prompt and re-accept input inside the while loop.

Try putting it right after you display an answer.

Murtan 317 Practically a Master Poster

If the include line looks like:

#include "Test/Testnamespaces.h"

it should look for the Test directory in the same directory the source file was located in, or in the include path.

If you used:

#include <Test/Testnamespaces.h>

the compiler will not look in the source file's directory first.

Which style of include did you use?

If this doesn't help, the relevant section from your code would be useful as well as the project directory listing to demonstrate where the files are located in relation to each other.

Murtan 317 Practically a Master Poster

It's been a while since I played in VB,
but doesn't the x = 1 run every time the timer is called?

The sub as displayed reads from Me.ProgressBar1 , but does not appear to set it, so the value doesn't change here.

So if neither Me.ProgressBar >= 10 or x >= 10 will ever be true, I wouldn't expect the 'loading' window to ever close.