These ducks are playing today: Some or all, depending on your choice, are hiding in the numbered check boxes at the bottom.
Find the ducks I have hidden. First pick game options then choose "Start New Game". (Choosing fewer animals and not allowing duplicate animals is much easier.) Now guess animals from the dropdowns at the bottom where it says "1st animal" "2nd" etc. After you have made all your guesses choose "Check". Then I will tell only how many(but not which) ducks are: (RED=wrong) (YELLOW=right animal but in wrong place) (GREEN=right animal and in right place) | ||||
DuckFrodo | DuckIncredible | DuckPurple | DuckTexas | Keep trying things and looking at results and you will be able to get them all green. |
:Class DuckHide : MiPage ⍝ With Thanks to Jerry and Anna Brennan :Include #.HTMLInput ⍝ Useful functions for creating HTML pages ⍝ --- Declare HTML Input Fields --- ⍝ Will be set on each POST or SUBMIT if present in input :Field Public Action←'' ⍝ All Buttons will have this name, Value will tell which one was pressed :Field Public Picker←'' ⍝ Dropdowns for guessing animals :Field Public nAnim←'3' ⍝ Number hidden Animals to find, used when starting new game # :Field Public tAnim←'4' ⍝ Total Number of Animals that might me hidden (pool of animals) :Field Public dAnim←'not allowed' ⍝ Duplicate Animals: 'allowed' or 'not allowed' :Field Public AgentCmds←'' ⍝ Hidden input field for driving the MS Agent ⍝ --- Additional fields can be declared, in order to preserve state when page (i.e. class) is modified --- ⍝ This allows smoother debugging, game does not need to restart on any change :Field Public State←⎕NS '' TEST←0 ⍝ TEST 1=Testing or 0="production" run? Initialised←0 ⍝ Set to 1 when Init has found images files etc ⎕RL←(1+TEST)⊃(1000⊥¯2↑⎕TS) 16807 ⍝ 0=Random or 1=Predictable initialization XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ∇ Render req;html;tbl;btn;UseAgent;Game;Score;nAnimals;btns;pickers;last;out;fill;done;win :Access Public ⍝ This method is called by framework each time Page is displayed UseAgent←∨/'MSIE'⍷req.GetHeader'user-agent' ⍝ Use MS Agent if browser is Internet Explorer NL←'<br>',CRLF :If Initialised ⋄ GetState ⋄ :Else ⋄ Init ⋄ :EndIf DoAction ⍝ Take action based on user input PutState ⍝ Store State ⍝ --- Prepare buttons for later use --- btns←('Action'Submit'Start New Game'),' with ' ⍝ Button for starting new game btns,←('nAnim'DropDown(,¨'2345')(,nAnim)),' animals from total of ' ⍝ Dropdown for picking # animals to guess btns,←('tAnim'DropDown(,¨'23456')(,tAnim)),' animals with duplicate animals' ⍝ Dropdown for picking total # animals in pool btns,←('dAnim'DropDown(,¨'not allowed' 'allowed')(,dAnim)),'.' ⍝ Dropdown for duplicates ⍝ --- Show user animals who might be in the game --- req.Title'Hidden Ducks - Find where they are hiding' ⍝ Page title html←'a href="/"'Enclose'Home' ⍝ A link back to the index page NEW html,←'h2'Enclose'Find Where Ducks Are Hiding Game' ⍝ Header in page hlp←'Find the ducks I have hidden. First pick game options then choose "Start New Game".<br>' hlp,←'(Choosing fewer animals and not allowing duplicate animals is much easier.)<br>' hlp,←'Now guess animals from the dropdowns at the bottom where it says "1st animal" "2nd" etc.<br>' hlp,←'After you have made all your guesses choose "Check".<br>' hlp,←'Then I will tell only how many(but not which) ducks are: (RED=wrong)<br>' hlp,←' (YELLOW=right animal but in wrong place) (GREEN=right animal and in right place)<br>' hlp←2 1⍴hlp'Keep trying things and looking at results and you will be able to get them all green.' html,←'p'Enclose'These ducks are playing today: Some or all, depending on your choice, are hiding in the numbered check boxes at the bottom.' html,←(Table(AnimalImgs[Animals],[0.5]AllAnimals[Animals]),hlp),NL :If TEST ⋄ html,←'p'Enclose'Test mode, answer is: ',,⍕AllAnimals[Animals[Answer]] ⋄ :EndIf ⍝ --- Show Turns so far and DropDowns for next guess fill←(nAnimals+1)⍴⊂'' win←3∧.=,¯1↑[1]Score ⍝ Did we win yet? last←1⌈,¯1↑[1]Game ⍝ Previous guess last←AllAnimals[last] ⍝ ... translated into animal names pickers←{'Picker'DropDown(AllAnimals[Animals])⍵}¨last ⍝ Dropdowns for guessing an animal out←((⍕¨⍳1↑⍴Game),¨'.'),AnimalImgs[Game],(⊂''),ScoreImgs[Score] ⍝ One row per turn so far out⍪←(⊂(~win)/'Action'Submit'Check'),pickers,fill ⍝ Final row: Submit button and dropdowns for next guess out⍪←(⊂(0≠1↑⍴Game)/'Round#'),((nAnimals↑'1st' '2nd' '3rd' '4th' '5th' '6th'),¨⊂' animal'),fill ⍝ Header row html,←win/'p'Enclose'Click "Start New Game" to start another game!' ⍝ If game over, instructions on how to start again html,←req('Post'Form)btns,NL,NL,(Table⊖out) ⍝ Wrap the above in a 'Post' form so buttons will work ⍝ --- Add OCX Controls for the Agent --- :If UseAgent html,←'AgentCmds'Hidden AgentCmds ⍝ Hidden input field with Agent commands html,←'<object ID=''TruVoice'' width=0 height=0 CLASSID=''CLSID:B8F2846E-CE36-11D0-AC83-00C04FD97575'' CodeBase=''#VERSION=6,0,0,0''></object>',CRLF html,←'<object ID=''AgentControl'' Width=0 Height=0 ClassID=''CLSID:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F'' CodeBase=''#VERSION=2,0,0,0''></Object>',CRLF html←html,req.JSPlugIn'AgentDoCmds.js' ⍝ JavaScript module which turns contents of AgentCmds into calls to OCX's :EndIf req.Return html ∇ ∇ DoAction;guess;mask;wrong;right;score ⍝ Score a turn or start a new game :Select Action~' +' :Case 'StartNewGame' ⋄ Start ⍝ Start a new game :Case 'Check' ⍝ Process a guess guess←(⍴Animals)⌊nAnimals↑AllAnimals[Animals]⍳Picker ⍝ Indices into Game Animals ⍝ Compute Mastermind score wrong←guess{2÷⍨+/|⊃-/(∪⍺,⍵)∘{+/⍺∘.=⍵}¨⍺ ⍵}Answer ⍝ Completely wrong guesses right←guess+.=Answer ⍝ Exactly right score←right,(nAnimals-right+wrong),wrong ⍝ In middle: Right animal in wrong position Game⍪←Animals[guess] Score⍪←score/3 2 1 ⍝ Indices into ScoreImgs :If score[1]=nAnimals ⍝ All Correct! AgentCmds←'speak Well done!;play DoMagic1;play Domagic2;play Pleased' :Else AgentCmds←'speak ',⊃,/(⍕¨score),¨' exactly match. ' ' in the wrong position. ' ' completely wrong guesses.' :EndIf AgentCmds←'moveto 600,300;show 1;',AgentCmds,';play Explain;Hide 1' :EndSelect ∇ ∇ Init;size;folder size←'height=100 width=100 ' folder←req.Server.Root,'jbgames\picsDucks\' ⍝ This is where we keep the BMP files AllAnimals←¯4↓¨#.Files.Dir folder,'*.bmp' ⍝ Use list of files as list of valid animals AllAnimals←(1≠⊃∘⍴¨AllAnimals)/AllAnimals ⍝ ... except single char names (faces for scoring) AnimalImgs←{'<img src="/jbgames/picsDucks/',⍵,'.bmp" ',size,'/>'}¨AllAnimals ⍝ HTML tags for all animal images ScoreImgs←{'<img src="/jbgames/picsDucks/',⍵,'.bmp" ',size,'/>'}¨'USE' ⍝ For scoring: U=No match, S=Wrong Position, E=Match :If 2=State.⎕NC'Animals' ⋄ GetState ⍝ Retrieve saved state :Else ⋄ Start ⋄ :EndIf ⍝ ... or start a new game Initialised←1 ∇ ∇ Start ⍝ New Game nAnimals←⊃2⊃⎕VFI nAnim ⍝ # of Animals to guess tAnimals←⊃2⊃⎕VFI tAnim ⍝ total # of Animals in pool Animals←tAnimals?⍴AllAnimals ⍝ select Animals in the game pool :If (dAnim≡'not allowed')∧(tAnimals≥nAnimals) ⍝ duplicates? and enough avail? Answer←nAnimals?tAnimals ⍝ The correct answers :Else ⍝ duplicates allowed Answer←?nAnimals⍴tAnimals ⍝ The correct answers :End Game←Score←(0,nAnimals)⍴0 ⍝ No "moves" yet AgentCmds←'moveto 100,100;show 1;play Greet;speak I have chosen ',(⍕nAnimals),' animals. ' AgentCmds,←'See if you can guess which ones I have selected.;play Explain;play Pleased;Hide 1' ∇ ∇ GetState ⍝ Make contents of State global Game Score nAnimals Animals Answer←State.(Game Score nAnimals Animals Answer) ⍝ Extract saved state ∇ ∇ PutState ⍝ Save State for next post State.(Game Score nAnimals Animals Answer)←Game Score nAnimals Animals Answer ⍝ "State" is public and will be saved in page ∇ ∇ Then ∇ :EndClass