Is my Logic wrong or QB64's ? - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Is my Logic wrong or QB64's ? (/showthread.php?tid=2098) Pages:
1
2
|
Is my Logic wrong or QB64's ? - bplus - 10-15-2023 I am doing a demo of setting up Conways Game of Life at other forum and run into a problem getting proper neighbor counts of a cell with this code: Code: (Select All) nc = 0 If I rework that first IF line to this: Code: (Select All) nc = 0 All is well! Fine I can get the code to work as expected with 2nd block but I am not understanding what is going wrong with the first code example? A professional Basic coder (non QB64 fan) said the logic is correct, has QB64 another glitch? BTW he showed a much better method to do count without IF. If anyone a connoisseur of methods it was this: Code: (Select All) nc = 0 As I recall my debug checks with the first block of code was messing up neighbor counts of live cells not that it should matter but with either -1 or 1 for live cell signal. oh wait, I see it now, the logic is wrong because if I break the first IF line into 2 it becomes obvious why the counts were failing: Code: (Select All) nc = 0 OK never mind, I got it now RE: Is my Logic wrong or QB64's ? - SMcNeill - 10-15-2023 Aren't you reversing logic? If x = 1 AND y = 1.... *magic revertso!!* If x <> 1 OR y <> 1 Then DON'T... Don't forget to reverse the middle AND/OR as well. RE: Is my Logic wrong or QB64's ? - bplus - 10-15-2023 Yep! here is a case where Charlie's DoNothing comes into play because it is so much clearer (the 2nd code block) to this tiny human brain if we list the one case to exclude and then do something for all the other ELSE cases. RE: Is my Logic wrong or QB64's ? - mnrvovrfc - 10-15-2023 Because BASIC never had a "boolean" type, and because so many programmers relied so much on "0 is false, non-zero is true", I have come across this situation with being able to write a condition, but needing to execute something when that condition is false, and not caring at all about when it's true. Something like this: Code: (Select All) if x = 1 and y = 2 then This is just an example but the condition could be a bit mind boggling. I simply do the "block if" and put "do nothing" comment on a line by itself. I do this programming in Lua as well. Even though in that scripting language, it's possible to assign a variable to "true" or "false" and the "if" statement responds to that. RE: Is my Logic wrong or QB64's ? - SMcNeill - 10-15-2023 If x <> 1 OR y <> 2 THEN 'A lot of code End If Why is basic logic hard in BASIC? RE: Is my Logic wrong or QB64's ? - bplus - 10-15-2023 Y'all did see the code that skipped the IF test altogether, just added in everything and then subtracted out the one thing not wanted. Time wise, BIG savings! RE: Is my Logic wrong or QB64's ? - SMcNeill - 10-15-2023 (10-15-2023, 11:50 AM)bplus Wrote: Y'all did see the code that skipped the IF test altogether, just added in everything and then subtracted out the one thing not wanted. Time wise, BIG savings! Code: (Select All)
RE: Is my Logic wrong or QB64's ? - bplus - 10-15-2023 (10-15-2023, 12:13 PM)SMcNeill Wrote:(10-15-2023, 11:50 AM)bplus Wrote: Y'all did see the code that skipped the IF test altogether, just added in everything and then subtracted out the one thing not wanted. Time wise, BIG savings! Yeah I like how yours takes the calc's out of the For loop and puts them in the counting line. Part of what makes Steve amazing is that he is also a connoisseur of coding method. RE: Is my Logic wrong or QB64's ? - James D Jarvis - 10-15-2023 (10-15-2023, 11:50 AM)bplus Wrote: Y'all did see the code that skipped the IF test altogether, just added in everything and then subtracted out the one thing not wanted. Time wise, BIG savings! I like. I similar in a life-like program. (and yes I have a honking load of if thens) Code: (Select All)
RE: Is my Logic wrong or QB64's ? - bplus - 10-15-2023 (10-15-2023, 04:07 PM)James D Jarvis Wrote:(10-15-2023, 11:50 AM)bplus Wrote: Y'all did see the code that skipped the IF test altogether, just added in everything and then subtracted out the one thing not wanted. Time wise, BIG savings! Oh man, you can do this without... well case 2 should be checking if cell is alive so it can stay alive. You can avoid border IF checking by allowing x, y to go only as close as 1 pixels away from border (but what does a screen return for a point outside it's border?) Funny! Case 3 : Pset(sx, sy), klr ' no if's, ands, or buts!!! Hey maybe your Pixel Life isn't exactly by Conway's Life Rules but it sure is pretty! |