Game kingdom of strategy

Difference between version 149 and 150 - Previous - Next
**Game Kingdom of Strategy **

This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Aside from your courtesy, your wiki MONIKER and date as a signature and minimal good faith of any internet post are the rules of this TCL-WIKI. Its very hard to reply reasonably without some background of the correspondent on his WIKI bio page. Thanks, [gold] 
----

<<TOC>>


----
Here is some eTCL starter code for Game Kingdom of Strategy. There is a post on wiki asking for a TCL version of
a text and strategy game, originally in basic language. See [Ideas for Projects in Tcl/Tk]. I am trying to find out
the status of the old game. A strategy game can be cobbled from older scraps of [Iching_Fortunes] code.
Using the Iching code, this page presents a trial console version for testing the concept, 
a console version, and a canvas version with some graphics. The Iching has a good handle on the
actions of an ancient kingdom, though in a random scattered pattern. The elements in most adventure
games are random generators, castles, tiled game boards, mazes, wildcards, gamepieces, and strategy situation.       
 
The canvas and buttons presented here are largely based on the [Simple Canvas Demo] by [HJG]. The random pick algorithm was posted by Suchenworth [RS] on [Horseracing in Tcl]. Another source of randomness was [A funny cookbook].
      
In pseudocode, the text adventure game is essentially a three line program in the old style unix wish. In etcl and windows, some buffering may be necessary. One display for response and one display for input would be easier in windows. 
======
    1) puts stdout "Please enter your name:"
    2) gets stdin name
    3) puts stdout "Hello $name"
    pseudocode.The user is directed into various possibilities. 
    2) 3) and 4) are looped.
    console show  
    1)puts stdout "Please enter your name:"
    2)gets stdin   
    pseudocode: analyze name and internal-references
    pseudocode : set random situation.
    pseudocode : game closes after 5 trials or 5 situations.
    3) puts stdout "action $name"
    4) pseudocode. return to 2) stdin 
======    
----
In the trial deck for console, the advisor would present the situation and the king's responses would have to be a table of abbreviated commands, like buy 200 or sell 300. Otherwise, there would be a lot difficult parsing, like the human language command of computers. The trial deck could call the procedure "advisor" to present the situation derived from random circumstances plague, rat infestation, and weather. The trial deck could call the procedure "king", so the command on the console window  would be king sell 20 or king buy 50. This have the advantage  of looking as a typical English sentence: subject verb object. In a loop, the king procedure calls on the advisor procedure, which presents a new situation. The king wins or loses based on his responses to the random situation. The game can be closed after a certain number of situation trials by a limiting statement in the advisor
procedure. The major subroutines or procedures were diagramed with TKpaint in the flowchart below. Those interested in flowcharting programs should be able to load the flowchart file into TKpaint or else load the file into eTCL with a few canvas display statements.

There are limits on the King for winning the game. The King starts out with 1000 barleyfields and 1000 measures of grain.  Each year a census is taken of the planted fields, grain in storage, and inhabitants. The king has effectively two degrees of freedom. 1) the king may either buy or sell barleyfields or, 2) the king may either buy or sell measures of grain. In terms of physics problems, the King, land, and grain are part of a three body problem or three corner problem.  Like sitting on a see-saw with three planks, the King is counterbalanced by the stored grain and planted land. Various disasters to the stored grain and planted land operate inversely to the  fortunes of the Kingdom. In the internal program, the chances of disaster are carefully set so the King will win in about 1 in 5 sessions. With the random factors set now, the King has about a 20 percent chance of winning and a corresponding 80 percent chance of losing.

The advisor role is part serious helper and part jester. The advisor subroutine presents the results of the census and accounting for the kingdom, together with predictions of weather. The advsor may report various disasters like rat infestation or plague. The advisor has a fairly detailed report of situation and previous years for the king's strategy,  when the console report is opened.   Only a short advisor gist can be included in the advisor display. Game is halted after 5 years, count > 5, and estimate whether winner conditions are set. Winner is declared if either barleyfields are greater than N1 ( 500) or  barley measures are greater than N2 ( 500).  A conservative approach as in selling land or buying little land does not work too well, as chances of plague or rat infestation will fall out to ruin the conservative player. Also, staying put with zero buy or sell is not allowed in the game, but a small ante of buy 1 land is allowed.  An aggressive approach against bad odds ( called going for broke in Las Vegas) is buying large amounts of land each year and sometimes wins. 

For the display of rectangular barley fields, numbers over 100 fields were difficult to register with the eye. With changes in buy or sell land, the display of rectangular fields are rescaled to a representative number. When the King sells land of 100 or so, the gap in the representative fields should be apparent.

