“拈”类游戏之一:抢21游戏
2020-12-28 15:12
本 GeoGebra 范例演示了经典的“抢21”游戏(Nim游戏的一种变体)。两名玩家(红方与蓝方)轮流从剩余物品中取走1个、2个或3个,最先取走第21个物品的玩家获胜。该模型通过交互式按钮、状态列表和胜负判定逻辑,直观展示了博弈论中的必胜策略与加法原理。适合用于数学逻辑、对策论及序列规律的互动教学与演示。
所属专题
用GeoGebra制作数学游戏
<?xml version="1.0" encoding="utf-8"?>
<geogebra format="5.0" version="5.0.620.0" app="classic" platform="w" id="9868ad3e-649d-4eea-9581-1e0f43e248fc" xsi:noNamespaceSchemaLocation="http://www.geogebra.org/apps/xsd/ggb.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<gui>
<window width="767" height="779" />
<perspectives>
<perspective id="tmp">
<panes>
<pane location="" divider="0.6688396349413298" orientation="1" />
</panes>
<views>
<view id="512" toolbar="0 | 1 501 5 19 , 67 | 2 15 45 18 , 7 37 | 514 3 9 , 13 44 , 47 | 16 51 | 551 550 11 , 20 22 21 23 , 55 56 57 , 12 | 69 | 510 511 , 512 513 | 533 531 , 534 532 , 522 523 , 537 536 , 535 | 521 520 | 36 , 38 49 560 | 571 30 29 570 31 33 | 17 | 540 40 41 42 , 27 28 35 , 6 , 502" visible="false" inframe="false" stylebar="false" location="1,1,1" size="500" window="100,100,600,400" />
<view id="4" toolbar="0 || 2020 , 2021 , 2022 , 66 || 2001 , 2003 , 2002 , 2004 , 2005 || 2040 , 2041 , 2042 , 2044 , 2043" visible="false" inframe="false" stylebar="true" location="1,1" size="300" window="100,100,600,400" />
<view id="8" toolbar="1001 | 1002 | 1003 || 1005 | 1004 || 1006 | 1007 | 1010 || 1008 1009 || 66 68 || 6" visible="false" inframe="false" stylebar="false" location="1,3" size="300" window="100,100,600,400" />
<view id="4097" visible="false" inframe="false" stylebar="true" location="1,1" size="395" window="-143,205,1612,941" />
<view id="1" visible="true" inframe="false" stylebar="false" location="1" size="767" window="100,100,600,400" />
<view id="2" visible="false" inframe="false" stylebar="true" location="3" size="513" tab="ALGEBRA" window="187,24,510,980" />
<view id="16" visible="false" inframe="false" stylebar="false" location="1" size="150" window="50,50,500,500" />
<view id="32" visible="false" inframe="false" stylebar="true" location="1" size="150" window="50,50,500,500" />
<view id="64" toolbar="0" visible="false" inframe="false" stylebar="false" location="1" size="150" window="50,50,500,500" />
<view id="128" visible="false" inframe="false" stylebar="false" location="1" size="480" window="50,50,500,500" />
<view id="70" toolbar="0 || 2020 || 2021 || 2022" visible="false" inframe="false" stylebar="true" location="1" size="150" window="50,50,500,500" />
</views>
<toolbar show="false" items="0 39 73 62 | 1 501 67 , 5 19 , 72 75 76 | 2 15 45 , 18 65 , 7 37 | 4 3 8 9 , 13 44 , 58 , 47 | 16 51 64 , 70 | 10 34 53 11 , 24 20 22 , 21 23 | 55 56 57 , 12 | 36 46 , 38 49 50 , 71 14 68 | 30 29 54 32 31 33 | 25 17 26 60 52 61 | 40 41 42 , 27 28 35 , 6" position="1" help="false" />
<input show="false" cmd="true" top="algebra" />
<dockBar show="false" east="false" />
</perspective>
</perspectives>
<labelingStyle val="3"/>
<font size="24"/>
</gui>
<euclidianView>
<viewNumber viewNo="1"/>
<size width="766" height="778"/>
<coordSystem xZero="244.87430539772737" yZero="465.93784730113623" scale="70.07421093749993" yscale="70.07421093749993"/>
<evSettings axes="false" grid="false" gridIsBold="false" pointCapturing="1" rightAngleStyle="1" checkboxSize="26" gridType="3" lockedAxesRatio="1"/>
<bgColor r="255" g="239" b="213"/>
<axesColor r="0" g="0" b="0"/>
<gridColor r="192" g="192" b="192"/>
<lineStyle axes="1" grid="0"/>
<axis id="0" show="false" label="" unitLabel="" tickStyle="1" showNumbers="true"/>
<axis id="1" show="false" label="" unitLabel="" tickStyle="1" showNumbers="true"/>
</euclidianView>
<kernel>
<continuous val="false"/>
<usePathAndRegionParameters val="true"/>
<decimals val="2"/>
<angleUnit val="degree"/>
<algebraStyle val="0" spreadsheet="0"/>
<coordStyle val="0"/>
</kernel>
<tableview min="-2" max="2" step="1"/>
<scripting blocked="false" disabled="false"/>
<construction title="" author="" date="">
<element type="angle" label="α">
<angleStyle val="3"/>
<value val="6.283185307179586"/>
<slider min="0°" max="360°" absoluteScreenLocation="true" width="180" x="66" y="120" fixed="true" horizontal="true" showAlgebra="false"/>
<show object="false" label="true" ev="5"/>
<objColor r="0" g="100" b="0" alpha="0.10000000149011612"/>
<layer val="8"/>
<labelMode val="1"/>
<lineStyle thickness="10" type="0" typeHidden="2" opacity="178"/>
<arcSize val="30"/>
<animation step="10°" speed="12" type="3" playing="false"/>
<ggbscript onUpdate="
If[α>=120°&&Mod(nleft,4)==0&&rnd==1,RunClickScript(buttonR1)]
If[α>=120°&&Mod(nleft,4)==0&&rnd==2,RunClickScript(buttonR2)]
If[α>=120°&&Mod(nleft,4)==0&&rnd==3,RunClickScript(buttonR3)]

