|
このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。 |
"When I was a boy", there were computer magazines 十分な of programs you could type into your computer.
BASIC was the usual language- pretty 限られた/立憲的な, but then, so were computers!
Even though the language was basic, some of the programming was far from trivial. And a lot of fun games were created. And a lot of fun was had typing them in, and learning a lot during the debugging 過程.
This is one of the longest, and to be honest, perhaps most tedious, of my tutorials.
Partly because it covers two separate topics.
Yes, by the end, you are 井戸/弁護士席 on the way to a 変えるd BASIC program, but, more importantly, and even if you don't want the BASIC program(!), I commend this to you: It trys to 伝える my しっかり掴む of how thinking of the computer as a "明言する/公表する machine" can help you 令状 bigger, better programs.
I'm new to the "明言する/公表する machine" 視野. But に引き続いて the 新たな展開s and turns of what I do understand may start you on the 旅行 に向かって having this useful trick in you armory.
Just as this tutorial is "about 変えるing a BASIC program", and about using the "明言する/公表する machine" model, I have another tutorial which you may 利益 from, even if you aren't an Arduino programmer. An Arduino program creating a "明言する/公表する machine".
It is 平易な to find listings of those old programs. If you want to try to 変える one to Lazarus, I hope this guide will help.
Three magnificent 調書をとる/予約するs, often 利用できる 経由で アマゾン or Abebooks... I'd commend Abebooks to you...
What to Do After You 攻撃する,衝突する Return... Or P.C.C.'S First 調書をとる/予約する of Computer Games Published by People's Computer Company (1977)
Gloriously "70's". Large... 14" x 10".
Amazing value... $8!
... and Ahl's "Basic Computer Games". There were two 容積/容量s, 利用できる 分かれて.
BASIC Computer Games: Microcomputer 版 David H. Ahl, Published by Workman Pub Co (1978) ISBN 10: 0894800523 ISBN 13: 9780894800528
(The second 容積/容量 was "More BASIC Computer Games")
If you 申し込む/申し出 the sourcecode for any game from them, 解放する/自由な, I'd be glad to put link here. There are adaptations of some, not always with sourcecode, but 解放する/自由な, on my SheepdogSoftware pages.
Modern programming languages and operating 申し込む/申し出 new 適切な時期s, but they also make planning a program different. Once the flowchart was king. (And it still has a place!) And the languages were "flowchart friendly".
Suppose you 手配中の,お尋ね者 to create the に引き続いて "game". (Called "Goldie's Game", by those who saw the BBC's wonderful 文書の on life at Radley College, 1979.) (There was an excellent follow up, 30 years later.) (The programmes are on YouTube.)
It is up to you, the programmer, to decide the 支配するs of your 見解/翻訳/版 of this. For today's discussion, I'm going to say that the 支配するs in this 見解/翻訳/版 are that you can't go on to the next part of the problem until you get the 現在の part 権利. Your "得点する/非難する/20" would be how quickly you 完全にする the 仕事. (Of course, the program would change the numbers in the problem each time you went through it.)
A flowchart for that might look like the に引き続いて, although they were usually draw 負かす/撃墜する a page, not across it. (I turned it for better on-審査する 見解(をとる)ing.)
A program to do that, written in BASIC, leaving out the stuff to change the numbers in the problems, might look something like...
050 REM デモ BASIC program
100 PRINT "What is 5+4?"
110 INPUT Ans
120 IF Ans>< 9 THEN GOTO 100
200 PRINT "... 加える 2?"
210 INPUT Ans
220 IF Ans>< 11 THEN GOTO 200
300 PRINT "... minus 5?"
310 INPUT Ans
320 IF Ans>< 6 THEN GOTO 300
400 PRINT "Good! Do another? ('N' for "no")"
410 INPUT Ans$
420 IF Ans>< "N" THEN GOTO 100
430 PRINT "Goodbye"
When you "ran" the program, it started with the line with the lowest line number. (Line numbers were very important to 早期に BASICs, but by the end were いっそう少なく important... "labels" had been 追加するd to the language.)
Any line beginning "REM" was (警察などへの)密告,告訴(状) for people reading the code.
PRINT put things on the 審査する.
INPUT would be followed by one or more variable 指名するs. Simple variables either held numbers or strings of characters. The latter had a $ at the end of the 指名する, e.g. Ans$, in line 410 of the example. (If there were square brackets, e.g. LikeThis[x], the variable was an element of an array.)
Apart from array elements, variable 指名するs started with a letter, and were made up of letters and digits. A $ might appear at the end, to say "this is a string variable". Other than that, that was it. 指名するs tended to be short.
If you see...
100 DIM X[3] 110 DIM P[2,2]
... you should 解釈する/通訳する it as...
始める,決める up arrays with the に引き続いて elements...
X[0], X[1], X[2], X[3] ... and... P[0,0],P[1,0],P[2,0] P[1,1],P[1,1],P[2,1] P[2,2],P[1,2],P[2,2]
In each 事例/患者, the "0" element may or may not have been 現在の, depending on the BASIC you were using.
Something like...
120 IF Ans>< 9 THEN GOTO 100
... would look at what was in the variable "Ans". If it were NOT 9, the flow of code 死刑執行 would jump to line 100 of the program. さもなければ, flow continued "負かす/撃墜する the page".
Not 現在の in the 現在の example, but also noteworthy....
120 FOR A=1 to 5 122 PRINT A 124 NEXT A 130 PRINT "Done"
Would have resulted in...
1 2 3 4 5 Done.
GOSUB 1000 sent the flow of code 死刑執行 off to line 1000, from whence it continued, until it 攻撃する,衝突する the word "RETURN", at which point it would jump 支援する ("return"!) to the line after the GOSUB 1000 that had 原因(となる)d the GO to the SUBroutine. (When you go to a subroutine, the system remembers where you were when you went, and sends you 支援する to the next line when "RETURN" is seen. Neat! Useful. In the 現在の program, I don't think any subroutine is used from more than one place... but they CAN be. (And often are.)
There was a nifty thing called "DATA". It was used with READ... for things much fancier than what follows...
110 DATA 123,456, 100, 300, 200 120 FOR A=1 to 5 122 READ X 124 PRINT X 126 NEXT A 130 PRINT "Done"
That would have given rise to...
123 456 100 300 200 Done.
The Wumpus program, 名簿(に載せる)/表(にあげる)ing follows, seemed to have a way to create 機能(する)/行事s! I don't 解任する using this much in my BASIC days... but that was my 証拠不十分, not a good idea.
Line 170 says...
170 DEF FNA(X)=INT(20*RND(0)))+1
I believe that RND(0) will return 0 to 0.99999.
I believe that this "始める,決めるs up" a 機能(する)/行事 called "FNA". I believe that if, as at line 250 (I've changed it わずかに), you say...
250 L[J]=FNA(27)
... then, at 250, the program will "look up" the 機能(する)/行事 it knows, and FNA(27) will "boil 負かす/撃墜する to", "be returned as" whatever INT(20*RND(0)))+1 評価するs to. In this instance, I believe the 27 in the calling 声明 was "thrown away". Had there been an X to the 権利 of the "=" in the 表現 at 170, I believe the 27 would have been "plugged in" there, and 影響する/感情d what FNA(27) "boiled 負かす/撃墜する to". // In any 事例/患者, when 250 was called, there was a value in J. Let's say it was 1. And FNA(27) boiled 負かす/撃墜する to something; let's say it was 16. After 250, in those circumstances, L[1] would 持つ/拘留する 16.
All of which is very 井戸/弁護士席, but I was supposed to be talking about how the 死刑執行 proceeds in an BASIC program. Which line is done when. But it is 同様に to have got some of the "petty" things out of the way.
In the "good old", "simple old" days, flow 支配(する)/統制する was 平易な. I hope that the little example above illustrates that.
However, there was an EVIL 命令(する) that had perfectly good uses... but which was often used 極端に ill-advisedly. "GOTO".
If you put GOTO 200 in a program, then when 死刑執行 reached that line, 死刑執行 jumped to line 200 without regard to ANYTHING. This led to some Really Bad programs.
As I say... it wasn't always a 災害 when it was used. Wumpus has two... one at 620 which says "Go 支援する, and do it all again" to a 使用者 who has finished a 一連の会議、交渉/完成する of the game.
支援する in the days of BASIC, having the computer just sit there until you answered a request for Input was no big 取引,協定. It wasn't doing anything else.
Today's multi-過程 operating systems 許容する such things 貧しく. If they are done crudely. But there are ways to make the program work just 罰金, even if you are slow to answer, from the small example this started from, "What is 5+4?"
Here's how it is done, with Lazarus...
We put a timer 反対する in our program, and from time to time... say 5 times a second or so?... we look to se if a button has been 圧力(をかける)d, etc, since we last looked.
If it has, we consider what we should do.
We start the 使用/適用 up in one STATE. We do all we can without using something that has to be waited for, e.g. an answer from the human as to the sum of 5 and 4, and then we settle 負かす/撃墜する, waiting.
Once the human has 供給(する)d an answer, we 評価する that answer, and move on to a new 明言する/公表する, if necessary.
Within the timer event handler, we'll have many 封鎖するs of code which will boil 負かす/撃墜する to something like the に引き続いて... which is NOT compilable code...
if we are in "明言する/公表する 0"... we need to... ---- check whether an answer has been 供給(する)d ---- if it has, we need to... ------------see if answer to first was 権利. ----------- if wrong, we move on to 明言する/公表する 1 ----------- if 権利, we move on to 明言する/公表する 2 if we are in "明言する/公表する 1"... we need to... ---- tell 使用者 answer was wrong, and ---- move on to 明言する/公表する 0 if we are in "明言する/公表する 2"... we need to... ---- put the next question on ---- move on to 明言する/公表する 0 AND SO ON...
When you 診察する the code... it is coming... it may all be more (疑いを)晴らす.
公式文書,認める in particular that when I say "move on to (a different 明言する/公表する)", the way I do that is to change the value in the bStateWeAreIn variable. Nothing happens すぐに, because of that, but the next time we enter the timer's event handler, we do a different bit from what is 利用できる there.
Here we have the 核心 of a small program that is a start に向かって the "明言する/公表する based" answer that is our 客観的な.
It is the 核心 central to an app with a 覚え書き (where 使用者 誘発するs will appear), an edit box (where 使用者 input will go) and a timer, to keep things ticking over.)
So far, it just flips 支援する and 前へ/外へ from 明言する/公表する "0" to 明言する/公表する "1". A label on the form... not 普通は 現在の... tells you the 現在の 明言する/公表する.
(The 使用/適用 doesn't 現実に "do" "anything" (else) yet!)
手続き Tlt3n_convert_old_basic_f1.FormCreate(Sender: TObject);
begin
lt3n_convert_old_basic_f1.caption:=
kPrgmName+' vers:'+kVers;
meShowUser.lines.(疑いを)晴らす;
Timer1.interval:=500;
Panel1.caption:='';
MakeState(0);//Initialize bState, 陳列する,発揮する
end;
手続き Tlt3n_convert_old_basic_f1.Timer1Timer(Sender: TObject);
begin
事例/患者 bState of
0:begin
MakeState(1);
end;
1:begin
MakeState(0);
end;
end;//事例/患者
end;//Timer1Timer
手続き Tlt3n_convert_old_basic_f1.
MakeState(bNewState:byte);
begin
bState:=bNewState;
laCurrentStateID.caption:=inttostr(bState);
end;//MakeState
Make sure you're (疑いを)晴らす about what the above does. Then we will move on.
Next, we will 追加する boInputReceived, and change the Timer event handler.
Now the 使用/適用 will stay in one 明言する/公表する or the other (... we have two so far. More will be typical...) UNTIL some data, any data is entered into the edit box, and the enter 重要な is 圧力(をかける)d, or something else 誘発する/引き起こすs the edit box's OnEditingDone event.
Here's the new code, with that 開発 in it. I've 除去するd from here, but not from the actual code, some things that 港/避難所't changed since the previous 名簿(に載せる)/表(にあげる)ing. 顕著に some "housekeeping" in FormCreate, and the 詳細(に述べる)s of what happens during MakeState()
手続き Tlt3n_convert_old_basic_f1.FormCreate(Sender: TObject);
begin
MakeState(0);//Initialize bState, 陳列する,発揮する
eUserInput.text:='';
boInputReceived:=誤った;
end;
手続き Tlt3n_convert_old_basic_f1.eUserInputEditingDone(Sender: TObject);
begin
boInputReceived:=true;
end;
手続き Tlt3n_convert_old_basic_f1.Timer1Timer(Sender: TObject);
begin
if boInputReceived then begin
boInputReceived:=誤った;//回復する to "waiting"
事例/患者 bState of
0:begin
MakeState(1);
end;
1:begin
MakeState(0);
end;
end;//事例/患者
end;//if boInputReceived
end;//Timer1Timer
What 明言する/公表するs will Goldie's Game entail?
For the sake of completeness, I will first について言及する: What happens during the FormCreate handler might be seen as the 使用/適用 passing through a 明言する/公表する. We were in no 明言する/公表する when the 使用/適用 started running. Things happened during FormCreate, and then we "changed 明言する/公表する" into whatever 明言する/公表する dictated by the code in FormCreate.
Before we begin the "blow by blow", let me remind you: This will not be "finished". (You can finish it!) In particular, it will give the same problem over and over! (The final answer is 6!)
What is at the heart of "存在 in a 明言する/公表する"?
The variable bState. If bState 持つ/拘留するs 0, we are in "明言する/公表する 0".
FormCreate will 普通は leave an 使用/適用 in 明言する/公表する 0. It is just 論理(学)の.
明言する/公表する 0: Start problem
We enter it from: The FormCreate handler
We go from it to: 明言する/公表する 1. While in 明言する/公表する 0, we put a "Welcome" message up, and we 地位,任命する the first part of the problem, e.g. "What is 5+4?".
We 始める,決める bTermsDone to 2, because when we leave, the 使用者 will have done 2 条件 of the problem.
We leave the 明言する/公表する when some input has been seen.
明言する/公表する 1: 過程 input. We enter it from: 明言する/公表する 0 the first time, and subsequently from 明言する/公表する 2
We go from it to: 2 if a 権利 answer has been given, or we stay in 1, or we go on to 明言する/公表する 3 if enough 条件 have been 現在のd and answered 正確に
明言する/公表する 2: 現在の next 称する,呼ぶ/期間/用語. We enter it from: 明言する/公表する 1
We go from it to: 明言する/公表する 1
明言する/公表する 3: 終わりにする/要約する, after last part of question done. We enter it from: 明言する/公表する 1
We go nowhere from it.. it 含む/封じ込めるs the end of the 使用/適用.
You can download the 十分な sourcecode of the little arithmetic 実験(する), if you wish. Try adapting it to time how long it takes the 使用者 to 完全にする the problem. Try adapting it to 現在の more than one problem to the 使用者.
It is "driven" by the code that happens every time the Timer counts 負かす/撃墜する to 無...
begin //main 封鎖する of Timer1Timer
//boInputReceived:=誤った;//回復する to "waiting"
事例/患者 bState of
0:begin
DoState0Things;
end;
1:begin
DoState1Things;
end;
2:begin
DoState2Things;
end;
3:begin
DoState3Things;
end;
end;//事例/患者
end;//Timer1Timer
(核心 to the whole design is that the value in bState いつかs changes inside one of the "DoThings" subroutines, of course.)
Here are the 詳細(に述べる)s of the DoThings subroutines...
手続き DoState0Things;
//State0: Start problem
begin
meShowUser.lines.追加する('Welcome!');
meShowUser.lines.追加する('-------');
meShowUser.lines.追加する('');
meShowUser.lines.追加する('What is 5+4?');
bAns:=9;
bTermsDone:=2;
MakeState(1);
end;//DoState0Things
手続き DoState1Things;
//State1 ProcessInput
begin
if boInputReceived then begin
boInputReceived:=誤った;
事例/患者 bTermsDone of
2:begin
if (extUserEntered=bAns) then
begin
sNextOpIs:='.. 追加する ';
bNextTerm:=2;
bAns:=11;
MakeState(2);
bTermsDone:=3;
end;//if extUserEntered=bAns
end;//事例/患者 2
3:begin
if (extUserEntered=bAns) then
begin
sNextOpIs:='.. subtact ';
bNextTerm:=5;
bAns:=6;
MakeState(2);
bTermsDone:=4;
end;//if extUserEntered=bAns
end;//事例/患者 3
4:begin
if (extUserEntered=bAns) then
begin
MakeState(3);
end;//if extUserEntered=bAns
end;//事例/患者 4
end;//事例/患者 bTerms of...
end;//If boInputReceived
end;//DoState1Things
手続き DoState2Things;
//State2: 現在の next 称する,呼ぶ/期間/用語
begin
meShowUser.lines.追加する('Yes! Now...');
meShowUser.lines.追加する(sNextOpIs+
inttostr(bNextTerm)+'?');
MakeState(1);
end;//DoState2Things
手続き DoState3Things;
//State3: 終わりにする/要約する
begin
meShowUser.lines.追加する('Yes again...');
meShowUser.lines.追加する('...and you are done!');
Timer1.enabled:=誤った;
end;//DoState3Things
What is MakeState()? I'm glad you asked...
begin bState:=bNewState; laCurrentStateID.caption:=inttostr(bState); laTermsDone.caption:=inttostr(bTermsDone); end;//MakeState
That's all 井戸/弁護士席 and good. And it is good, by the way. Thinking of an 使用/適用 as a 明言する/公表する machine is very useful.
But this page was supposed to be about 変えるing an old BASIC program to Lazarus.
We're going to make a 明言する/公表する machine to "持つ/拘留する" the Lazarus program.
The program we'll take as an example appeared in 1978 in the wonderful "What to do after you 攻撃する,衝突する Return", the 調書をとる/予約する I について言及するd earlier.
Wumpus is a 洞穴 adventure. There's a Wumpus in the 洞穴. No one has seen a Wumpus and lived to tell the tale, so they are assumed to be dangerous.
You wander from 議会 to 議会 withing a 洞穴 system. From time to time you are told "There are bats nearby", or "There is a Wumpus smell".
Either means a hazard in an 隣接する 洞穴 議会. Not the one you just (機の)カム from, 明白に. One of the ones in 前線 of you.
If you つまずく into a 議会 with bats, they will snatch you up, 素早い行動 you to some other 議会. If you enter one with the Wumpus you die.
反対する of the game?
The Wumpus is big, and for some 推論する/理由 you want it dead. It is enough to 解雇する/砲火/射撃 one of your 魔法 arrows into the 議会 the Wumpus is in... you will 攻撃する,衝突する it, and kill it. "魔法" arrows? They were 早期に 巡航する ミサイルs. If 議会 3 connects to 4 connects to 5, and the Wumpus is in 5, you can 解雇する/砲火/射撃 an arrows from three, with it programmed to go to 4 then to 5. Be careful. If you accidentally send the arrow to the 議会 you are in, you will kill yourself.
その上に, while 普通は the Wumpus is a placid creature, stays put, he hates the sound of bowstrings. If you shoot at him and MISS, he will move. If he moves into the 議会 you are in, he will eat you.
And there's another hazard, which you'll find out about in 予定 course.
So... wander about. Build a 地図/計画する ("議会 1 connects to 議会s 3, 6 and 8. 議会 3 connects to... Etc.) Find the Wumpus by smell. Kill it.... 平易な! (Easier than 令状ing the program, anyway.)
We don't have to 令状 the program! It's been written. But we have to 変える it.
Start with the 名簿(に載せる)/表(にあげる)ing. Below.
(I should について言及する at this point that I have not FINISHED the 転換 of Wumpus to Lazarus... ran out of time! Will try to come 支援する to it. But I've made a good start, and the sourcecode of that is 利用できる to you as a 解放する/自由な download. And I sketched all that remains. You do it, if you don't want to wait for me!
Draw a diagram of the times that 死刑執行 can go someplace other than just onward to the next line. Also below, although the diagram has at least one slight 欠陥. Diagram below is a starting point.
Build 明言する/公表する diagram. At first, "偽の" many parts of the program. Instead of using the 使用者's input as it will be used 結局, use it to ふりをする the bits of the program you 港/避難所't got to yet, so you can build it bit by bit. To be more 明確な/細部...
I've started the Lazarus Wumpus with the code for "see how "shoot arrow" went". At this 行う/開催する/段階, you may have won, or lost, or 単に have used up an arrow without hitting the Wumpus. After this 行う/開催する/段階, what was called "F" in the 初めの, which I've 改名するd "siF_inished", 持つ/拘留するs 1, -1 or 0, それぞれ. "siF_inished" will 持つ/拘留する a code for whether we have finished, and if so, how did things turn out? In this text I may use either 指名する... F or siF_inished... because all of the variable 指名するs in the 初めの consist of only one letter, or a letter and a digit, e.g. A1. "siF_inished" must be the Lazarus code 同等(の) of "F", so either should make sense to you. (When I について言及するd "A1", I MEANT A1, not A[1]. The latter would be an element of the ARRAY A[]. "A1" is just an "ordinary" variable, with a わずかに "long" 指名する. If A1 in the BASIC 見解/翻訳/版 was 持つ/拘留するing 空気/公表する left, as a byte, in the Lazarus 見解/翻訳/版, I'd call it bA1_irLeft. 詳細(に述べる)s! 詳細(に述べる)s! Sigh. Must keep that devil managed.
The BASIC code 取引,協定s with what's in F from line 490. At that point the value in F, we see from 3000 onward, is either 0, (game not over yet), 1 (you won) or -1 (you lost) or something greater than 無. (熟考する/考慮する those lines... see for yourself how those lines tell us that the "code" used in F is what I say. You have to sort of skim, sort of read. You won't understand every line, but you should find enough that you do understand to 割れ目 the code. Lines 490-620 are a help too... but where line 500 says "IF F>0..." you don't know if F can be more than one thing >0, or if it is what the difference would be between those "codes".)
We're going to start with 変えるing...
490 IF F=0 THEN 390
500 IF F>0 THEN 550
510 REM-LOSE
520 PRINT "You lose.":REM (You can make the messages
more fun as you go along)
530 GOTO 560
540 REM-WIN
550 PRINT "You won!"
560 FOR J=1 TO 6
570 L[J]=M[J]
580 NEXT J
590 PRINT "Same 始める,決める-up? (Y/N)";
600 INPUT I$
610 IF I$<>"Y" THEN 240
620 GOTO 360
(A 詳細(に述べる): At 460, we have a "GOTO 500". The way I am 変えるing this, it is as if I have changed that to a "GOTO 490"... but it won't 事柄 to what the 使用者 sees. (The 初めの saved one "if" 実験(する), because at 460, F couldn't be 0, but it might be -1 or +1. Saving that one IF "絡まるd" the code. Doing the unnecessary IF (as I am doing) makes the code tidier. END OF "詳細(に述べる)")
権利. Before we even try to 変える that, a number of things...
*IF* I have 分析するd the code we are 変えるing, 正確に... a big if, of course... ESSENTIAL the only way we would enter this 封鎖する of code is 経由で line 490... although we might have gone straight to 500 in 事例/患者s where doing 490 would not have had any 影響.
It seemed "do-able"... that's why I chose to start with this. When this is "done" the "game" will consist of an app that starts with a question: "Did the player 勝利,勝つ, lose, or neither?" And then the 権利 things will happen, depending on the answer, and we will either get the question again or the 使用/適用 will の近くに 負かす/撃墜する. We can build from there!
But.. in the above BASIC code? A few 詳細(に述べる)s...
Lines 560-580: I don't know WHY the values in L[x] are 存在 changed. But I don't need to know why. I just Do It.
Line 520: The rem on the end, に引き続いて the 結腸? You can do that. Put a 結腸, and then another 声明 after it. Not often a good idea, but 許すd. ("REM" is a 声明. Just not the only one that can be "tacked on" with a 結腸.)
Line 590: When there's a semicolon after a PRINT, it stops the 生産(高) 装置 from starting a new line. Thus, in this 事例/患者, the cursor would be flashing just after "Same 体制/機構? (Y/N)".
Line 610: That should make 平易な sense, as you see it above. 公式文書,認める that in the listings, "<&" is shown as "#"
Variable 指名するs: We have already seen that I 計画(する) to change the BASIC program's "F" to "siF_inished".
If at first we don't know why something was called, say, L, we can use "L_x" until we 人物/姿/数字 it out, and then use Search and 取って代わる. (Search and 取って代わる would find extra things if we used just "L".)
Line numbers: Lazarus doesn't use line numbers the way BASIC did, but as an 援助(する) to going 支援する and 前へ/外へ between the Lazarus code as we create it and the BASIC 初めの, I will be making the line numbers part of the Lazarus.
The bit we are working on is going to be the "DecideIfDone" 明言する/公表する... which I will 言及する to as "DecideIfDone_490-620", to point me to line 490, the source of the code.
公式文書,認める the "superfluous" 構成要素 in what follows which 許すs the 使用者 to have text 指名するs for the さまざまな 明言する/公表するs. The program may be using the simple "bState" value internally, but programmer-friendly 見解/翻訳/版 of the 明言する/公表する's id will also be 利用できる!
Here are some 核心 elements of the 転換 at this 早期に 行う/開催する/段階. Useless in it's own 権利, but perhaps what is here will 援助(する) your しっかり掴む of how a 転換 is done. Yes! The Lazarus Wumpus was "grown" out of the seemingly useless little arithmetic 演習. Not so "useless", after all, eh?
公式文書,認める: For the moment, Timer1.interval is 始める,決める to 900, so that the there-for-one-cycle-only passage through the first 明言する/公表するs can be 観察するd...
明言する/公表する 0: Start 開会/開廷/会期 明言する/公表する 1: Start Game 明言する/公表する 2: Start 一連の会議、交渉/完成する 明言する/公表する 3: FakeMostOfWumpus...
And then the 使用/適用 finishes up in 明言する/公表する 7, DealWithWonLostOrNewRound, from whence it goes nowhere... as you can see from the code!
DealWithWonLostOrNewRound is going to do the things that lines 490-620 of the 初めの dealt with.
At this point, the 使用/適用 has an edit box, eUserInput and a 覚え書き, meShowUser. When it is run, さまざまな messages appear in the 覚え書き. The edit box is, so far, irrelevant.
Those are the 必須のs. There is also a パネル盤, on which 確かな things... the value in bState, for instance, are 陳列する,発揮するd. They are not "necessary" to the game, but may be helpful in debugging the code as we build the game.
(*Wumpus:
"一連の会議、交渉/完成する" will be the playing of a turn...
審理,公聴会 where you are
deciding what to do
審理,公聴会 result
"Game" will be a number of "一連の会議、交渉/完成するs"...
from the first, through to the
one where you 勝利,勝つ or lose
"開会/開廷/会期" will be from when app
starts to when it の近くにs... it
may consist of one or more games.
*)
手続き Tlt3n_wumpus_f1.FormCreate(Sender: TObject);
begin
lt3n_wumpus_f1.caption:=
kPrgmName+' vers:'+kVers;
meShowUser.lines.(疑いを)晴らす;
Timer1.interval:=1500;
eUserInput.text:='';
Panel1.caption:='';
laTermsDone.caption:='';
FillSState;//始める,決める up strings 述べるing the 明言する/公表するs
MakeState(0);//Initialize bState, 陳列する,発揮する
laTxtUserInputUse.caption:='圧力(をかける) the Enter 重要な after'+
chr(13)+'any answers are entered,'+
chr(13)+'to say "answer 完全にする"';
boInputReceived:=誤った;//Initialize
boFirstVisitToStatesHandler:=true;
end;
手続き Tlt3n_wumpus_f1.FillSState;
var bTmp:byte;
begin
//設立する default values...
for bTmp:=0 to kStatesAllowed do
sState[bTmp]:='明言する/公表する '+inttostr(bTmp)+' not 割り当てるd yet';
//Over-令状 some of them...
//sState[]:='';
sState[0]:='GettingStarted-開会/開廷/会期';
sState[1]:='GettingStarted-Game';
sState[2]:='GettingStarted-一連の会議、交渉/完成する';
sState[3]:='FakeMostOfWumpus';
sState[7]:='DealWithWonLostOrNewRound';
end;//FillSState;
手続き Tlt3n_wumpus_f1.eUserInputEditingDone(Sender: TObject);
//If you (機の)カム to this code from one of my earlier essays on
// using 明言する/公表するs, you may be surprised that this isn't more
// コンビナート/複合体. 以前, the input HAD to be a number, for
// the 目的s of the 残り/休憩(する) of the 使用/適用. In Wumpus
// that is not the 事例/患者. ANY input is 許容できる... at this
// point in the code. (It may have other 必要物/必要条件s 課すd
// on it どこかよそで, later.)
begin
boInputReceived:=true;
eUserInput.text:='';//(疑いを)晴らす the edit box for the next
//problem. (Happily, this does not 誘発する/引き起こす an
//OnInputEditingDone event.)
end;
手続き Tlt3n_wumpus_f1.Timer1Timer(Sender: TObject);
手続き DoState0Things;//SR of Timer1Timer event handler.
//State0: StartSession
begin
meShowUser.lines.追加する('Welcome to Wumpus!');
meShowUser.lines.追加する('-------');
meShowUser.lines.追加する('("Start 開会/開廷/会期" done)');
meShowUser.lines.追加する('');
MakeState(1);
end;//DoState0Things
手続き DoState1Things;//SR of Timer1Timer event handler.
//State1 StartGame
begin
meShowUser.lines.追加する('("Start Game" done)');
meShowUser.lines.追加する('');
MakeState(2);
end;//DoState1Things
手続き DoState2Things;//SR of Timer1Timer event handler.
//State1 StartRound
begin
meShowUser.lines.追加する('("Start 一連の会議、交渉/完成する" done)');
meShowUser.lines.追加する('');
MakeState(3);
end;//DoState2Things
手続き DoState3Things;//SR of Timer1Timer event handler.
//State3:
begin
meShowUser.lines.追加する('Doing State3... which FOR NOW is');
meShowUser.lines.追加する('"偽の most of the 使用/適用... and');
meShowUser.lines.追加する('go to 明言する/公表する 7 after filling F with');
meShowUser.lines.追加する('-1,0, or 1 (lost, do another 一連の会議、交渉/完成する, won');
meShowUser.lines.追加する('');
MakeState(7);
end;//DoState3Things
手続き DoState7Things;//SR of Timer1Timer event handler.
//State7: を取り引きする end of 一連の会議、交渉/完成する, where siF_inished 持つ/拘留するs
//a value to say we've won, lost, or neither (go 支援する,
//do another 一連の会議、交渉/完成する. (Codes 1,-1, and 0, respecitively.)
begin
if boFirstVisitToStatesHandler then begin
boFirstVisitToStatesHandler:=誤った;
meShowUser.lines.追加する('We reached the bit we need to');
meShowUser.lines.追加する('令状 next... When done, it');
meShowUser.lines.追加する('will 行為/法令/行動する によれば the value');
meShowUser.lines.追加する('in siF_inished. and then');
meShowUser.lines.追加する('始める,決める a new value in bState.');
meShowUser.lines.追加する('');
end;//if....
end;
end;//DoState7Things
(*Boilerplate...
手続き DoStateThings;//SR of Timer1Timer event handler.
begin
end;//DoState2Things
*)
begin //main 封鎖する of Timer1Timer
//boInputReceived:=誤った;//回復する to "waiting"
事例/患者 bState of
0:begin
DoState0Things;
end;
1:begin
DoState1Things;
end;
2:begin
DoState2Things;
end;
3:begin
DoState3Things;
end;
7:begin
DoState7Things;
end;//; 許すd here, even though Else follows
else begin
showmessage('An un-programmed 明言する/公表する was entered.18b17a');
end;//扱う default 事例/患者
end;//事例/患者
end;//Timer1Timer
手続き Tlt3n_wumpus_f1.
MakeState(bNewState:byte);
begin
if (bState<>bNewState) then
boFirstVisitToStatesHandler:=true;
bState:=bNewState;
laCurrentStateID.caption:=inttostr(bState);
laTermsDone.caption:=inttostr(bTermsDone);
laStateString.caption:='STATE: '+sState[bNewState];
end;//MakeState</pre>
That first fragment may not seem very impressive, but it gives us a working 爆撃する, which we will now proceed to make more 完全にする.
The next 行う/開催する/段階 is mostly 令状ing an 改善するd DoState3Things, and "直す/買収する,八百長をするing" 半端物s and end connected with that. 以前, we made it so that only numbers would be 受託するd 経由で eUserInput. The number entered was returned in the 全世界の "extUserEntered". (非,不,無-numeric 入ること/参加(者)s were just ignored. It was as if nothing had been entered.)
A tweak of the event handler now 受託するs anything, and returns it in "sUserEntered".
And that 覆うd the way for DoState3Things to pass on to the next 明言する/公表する a -1, 0 or 1 in siF_inished, depending NOT upon the things which will EVENTUALLY 決定するs fills siF_inished, but depending 簡単に on what we TELL the code to put there. Thus we can 実験(する) WHAT IS DONE WITH the value in siF_inished easily, get that 権利 (in 孤立/分離), and then move on to the next thing.
The code needed...
手続き DoState3Things;//SR of Timer1Timer event handler.
//State3:
begin
meShowUser.lines.追加する('Doing State3... which FOR NOW is');
meShowUser.lines.追加する('"偽の most of the 使用/適用... and');
meShowUser.lines.追加する('go to 明言する/公表する 7 after filling F with');
meShowUser.lines.追加する('-1,0, or 1 (lost, do another 一連の会議、交渉/完成する, won');
meShowUser.lines.追加する('+++++++++++++++++');
meShowUser.lines.追加する('Enter W, L or G for ふりをする "Won",');
meShowUser.lines.追加する(' ふりをする "Lost" or ふりをする "Go on,');
meShowUser.lines.追加する(' do another 一連の会議、交渉/完成する".');
meShowUser.lines.追加する('');
if boInputReceived then begin
sUserEntered:=UpperCase(sUserEntered);//Turns "y" to "Y"
if (sUserEntered)='W' then begin
siF_inished:=1;
MakeState(7);;
end;//使用者 entered "W"
if (sUserEntered)='L' then begin
siF_inished:=-1;
MakeState(7);;
end;//使用者 entered "L"
if (sUserEntered)='G' then begin
siF_inished:=0;
MakeState(7);;
end;//使用者 entered "G"
end;//if boInputReceived...
end;//DoState3Things
You may have noticed something: This is not, perhaps, the most efficient way 今後. But it is the most 歩行者, and thus a way 今後 that is easiest to understand. (If you 手配中の,お尋ね者 to be clever, you could leave setting siF_inished out, if you assume that ALL it does is decide where we go next. Such 仮定/引き受けることs tend to come 支援する to bite you someplace painful.
以前, I called 明言する/公表する 7 "DealWithWonLostOrNewRound". Now that we're getting 負かす/撃墜する to some of the 詳細(に述べる)s, I have 改訂するd that 指名する to "DealWithWonLostOrNewRound-490-620" (I 追加するd the line numbers at the end)... to make it 平易な to 言及する 支援する to the BASIC code if I am puzzled by something in the Lazarus code 取引,協定ing with... 恐らく!... what lines 490-620 dealt with.
So far, we only have a 爆撃する....
We arrive into State7, DealWithWonLostOrNewRound-490-620, with something in siF_inished... but we don't, yet, DO anything WITH it. So. We know the code it is meant to 取って代わる. What does that code do? Make the State7 "DoIt"... umm... do it!
Look at the BASIC. It doesn't look like this, but it (almost) boils 負かす/撃墜する to it, if you think about it. (The に引き続いて is neither Lazarus nor BASIC... but I think you'll follow it, anyway!
詳細(に述べる): Unless I've 行方不明になるd something, siF_inished can only 持つ/拘留する -1, 0 or +1. But the 初めの coder, for good 推論する/理由s, didn't want to say "If siF_inished=-1", so he used "If siF_inished<0", which of course INCLUDES the times it is -1, but 取引,協定s with other things too. (End of 詳細(に述べる))
if siF_inished=0 then GOTO 390 if siF_inished<0 then begin Print "You lost" GOTO 560
So far, so good? Make sure you "see" that!
Lazarus, of course, "doesn't do" GOTO's like we might want. But where we see "GOTO"- some- other- bunch- of code, we should be thinking "Ah! Time to tidy up, 準備する the way, and then change 明言する/公表する. We'll come 支援する to this, but first, the pseudo-code for the 残り/休憩(する) of what we need to 供給する for in the State7 do it. We need to を取り引きする...
It's a little tedious... but not too bad if you take a 深い breath, and are 患者...
if siF_inished>0 then begin
Print "You won"
For J=1 to 6
L[J]=M[J]
Next J: REM line 580
THEN SOME OTHER STUFF: Lines 590-620
end;//Was <0 (1, in fact- code for "you won")
The basic code doesn't use explicit "begins" and "ends", and so what is happening is a little hard to follow. But if you look at 590-620, you will see that a question is asked, and then you either GOTO 240 or to 360.
All WE need to do is to 人物/姿/数字 out, decide, 準備する for, etc, what STATE we should program the 使用/適用 to move to in the lines replicating lines 590-620, and THIS bit is 平易な, too!
Before we worry about that: What is held in the arrays, L and M??
I want to know, because I want to give them better 指名するs, now. Also, because there is no $ in the 指名する, we know they 持つ/拘留する numbers... but for Lazarus we want to know what TYPE of numbers... integers, real... small, large?
Lines 240-270 make a good start. The fact that each array has only 6 elements is a help, in itself. The 洞穴 has more than 6 rooms.
What's this "FNA" thing? A 機能(する)/行事. See line 170. I would guess that FNA returns a 無作為の integer, in the 範囲 1-20, inclusive. It may be something I will 悔いる later, but I'm going to "go with" that.
But what are they used for?? This will help us choose a 指名する. 240-340 would be a hint... if I could 人物/姿/数字 it out! Ah! Lines 200,210: It seems that L 持つ/拘留するs the *L*ocation of さまざまな things... My (experienced) guess? Based on 200,210, if L[1] 持つ/拘留するs 12, you are in cavern 12. (What L[2]-L[6] 持つ/拘留する can be told from line 210, if I am 権利. (The fact that FNA returns 1-20 示唆するs there are 20 caverns. So I am 改名するing L bL_ocationOf. And "M" is, at the start, a second copy of L. Again, it is mostly a guess, but I am going to guess that it
Line 590 is the 重要な to the "what is M" mystery. And the code does make it all a bit hard to see... but I'm pretty sure that the array M is used to keep 跡をつける of what the starting position was of you, the Wumpus, the bats and the 炭坑,オーケストラ席s. If you want to play the game again, from the same starting 条件s, they are taken from M. (現実に, and this is what make it いっそう少なく 平易な than it might have been: The code always puts L[] 支援する to what it was before you started, and if you don't want to play the same game, what's in L (and M) is shuffled.)
So! I will call M[] bM_emoryOfWhereThingsWere. A someone "over the 最高の,を越す" 指名する, but we 言及する to it seldom!
公式文書,認める how I have transcribed the REMs of the 初めの program to the new one, just after the 宣言 of the two "where things are" arrays.
====
The good news: We are making 進歩. The bad? We are still trying to create the Lazarus for lines 490-620, and there's a problem.
Remember the bit I glossed over with "THEN SOME OTHER STUFF: Lines 590-620"?
Here are those lines again...
590 PRINT "Same 始める,決める-up? (Y/N)"; 600 INPUT I$ 610 IF I$<>"Y" THEN 240 620 GOTO 360
The idea there isn't hard, I hope? The 使用者 is asked a question, and what happens next depends on the answer.
The "bad news" is that we don't want to be "stuck" here, waiting for the answer. The 使用/適用 is meant to run through all of "the stuff" in the code that 扱うs the timeout of the timer very quickly. Waiting for an answer from the humnan does NOT come under the 長,率いるing of "happen quickly".
Happily, there is an answer.
The "stuff" that has to happen never leads BACK to other things inside 明言する/公表する 7, "DealWithWonLostOrNewRound-490-620"
In a sense, we are "done" with 明言する/公表する 7 when we get to 590. So, in the 転換, we can just create another 明言する/公表する, and, just before 590 in DealWithWonLostOrNewRound-490-620 we say: "Finish the DoIt for that, 始める,決める things up so that the next time we pass though the Timer1 timeout event handler, we will be in the 明言する/公表する for 590-620.
NOT hard... really... to (米ソ間の)戦略兵器削減交渉 doing that... Or start 単に gets us to State7 at the 権利 time, for our "骸骨/概要" of Wumpus, and then, always, goes on to State6, where it stops and stays. When we are done, State7 will not always lead to 明言する/公表する 6. AND when we are done, the 使用/適用 will not stop and stay in State6 if it enters it. But we have to start somewhere, and this is where we are starting. With what I just said. We will then "fill in the State7 and State6 DoIts, so that they DO the things that are meant to happen at those 行う/開催する/段階s in the code. And then we will continue the 過程, turning our attention to other places that are 現在/一般に only "現在の" with "placeholders".
The (米ソ間の)戦略兵器削減交渉 of building the handlers for State7 and State6...
手続き DoState6Things;//SR of Timer1Timer event handler.
//State6 DealWith590-620-part of 再開する
begin
if boFirstVisitToStatesHandler then begin
boFirstVisitToStatesHandler:=誤った;
meShowUser.lines.追加する('(を取り引きする 590-620)');
meShowUser.lines.追加する('');
MakeState(6);//Tmp... this will NOT be the next
//明言する/公表する in the final code.
end;//if boFirstVisit....
end;//DoState6Things
手続き DoState7Things;//SR of Timer1Timer event handler.
//State7: を取り引きする end of 一連の会議、交渉/完成する, where F_inished 持つ/拘留するs
//a value to say we've won, lost, or neither (go 支援する,
//do another 一連の会議、交渉/完成する. (Codes 1,-1, and 0, それぞれ.)
//Takes care of what lines 490-620 of 初めの dealt with.
//現実に... MOSTLY takes care of that... although if it
//gets to what was in 590, we go to a different 明言する/公表する to
//take care of those 事柄s. But if we DO get to what
//was in 590, and we change to a 明言する/公表する that 取引,協定s with
//590-620's code, we don't need to remember any of the
//things we were doing in this 明言する/公表する (State7), when we
//are done with the 明言する/公表する for 590-620. So! 平易な-peasy!
begin
if boFirstVisitToStatesHandler then begin
boFirstVisitToStatesHandler:=誤った;
meShowUser.lines.追加する('We reached the bit we need to');
meShowUser.lines.追加する('令状 next... When done, it');
meShowUser.lines.追加する('will 行為/法令/行動する によれば the value');
meShowUser.lines.追加する('in F_inished. and then');
meShowUser.lines.追加する('始める,決める a new value in bState.');
meShowUser.lines.追加する('');
end;//if boFirstVisit....
MakeState(6);//Tmp and 天然のまま... will need making fancier
end;//DoState7Things
====================
The above may seem "sad"... but it isn't! It is a Solid 創立/基礎. And our "build" is under 支配(する)/統制する, can 進歩 without worrying that anything is getting out of 手渡す.
Take a step 支援する. Where are we? We have a 骸骨/概要. It 作品.
Now let's look again at what was in 490-620.
With a bit of work, you can see that the only ways OUT of 490-620 are...
490... GOTO 390 610... GOTO 240 620... GOTO 360
We weren't "lucky" that there are so few 関係s to the 残り/休憩(する) of the BASIC code.
Part of the 推論する/理由 is that the 初めの was 井戸/弁護士席 written. And the other part is that I chose 井戸/弁護士席, when I said THIS chunk will "分裂(する) off" 井戸/弁護士席.
Anyway... we DO have やめる a nice 状況/情勢 here...
We don't やめる know what the 目的 is of the code at 390, 240 or 360 is... but we can 推定する that we should change 明言する/公表するs at the point where the BASIC code goes to those lines. And because we are just getting going, we can "cheat" a little, and make three 明言する/公表するs that 単に put "We've gone into the 明言する/公表する for 390/ 240/ 360" on the 審査する, and then do nothing more... for now. They don't take us on to その上の 明言する/公表するs... for now. EVENTUALLY things will have to happen when we enter those other 明言する/公表するs, but for now we can concentrate on getting the code for State6 and 7 done.
Divide (井戸/弁護士席) and you WILL 征服する/打ち勝つ.
Here's the more better State7. It, remember, takes care of....
if siF_inished=0 then GOTO 390
if siF_inished<0 then begin
Print "You lost"
GOTO 560
if siF_inished>0 then begin
Print "You won"
560: For J=1 to 6
L[J]=M[J]
Next J
590: THEN change to 明言する/公表する 6 to do Lines 590-620
(Where there's a GOTO 240, a GOTO 360
end;//Was <0 (1, in fact- code for "you won")
(of course, before we can run the に引き続いて, we need to 令状, and 始める,決める up the CASE 声明 to を取り引きする, States13, 14 and which stand in, for now, for GOTO 390, GOTO 560, and GOTO 240. (Not やむを得ず それぞれ!)
Here are the 関連した bits, as 改訂するd...
手続き DoState6Things;//SR of Timer1Timer event handler.
//State6 DealWith590-620-part of 再開する
//取引,協定s with 事実上の/代理 によれば the value
//in F_inished. Then 始める,決めるs a new value in bState.');
var bCount:byte;
begin
if boInputReceived then boFirstVisitToStatesHandler:=true;
if boFirstVisitToStatesHandler then begin
boFirstVisitToStatesHandler:=誤った;
meShowUser.lines.追加する('(取引,協定ing with 590-620)');
if siF_inished=0 then begin
meShowUser.lines.追加する('You decided to '+
'go on... which isn''t coded for yet!');
meShowUser.lines.追加する('');
MakeState(13);//0: Go on
end;//if siF_inished=0
if siF_inished<0 then begin
meShowUser.lines.追加する('You lost. And for now '+
'program enters a "sit there" 宙返り飛行.');
meShowUser.lines.追加する('');
MakeState(14);//-1: Lost
end;//if siF_inished いっそう少なく than 0
//And now for the last possible 事例/患者...
//... but we still need the "if...", don't we. (Think!)
if siF_inished>0 then begin
meShowUser.lines.追加する('You Won. And for now '+
'program');
meShowUser.lines.追加する('enters a "sit there" 宙返り飛行.');
meShowUser.lines.追加する('.. after 取引,協定ing with ' +
'things that don''t');
meShowUser.lines.追加する('現実に 事柄 for '+
'now, but WILL.');
meShowUser.lines.追加する('');
for bCount:=1 to 6 do begin
//Put things 支援する as they were
//before game played, so it can,
//if 手配中の,お尋ね者, be re-played.
bL_ocationOf[bCount]:=
bM_emoryOfWhereThingsWere[bCount];
end;//for..
MakeState(15);//1: won
end;//if siF_inished greater than 0
end;//if boFirstVisit....
end;//DoState6Things
手続き DoState7Things;//SR of Timer1Timer event handler.
//State7: を取り引きする end of 一連の会議、交渉/完成する, where F_inished 持つ/拘留するs
//a value to say we've won, lost, or neither (go 支援する,
//do another 一連の会議、交渉/完成する. (Codes 1,-1, and 0, それぞれ.)
//Takes care of what lines 490-620 of 初めの dealt with.
//現実に... MOSTLY takes care of that... although if it
//gets to what was in 590, we go to a different 明言する/公表する to
//take care of those 事柄s. But if we DO get to what
//was in 590, and we change to a 明言する/公表する that 取引,協定s with
//590-620's code, we don't need to remember any of the
//things we were doing in this 明言する/公表する (State7), when we
//are done with the 明言する/公表する for 590-620. So! 平易な-peasy!
begin
if boFirstVisitToStatesHandler then begin
boFirstVisitToStatesHandler:=誤った;
meShowUser.lines.追加する('We reached the bit we need to');
meShowUser.lines.追加する('令状 next... When done, it');
meShowUser.lines.追加する('will 行為/法令/行動する によれば the value');
meShowUser.lines.追加する('in F_inished. and then');
meShowUser.lines.追加する('始める,決める a new value in bState.');
meShowUser.lines.追加する('');
end;//if boFirstVisit....
MakeState(6);//Tmp and 天然のまま... will need making fancier
end;//DoState7Things
//---
手続き DoState13Things;//SR of Timer1Timer event handler.
begin
if boFirstVisitToStatesHandler then begin
boFirstVisitToStatesHandler:=誤った;
meShowUser.lines.追加する('(Entered Do13Things)');
meShowUser.lines.追加する('');
//MakeState();//Tmp... this will NOT be
// remmed out in the final code.
end;//if boFirstVisit....
end;//DoStateThings
手続き DoState14Things;//SR of Timer1Timer event handler.
begin
if boFirstVisitToStatesHandler then begin
boFirstVisitToStatesHandler:=誤った;
meShowUser.lines.追加する('(Entered Do14Things)');
meShowUser.lines.追加する('');
//MakeState();//Tmp... this will NOT be
// remmed out in the final code.
end;//if boFirstVisit....
end;//DoStateThings
手続き DoState15Things;//SR of Timer1Timer event handler.
begin
if boFirstVisitToStatesHandler then begin
boFirstVisitToStatesHandler:=誤った;
meShowUser.lines.追加する('(Entered Do15Things)');
meShowUser.lines.追加する('');
//MakeState();//Tmp... this will NOT be
// remmed out in the final code.
end;//if boFirstVisit....
end;//DoStateThings
begin //main 封鎖する of Timer1Timer
//boInputReceived:=誤った;//回復する to "waiting"
事例/患者 bState of
0:begin
DoState0Things;
end;
1:begin
DoState1Things;
end;
2:begin
DoState2Things;
end;
3:begin
DoState3Things;
end;
6:begin
DoState6Things
end;
7:begin
DoState6Things
end;
13:begin
DoState13Things;//go on
end;
14:begin
DoState14Things;//lost
end;
15:begin
DoState15Things;//won
end;//; 許すd here, even though Else follows
else begin
showmessage('An un-programmed 明言する/公表する was entered.18b17a');
end;//扱う default 事例/患者
end;//事例/患者
end;//Timer1Timer
手続き Tlt3n_wumpus_f1.FillSState;
var bTmp:byte;
begin
//設立する default values...
for bTmp:=0 to kStatesAllowed do
sState[bTmp]:='明言する/公表する '+inttostr(bTmp)+' not 割り当てるd yet';
//Over-令状 some of them...
//sState[]:='';
sState[0]:='GettingStarted-開会/開廷/会期';
sState[1]:='GettingStarted-Game';
sState[2]:='GettingStarted-一連の会議、交渉/完成する';
sState[3]:='FakeMostOfWumpus';
sState[6]:='DealWith590-620-part of 再開する';
sState[7]:='DealWithWonLostOrNewRound-490-620';
sState[13]:='TmpEnterAt240';
sState[14]:='TmpEnterAt360';
sState[15]:='TmpEnterAt390';
end;//FillSState;
.. but I passionately hope that my uncertain belief that we have broken the 支援する of what we need to do is not unfounded!
PS- Umm... That WAS the 計画(する). And the program developed ALONG THOSE LINES... but what was, by the end, in which 明言する/公表する didn't always 反映する was WAS in a given 明言する/公表する 支援する in the 早期に days of the program's 進化.
We have a working 骸骨/概要! We "just" have a "few bits" to fill in.
At the moment, the app starts. We TELL it whether "in the middle" the player won or lost or has only 完全にするd a 一連の会議、交渉/完成する, and now needs to go 支援する to do another. (If player has won or lost, he/she is 許すd to start a new game, either with the same cavern system or a new one.)
BUT, instead of the "going 支援する" that is supposed to happen, after one pass through the start and "playing a 一連の会議、交渉/完成する", the 使用/適用 just grinds to a 停止(させる).
Not impressive! But a way-駅/配置する along the road to what we want!
Good news! Don't (for now) worry about the stuff in the BASIC 名簿(に載せる)/表(にあげる)ing AFTER line 620... it is all sub-決まりきった仕事s. Already neatly 小包d up for 取引,協定ing with later.
Think about what we have so far... Starts, gets to the end of the playing of a 一連の会議、交渉/完成する, and then you go 支援する... how far depending on whether you've won, lost, etc.
"Go 支援する" is another way to say "change 明言する/公表する". We've even got the "going to a 明言する/公表する" in place. We just need to tweak that, so our 使用/適用 goes to a GOOD place, instead of the TEMPORARY place we've got it going so far.
Look again at the diagram. And look at the listings.
A few things... those on lines 10-239... only ever happen ONCE. They, probably, can go in the Lazarus FormCreate. (We'll move the stuff from lines 20-60 負かす/撃墜する, and put them to 341-348.)
A few things... those on lines 240-349 are a nice tidy 封鎖する which we don't pass through very often... happen once during the first run, and after that, only if at line 610, which we only get to when someone has finished a game, and is wanting to start another, and the 使用者 said he/she 手配中の,お尋ね者 a DIFFERENT 始める,決める-up.
This 封鎖する is a 候補者 for a 明言する/公表する!! 現実に, it looks a lot like the code for what we called State1... "GettingStarted-Game".
I'm going to make State12 into something we reach after learning we've won or lost. It will say "Hope you enjoyed game.", and put two buttons on the 審査する, and 扱う clicks from them, 再開するing the game with or without a new 体制/機構 存在 生成するd, depending on which button you click.
That's so "simple" that I won't do listings. I will tell you that the buttons 関心d will be grayed out when irrelevant, and the captions on them will change from time to time!
We've 設立するd a solid beach-長,率いる!
We've created ways "in" to a game with or without a 体制/機構 緊急発進する. (When we do a 体制/機構 緊急発進する (明言する/公表する 12's 職業, replicating lines 240-359), we 単に always just go straight on to 明言する/公表する 11, which takes care of all the 残り/休憩(する) of the Start- A- Game stuff, the work of lines 360 onwards.
So where we were using 明言する/公表する 1 to "偽の" a game start, we can 簡単に put the 使用/適用 into 明言する/公表する 12. That will 緊急発進する the 体制/機構, and then follow on, as it always should, into the 交替/補充s for lines 360 onward... i.e. change the 明言する/公表する to 明言する/公表する 11.
At the moment, 明言する/公表する 11 "does" far too much... it does everything from line 360 to line 489. But it doesn't really "do" it... it 単に takes us from where we were when we went into it to a "mock up" of where we COULD be, leaving the 封鎖する.
We will break 明言する/公表する 11 into smaller pieces, using the same techniques as we've used before. More and more, the 操作/手術 of our Lazarus program will be like the 操作/手術 of the 初めの. いっそう少なく and いっそう少なく will we be 供給(する)ing things like the answer to the 現在の question "At the end of 明言する/公表する 11, did you 勝利,勝つ, Lose, or want to Go on with the 一連の会議、交渉/完成する you are doing?".
Read through the next few paragraphs quickly, once. At the 権利 point, you will be given a link to bring you 支援する here. After a quick skim, work through carefully on a second (or third!) pass.
Also: If you start to puzzle over a mystery 関心ing the place of State14 in the 計画/陰謀 of things, put THAT worry on 持つ/拘留する. (I'll を取り引きする it later!)
In what follows, you will see, twice, 指示/教授/教育s about "taking out" some code. I've put those 指示/教授/教育s in italic. While, as a general explanation of how you do what this is an example of, "take out" makes sense, in this 事例/患者 there is nothing to take out!. Our "骸骨/概要 code" is SO skeletal that, in this 事例/患者, a tweak of the messages is all the change needed to make State10 and 11 "do" all that they need to... for now.
So what was the point? The point is that we have built some finer 詳細(に述べる) into our 骸骨/概要. Once we have those 明言する/公表するs 存在するing, and linked into the 支配(する)/統制する 機械装置 of the "明言する/公表する machine", we can "fill" them with the code for the things that need to happen at those points in the playing of the game.
Our flow 分析 diagram tells us that program 支配(する)/統制する いつかs 宙返り飛行s 支援する to 390. 罰金. We'll make that possible, as follows.
First we'll make a new 明言する/公表する (10) that does EVERYTHING that 明言する/公表する 11 現在/一般に does. 結局, 明言する/公表する 10 will be in 告発(する),告訴(する)/料金 of only 390-489, instead of the 現在の 360-489, and 明言する/公表する 11 will を取り引きする 360-389.
(公式文書,認める: One of the 境界s is at 389, and another is at 489. Just a coincidence... but a tedious one.)
Creating the starting point is mostly just a "copy/paste", and the 創造 of the "枠組み". The "枠組み" bits are...
sState[10]:='DealWith390-489'; (and change... sState[11]:= ... to... 'DealWith360-389' ... in 予期 of what it will be. And 追加する... 10:begin DoState10Things; end; ... to the 事例/患者... 声明, And 追加する a skeletal... 手続き DoState10Things;//SR of Timer1Timer event handler. //Do what 390-489 did begin end;//DoStateThings
It is into that skeletal DoState10Things that the copy... for now... of the old DoState11Things goes.
Now... go into DoState11Things... the 明言する/公表する we're going to make into 'DealWith360-389', the first part of what State11 is doing at the moment. Put a MakeState(10); at the end of it. (Because of where we "broke" the old into 明言する/公表するs, happily, 明言する/公表する 11 always goes on to State10.) Take out most of what was in 明言する/公表する 11 before we started making this 分裂(する). (Remember: That's what you'd GENERALLY do here, when "splitting" a 明言する/公表する. In this instance, there's little to take out.) Tidy the rems to 反映する the new reality.
Do a 類似の 演習 with the 現在の, work- in- 進歩 code for 明言する/公表する 10, but this time you are taking out the stuff that did what lines 360-389 did. (Remember: That's what you'd GENERALLY do here, when "splitting" a 明言する/公表する. In this instance, there's little to take out.)
Now go 支援する to where I said "skim first", if this is the first time you've got to here!
A little while ago, I said "If you start to puzzle over a mystery 関心ing the place of State14 in the 計画/陰謀 of things, put THAT worry on 持つ/拘留する."
I'd done the "分裂(する) 明言する/公表する 11 into two 明言する/公表するs" work, and got the typos out, got it running, when I saw something unwelcome:
....create a a NEW 体制/機構, along the way to game 再開する. CODE EQUIV to 240-359 MUST GO HERE! (Entered Do11Things) Will one day start game, do 360-389. New game, using same 体制/機構 as before, unless the 体制/機構 has just been 緊急発進するd. (Entered Do10Things) Will one day start game, do 390-489. New game, using same 体制/機構 as before, unless the 体制/機構 has just been 緊急発進するd. ***(Entered DealWith380- (a 一連の会議、交渉/完成する)) ***Will one day will do heart of 開会/開廷/会期 Doing State3... which FOR NOW is "偽の most of the 使用/適用...
(I've 示すd the 感情を害する/違反するing two lines with "***"s, which were not 現在の on my 審査する.)
A quick search of the code for "DealWith380" showed that this was not the 災害 I 恐れるd.
Long ago, at the start of this, I created 明言する/公表する 14, a "stand in" for "Start 一連の会議、交渉/完成する".
Much later in the 過程, I inadvertently created another stand in for the start of "Start 一連の会議、交渉/完成する"... 明言する/公表する 10.
In the rems for one I speak of it doing what lines 380- did, in the other I speak of it doing what 390- did. If you check the code, you will see that 380-389 持つ/拘留するs only a "REM". So whether you "start starting a 一連の会議、交渉/完成する" at 380 or 390 makes little difference. (If you get to 390 having started at 370, you WILL "do" 380... but it does nothing. However, どこかよそで in the code, e.g. 490, we have GOTO 390, so 390 "looked" important. Sigh.
ANYWAY... it is just a 事例/患者 of duplication.
When you start at the beginning, at the moment, you go through the 明言する/公表するs as follows:
It is at 明言する/公表する 6 that things get 利益/興味ing! From 6, we can go to 明言する/公表する 14 or, 明言する/公表する 7!
From 14, we would go to 3.
From 7, we would go to 11.
IN EITHER CASE, we now go 支援する around the 宙返り飛行 again. If we go from 6 to 3, we don't go 支援する very far, but we DO go 支援する. If we go from 6 to 7, we go 支援する その上の, but still we are going to repeat things we've done before.
This is not a problem! This 宙返り飛行ing is normal, and at the heart of how computer programs are powerful.
(公式文書,認める, by the way, that the 計画/陰謀 above will be 修正するd before we are done. The 計画/陰謀 isn't 正確に/まさに as above, even in the half done 転換 of Wumpus.)
Even though I have fallen to my usual sloppiness, and the sState[x]:= part of the program isn't 完全に up to date, a ちらりと見ること at that (after a little tidying) soon turns up the place the duplication arose...
sState[10]:='DealWith390-489'; sState[14]:='DealWith380- (a 一連の会議、交渉/完成する)'
Remember- our look at the DoIts a moment ago said that from 明言する/公表する 10 we go to 明言する/公表する 14. But look at the descriptions of what they are supposed to do!
From 14, we go to 明言する/公表する 3: 'FakeMostOfWumpus'
What's in 14, 現在の 明言する/公表する?
meShowUser.lines.追加する('(Entered DealWith380- (a 一連の会議、交渉/完成する))');
meShowUser.lines.追加する('Will one day will do heart of 開会/開廷/会期');
meShowUser.lines.追加する('');
MakeState(3);
Yep! That can go!
改訂する 10 to send us straight to 3. Rem out 14... it isn't called from anywhere else.
(The review also threw up the fact that the old 明言する/公表する 2 was written out at some 行う/開催する/段階, but the code was still ぐずぐず残る. Remmed it, and 関係s to it, out. Such things are "okay"... a program grows in 行う/開催する/段階s. いつかs "stuff" that was useful in the 早期に 行う/開催する/段階s DOES get written out as you go along. (Though it is best to rem things out when you 令状 them out!))
Ah ha!... no sooner than I had that behind me, and I went looking for "what next", thought for a bit that 明言する/公表する 10 was another superfluous duplication.
In fact, it was 単に my documentation that was poor. 明言する/公表する 10, as it was already 説, was a placeholder for 390-489, created 早期に in the 転換 事業/計画(する). (The さまざまな bold digits are an 試みる/企てる to help you notice when something is 390, when it is 490. (or 389, 489.) What a pity that two such 類似の numbers should both be on 境界s. Oh 井戸/弁護士席.)
明言する/公表する 3, when I was at this 行う/開催する/段階 of the 事業/計画(する), was 述べるd as "偽のing" most of the 使用/適用... i.e. the heart... which before I thought carefully, made me think it was another stand in for 390-489.
In fact, 明言する/公表する 3 偽のs things that will have happened in the code running up to 490, the code 遂行する/発効させるd during 明言する/公表する 10, once the final 明言する/公表する 10 code is in place to fully 器具/実施する 明言する/公表する 10. (We pass from 明言する/公表する 10 to 明言する/公表する 3... at the moment. In 明言する/公表する 3 we give siF_inished a value, "by 手渡す". The program should be 生成するing that value, in 明言する/公表する 10.) From 明言する/公表する 3 we pass to 明言する/公表する 6.
When the code for 明言する/公表する 10 is finished, we will 簡単に change the MakeState(3) at the end of that to MakeState(6). The code relating to 明言する/公表する 3 will be redundant then.
So! We DO need 明言する/公表する 10. It and 明言する/公表する 3 do not duplicate 成果/努力s, the way the two we 削減(する) 負かす/撃墜する to one a moment ago were doing. BAD DOCUMENTATION wasted my time. If I'd written what each 明言する/公表する was 責任がある more 明確に while I was creating them the 問題/発行するs would not have arisen.
Earlier I について言及するd that I wasn't 完全に happy with my flow 分析 diagram. The poor section covered the code from 370-500, inclusive.
I've done a new, more careful diagram. (It appears just a little その上の 負かす/撃墜する the page.)
It threw up a little 詳細(に述べる), something that can... but must... be dealt with by 追加するing another 明言する/公表する, but one that 単に puts "追跡(する) the Wumpus" into the 覚え書き. I.e. a 明言する/公表する we pass through, 存在 there for just a cycle, a 明言する/公表する to 遂行する/発効させる line 375 of the 初めの program.
That new 明言する/公表する goes "in" 明言する/公表する 11.
We will 分裂(する) 明言する/公表する 11 into a "new" 明言する/公表する 11... which will be the first part of the old... and a new 明言する/公表する, 明言する/公表する 16. (Don't worry if you see the "but..!" element in that... I'll come to it.)(Also- We have some old 明言する/公表するs which have become redundant, but I am 気が進まない to 再生利用する their 指名するs, because 捨てるs of documentation may ぐずぐず残る. If I call the new 明言する/公表する, say, 明言する/公表する 4, and see a 言及/関連 to the old 4, will I realize that's an old 言及/関連??)
So... 11 will be 分裂(する) into a new 11 and a 16. And an 完全に new 17 will be created to を取り引きする...
meShowUser.lines.追加する('HuntTheWumpus');
At the end of the new 明言する/公表する 11: MakeState(17);
At the end of 明言する/公表する 17: MakeState(16);
At the end of 明言する/公表する 16: MakeState(... whatever it was at the end of the old 明言する/公表する 11... 10, as it happens.
See how 井戸/弁護士席 designed, 井戸/弁護士席 文書d programs are 井戸/弁護士席 behaved when you work on them?
I was a bit silly to be so "rigorous" in my approach to 蜂の巣ing off the bit that I put into the "middle" of the old 11. The bit I put into 17... the "middle bit"... was 現実に a few lines from the END of 11! There's nothing to put in 16, the 明言する/公表する that was created to 持つ/拘留する "the stuff from 11 from after the stuff we put into 17". Ah 井戸/弁護士席. What I did- link the new 11... the first part of the old 11... to the new 17. And then 17 linked to 16... the "底(に届く)" of the old 11. And then 16 linked to the place the 初めの 11 linked to.
Because there's no need 16, we 簡単に change the MakeState at the end of 17 point to what 16 (and the old 11) pointed to, and 令状 out all 言及/関連s to 16. Sigh.
There were some "bad bits" in the above! The THEORY was 罰金, but I fluffed some 詳細(に述べる)s. And I am NOT re-令状ing it to 反映する the 詳細(に述べる)s that I've now アイロンをかけるd out in the sourcecode.
A 解放する/自由な downloadable zip 古記録 of the of the 使用/適用's sourcecode at this point in it's 開発 is 利用できる, if you want to dig into the 詳細(に述べる)s, or maybe finish the 職業 of 転換!
We've brought the new 使用/適用 a long way 今後. We have a sensible "骸骨/概要", for the most part. Think of it as a sketch of the finished 使用/適用. Every bit will need "filling in". Most will be やめる 平易な. Getting the flow arranged was the hard part.
There is one area that is NOT 井戸/弁護士席 "sketched" yet.
We had to start somewhere, and I started at the "outside ends". The parts of the code that start a 開会/開廷/会期, and start a game. And the part that "包むs things up".
However, at the moment, our 明言する/公表する 10 needs a LOT of work. In that one 明言する/公表する we're taking care of everything that happened in lines 380-489 of the 初めの program. They are the "heart" of the program. A lot goes on there.
I hope you won't be surprised to learn that what is 現在/一般に "明言する/公表する 10" will be broken up into many smaller pieces?
A long time ago, I 現在のd a diagram, 分析するing the flow of the 使用/適用's 死刑執行. And I について言及するd that the 分析 at the heart of that had 欠陥s.
Here's a new 試みる/企てる to 分析する what's happening 予定 to lines 370 to 490.
The box 示すd "S17" in green is our 存在するing 明言する/公表する 17, which has MakeState(10) at it's end, at the moment.
We're going to have to re-engineer the 明言する/公表する machine. We need to 追加する 明言する/公表するs 20 to 23. (And some of those will, in 予定 course, be transformed to smaller pieces, too.) 満たすd 20-23 will 取って代わる the 現在の 明言する/公表する 10.
I hope, after looking at the diagram to the 権利, that you would 推定する/予想する the 現在の 明言する/公表する 10 to have MakeState(3) at it's end?
明言する/公表する 3 is a little unusual. Once we've been in 明言する/公表する 3 once, we may pass 徹底的な its code many times. It doesn't always 遂行する/発効させる a MakeState. It only does the MakeState change when, on the program visiting 明言する/公表する 3 again, there is input from the 使用者. Once that input has been 供給するd, 明言する/公表する 6 become the machine's 明言する/公表する.
There are two arrows 主要な into many of the 明言する/公表するs ' boxes. In the 初めの program, there was a "GOTO 480". In the adaptation, 明言する/公表する 22 is going to "take care" of what lines *470* and 480 did. 言及/関連s to 明言する/公表する 22 speak of lines 470-489. But there's no "GOTO 470" in the 初めの. I hope my 試みる/企てる to 除去する a 可能性のある source of 混乱 hasn't been more 混乱させるing that the 初めの 状況/情勢?
明言する/公表する S3/ S6: In the 初めの program, there are GOTO's to 490 and to 500. In creating a 明言する/公表する Machine 同等(の), this could have been a (minor) nuisance.
However: Look at line 490. It says "IF F=0 then...".
Careful 熟考する/考慮する of all the times in the 初めの program that there is a GOTO 500 明らかにする/漏らすs that F would never be 無 at the times those GOTOs were arising. Thus, we can use GOTO 490 both for this program's GOTO 490s, AND for its GOTO 500's... 除去するing the need for the nuisance, 関わりなく the fact it wouldn't have been 抱擁する.
In 明言する/公表する 22, we have lines 450 and 460. If F=0 at that point, we switch to 明言する/公表する S3. If it isn't, we switch to 明言する/公表する 22. F will have acquired a value during GOSUB 3000.
明言する/公表する 21 いつかs switches the 明言する/公表する machine to 明言する/公表する 22, いつかs to 明言する/公表する 23... and いつかs it leaves the 明言する/公表する 始める,決める to 21.
It leaves the 明言する/公表する 始める,決める to 21 until the 使用/適用 has had some input from the human 使用者. That "stay in 明言する/公表する" is 示すd by the dashed line at the 権利 味方する of the box delineating the 明言する/公表する. 公式文書,認める that the 使用/適用 doesn't "stay in the 明言する/公表する", in a general sense. It is only "in" the 明言する/公表する 簡潔に. 公正に/かなり often, admittedly. (Every time the Timer times out.) But to play nicely on a multi-仕事ing operating system, we can't enter a 宙返り飛行 like...
(Pseudo code...) Repeat look for input Until input seen
Line 420 either says "GOTO O of 440, 480", or it says "GOTO O of 440, 480, 410".
Perhaps puzzling?
First of all, the programmer did something dreadful: He/ she used the letter O ("oh") for a variable. (Don't use O... it is too much like "無".
We'll change that variable's 指名する to siO_ption, as I think "選択" was the word the 初めの programmer had in mind when he chose "O" as the variable 指名する. At this point in the program's use, the 使用者 if making a choice. He has two 選択s: Move, or try to shoot the Wumpus. In the subroutine at 2500, he's given the chance to say which he wants, and the appropriate value is put into "O"... which we are calling siO_ption. (Which may be harder to read, but you'll never 混乱させる it with "無", and WHY "Oh" will not need any thought. (si at the start, to say that this is a variable of type "shortint".))
Yes, 罰金, but still: What does 420 mean?
"GOTO O of ..." was BASIC's idea of what we do with the CASE 声明 in Lazarus.
In the 明確な/細部 instance of line 420, if siO_ption is 持つ/拘留するing a 1, the program will go to line 400. If siO_ption is 持つ/拘留するing a 2, the program will go to line 480. And if it is 持つ/拘留するing anything else, it will go to line 410... which gives the 使用者 another chance to tell the program what he/she wants to go. On the first 試みる/企てる, he gave it something that was of no use to the program. The program wants 1 or 2.
You can see all of that for yourself, if you look into the code at 2500. The REMs help enormously, of course... 特に the ones at 400, 430 and 470. PUT REMs IN *your* CODE! They are a Good Thing.
THIS TUT IS BEING WRITTEN 19 Nov 18.... I'm afraid that's all there is for the moment... I'm busy 令状ing that code for you just now! If you see this message 21 Nov 18, please 令状, 特記する/引用する "lt3n-変える-old-basic.htm", and COMPLAIN!
====================
The に引き続いて is, 式のs, not 100% 正確な... 扱う/治療する it as a starting point, and an 指示,表示する物 of how you go about 逆転する-工学 an 存在するing BASIC program, to tease out the flow 支配(する)/統制する, the places where things happen, where 支店s and jumps occur. It IS 権利, I believe, apart from the bit shaded yellow... and there's a second 試みる/企てる at that part of the flow 分析 in a diagram in the 団体/死体 of this tutorial, above.
The 構成要素 on the 権利 was my first 試みる/企てる. The 構成要素 in the cyan パネル盤 is derivative, an 試みる/企てる to identify the "明言する/公表するs" the program passes through during 死刑執行.
Search across all my 場所/位置s with the Google search...
|
|
Page 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes. There were two "unknown せいにするs" in Google+ button code. Sigh.
....... P a g e . . . E n d s .....