数当てゲームサイモンとライフゲーム
13.サイモン
100 rem simon
110 cls
120 randomize timer
130 print "2-keta no Sei no Kazu wo Kangaete kudasai." : print
140 for i = 1 to 500000 : next i
150 n = 0
160 pmax = 100 : pmin = 0
170 p = rnd(100)
180 n = n+1 : print "n=";n,p;"desuka?"
190 gosub 220
200 goto 180
210 end
220 rem sub Shori
230 input "Kono Suuji de Atteimasuka? Atteireba 1, Matigatte-ireba 2 wo Irete kudasai. ",a
240 if a = 1 then print "Yatta!!" : end
250 rem chigatta baai
260 input "Kore yori Ookii desuka? Ookikereba 1, Chiisakereba 2 wo Irete kudasai.",aa
270 if aa = 2 then pmax = p : else pmin = p
280 x = rnd(100)
290 if x < pmax and x > pmin then p = x : return : else goto 280
300 end
解説)
2桁の(正の)数字を当てるゲームです。パソコンが適当な数字を言い、それより大きいか
小さいかを答えて行きます。270-290がこのプログラムの要(?)になります。乱数を発
生させる範囲をこれでどんどん狭めて行きます。
ただ、このプログラムは相手が嘘を言った時には、対応できません。いつまでも考えて
いますので、その場合はSTOPをかけて下さい。
14.ライフゲーム
100 rem life game
110 cls
120 graphics 0
130 graphics window 400,250
140 randomize timer
150 dim a(202),b(202)
160 for i = 0 to 201
170 a(i) = 0 : b(i) = 0
180 next i
190 for i = 1 to 200
200 x = rnd(40)
210 if x = 2 then a(i) = 1 : graphics color 100,0,0 : graphics pset i+100,10
220 next i
230 for j = 1 to 200
240 for i = 1 to 200
250 if a(i-1) = 0 and a(i) = 0 and a(i+1) = 0 then b(i) = 0 : goto 330
260 if a(i-1) = 1 and a(i) = 0 and a(i+1) = 0 then b(i) = 1 : goto 330
270 if a(i-1) = 0 and a(i) = 1 and a(i+1) = 0 then b(i) = 1 : goto 330
280 if a(i-1) = 0 and a(i) = 0 and a(i+1) = 1 then b(i) = 1 : goto 330
290 if a(i-1) = 1 and a(i) = 1 and a(i+1) = 0 then b(i) = 1 : goto 330
300 if a(i-1) = 1 and a(i) = 0 and a(i+1) = 1 then b(i) = 0 : goto 330
310 if a(i-1) = 0 and a(i) = 1 and a(i+1) = 1 then b(i) = 0 : goto 330
320 if a(i-1) = 1 and a(i) = 1 and a(i+1) = 1 then b(i) = 1
330 next i
340 for i = 1 to 200
350 if b(i) = 1 then graphics color 100,0,0 : graphics pset i+100,j+10
360 next i
370 for i = 1 to 200
380 a(i) = b(i)
390 b(i) = 0
400 next i
410 next j
420 end
解説)
1次元のライフゲームです。200-210行で初期値をきめています。250-320行で生存
条件を簡単にかえられます。
人工生命の研究の一つということで一時期流行った時には2次元のものでしたが、本質
的なものは1次元でも変わらないと言うことです。グライダーとかブーメランとかあり
ましたが、もう廃れて死後になったのでしょうか。当時、そのような用語が小説にも出
てきました。「謀殺のチェスゲーム」の中かな。
210行目のpsetは点を打つ命令です。pset x,yでx座標(横),y座標(縦)の位置を指定しま
す。