If[α>=120°&&Mod(nleft,4)==1,RunClickScript(buttonR1)]
If[α>=120°&&Mod(nleft,4)==2,RunClickScript(buttonR2)]
If[α>=120°&&Mod(nleft,4)==3,RunClickScript(buttonR3)]

If[α==360°,RunClickScript(buttonOkR)]
If[α==360°,SetValue(showThinking,false)]
"/>
</element>
<expression label="A" exp="(5.4, 5.65)" type="point"/>
<element type="point" label="A">
<show object="false" label="true" ev="4"/>
<objColor r="77" g="77" b="255" alpha="0"/>
<layer val="8"/>
<labelMode val="0"/>
<animation step="0.1" speed="1" type="1" playing="false"/>
<coords x="5.4" y="5.65" z="1"/>
<pointSize val="5"/>
<pointStyle val="0"/>
</element>
<element type="numeric" label="n">
<value val="21"/>
<show object="false" label="true"/>
<objColor r="0" g="0" b="0" alpha="0.10000000149011612"/>
<layer val="8"/>
<labelOffset x="-3" y="-3"/>
<labelMode val="1"/>
<animation speed="1" type="0" playing="false"/>
</element>
<element type="button" label="buttonNewGame">
<show object="true" label="true"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<bgColor r="255" g="255" b="0" alpha="255"/>
<layer val="7"/>
<labelOffset x="89" y="721"/>
<labelMode val="3"/>
<tooltipMode val="2"/>
<fixed val="true"/>
<auxiliary val="true"/>
<ggbscript val="SetValue(showNewGame,true)
"/>
<font serif="false" sizeM="4" size="72" style="1"/>
<startPoint x="-2" y="-3.3" z="1"/>
<caption val="New Game"/>
</element>
<element type="button" label="buttonR1">
<show object="false" label="true"/>
<condition showObject="nleft ≥ 1"/>
<objColor r="255" g="0" b="0" alpha="1"/>
<bgColor r="255" g="255" b="255" alpha="255"/>
<layer val="1"/>
<labelOffset x="648" y="378"/>
<labelMode val="3"/>
<tooltipMode val="2"/>
<fixed val="true"/>
<auxiliary val="true"/>
<ggbscript val="SetBackgroundColor[buttonR1,"yellow"]
SetBackgroundColor[buttonR2,"white"]
SetBackgroundColor[buttonR3,"white"]
If[nleft>0,SetValue(listTmp,{listLeft(1)})]
showOkR=true
"/>
<font serif="false" sizeM="8" size="168" style="0"/>
<dimensions width="120" height="128" />
<startPoint x="5.4" y="1" z="1"/>
<caption val="1"/>
</element>
<element type="button" label="buttonR2">
<show object="true" label="true"/>
<condition showObject="nleft ≥ 2"/>
<objColor r="255" g="0" b="0" alpha="1"/>
<bgColor r="255" g="255" b="255" alpha="255"/>
<layer val="1"/>
<labelOffset x="647" y="236"/>
<labelMode val="3"/>
<tooltipMode val="2"/>
<fixed val="true"/>
<auxiliary val="true"/>
<ggbscript val="SetBackgroundColor[buttonR1,"white"]
SetBackgroundColor[buttonR2,"yellow"]
SetBackgroundColor[buttonR3,"white"]
If[nleft>0,SetValue(listTmp,{listLeft(1),listLeft(2)})]
showOkR=true"/>
<font serif="false" sizeM="8" size="168" style="0"/>
<dimensions width="120" height="128" />
<startPoint x="5.4" y="3" z="1"/>
<caption val="2"/>
</element>
<element type="button" label="buttonR3">
<show object="true" label="true"/>
<condition showObject="nleft ≥ 3"/>
<objColor r="255" g="0" b="0" alpha="1"/>
<bgColor r="255" g="255" b="255" alpha="255"/>
<layer val="1"/>
<labelOffset x="648" y="91"/>
<labelMode val="3"/>
<tooltipMode val="2"/>
<fixed val="true"/>
<auxiliary val="true"/>
<ggbscript val="SetBackgroundColor[buttonR1,"white"]
SetBackgroundColor[buttonR2,"white"]
SetBackgroundColor[buttonR3,"yellow"]
If[nleft>0,SetValue(listTmp,{listLeft(1),listLeft(2),listLeft(3)})]
showOkR=true"/>
<font serif="false" sizeM="8" size="168" style="0"/>
<dimensions width="120" height="128" />
<startPoint x="5.4" y="5" z="1"/>
<caption val="3"/>
</element>
<element type="button" label="buttonB1">
<show object="true" label="true"/>
<condition showObject="nleft ≥ 1"/>
<objColor r="0" g="0" b="255" alpha="1"/>
<bgColor r="255" g="255" b="255" alpha="255"/>
<layer val="1"/>
<labelOffset x="46" y="390"/>
<labelMode val="3"/>
<tooltipMode val="2"/>
<fixed val="true"/>
<auxiliary val="true"/>
<ggbscript val="SetBackgroundColor[buttonB1,"yellow"]
SetBackgroundColor[buttonB2,"white"]
SetBackgroundColor[buttonB3,"white"]
If[nleft>0,SetValue(listTmp,{listLeft(1)})]
showOkB=true"/>
<font serif="false" sizeM="8" size="168" style="0"/>
<dimensions width="120" height="128" />
<startPoint x="-3" y="1" z="1"/>
<caption val="1"/>
</element>
<element type="button" label="buttonB2">
<show object="true" label="true"/>
<condition showObject="nleft ≥ 2"/>
<objColor r="0" g="0" b="255" alpha="1"/>
<bgColor r="255" g="255" b="255" alpha="255"/>
<layer val="1"/>
<labelOffset x="46" y="243"/>
<labelMode val="3"/>
<tooltipMode val="2"/>
<fixed val="true"/>
<auxiliary val="true"/>
<ggbscript val="SetBackgroundColor[buttonB1,"white"]
SetBackgroundColor[buttonB2,"yellow"]
SetBackgroundColor[buttonB3,"white"]
If[nleft>0,SetValue(listTmp,{listLeft(1),listLeft(2)})]
showOkB=true"/>
<font serif="false" sizeM="8" size="168" style="0"/>
<dimensions width="120" height="128" />
<startPoint x="-3" y="3" z="1"/>
<caption val="2"/>
</element>
<element type="button" label="buttonB3">
<show object="true" label="true"/>
<condition showObject="nleft ≥ 3"/>
<objColor r="0" g="0" b="255" alpha="1"/>
<bgColor r="255" g="255" b="255" alpha="255"/>
<layer val="1"/>
<labelOffset x="46" y="96"/>
<labelMode val="3"/>
<tooltipMode val="2"/>
<fixed val="true"/>
<auxiliary val="true"/>
<ggbscript val="SetBackgroundColor[buttonB1,"white"]
SetBackgroundColor[buttonB2,"white"]
SetBackgroundColor[buttonB3,"yellow"]
If[nleft>0,SetValue(listTmp,{listLeft(1),listLeft(2),listLeft(3)})]
showOkB=true"/>
<font serif="false" sizeM="8" size="168" style="0"/>
<dimensions width="120" height="128" />
<startPoint x="-3" y="5" z="1"/>
<caption val="3"/>
</element>
<expression label="listLeft" exp="{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}"/>
<element type="list" label="listLeft">
<objColor r="0" g="100" b="0" alpha="0.10000000149011612"/>
<animation step="1" speed="1" type="0" playing="false"/>
<lineStyle thickness="5" type="0" typeHidden="1"/>
<pointSize val="5"/>
<pointStyle val="0"/>
<angleStyle val="0"/>
</element>
<expression label="listBlue" exp="{}"/>
<element type="list" label="listBlue">
<show object="false" label="false"/>
<objColor r="0" g="100" b="0" alpha="0.10000000149011612"/>
<layer val="8"/>
<labelMode val="0"/>
<animation step="1" speed="1" type="0" playing="false"/>
<lineStyle thickness="5" type="0" typeHidden="1"/>
<listType val="numeric"/>
<pointSize val="5"/>
<pointStyle val="0"/>
<angleStyle val="0"/>
</element>
<command name="Polygon">
<input a0="{Corner[1], Corner[2], (x(Corner[3]), -3), (x(Corner[4]), -3)}"/>
<output a0="backM"/>
</command>
<element type="polygon" label="backM">
<lineStyle thickness="0" type="0" typeHidden="1" opacity="178"/>
<show object="true" label="false" ev="4"/>
<objColor r="128" g="0" b="128" alpha="1"/>
<layer val="3"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
</element>
<expression label="listRed" exp="{}"/>
<element type="list" label="listRed">
<show object="false" label="false"/>
<objColor r="0" g="100" b="0" alpha="0.10000000149011612"/>
<layer val="8"/>
<labelMode val="0"/>
<animation step="1" speed="1" type="0" playing="false"/>
<lineStyle thickness="5" type="0" typeHidden="1"/>
<listType val="numeric"/>
<pointSize val="5"/>
<pointStyle val="0"/>
<angleStyle val="0"/>
</element>
<command name="Length">
<input a0="listLeft"/>
<output a0="nleft"/>
</command>
<element type="numeric" label="nleft">
<value val="21"/>
<objColor r="0" g="0" b="0" alpha="0.10000000149011612"/>
</element>
<command name="Polygon">
<input a0="{Corner[1], (-1, y(Corner[1])), (-1, y(Corner[4])), Corner[4]}"/>
<output a0="backB"/>
</command>
<element type="polygon" label="backB">
<lineStyle thickness="0" type="0" typeHidden="1" opacity="178"/>
<show object="true" label="false" ev="4"/>
<objColor r="0" g="0" b="255" alpha="1"/>
<layer val="0"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
</element>
<command name="Polygon">
<input a0="{Corner[2], (5, y(Corner[2])), (5, y(Corner[3])), Corner[3]}"/>
<output a0="backR"/>
</command>
<element type="polygon" label="backR">
<lineStyle thickness="0" type="0" typeHidden="1" opacity="178"/>
<show object="true" label="false" ev="4"/>
<objColor r="255" g="0" b="0" alpha="1"/>
<layer val="0"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
</element>
<command name="Polygon">
<input a0="{Corner[1], (-1, y(Corner[1])), (-1, y(Corner[4])), Corner[4]}"/>
<output a0="maskB"/>
</command>
<element type="polygon" label="maskB">
<lineStyle thickness="5" type="0" typeHidden="1" opacity="178"/>
<show object="false" label="false" ev="4"/>
<condition showObject="showMaskB"/>
<objColor r="0" g="0" b="255" alpha="1"/>
<layer val="2"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
</element>
<command name="Polygon">
<input a0="{Corner[2], (5, y(Corner[2])), (5, y(Corner[3])), Corner[3]}"/>
<output a0="maskR"/>
</command>
<element type="polygon" label="maskR">
<lineStyle thickness="5" type="0" typeHidden="1" opacity="178"/>
<show object="false" label="false" ev="4"/>
<condition showObject="showMaskR"/>
<objColor r="255" g="0" b="0" alpha="1"/>
<layer val="2"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
</element>
<element type="button" label="buttonOkB">
<show object="true" label="true"/>
<condition showObject="showOkB"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="2"/>
<labelOffset x="27" y="529"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<fixed val="true"/>
<auxiliary val="true"/>
<ggbscript val="SetBackgroundColor[buttonB1,"white"]
SetBackgroundColor[buttonB2,"white"]
SetBackgroundColor[buttonB3,"white"]
SetValue(listLeft,Remove(listLeft,listTmp))
SetValue(listBlue,Join(listBlue,listTmp))
SetValue[listTmp,{}]
showOkB=false
showMaskB=true
showMaskR=false

