Thread: how to declare an external variable of type "enum"?

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Adam Rinkleff
    I do because I don't really know what I'm doing, so I'm happy if it compiles, and passing variables back and forth seems awfully difficulty.
    Working with global variables is even more difficult because you have to keep global state in your mind all the time. When you don't really know what you're doing, global variables => guaranteed epic fail.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by grumpy View Post
    If you are happy for each source file to have its own local version of the variable (so changes made to the value in one source file are not visible to other source files) the variable doesn't need to be extern.
    Yes, but in this case it needs to be static.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #18
    Registered User
    Join Date
    Jun 2011
    Posts
    78
    Quote Originally Posted by laserlight View Post
    Working with global variables is even more difficult because you have to keep global state in your mind all the time. When you don't really know what you're doing, global variables => guaranteed epic fail.
    Can you explain, because I really don't understand. I don't really have a global state to keep track of, I think you are overestimating the amount of skill that I possess. I'm just trying to write a chess program (I'm a chess player, not a programmer), and I find that just about every function I make wants to know the color, along with about 50'000 other variables, so I've just made everything global.

  4. #19
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by Adam Rinkleff View Post
    ...I think you are overestimating the amount of skill that I possess. I'm just trying to write a chess program (I'm a chess player, not a programmer), ...
    You do realize that creating a chess program is one of the more difficult programming tasks to perform right?

  5. #20
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by AndrewHunter View Post
    You do realize that creating a chess program is one of the more difficult programming tasks to perform right?
    Not true, creating a good chess program might be very hard; but the bad ones was not so hard.

    Tim S.

  6. #21
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by Adam Rinkleff View Post
    Can you explain, because I really don't understand. I don't really have a global state to keep track of, I think you are overestimating the amount of skill that I possess. I'm just trying to write a chess program (I'm a chess player, not a programmer), and I find that just about every function I make wants to know the color, along with about 50'000 other variables, so I've just made everything global.
    When you write code, you want to be able to use the same techniques for tiny program as for large ones. Global variables are something that are somewhat easy to use in tiny programs, but for even moderately sized programs they are harder to work with. Someone can probably give you a good link to explain why in detail.

    Passing variables as function arguments is easy for both large and small programs.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Adam Rinkleff
    I don't really have a global state to keep track of (...) I find that just about every function I make wants to know the color, along with about 50'000 other variables, so I've just made everything global.
    It looks like you do have global state. I suggest that you mitigate this by grouping variables into structs, then pass the structs around (through passing pointers to them).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by AndrewHunter View Post
    You do realize that creating a chess program is one of the more difficult programming tasks to perform right?
    Creating a chess AI that plays against you is hard. Creating a chess program that simply allows you to input moves and possibly check to see if the move is valid is not quite hard.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #24
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by quzah View Post
    Creating a chess AI that plays against you is hard.
    Creating a chess program that plays against you is relatively easy. Creating a chess program that plays well against you is more difficult.

    The basic problem is that chess is most effectively played as a strategic game: a strategic player will easily beat a tactical player. Computers are good at doing things tactically (or repetitively searching through a set of possible tactics for a "best" option) but not generally good at strategy. Most of the programs that have beaten professional players are implemented using some combination of smart heuristics and brute-force search involving large amounts of computing power. Deep Blue, for example, was a 30-node super-computer capable of evaluating 200 million moves per second and, even then, could not consistently beat a professional chess player (Kasparov) who, as a human, presumably does not examine 200 million moves every second.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  10. #25
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by grumpy
    The basic problem is that chess is most effectively played as a strategic game: a strategic player will easily beat a tactical player.
    I think that a strategic player will lose to a tactical player: strategy is useless when there is no material to execute it. In practice, strategic players are also tacticians, so the notion of a purely strategic player is fantasy.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #26
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by laserlight View Post
    I think that a strategic player will lose to a tactical player: strategy is useless when there is no material to execute it. In practice, strategic players are also tacticians, so the notion of a purely strategic player is fantasy.
    Yes, strategic players can function as tacticians. However, the bulk of tactical players rarely employ strategy.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  12. #27
    Registered User
    Join Date
    Jun 2011
    Posts
    78
    I play an awful lot of chess, and I rather think that the debate over 'strategic' versus 'tactical' players is a little bit exaggerated. The fact of the matter is that strategy and tactics are really the same thing. Strategic players are simply very good tactical players, who are thinking a bit more deeply. Someone who says they understand strategy, but ignores tactics, is going to get crushed -- and vice-versa.
    Last edited by Adam Rinkleff; 06-23-2011 at 01:58 PM.

  13. #28
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    The field of chess AI is well researched. It is not hard to create a good chess program, it's been done, and the known effective algorithms can be implemented. With modern resources it is not hard to write an AI that will beat most players.

    You can tweak heuristics and the amount of game tables to beat the better players.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  14. #29
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Adam Rinkleff
    The fact of the matter is that strategy and tactics are really the same thing. Strategic players are simply very good tactical players, who are thinking a bit more deeply.
    That sounds like an over-simplification, e.g., "thinking a bit more deeply" in the same way as one would to say calculate a combination would not necessarily work in the development of a plan as the horizon effect also applies to human players.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GCC lets you forward declare a struct with "class /name/"
    By Mozza314 in forum C++ Programming
    Replies: 12
    Last Post: 02-20-2011, 04:52 AM
  2. Replies: 3
    Last Post: 05-01-2010, 02:26 AM
  3. problem about handle "double" variable type? or?
    By Mathsniper in forum C Programming
    Replies: 4
    Last Post: 12-31-2006, 10:11 PM
  4. "Deciding" in runtime the type of a variable
    By mikahell in forum C++ Programming
    Replies: 28
    Last Post: 07-22-2006, 09:51 AM
  5. Ask about error when declare "static inline int"
    By ooosawaddee3 in forum C Programming
    Replies: 3
    Last Post: 05-25-2002, 05:03 AM