ã²ã¼ã ã®ãã©ã°ç®¡çã¯ãããæ¼ç®ã§å¹çãã¤ç°¡åã«ç®¡çãã
ã©ããæ´æ°ããµããã¾ããã®ææ«ã§ãã æ¬æ¥ã¯ã²ã¼ã ãªã©ã®ãã©ã°ç®¡çã«ä½¿ãããããæ¼ç®ã«ã¤ãã¦æ¸ãããã¨æãã¾ãã
é²æ°
æ¥æ¬äººã®100人ã«ã¢ã³ã±ã¼ããåãã°ããããã9ã®æ¬¡ã¯10ã¨çãã人ã大å¤æ°ã ã¨æãã¾ãã ãã ãããã¯å³å¯ã«ã¯ééã£ã¦ãã¦9ã®æ¬¡ã10ã«ãªãã®ã¯10é²æ°ã§ç©äºãèãã¦ããããã§ãã
é²æ°ã¨ããã®ã¯ç°¡åã«è¨ãã¨ããã¤æ¡ãããããï¼ãã¨ããäºã§ãã ä¾ãã°æ®æ®µä½¿ç¨ãã¦ãã10é²æ°ã§ããã°0ããæ°ãã¦10åç®ï¼9ï¼ã¾ã§ã¯1æ¡ã§è¡¨ãã¾ãã 11åç®ï¼10ï¼ããã¯2æ¡ã«ãªãã¾ãã
ãªããªãã¤ã¡ã¼ã¸ããé£ãã¨æãã®ã§ä»¥ä¸2é²æ°ã8é²æ°ã10é²æ°ã16é²æ°ãè¦ã¦è¡ãã¾ãã æ¡ããã¤å¢ãããï¼ã«æ³¨ç®ãã¦ãã ããã
2é²æ° | 8é²æ° | 10é²æ° | 16é²æ° |
---|---|---|---|
0 | 0 | 0 | 0 |
1 | 1 | 1 | 1 |
10 | 2 | 2 | 2 |
11 | 3 | 3 | 3 |
100 | 4 | 4 | 4 |
101 | 5 | 5 | 5 |
110 | 6 | 6 | 6 |
111 | 7 | 7 | 7 |
1000 | 10 | 8 | 8 |
1001 | 11 | 9 | 9 |
1010 | 12 | 10 | A |
1011 | 13 | 11 | B |
1100 | 14 | 12 | C |
1101 | 15 | 13 | D |
1110 | 16 | 14 | E |
1111 | 17 | 15 | F |
10000 | 20 | 16 | 10 |
ã¾ã2é²æ°ã¯ 0 㨠1 ã ãã§æ°åã表ãã¦ããã¨ãããã¨ã ãããã£ã¦ããã ããã°çµæ§ ã§ãã
ãããæ¼ç®
ãã¦2é²æ°ã®èª¬æãçµãã£ãã®ã§ãããæ¼ç®ã«ã¤ãã¦èª¬æãããã¨æãã¾ãã
ãããæ¼ç®ã¨ã¯2é²æ°ã§è¡¨ãããæ°å¤ï¼ããããã¿ã¼ã³ï¼ãæä½ããæ¼ç®ã®ãã¨ã§ãã 主ã«ANDãORãNOTã¨ãã3ã¤ã®æ¼ç®ããæãç«ã¡ã¾ãï¼XORã¨ã·ããã¯ãã ãããã®ã§ãã®è¨äºã§ã¯æ±ãã¾ããï¼ã ããããã©ã®ãããªæ¼ç®ãè¦ã¦è¡ãã¾ãããã
AND
ANDæ¼ç®ã¯2ã¤ã®ããããã¿ã¼ã³ãåãã1ã¤ã®ããããã¿ã¼ã³ãè¿ãæ¼ç®åã§ãã åãããã«ããã¦åæ¹ã1ã®å ´åã¯1ãããã以å¤ã®å ´åã¯0ãè¿ãã¾ãã 以ä¸ä¾ã§ãï¼1ãããã®å ´åï¼ã
1 AND 1 = 1 0 AND 1 = 0 1 AND 0 = 0 0 AND 0 = 0
ã¾ããããæ¼ç®ã¯åæ¡æ¯ã®æ¼ç®ã«ãªãã®ã§ããããã¿ã¼ã³ã«å¯¾ãã¦ã¯ä¸è¨ã®ããã« åãã¾ãï¼çç®ã®ããã«ä¸ä¸ã§ANDãé©ç¨ãã¦ãã ããï¼ã
1100 AND 1010 ---------- 1000
OR
ORæ¼ç®ã2ã¤ã®ããããã¿ã¼ã³ãåãã1ã¤ã®ããããã¿ã¼ã³ãè¿ãæ¼ç®åã§ãã åãããã«ããã¦ã©ã¡ããã1ã®å ´åã¯1ããã©ã¡ãã0ã®å ´åã¯0ãè¿ãã¾ãã 以ä¸ä¾ã§ãï¼1ãããã®å ´åï¼ã
1 OR 1 = 1 0 OR 1 = 1 1 OR 0 = 1 0 OR 0 = 0
ãªããããããã¿ã¼ã³ã«å¯¾ãã¦ã¯ä¸è¨ã®ããã«åãã¾ãã
1100 OR 1010 ---------- 1110
NOT
NOTæ¼ç®ã¯1ã¤ã®ããããã¿ã¼ã³ãåãã1ã¤ã®ããããã¿ã¼ã³ãè¿ãæ¼ç®åã§ãã åãããã«ããã¦1ã®å ´åã¯0ãã0ã®å ´åã¯1ãè¿ãã¾ãã 以ä¸ä¾ã§ãï¼1ãããã®å ´åï¼ã
NOT 1 = 0 NOT 0 = 1
ãªããããããã¿ã¼ã³ã«å¯¾ãã¦ã¯ä¸è¨ã®ããã«åãã¾ãã
NOT 1010 ---------- 0101
ãããæ¼ç®ã使ã£ããã©ã°ç®¡ç
æ°å¤ãããããã¿ã¼ã³ã§è¡¨ãã¨ãåæ¡ã 0 ã 1 ã§è¡¨ããã¾ãã ãããã£ã¦ 0 ã OFFã1 ã ON ã¨å®ç¾©ããã¨å¤§éã®ç¶æ ï¼ãã©ã°ï¼ãä¸ã¤ã®æ°åã¨ã㦠管çãããã¨ãã§ãã¾ãã
å ·ä½çã«èãã¾ãã RPGãªã©ã«ããã¦ããã£ã©ã¯ã¿ã¼ãã¨ã«ãç ãããã麻çºããªã©ã®ç¶æ ãåå¨ãã¾ãã ãããï¼ãªãã¸ã§ã¯ãæåã使ããã«ï¼4人ãã¼ãã£ã¼ã§æ®éã«ç®¡çããã¨ä»¥ä¸ã®ãã㪠ã³ã¼ãã«ãªãã§ãããï¼Pythonçä»®æ³è¨èªï¼ã
player1_sleep = false # ç ã player1_palarysis = false # éº»çº player1_poison = false # æ¯ player1_excitation = false # è奮 player2_sleep = false player2_palarysis = false player2_poison = false player2_excitation = false player3_sleep = false player3_palarysis = false player3_poison = false player3_excitation = false player4_sleep = false player4_palarysis = false player4_poison = false player4_excitation = false
ãã®ä¾ã§ã¯ç¶æ ç°å¸¸ã4ã¤ã ããªã®ã§ä½ã¨ããªãã¾ãããæ°ãå¢ããã¨é¢åã§ããã ãããªæã¯ããããã¿ã¼ã³ã使ã£ã¦ç¶æ ã管çãããã¨ãèãã¾ãã 以ä¸ã®ãããªã¤ã¡ã¼ã¸ã§ãã 0ã¯ãã®æ¡ã®ç¶æ ç°å¸¸ã¯ç¡ããã¨ã表ãã1ã¯ãã®æ¡ã®ç¶æ ç°å¸¸ã§ãããã¨ã表ãã¾ãã
sleep palarysis poison excitation player1_state = 0 0 0 0
ãã®ããã«ããããã¿ã¼ã³ã®åæ¡ãç¶æ ã¨ãã¦å®ç¾©ãã¦ããã¨ã以ä¸ã®ããã«é常ã«ç°¡åã« ç¶æ ãå¤æ´ã§ãã¾ãã
ãã©ã°ãç«ã¦ãï¼ç¶æ ç°å¸¸ã追å ï¼
ãã©ã°ãç«ã¦ãã«ã¯ORæ¼ç®åã使ãã¾ãã ãã©ã°ãç«ã¦ããæ¡ã 1 ã®ããããã¿ã¼ã³ãORãããã¨ã§ ã¹ãã¼ã¿ã¹å¤æ°ã®ä¸ã®æ°å¤ãã©ã®ãããªæ°å¤ã§ãã£ã¦ã確å®ã«ä»»æã®æ¡ã 1 ã«ããã㨠ãã§ãã¾ãã
# ç¶æ ãåæå player1_state = 0000 # æ¯ç¶æ ã«ãã # 0000 OR 0010 = 0010 player1_state = player1_state OR 0010 # 麻çºç¶æ ã«ãã # 0010 OR 0100 = 0110 player1_state = player1_state OR 0100
ãã©ã°ãä¸ããï¼ç¶æ ç°å¸¸ãåé¤ï¼
ãã©ã°ãä¸ããã«ã¯ANDã¨NOTãçµã¿åããã¾ãã
ãã©ã°ãä¸ãããæ¡ã 1 ã®ããããã¿ã¼ã³ãNOTãããã¨ã§
ãã©ã°ãä¸ãããæ¡ä»¥å¤ããã¹ã¦1ã®ããããã¿ã¼ã³ã«ãã¾ãã
ãã®å¾ANDããããã¨ãã©ã°ãä¸ãããæ¡ã¯? AND 0 = 0
ã§ç¢ºå®ã« 0 ã«ãªãã
ä»ã®æ¡ã¯ãã©ã°ãç«ã£ã¦ããå ´åã¯1 AND 1 = 1
ããã©ã°ãç«ã£ã¦ããªãã£ãå ´åã¯
0 AND 1 = 0
ã¨ãªãã®ã§ç¢ºå®ã«ä¿åããã¾ãã
# ç¶æ ãåæåï¼éº»çºã»æ¯ç¶æ ï¼ player1_state = 0110 # æ¯ç¶æ ãè§£é¤ # 0110 AND (NOT 0010) = 0110 AND 1101 = 0100 player1_state = player1_state AND (NOT 0010) # 麻çºç¶æ ãè§£é¤ # 0100 AND (NOT 0100) = 0100 AND 1011 = 0000 player1_state = player1_state AND (NOT 0100)
ãã©ã°ãå¤å¥ããï¼ç¶æ ç°å¸¸ãå¤å¥ããï¼
ãã©ã°ãå¤å¥ããã«ã¯ANDã使ç¨ãã¾ãã
å¤å¥ãããæ¡ã 1 ã®ããããã¿ã¼ã³ãANDããã¨ãã©ã°ãç«ã£ã¦ããå ´åã¯
1 AND 1 = 1
ã§ãã©ã°ãç«ã£ã¦ããªãã£ãå ´åã¯0 AND 1 = 0
ã¨ãªãã¾ãã
ã¾ãå¤å¥ãããæ¡ä»¥å¤ã¯ 0 ãªã®ã§? AND 0 = 0
ã¨ãªãã®ã§ANDãããã
ããããã¿ã¼ã³ã¨çãããªããã©ããã§å¤å¥ã§ãã¾ãã
# ç¶æ ãåæåï¼éº»çºã»æ¯ç¶æ ï¼ player1_state = 0110 # ç ããï¼ # 0110 AND 1000 = 0000 sleep = player1_state AND 1000 if sleep == 1000: ç ã # 麻çºãï¼ # 0110 AND 0100 = 0100 palarysis = player1_state AND 0100 if palarysis == 0100: 麻çº
ãã®ããã«ãããæ¼ç®ã使ããã¨ã§ç°¡åã«å¤§éã®ãã©ã°ã管çãããã¨ãã§ãã¾ãã ã¾ããããæ¼ç®ã¯åç´ãªè«çå¼ã§æãç«ã¤ã®ã§å¦çãé«éã§ãã RPGãªã©ã²ã¼ã å¶ä½ã«ããã¦ç¥ã£ã¦ããã¨ä¾¿å©ãªæ¹æ³ãªã®ã§ãã²é ã®çé ã«ããã¦ãã㦠ãã ããã