If[nleft!=0&&SelectedIndex(mode)!=1,SetValue(α,0°)]
If[nleft!=0&&SelectedIndex(mode)!=1,SetValue(showThinking,true)]

If[nleft!=0&&SelectedIndex(mode)!=1,SetValue(rnd,Random(1, 3))]
If[nleft!=0&&SelectedIndex(mode)!=1,StartAnimation(α)]
SetValue[rnd,Random(1, 3)]"/>
<font serif="false" sizeM="4" size="72" style="1"/>
<dimensions width="121" height="100" />
<startPoint x="-3" y="-1" z="1"/>
<caption val="OK?"/>
</element>
<element type="button" label="buttonOkR">
<show object="true" label="true"/>
<condition showObject="showOkR"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="2"/>
<labelOffset x="626" y="529"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<fixed val="true"/>
<auxiliary val="true"/>
<ggbscript val="SetBackgroundColor[buttonR1,"white"]
SetBackgroundColor[buttonR2,"white"]
SetBackgroundColor[buttonR3,"white"]
SetValue(listLeft,Remove(listLeft,listTmp))
SetValue(listRed,Join(listRed,listTmp))
SetValue[listTmp,{}]
showOkR=false
showMaskB=false
showMaskR=true"/>
<font serif="false" sizeM="4" size="72" style="1"/>
<dimensions width="121" height="100" />
<startPoint x="5.4" y="-1" z="1"/>
<caption val="OK?"/>
</element>
<expression label="listTmp" exp="{}"/>
<element type="list" label="listTmp">
<show object="false" label="false"/>
<objColor r="0" g="100" b="0" alpha="0.10000000149011612"/>
<layer val="8"/>
<labelMode val="0"/>
<animation step="1" speed="1" type="0" playing="false"/>
<lineStyle thickness="5" type="0" typeHidden="1"/>
<listType val="numeric"/>
<pointSize val="5"/>
<pointStyle val="0"/>
<angleStyle val="0"/>
</element>
<expression label="showOkB" exp="false"/>
<element type="boolean" label="showOkB">
<value val="false"/>
<show object="false" label="true"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="0"/>
<labelMode val="0"/>
<checkbox fixed="true"/>
</element>
<expression label="showOkR" exp="false"/>
<element type="boolean" label="showOkR">
<value val="false"/>
<show object="false" label="true"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="0"/>
<labelMode val="0"/>
<checkbox fixed="true"/>
</element>
<element type="boolean" label="showMaskB">
<value val="false"/>
<show object="false" label="true"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="0"/>
<labelMode val="0"/>
<checkbox fixed="true"/>
</element>
<element type="boolean" label="showMaskR">
<value val="true"/>
<show object="false" label="true"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="0"/>
<labelMode val="0"/>
<checkbox fixed="true"/>
</element>
<expression label="showBok" exp="true"/>
<element type="boolean" label="showBok">
<value val="true"/>
<show object="false" label="true"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="0"/>
<labelMode val="0"/>
<checkbox fixed="true"/>
</element>
<element type="image" label="picWinner">
<file name="b03b20b84a758705a19a170f9dfc7634/winner.png"/>
<inBackground val="false"/>
<startPoint number="0" exp="If[n ∈ listBlue, (-3.1, 3), (5.1, 3)]"/>
<startPoint number="1" exp="If[n ∈ listBlue, (-1.1, 3), (7.1, 3)]"/>
<show object="true" label="false"/>
<condition showObject="nleft ≟ 0"/>
<objColor r="0" g="0" b="0" alpha="1"/>
<layer val="4"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<animation step="1" speed="1" type="0" playing="false"/>
</element>
<expression label="textP1" exp=""Player1""/>
<element type="text" label="textP1">
<show object="true" label="false" ev="41"/>
<objColor r="255" g="255" b="0" alpha="0"/>
<layer val="4"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
<font serif="false" sizeM="1.4" size="10" style="1"/>
<startPoint x="-2.9" y="5.5" z="1"/>
</element>
<expression label="textP2" exp=""Player2""/>
<element type="text" label="textP2">
<show object="true" label="false" ev="41"/>
<objColor r="255" g="255" b="0" alpha="0"/>
<layer val="4"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
<font serif="false" sizeM="1.4" size="10" style="1"/>
<startPoint x="5.3" y="5.5" z="1"/>
</element>
<command name="Sequence">
<input a0="Circle[(Mod[k, 5], 5 - floor(k / 5)), 0.4]" a1="k" a2="0" a3="n - 1"/>
<output a0="takeAll"/>
</command>
<element type="list" label="takeAll">
<show object="true" label="false" ev="4"/>
<objColor r="128" g="0" b="128" alpha="0.20000000298023224"/>
<layer val="0"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
<lineStyle thickness="5" type="0" typeHidden="1"/>
<pointSize val="5"/>
<pointStyle val="0"/>
<angleStyle val="0"/>
</element>
<command name="Sequence">
<input a0="Circle[(Mod[listBlue(k) - 1, 5], 5 - floor((listBlue(k) - 1) / 5)), 0.4]" a1="k" a2="1" a3="Length[listBlue]"/>
<output a0="takeB"/>
</command>
<element type="list" label="takeB">
<show object="true" label="false" ev="4"/>
<objColor r="0" g="0" b="255" alpha="1"/>
<layer val="0"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
<lineStyle thickness="1" type="0" typeHidden="1"/>
<listType val="conic"/>
<pointSize val="9"/>
<pointStyle val="1"/>
<angleStyle val="0"/>
</element>
<command name="Sequence">
<input a0="Circle[(Mod[listRed(k) - 1, 5], 5 - floor((listRed(k) - 1) / 5)), 0.4]" a1="k" a2="1" a3="Length[listRed]"/>
<output a0="takeR"/>
</command>
<element type="list" label="takeR">
<show object="true" label="false" ev="4"/>
<objColor r="255" g="0" b="0" alpha="1"/>
<layer val="0"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
<lineStyle thickness="1" type="0" typeHidden="1"/>
<listType val="conic"/>
<pointSize val="9"/>
<pointStyle val="1"/>
<angleStyle val="0"/>
</element>
<command name="Sequence">
<input a0="Point[{(Mod[listTmp(k) - 1, 5], 5 - floor((listTmp(k) - 1) / 5))}]" a1="k" a2="1" a3="Length[listTmp]"/>
<output a0="takeT"/>
</command>
<element type="list" label="takeT">
<show object="true" label="false" ev="4"/>
<objColor r="128" g="0" b="128" alpha="0"/>
<layer val="2"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
<lineStyle thickness="5" type="0" typeHidden="1"/>
<listType val="point"/>
<pointSize val="9"/>
<pointStyle val="2"/>
<angleStyle val="0"/>
</element>
<command name="Polygon">
<input a0="{(x(Corner[1]), -3), (x(Corner[2]), -3), Corner[3], Corner[4]}"/>
<output a0="maskRule"/>
</command>
<element type="polygon" label="maskRule">
<lineStyle thickness="5" type="0" typeHidden="1" opacity="178"/>
<show object="true" label="false" ev="4"/>
<condition showObject="showRule"/>
<objColor r="64" g="64" b="64" alpha="0.949999988079071"/>
<layer val="7"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<ggbscript val="SetValue[showRule,false]"/>
</element>
<element type="button" label="buttonRule">
<show object="true" label="true"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<bgColor r="255" g="250" b="205" alpha="255"/>
<layer val="7"/>
<labelOffset x="414" y="721"/>
<labelMode val="3"/>
<tooltipMode val="2"/>
<fixed val="true"/>
<auxiliary val="true"/>
<ggbscript val="SetValue[showRule,!showRule]"/>
<font serif="false" sizeM="4" size="72" style="1"/>
<startPoint x="2.4" y="-3.3" z="1"/>
<caption val="Game Rule"/>
</element>
<command name="Polygon">
<input a0="{Corner[1], Corner[2], (x(Corner[3]), -1), (x(Corner[4]), -1)}"/>
<output a0="maskNewGame"/>
</command>
<element type="polygon" label="maskNewGame">
<lineStyle thickness="5" type="0" typeHidden="1" opacity="178"/>
<show object="true" label="false" ev="4"/>
<condition showObject="showNewGame"/>
<objColor r="128" g="0" b="128" alpha="1"/>
<layer val="8"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
</element>
<expression label="textRule" exp=""遊戲規則
 檯面上有若干顆彈珠,兩位玩家輪流取珠,