The calculation subroutine is the workhorse for creating the random situation and disasters in the kingdom using flag variables. This subroutine makes use of what were called logic condition flags in large Fortran programs. The condition flags are variables with  binary values of zero for no or one for positive yes (0,1). In the calculation subroutine, the conditions for the disasters of plague, rat infestation, and starvation are set as 0 or 1 flags. The disaster effects and land prices for each year are estimated from rand() expressions.  Later in the subroutine, the flag conditions are  used in the calculations for loss of inhabitants and loss of stored grain.
For the example code with flag variables below, the rand() statements set a 15 percent chance of rat infestation for the year. These rand() statements are similar to the rand() statements used in the [Random Walk Equation Slot Calculator Example].

======
if { [ expr { rand() } ] <= .15 } {set rat_infest_this_year 1 } 
set rat_liters [ expr { $liters*.1*rand() } ] 
set rat_liters [ expr { int($rat_liters) } ] 
[...many...] set liters [ expr { $liters - $rat_liters*.1*$rat_infest_this_year } ] 
======

Once the flag variable  for rat infestation is set positive (1), the potential loss of grain in rat_liters for the year is estimated from a random calculation. Notice the potential grain loss for the year is calculated independent of whether the infestation flag is yes or no (0 or 1). Only in the final calculation of grain stores is the loss of grain subtracted, since final grain equals total grain minus ( loss of grain*scale_factor*flag(1) ). The effect is cosmetic, but the flags keep confusion and gritty details out of the final accounting statements. Once the flags are set, the flags can be reported and evaluated at all subsequent points in the subroutine. The flags can even be sent outside the subroutine with possible global statements as, global plague_this_year rat_infest_this_year. In executive decisions, potential loss must be a factor. For example, if the kingdom needs 100 grain liters, then perhaps the order should be grain requirement plus [abs]  potential loss or additional planted fields  to assure filled grain bins.

On the clay tablets from the kingdom of UrIII (Sumer circa 2300 to 2400 BCE), the issues from UrIII accounts have some interesting parallels to the Game Kingdom of Strategy. Over a period of several generations in UrIII, the ratio of fallow fields to total fields went from the traditional 50 per cent fallow fields to probably 30 to 20 percent fallow fields.  In terms of yearly ratios, the Sumerians went from 1/2 fallow years,  (1 of 2) years or  (fallow year/(total years)) to possible range of 1/3 to 1/5 fallow years. Also, the recorded barley yield went down probably due to fields salting up. A lot of this evidence is anecdotal; overseers reporting on a group of fields in the lucky clay tablets that survived.   Clearly the Kingdom of UrIII was entering a long period of agricultural stress during the last recorded years (circa 2400 BCE).

For comparison, the Hebrew records in the Torah represent a later era and country (Israel circa 650 BCE).  In the Torah, the traditional 1 year of fallow in seven years for a field is another peg point (1/7). From the decree of the King Shulgi, the grain harvest in Sumer was taxed at 50 percent to the King (ie. taxes paid in grain). In the Torah, the traditional temple tax was 10 percent (circa 650 BCE), but not sure about the total Hebrew taxes on the inhabitants. However, it is a fair statement that the barley field lands were overtaxed in the last years of UrIII, if not the inhabitants.

Returning to the safer ground of the Game Kingdom of Strategy, it might be worthwhile to open a tax window or input window of fallow field ratios. If the predominant taxes are paid in grain or kind (like Sumer),  high grain taxes or low fallow ratios (inversely) would represent an equivalent drain on the grain supply.  At the start of the session, a window or label on game display could be set at 1/2, 1/3, 1/5, 1/7, or 1/10 grain taxes or fallow years from the traditional values above. Then the player could go through the usual 5 year cycles and record the wins under the different ratios. 

On 27Jul2010, there was a challenge posted on converting Hamurabi.bas to "modern" computer language. The turn-around from other languages (not me!) is fairly impressive. There was a Lua program posted on 28Jul2010, Java on 28Jul2010, common Lisp program on 31Jul210, and Factor program by 3Aug2010. As best of memory, the original Game Kingdom of Strategy was posted starting 1Aug2010, but a long way from completed. Basic code was fairly terse, so there has been some real hoofing on the contributions. As a fortran programmer, I remember basic envy on the basic string addition, let it$ = "be"+"so"
     
The Game Kingdom of Strategy was compiled on the freewrap TCL compiler for the windows pc.  Also, I found a Facebook game called Farmville, with some similar features. Quite possible to add the Eliza namespace to the game. Adding Eliza will get some context sensitive analysis/quirks  into the game. Refer to [A simple version of Eliza].


