Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old July 13, 2016, 07:26   #41
Elfin Jedi
Adept
 
Join Date: Mar 2013
Posts: 102
Elfin Jedi is on a distinguished road
Quote:
Originally Posted by Pete Mack View Post
@EJ:
This is when I would start up the debugger. Have you tried making some of those books always rather than normal in the text file? (At the least, the beginners books need to be, to allow the start-with-gold-no start option.)
Oh, good point. I never use that start option, so it didn't occur to me.
Elfin Jedi is offline   Reply With Quote
Old July 13, 2016, 08:01   #42
Elfin Jedi
Adept
 
Join Date: Mar 2013
Posts: 102
Elfin Jedi is on a distinguished road
Thanks for the link, it looks useful, I bookmarked the site.

I added a closing ")" (which it likes) right here:

if (!rf_has(mon->race->flags, RF_INVISIBLE) || (mon->m_timed[MON_TMD_INVISIBLE]) &&
!mflag_has(mon->mflag, MFLAG_UNAWARE))

But when I try to add parentheses to the && it gives me an error for each one, for the first:

effects.c:1369:84: error: called object is not a function or function pointer
if (!rf_has(mon->race->flags, RF_INVISIBLE) || (mon->m_timed[MON_TMD_INVISIBLE]) (&&)

and for the second:

effects.c:1369:87: error: expected identifier before ')' token
if (!rf_has(mon->race->flags, RF_INVISIBLE) || (mon->m_timed[MON_TMD_INVISIBLE]) (&&)
Elfin Jedi is offline   Reply With Quote
Old July 13, 2016, 16:11   #43
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 4,317
Donated: $40
Pete Mack is on a distinguished road
Here is what you probably need: Otherwise the && will execute before || (unless this is what you had in mind.)
if (!(rf_has(mon->race->flags, RF_INVISIBLE) || (mon->m_timed[MON_TMD_INVISIBLE])) &&
!mflag_has(mon->mflag, MFLAG_UNAWARE))

However, this is seriously confusing. You might look at De Morgan's laws and simplify.

https://en.wikipedia.org/wiki/De_Morgan%27s_laws

Or better yet, write a little function that returns whether the monster is invisible.
Pete Mack is offline   Reply With Quote
Old July 13, 2016, 18:24   #44
Elfin Jedi
Adept
 
Join Date: Mar 2013
Posts: 102
Elfin Jedi is on a distinguished road
Quote:
Originally Posted by Pete Mack View Post
The warning about && is because the precedence is sometimes non-intuitive (as in, it can get evaluated before you think it should.) And in this case, you want the || (OR) evaluated before the AND, so you absolutely need it. (In effect && has precedence like *, and || has precedence like +, so && is applied first.)
\
I thought that you meant that I needed to put the parentheses around the &&.

It was happy with the first change (the closing ")") before I added the parentheses around the &&, so if I don't need the AND parentheses it seems to make sense to just keep the first change and go on to the next invisibility check.
Elfin Jedi is offline   Reply With Quote
Old July 13, 2016, 20:28   #45
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 4,317
Donated: $40
Pete Mack is on a distinguished road
Yikes. You have 3 conditionals in your statement, call them a, b, c. Depending on paranthesization, they will do very different things. Do you want:

!a || (b && !c) -- this is what you will get without parentheses.
Or do you want (which looks right without context)
!(a || b) && !c
which is equivalent to the more readable forms (by Demorgan's laws):
!a && !b && !c
or:
!(a || b || c)
Or possibly another alternative:
(!a || b) && !c
Pete Mack is offline   Reply With Quote
Old July 14, 2016, 01:07   #46
Elfin Jedi
Adept
 
Join Date: Mar 2013
Posts: 102
Elfin Jedi is on a distinguished road
I believe I want !(a || b) && !c (if monster has race flag: invisible, or temporary effect: invisible, and player is unaware; then don't detect monster without detect invisible)

Or else (!a || b) && !c (I don't know what the effect/meaning of the "!" is)
Elfin Jedi is offline   Reply With Quote
Old July 14, 2016, 01:19   #47
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 4,317
Donated: $40
Pete Mack is on a distinguished road
! means NOT. So for proposition p, codeblocks A and B
if (p) {B}
else {A}
is equivalent to
if (!p) {A}
else {B}

My additional point was that
!(a || b) && !c
is a more complex expression than the other two ways of writing it. Either put all conditions in the parentheses, or none, as I tried to show in the previous post.
Pete Mack is offline   Reply With Quote
Old July 14, 2016, 01:45   #48
Elfin Jedi
Adept
 
Join Date: Mar 2013
Posts: 102
Elfin Jedi is on a distinguished road
Ok, so if monster does not have race flag invisible or monster timed invisible, and does not have monster flag unaware, then detect the monster. Right?

/* Detect all non-invisible, obvious monsters */
if (!rf_has(mon->race->flags, RF_INVISIBLE) || (mon->m_timed[MON_TMD_INVISIBLE]) &&
!mflag_has(mon->mflag, MFLAG_UNAWARE))
{
/* Hack -- Detect the monster */
mflag_on(mon->mflag, MFLAG_MARK);
mflag_on(mon->mflag, MFLAG_SHOW);

So, in that case !a && !b && !c means if the monster does not have a AND does not have b AND does not have c then detect it vs. !(a || b || c) if the monster does not have a OR b OR c then detect it.

Would !a && !b && !c mean that to go undetected a monster would have to have all three flags?

And would !(a || b || c) mean that if the monster has any of these flags it goes undetected?

Because in that case I like !(a || b || c) better.

P.S.

Ok, so looking at it more !a && !b && !c also should mean having any of those flags makes it undetected, so they really are completely equivalent in effect then?
Elfin Jedi is offline   Reply With Quote
Old July 14, 2016, 02:03   #49
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 4,317
Donated: $40
Pete Mack is on a distinguished road
They really are equivalent. This is a standard trick--do look at that Wikipedia page for De Morgan's laws. It is likely to help you understand this kind of manipulation. (It is very common--that you ran into it right off is no accident.)
Edit:
If you are new to this think of AND--&&-- as multiply and OR as add* where all numbers are zero or one. So NOT x becomes 1 - x. All the math that holds for addition and multiplication holds for AND an OR in this special number system.
* Note: 1 + x = x in this arithmetic.

Last edited by Pete Mack; July 14, 2016 at 02:11.
Pete Mack is offline   Reply With Quote
Old July 14, 2016, 02:10   #50
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,827
Donated: $40
takkaria is on a distinguished road
Quote:
Originally Posted by Elfin Jedi View Post
Ok, so looking at it more !a && !b && !c also should mean having any of those flags makes it undetected, so they really are completely equivalent in effect then?
Yes, !(a || b || c) and (!a && !b && !c) are totally equivalent.

I made this table that may or may not help show why! On the left you've got all the possible values of a, b and c. Then in the middle you have the OR version, and on the right you have the AND version and why they result in the same outcome.
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2016-07-14 at 01.08.14.jpg
Views:	47
Size:	23.3 KB
ID:	1436  
__________________
"Physician, heal thyself."
takkaria is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[PosChengband] Making Realms Questions riftor_77 Development 5 August 4, 2014 13:24
Spellbooks as artifacts TJS Vanilla 48 July 29, 2010 06:12
Sangband and spell realms Malak Darkhunter Variants 21 March 18, 2009 05:03
Spellbooks curinor Variants 3 April 20, 2008 14:38
Spellbooks curinor Vanilla 1 April 19, 2008 23:07


All times are GMT +1. The time now is 20:29.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.