每人每次可取1~3顆,最後將檯面上的彈珠
取完的玩家獲勝。

Game Rule
 There are pinballs on the table. Two players
take turns getting pinballs. You can take 1~3 
pinball(s) each turn. The one who taking the
last pinball wins the game.""/>
<element type="text" label="textRule">
<show object="true" label="false" ev="40"/>
<condition showObject="showRule"/>
<objColor r="255" g="255" b="0" alpha="0"/>
<layer val="8"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
<font serif="false" sizeM="1.4" size="10" style="1"/>
<startPoint x="-2.5837768439666284" y="5.502045310344636" z="1"/>
</element>
<element type="boolean" label="showNewGame">
<value val="false"/>
<show object="false" label="true"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="0"/>
<labelMode val="0"/>
<checkbox fixed="true"/>
</element>
<element type="numeric" label="nSetup">
<value val="21"/>
<show object="true" label="true"/>
<condition showObject="showNewGame"/>
<objColor r="255" g="255" b="0" alpha="0.10000000149011612"/>
<bgColor r="255" g="250" b="205" alpha="255"/>
<layer val="8"/>
<labelOffset x="-80" y="-2"/>
<labelMode val="3"/>
<tooltipMode val="2"/>
<slider min="10" max="30" absoluteScreenLocation="true" width="440" x="275" y="717" fixed="true" horizontal="true" showAlgebra="false"/>
<pointSize val="20"/>
<lineStyle thickness="50" type="0" typeHidden="1"/>
<animation step="1" speed="1" type="0" playing="false"/>
<caption val="彈珠數 PinBalls:%v"/>
</element>
<element type="boolean" label="showRule">
<value val="false"/>
<show object="false" label="true"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="0"/>
<labelMode val="0"/>
<checkbox fixed="true"/>
</element>
<element type="button" label="buttonNewStart">
<show object="false" label="true"/>
<condition showObject="showNewGame"/>
<objColor r="0" g="0" b="0" alpha="1"/>
<bgColor r="255" g="255" b="0" alpha="255"/>
<layer val="8"/>
<labelOffset x="49" y="564"/>
<labelMode val="3"/>
<tooltipMode val="2"/>
<animation step="0.1" speed="1" type="0" playing="false"/>
<auxiliary val="true"/>
<ggbscript val="If[SelectedIndex(mode)==1,SetVisibleInView( textP1, 1, true ),SetVisibleInView( textP1, 1, false )]
If[SelectedIndex(mode)==1,SetVisibleInView( textP2, 1, true ),SetVisibleInView( textP2, 1, false )]
If[SelectedIndex(mode)!=1,SetVisibleInView( textPlayer, 1, true ),SetVisibleInView( textPlayer, 1, false )]
If[SelectedIndex(mode)!=1,SetVisibleInView( textCom, 1, true ),SetVisibleInView( textCom, 1, false )]