----
**session from trial console script**
======
    buy or sell, my lord? 
    starts with 1000 units 
    answer has form:  king buy 20 or king sell 30  
   1% king buy 20
    decision was buy 20, total was 1020.0 
 
   advisor:  new situation 
   need 10 liters of grain.
   need 60 hectares of land.
   predict rain.
   subjects from census 5000. 

    advisor: buy or sell, my lord? 
    2% king sell 500
    decision was sell 500, total was 520.0 
 
    advisor:  new situation 
    need 10 liters of grain.
    need 100 hectares of land.
    predict cold.
    subjects from census 3000. 

    advisor: buy or sell, my lord? 
======
----
**canvas button operation**
======
     So the order of button actions should be:
     push castle
     push situation, read advisors' comment
     type in king's response in upper entry field
     push console
     push record, should see record of play on console.
     %quit day job
     %{advisor:buy or sell, my lord?} {king:get lost}
         note: pass or veto should be option
     clear to resume play
======     
**Sample commands from King**
======
      Commands from the king on the eTCL console  
      or commands in the king entry field (canvas)
      vary on versions, but here are some samples.
      initial land is 1000 barleyfields
      initial barley is 1000 measures
      king buy 22
      king sell 100
       else 
      king buy 100 land
      king sell 33 land
      king buy 222 barley
      king sell 33 barley
      conditions for winner are very liberal.
======
----
**Pseudocode for Endgame **

======
    pseudocode: game is halted after 5 trials, count > 5,
    and estimate if (winner) conditions prevail.
    pseudocode:  if barleyfields > 500 , winner declared
    pseudocode:  if barley  > 500 winner declared
    pseudocode:  clear resets counter to zero
    pseudocode:  clear zeros king & advisor entry fields, 
    pseudocode:  & zeros canvas
======
----   
** Dialog from Trial Merge of  Eliza namespace **
======
      Refer to [A simple version of Eliza].    
      Console:  king sell 11 barley 
     1% ::Talk::replyto { barley }
      advisor says : Shall we continue? 
     2% ::Talk::replyto { king sell barley }
       advisor says worried about total  barleyfields. ? 
     3% ::Talk::replyto { king sell 11 barley }
       advisor says : worried about total barleyfields. ? 
     4% king sell 11 barley
     decision was sell 11, total was   land 1000, barley 989.0 
