Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
when GOTO makes sense.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Ed Morton, post: 1691264"] Not at all. Likewise, I appologise if I was rude or sounded offended. I've added an "OT" label to the subject as I'm about to talk about algorithms rather than ANSI C: I took another look at the code and, though I don't get the details, the comments sound like you're (very roughly) attempting to deal the cards until some predefined outcome, and backtracking when you hit dead-ends. If so, did you consider using, say, bit-state-hashing with a depth-first (recursive-descent) algorithm, e.g. something like this pseudo-code: play() { deal(); /* determine possible next states from the * current state, e.g. card hand combinations. */ for (state in possibleStates) { if (state == the_desired_result) { return; } else { idx = hash(state); if (hashTbl[idx] == 0) { /* This is a new configuration * so continue */ hashTbl[idx] = 1; play(); } /* else, we've seen this configuration * before so move on or backtrack */ } } } main() { bool hashTbl[size] = { 0 }; play(); printState(state); } Regards, Ed. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
when GOTO makes sense.
Top