SetValue[n,nSetup]
SetValue[showNewGame,false]
SetValue[showRule,false]

listLeft=CopyFreeObject(Sequence(n))
listBlue={}
listRed={}
listTmp={}
showOkB=false
showOkR=false
SetBackgroundColor[buttonB1,"white"]
SetBackgroundColor[buttonB2,"white"]
SetBackgroundColor[buttonB3,"white"]
SetBackgroundColor[buttonR1,"white"]
SetBackgroundColor[buttonR2,"white"]
SetBackgroundColor[buttonR3,"white"]

If[SelectedIndex(mode)==3,SetValue(showMaskB,true),SetValue(showMaskB,false)]
If[SelectedIndex(mode)==3,SetValue(showMaskR,false),SetValue(showMaskR,true)]
If[SelectedIndex(mode)==3,SetValue(α,0°)]
If[SelectedIndex(mode)==3,SetValue(showThinking,true)]
If[SelectedIndex(mode)==3,StartAnimation(α)]"/>
<font serif="false" sizeM="4" size="72" style="1"/>
<dimensions width="180" height="80" />
<startPoint x="-2.8" y="-1.4" z="1"/>
<caption val="Start"/>
</element>
<element type="button" label="buttonNewCancel">
<show object="true" label="true"/>
<condition showObject="showNewGame"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<bgColor r="255" g="250" b="205" alpha="255"/>
<layer val="8"/>
<labelOffset x="50" y="654"/>
<labelMode val="3"/>
<tooltipMode val="2"/>
<animation step="0.1" speed="1" type="0" playing="false"/>
<auxiliary val="true"/>
<ggbscript val="SetValue[showNewGame,false]
SetValue[showRule,false]
SetValue[nSetup,n]"/>
<font serif="false" sizeM="4" size="72" style="1"/>
<dimensions width="180" height="80" />
<startPoint x="-2.8" y="-2.8" z="1"/>
<caption val="Cancel"/>
</element>
<expression label="mode" exp="{"Palyer1 vs Player2", "Player first vs Com", "Com first vs Player"}"/>
<element type="list" label="mode">
<show object="true" label="false" ev="4"/>
<condition showObject="showNewGame"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<bgColor r="255" g="250" b="205" alpha="255"/>
<layer val="8"/>
<labelOffset x="252" y="572"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<animation step="1" speed="1" type="0" playing="false"/>
<lineStyle thickness="5" type="0" typeHidden="1"/>
<selectedIndex val="1"/>
<comboBox val="true"/>
<pointSize val="5"/>
<pointStyle val="0"/>
<font serif="false" sizeM="2" size="24" style="1"/>
<angleStyle val="0"/>
<symbolic val="true" />
</element>
<expression label="textCom" exp=""Com""/>
<element type="text" label="textCom">
<show object="true" label="false" ev="40"/>
<objColor r="255" g="255" b="0" alpha="0"/>
<layer val="4"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
<font serif="false" sizeM="1.4" size="10" style="1"/>
<startPoint x="5.7" y="5.5" z="1"/>
</element>
<expression label="textPlayer" exp=""Player""/>
<element type="text" label="textPlayer">
<show object="true" label="false" ev="40"/>
<objColor r="255" g="255" b="0" alpha="0"/>
<layer val="4"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
<font serif="false" sizeM="1.4" size="10" style="1"/>
<startPoint x="-2.8" y="5.5" z="1"/>
</element>
<element type="numeric" label="rnd">
<value val="3"/>
<show object="false" label="true"/>
<objColor r="0" g="0" b="0" alpha="0.10000000149011612"/>
<layer val="8"/>
<labelMode val="1"/>
<animation speed="1" type="0" playing="false"/>
</element>
<element type="boolean" label="showThinking">
<value val="false"/>
<show object="false" label="true"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="0"/>
<labelMode val="0"/>
<checkbox fixed="true"/>
</element>
<command name="Circle">
<input a0="A" a1="0.2"/>
<output a0="thinkingC"/>
</command>
<element type="conic" label="thinkingC">
<show object="true" label="false" ev="4"/>
<condition showObject="showThinking"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="8"/>
<labelMode val="0"/>
<lineStyle thickness="5" type="0" typeHidden="1" opacity="178"/>
<eigenvectors x0="1" y0="0" z0="1.0" x1="0" y1="1" z1="1.0"/>
<matrix A0="1" A1="1" A2="61.042500000000004" A3="0" A4="-5.4" A5="-5.65"/>
<eqnStyle style="specific"/>
</element>
<command name="CircleSector">
<input a0="A" a1="A + ((0.2 * cos(90° - α)), (0.2 * sin(90° - α)))" a2="A + (0, 0.5)"/>
<output a0="thinkingS"/>
</command>
<element type="conicpart" label="thinkingS">
<show object="true" label="false" ev="4"/>
<condition showObject="showThinking"/>
<objColor r="153" g="51" b="0" alpha="1"/>
<layer val="8"/>
<labelMode val="0"/>
<lineStyle thickness="5" type="0" typeHidden="1" opacity="178"/>
<eigenvectors x0="1" y0="0" z0="1.0" x1="0" y1="1" z1="1.0"/>
<matrix A0="1" A1="1" A2="61.042500000000004" A3="0" A4="-5.4" A5="-5.65"/>
<eqnStyle style="implicit"/>
<outlyingIntersections val="false"/>
<keepTypeOnTransform val="true"/>
</element>
<expression label="textLeft" exp=""剩餘 Left:" + (nleft - Length[listTmp]) + """ />
<element type="text" label="textLeft">
<show object="true" label="false" ev="8"/>
<objColor r="0" g="0" b="0" alpha="0"/>
<layer val="4"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<selectionAllowed val="false"/>
<font serif="false" sizeM="1.4" size="10" style="1"/>
<startPoint x="0.5380659296781034" y="-2.461417756899343" z="1"/>
</element>
<element type="image" label="picDia">
<file name="00738fee1b951a9c625ae689973d2aa2/鑽石.png"/>
<inBackground val="false"/>
<startPoint number="0" exp="(Mod[n - 1, 5] - 0.3, 4.65 - floor((n - 1) / 5))"/>
<startPoint number="1" exp="(Mod[n - 1, 5] + 0.3, 4.65 - floor((n - 1) / 5))"/>
<show object="true" label="false"/>
<objColor r="0" g="0" b="0" alpha="1"/>
<layer val="4"/>
<labelMode val="0"/>
<tooltipMode val="2"/>
<animation step="1" speed="1" type="0" playing="false"/>
<selectionAllowed val="false"/>
</element>
</construction>
</geogebra>