======                  
----
**Screenshots Section**
**Figure 1**
[http://farm5.static.flickr.com/4122/4866853039_0a6798b1f8.jpg]
**Figure 2**
[http://farm5.static.flickr.com/4120/4854141292_07b57692b7.jpg]

**Flowchart for Graphics Version**
[http://farm5.static.flickr.com/4096/4857240469_6d23f1b62c.jpg]

test of offsite image retrieval 
***Screenshots Section***
****figure 1.****
[Game Kingdom of Strategy figure1.png%|% width=600 height=400]
****figure 2.****
[Game Kingdom of Strategy figure2.png%|% width=600 height=400]
****figure 3.****
[Game Kingdom of Strategy TCL WIKI figure2%|% width=600 height=400]

----
**Comments Section**

Please place any comments here, Thanks.

[gold] Changes.

What is your purpose in binding the motion event on your main window to
execute the wm title command.  I.e., this line:
======
  bind . <Motion> {wm title . " Game kingdom of strategy "}
======
The result of that binding is that every time you move the mouse, the "wm   
title" subcommand is called repeatedly.  To set the window title, you just  
need to call "wm title . title" once, not on every event update upon mouse  
pointer motion.
[gold] changed to bare "wm title . title"
----
**References**
   *  King that learns? [A Program That Learns]
   * [Random Walk Equation Slot Calculator Example] 
   * [Chinese Fortune Casting Example Demo]
   * [Chinese Iching Hexagrams on Chou Bronzes : TCL Example] 
   * [Chinese Iching Random Weather Predictions]
   * [Simple Canvas Demo]
   * [Clock and daylight saving time corrections]
   * [Ideas for Projects in Tcl/Tk]
   * [A funny cookbook]
   * [Tkpaint]
   * http://mars.netanya.ac.il/~samy/tkpaint.html
   * The older tkpaint  1.5 executable that I used was loaded here: [ftp://ftp.procplace.com/pub/tcl/sorted/packages-8.0/graphics/tkpaint/1.51/TKPAINT-1.5.3.TAR.GZ] [ftp://ftp.procplace.com/pub/tcl/sorted/packages-8.0/graphics/tkpaint/1.52/tkpaint.zip]
   * http://en.wikipedia.org/wiki/Hamurabi
   * http://www.dunnington.u-net.com/public/basicgames/HMRABI
   * http://www.apollowebworks.com/russell/samples/hamurabi.html
   * http://www.cse.lehigh.edu/~munoz/ComputerGameDesignClass/classes/GameTheory.pptx.
   * http://en.wikipedia.org/wiki/Hamurabi
   * http://en.wikipedia.org/wiki/List_of_games_in_game_theory
   * http://en.wikipedia.org/wiki/Game_theory
   * http://www.dallasuu.org/re/adult/huumanist/TitTatSagan.pdf
   * http://en.wikipedia.org/wiki/Dictator_game
   * http://www.hammurabigame.com/hammurabi-game.php
   * http://www.codeproject.com/KB/game/Hammurabi.aspx
   * http://www.esajournals.org/doi/abs/10.1890/1540-9295(2003)001%5B0367%3AMRAPTB%5D2.0.CO%3B2
   * http://ipsnews.net/fao_magazine/indian.shtml
   * http://biology.clc.uc.edu/courses/bio104/sci_meth.htm
   * http://programmingpraxis.com/2010/07/27/hamurabi-bas/
   * http://www.pbs.org/wgbh/nova/nature/plant-vs-predator.html
   * http://lisp.pastebin.com/r1gL4zYT
   * http://codepad.org/pc8FSfnQ
   * http://www.econ.umn.edu/~foster/Handouts%20Games.pdf
   * http://re-factor.blogspot.com/2010/08/hamurabi.html
   * http://www.moorecad.com/classicbasic/basic/creative/hamurabi.bas
   * http://www.cis.upenn.edu/~matuszek/cit590-2010/Assignments/02-hammurabi.html
   * http://playtechs.blogspot.com/2009/06/charlemagne-disraeli-and-jefferson.html
   * http://www.econ.cam.ac.uk/seminars/Marshall_Lecture/09/marshall_lecture_2_Oct_21.pdf
   * http://roseindia.net/java/java-tips/oop/q-hammurabi/q-pr-hammurabi-1.shtml
   * http://en.wikipedia.org/wiki/Hammurabi

----
**appendix TCL programs**
**console version**
======
    # pretty print autoindent from ased editor
    # trial console operation    
    # written on Windows XP on eTCL
    # working under TCL version 8.5.6 and eTCL 1.0.1
    # gold on TCL WIKI , 1Aug2010   
    console show
    proc ? L {
        lindex $L [expr {int(rand()*[llength $L])}]
    }
    if 0 {This is used several times in:}
    proc tidings {} {
        set a {
            {70 liters of grains} {20 liters of grain} {10 liters of grain}
            {10 liters of grain} {50 liters of grain}
        }
        set b {
            {400 hectares of land} {60 hectares of land} {50 hectares of land}
            {100 hectares of land} {20 hectares of land}
        }
        set c {rain dry heat cold drought  snow }
        set d {
            {census 1000} {census 3000} {census 2000} {census 5000} {census 8000} {census 4000}
        }
        return "   need [? $a].
        need [? $b].
        predict [? $c].
        subjects from [? $d]. \n"
    }
    set sumit 1000
    proc advisorx {aa bb} {
        puts " "
        puts "advisor:  new situation "
        puts [ tidings ]
        puts "advisor: buy or sell, my lord? "
        
    }
    proc king { aa bb } {
        global sumit
        if { $aa == "buy" } {set token [ expr { 1.* $bb } ] }
        if { $aa == "sell" } {set token [ expr { -1.* $bb } ] }
        set sumit [ expr { $sumit + $token } ]
        puts " decision was $aa $bb, total was $sumit "
        advisorx 50 50
    }
    puts [ tidings ]
    puts "buy or sell, my lord? "
    puts " starts with 1000 units "
    puts "answer has form:  king buy 20 or king sell 30  "
======    
----
 
*** Graphics Version*** 

======
        #  pretty print autoindent from ased editor
        # by gold,   Game Kingdom of Strategy
        # written on Windowws XP on eTCL
        # working under TCL version 8.5.6 and eTCL 1.0.1
        # gold on TCL WIKI , 1Aug2010
        package require Tk
        proc ? L {
            lindex $L [expr {int(rand()*[llength $L])}]
        }
        if 0 {This is used several times in:}
        proc tidings {} {
            set a {
                {70 measures of barleys} {20 measures of barley} {10 measures of barley}
                {10 measures of barley} {50 measures of barley}
            }
            set b {
                {400 barleyfields of land} {60 barleyfields of land} {50 barleyfields of land}
                {100 barleyfields of land} {20 barleyfields of land}
            }
            set c {rain dry heat cold drought  snow }
            set d {
                {census 99} {census 100} {census 120} {census 110} {census 120} {census 80}
            }
            return "   need [? $a].
            need [? $b].
            predict [? $c].
            subjects from [? $d].
            ans.form:king buy 20 land  n                         "
        }
        proc lpick L {lindex $L [expr int(rand()*[llength $L])];}
        #proc poly args {eval .cv create polygon $args}
        set lister { 5 5 6 6 6 6 6 6 7 7 7 7 8 8 1 1 1 1 1 1 1 1 1 }
        proc transnumber {lister} {
            set choutext [list ]
            foreach item $lister {
                if { $item == 1 } {lappend choutext \u4E00}
                if { $item == 5 } {lappend choutext \u3024}
                if { $item == 6 } {lappend choutext \u4E00}
                if { $item == 7 } {lappend choutext \u4E00}
                if { $item == 8 } {lappend choutext \u3024}
                if { $item >= 9 } {lappend choutext ? }
            }
            return $choutext}
        proc advisorcom {lister} {
            set choutext [list ]
            foreach item $lister {
                if { $item == 1 } {lappend choutext "second rate" }
                if { $item == 2 } {lappend choutext "fifth rate" }
                if { $item == 3 } {lappend choutext "performance comparable to bonzo" }
                if { $item == 4 } {lappend choutext "fourth rate" }
                if { $item == 5 } {lappend choutext "no bread left" }
                if { $item == 6 } {lappend choutext "surving inhabitants have fled" }
                if { $item == 7 } {lappend choutext "third rate" }
                if { $item == 8 } {lappend choutext "lacking any sense" }
                if { $item >= 9 } {lappend choutext ? }
            }
            return $choutext}
        set loser5 0
        set counter 0
        set sumit 1000
        set sumitland 1000
        set sumitbarley 1000
        proc winnerx {aa bb} {
            global sumit sumitland sumitbarley
            global sumerians liters winner5
            global loser5
            puts "   end of game  "
            .zzz delete 0 end
            .xxx delete 0 end
            .t delete 1.0 end
            .t insert 1.0 "  end of game  "
            .zzz insert 0 "  end of game  "
            .xxx insert 0 "  end of game  "
            if { $sumerians >= 120 } {
                .zzz insert 0 " king is winner declared "
                .xxx insert 0 " king is winner declared "
                .t insert 1.0 " king is winner declared "
                puts " king is winner declared "
                set winner5 1
            }
            if { $sumitland >= 700 } {
                .zzz insert 0 "king is winner declared"
                .xxx insert 0 "king is winner declared"
                .t insert 1.0 "king is winner declared"
                puts "king is winner declared"
                set winner5 1
            }
            if { $sumerians <= 40 } {
                .zzz insert 0 "loser declared"
                .xxx insert 0 "loser declared"
                .t insert 1.0 "loser declared"
                puts "loser declared"
                set loser5 1
            }
            if { $sumitbarley <= 300 } {
                .zzz insert 0 "loser declared"
                .xxx insert 0 "loser declared"
                .t insert 1.0 "loser declared"
                puts "loser declared"
                set loser5 1
            }
        }
        proc advisorx {aa bb} {
            global counter
            if { $counter >= 5 } {winnerx $aa $bb }
            .t delete 1.0 end
            puts " "
            puts "advisor:  new situation "
            if { $counter <= 6 } {
                .t insert 1.0 [ tidings ]
                .zzz delete  0 end
                set bl "               "
                .zzz insert  end "advisor:buy or sell, my lord? $bl (for year $counter )"
            }
            if { $counter >= 6 } {
                .t delete 1.0 end }
            puts  [.t get 1.0 end ]
            puts "advisor: buy or sell, my lord? (for year $counter ) "
            incr counter
        }
        set sumerians  100
        proc calculation { aa bb cc dd ee } {
            global counter fieldsdisplay
            global  sumitland sumitbarley
            global  buyland  buybarley sumerians
            set annum    0
            set provisions    1000
            set liters 5000
            set land    1000
            set barleyfields   1000
            set landprice 26
            set litersperacre  3
            set totalmortality   10
            set mortalrateer  10
            set ratliters 1
            set citymortal 5
            set landfraction .1
            set sumeriansgain 5
            set produce 4
            set buyland 1
            set buybarley 1
            set plaguethisyear 0
            set ratinfestthisyear 0
            set famineyear 0
            set immigrantyear 0
            set fieldsdisplay 20
            if { [ expr { rand() } ] <= .15 } {set immigrantyear  1 }
            if { [ expr { rand() } ] <= .15 } {set plaguethisyear 1 }
            if { [ expr { rand() } ] <= .41 } {set ratinfestthisyear 1 }
            set ratliters  [ expr { $liters*.1*rand()   } ]
            set ratliters [ expr { int($ratliters) } ]
            set sumeriansstarved [ expr { $sumerians*.02*rand()   } ]
            set landfraction  [ expr {   rand() } ]
            if { $immigrantyear == 1 } {
                set sumeriansgain   [ expr {  $sumerians  * .05 } ] }
            set sumeriansgain   [ expr {  int($sumeriansgain) } ]
            set sumerians [ expr { $sumerians + $sumeriansgain   } ]
            set produce [ expr {  $land * 3 } ]
            set landprice [ lpick { 26 25 24 23 22 21 20 19 18 17 16 } ]
            set landprice [ expr { int($landprice) } ]
            set liters $sumitbarley
            set liters [ expr {  $liters + $sumitland*.8 } ]
            set liters [ expr {  $liters - $landprice* $buyland } ]
            set liters [ expr {  $liters - $sumerians* 7 } ]
            set liters [ expr {  $liters - $liters*.1*$ratinfestthisyear } ]
            set liters [ expr { int($liters) } ]
            set foodrequire [ expr {$sumerians*7 }]
            if {   $liters <= $foodrequire   } {
                set sumeriansstarved [expr {$sumerians*.2  } ]
                set famineyear 1                                              }
            set sumeriansstarved [ expr { int($sumeriansstarved)  } ]
            set sumitbarley $liters
            set sumitland  [ expr { int($sumitland)  } ]
            set sumerians  [ expr { $sumerians + $sumerians*.1 -$sumeriansstarved} ]
            set sumerians  [ expr { $sumerians - $sumerians*.5*$plaguethisyear } ]
            set sumerians [ expr { int($sumerians) } ]
            set percentfields [ expr { ($sumitland/1000.)*100.   } ]
            set percentfields [ expr { int($percentfields) } ]
            set fieldsdisplay [ expr { 35*$percentfields*.01 } ]
            set fieldsdisplay [ expr {int($fieldsdisplay)  } ]
            if {  $fieldsdisplay <= 1   } { set fieldsdisplay 1 }
            if {  $fieldsdisplay >= 35   } { set fieldsdisplay 35 }
            .cv delete landbarley
            barley .cv $fieldsdisplay
            puts  "annum $counter "
            puts  "$plaguethisyear plague this year,  0 or 1. "
            puts  "$ratinfestthisyear rats infest  this year,  0 or 1."
            puts "$percentfields percent fields "
            puts " $fieldsdisplay  fieldsdisplay "
            puts "$sumeriansstarved sumerians starved"
            puts "$sumeriansgain immigrated to city."
            puts "census $sumerians  "
            puts "total  $sumitland barleyfields."
            puts "yielded 3 measures per barleyfield"
            puts "rats devoured $ratliters measures."
            puts  "$liters  measures in palace."
            puts "land $landprice measures per barleyfield"
            puts "how many barleyfields do you wish to buy?"
            set listx  "
            annum $counter,   $liters  measures
            census $sumerians,  $sumitland barleyfields.
            $landprice landprice measures
            $plaguethisyear plague this year,  0 or 1.
            $famineyear  famineyear ,0 or 1
            $ratinfestthisyear rats infest  this year,  0 or 1.
            $sumeriansstarved sumerians starved
            $sumeriansgain immigrated to city.
            census $sumerians
            total  $sumitland barleyfields.
            yielded 3 measures per barleyfield
            rats devoured $ratliters measures.
            $liters  measures in palace.
            land $landprice measures per barleyfield "
            return " $listx "
        }
        proc king { aa bb cc} {
            global  sumitland sumitbarley
            global buyland buybarley
            global counter
            if { $aa == "buy" } {set token [ expr { 1.* $bb } ] }
            if { $aa == "sell" } {set token [ expr { -1.* $bb } ] }
            if { $cc == "land" } { set sumitland [ expr { $sumitland + $token } ] }
            if { $cc == "barley" } { set sumitbarley [ expr { $sumitbarley + $token } ] }
            if { $cc == "land" } { set buyland  $token  }
            if { $cc == "barley" } { set buybarley  $token  }
            puts " decision was $aa $bb, total was  land $sumitland, barley $sumitbarley "
            puts " advisor says   [ advisorcom [ lpick { 1 2 3 4 5 6 7 8 }]]   "
            advisorx 50 50
        }
        set listx [ transnumber $lister ]
        proc tactics  {w} {
            global listx
            set yy 100
            set font3 {Hevetica 20}
            set font5 {Hevetica 150}
            set lister { 5 5 6 6 6 6 6 6 7 7 7 7 8 8 1 1 1 1 1 1 1 1 1 }
            $w create rect 150 50 250 400 -fill gold
            $w create polygon  -80 100  -80 70  -50 70  -20 -10  -40 -50  -20 -100  20 -100  40 -50  20 -10  50 70  80 70  80 100 -fill gold -tags figure
            $w move figure 150 150
            # $w create text 200 400 -text u2617  -tags "text" -fill tan -font $font5
            foreach i {1 2 3 4 5 6 } {
                $w create text 200 $yy -text [lpick $listx ]  -tags "text"  -font $font3
                incr yy 50
            }
        }
        proc clrcanvas {w} {
            global counter winner5
            $w delete  "all"
            .zzz delete  0 end
            .xxx delete  0 end
            .t delete 1.0 end
            set counter 0
            set winner5 0
            set loser5 0
        }
        proc leave {w} {
            exit
        }
        proc board {w} {
            #set state3 1
            set state2 1
            clrcanvas $w
            . configure -background orange -highlightcolor brown -relief raised -border 30
            $w configure -bg tan
        }
        proc  replyit {w} {
            global counter
            .t delete 1.0 end
            .zzz delete  0 end
            .xxx delete  0 end
            .zzz insert  end "advisor:buy or sell, my lord? "
            .xxx insert  end "king "
        }
        set keeperer { 1 2 3 }
        proc  record {w} {
            global side2 side1 buy sell
            global winner5 loser5
            lappend keeperer $side2
            lappend keeperer $side1
            puts $keeperer
            eval [ split  $side1 " " ]
            set results  [ calculation 10 10 10 10 10 ]
            puts $results
            .t delete 1.0 end
            .t insert 1.0 $results
            .zzz delete  0 end
            .zzz insert  end "advisor says: [ advisorcom [ lpick { 1 2 3 4 5 6 7 8 }]]"
            if { $winner5 == 1} {
                .zzz delete  0 end
                .zzz insert  end "advisor says: king is winner " }
        }
        proc  reportx {w} {
            console show
            puts "fifth rate"
            puts "performance comparable to bonzo"
            puts "surving inhabitants have fled"
            puts "mandated poll results"
            puts "lacking any sense"
            puts "second rate";
            puts "no bread left"
            puts "third rate"
            puts "quit day job"
        }
        proc castle {w} {
            global dx dy fieldsdisplay
            set dx 50
            set dy 30
            set gualisting { 8 8 8 8 8 7 }
            set second_hexagram { 8 8 8 8 8 7 }
            set colorx black;
            for {set i 0; set y 20} {$i<6} {incr i; incr y $dy} {
                set colorx brown;
                for {set j 0; set x 50} {$j<3} {incr j; incr x $dx} {
                    set colorx brown;
                    if { $j == 1} {
                        if { [lindex $gualisting $i ] == 6} {set colorx tan}
                        if { [lindex $gualisting $i ] == 7} {set colorx brown}
                        if { [lindex $gualisting $i ] == 8} {set colorx tan}
                        if { [lindex $gualisting $i ] == 9} {set colorx brown}
                    }
            $w create rectangle $x $y [expr {$x+$dx}] [expr {$y+$dy}] -fill $colorx }}
            set dx 50
            set dy 30
            set colorx blue;
            for {set i 0; set y 20} {$i<6} {incr i; incr y $dy} {
                set colorx blue;
                for {set j 0; set x 50} {$j<3} {incr j; incr x $dx} {
                    set colorx blue;
                    if { $j == 1} {
                        if { [lindex $second_hexagram $i ] == 6} {set colorx tan}
                        if { [lindex $second_hexagram $i ] == 7} {set colorx blue}
                        if { [lindex $second_hexagram $i ] == 8} {set colorx tan}
                        if { [lindex $second_hexagram $i ] == 9} {set colorx blue}
                    }
        $w create rectangle [expr $x + 180] $y [expr {[expr $x +180 ]+$dx}] [expr {$y+$dy}] -fill $colorx }}
        }
        proc barley {w fieldsdisplay } {
            global dx dy
            set dx 5
            set dy 10
            set gualisting { 8 8 8 8 8 7 }
            set second_hexagram { 8 8 8 8 8 7 }
            set colorx black;
            $w delete landbarley
            for {set i 0; set y 220} {$i<6} {incr i; incr y $dy} {
                set colorx green;
                for {set j 0; set x 30} {$j<$fieldsdisplay} {incr j; incr x $dx} {
                    set colorx green;
                    if { $j == 1} {
                        if { [lindex $gualisting $i ] == 6} {set colorx green}
                        if { [lindex $gualisting $i ] == 7} {set colorx green}
                        if { [lindex $gualisting $i ] == 8} {set colorx green}
                        if { [lindex $gualisting $i ] == 9} {set colorx green}
                    }
            $w create rectangle $x $y [expr {$x+$dx}] [expr {$y+$dy}] -fill $colorx -tag landbarley }}
            set dx 5
            set dy 10
            set colorx green;
            for {set i 0; set y 220} {$i<6} {incr i; incr y $dy} {
                set colorx blue;
                for {set j 0; set x 30} {$j<$fieldsdisplay} {incr j; incr x $dx} {
                    set colorx green;
                    if { $j == 1} {
                        if { [lindex $second_hexagram $i ] == 6} {set colorx green}
                        if { [lindex $second_hexagram $i ] == 7} {set colorx green}
                        if { [lindex $second_hexagram $i ] == 8} {set colorx green}
                        if { [lindex $second_hexagram $i ] == 9} {set colorx green}
                    }
   $w create rectangle [expr $x + 180] $y [expr {[expr $x +180 ]+$dx}] [expr {$y+$dy}] -fill $colorx -tag landbarley
                }}
        }
        proc about {w} {
            set msg "Game kingdom of strategy.
            from TCL WIKI,
            written on eTCL
            Normal play sequence for 8 buttons
            1) Push castle, initial display.
            2) Push situation, advisor's report displayed.
            3) type king's commands, no caps.
            4) Push record (ie. record kings reply)
            5) Return to 3, Push new situation.
            6) Console report is optional.
               Console report gives detailed history.
               Screen copy console to wordprocessor for 
               game history and strategy analysis.
            7) wildcard is optional, traditional game bonus.
            8) clear optional, but clears deck for new play.
            9) about shows basic commands.
            10) exit leaves program.
            Cmds from king take form
            king buy 33 land
            king sell 11 land
            king sell 55 barley
            king buy 33 barley "
            tk_messageBox -title "About" -message $msg
        }
        #: Main :
        frame .f1
        frame .f2
        frame .f3
        pack  .f1 .f2 .f3
        set maxX 400
        set maxY 300
        set y      0
        set x1 120
        set x2 150
        set y1  50
        set y2  80
        canvas  .cv -width $maxX -height $maxY  -bg tan
        pack    .cv -in .f1
        #set side2 2
        button  .b0 -text "clear" -command { clrcanvas .cv }
        button  .b9 -text "about"   -command {about   .cv }
        button  .b3 -text "castle"   -command {clrcanvas .cv;barley .cv 20; castle  .cv; }
        button  .b7 -text "situation"   -command {castle .cv;replyit .cv; advisorx 50 50  }
        button  .b6 -text "record"   -command { record  .cv }
        
        button .b4 -text "console report"   -command {reportx .cv  }
        button  .b5 -text "wildcard"   -command {clrcanvas .cv; tactics   .cv }
        button  .b8 -text "exit"   -command {leave   .cv }
        text .t -width 40 -height 5 -bg bisque
        entry .xxx -width 50  -bg bisque -textvariable side1
        entry .zzz -width 50 -textvariable side2 -bg bisque
        pack  .b9 .b3  .b7 .b6 .b4 .b0 .b5  .b8  -in .f2  -side left -padx 2
        .f2 configure  -bg orange
        label .kingx  -text "king"
        label .advisora  -text "advisor"
        pack  .advisora .zzz .t   .kingx  .xxx -in .f3  -side bottom -padx 2
        focus .xxx
        focus .zzz
        board   .cv
        wm title . " Game Kingdom of Strategy "
   
   
======

----[gold] This page is copyrighted under the TCL/TK license terms, [http://tcl.tk/software/tcltk/license.html%|%this license]. 
----
**Hidden Comments Section**
----
<<discussion>>
----
Please place any comments here with your wiki MONIKER and date, Thanks.[gold]12Dec2018

----


<<categories>> Numerical Analysis | Toys | Calculator | Mathematics| Example| Toys and Games | Games | Application | GUI
----
<<categories>> Development | Concept| Algorithm|Language|programming language| Fortran
----
<<categories>> | Characters | Math