    %eden

    /* This file sets up an interactive environment for playing Nim in the traditional way */

    /* 	Some of the interface components are common to nimLeeke2008 but they are relocated
    	on the display, and have simpler less contrained actions associated with them
    */

    %eden
    pileSizeOne = pileSizeTwo = pileSizeThree = 15;

    %donald
    viewport pileOne
    openshape pictPileOne
    within pictPileOne {
    	point p0,p1,p2,p3,p4
    	point p5,p6,p7,p8,p9
    	point p10,p11,p12,p13,p14,p15
    	circle stone0,stone1,stone2,stone3,stone4
    	circle stone5,stone6,stone7,stone8,stone9
    	circle stone10,stone11,stone12,stone13,stone14,stone15

    	int stoneSize
    	stoneSize = 10

    	stone0 = circle(p0,stoneSize)
    	stone1 = circle(p1,stoneSize)
    	stone2 = circle(p2,stoneSize)
    	stone3 = circle(p3,stoneSize)
    	stone4 = circle(p4,stoneSize)

    	stone5 = circle(p5,stoneSize)
    	stone6 = circle(p6,stoneSize)
    	stone7 = circle(p7,stoneSize)
    	stone8 = circle(p8,stoneSize)
    	stone9 = circle(p9,stoneSize)

    	stone10 = circle(p10,stoneSize)
    	stone11 = circle(p11,stoneSize)
    	stone12 = circle(p12,stoneSize)
    	stone13 = circle(p13,stoneSize)
    	stone14 = circle(p14,stoneSize)
    }

    %scout
    window winPileOne = {
      type: DONALD
      box: [{10, 10}, {480, 480}]
      pict: "pileOne"
      border: 1
      bdcolor: "white"
      bgcolor: "lightblue"
      xmin: -100
      ymin: -100
      ymax: 100
      xmax: 100
    };

    %donald

    within pictPileOne {
    	p0 = {0, 80}
    	p4 = {0,0}
    	p3 = {-40, 0}
    	p2 = {20, 40}
    	p5 = {40,0}
    	p6 = {-60,-40}
    	p1 = {-20,40}
    	p7 = {-20, -40}
    	p8 = {20,-40}
    	p9 = {60,-40}
    	p10 = {-80, -80}
    	p11 = {-40, -80}
    	p12 = {0, -80}
    	p13 = {40, -80}
    	p14 = {80, -80}
    }

    %donald
    viewport pileTwo
    openshape pictPileTwo
    within pictPileTwo {
    	point p0,p1,p2,p3,p4
    	point p5,p6,p7,p8,p9
    	point p10,p11,p12,p13,p14,p15
    	circle stone0,stone1,stone2,stone3,stone4
    	circle stone5,stone6,stone7,stone8,stone9
    	circle stone10,stone11,stone12,stone13,stone14,stone15

    	int stoneSize
    	stoneSize = 10

    	stone0 = circle(p0,stoneSize)
    	stone1 = circle(p1,stoneSize)
    	stone2 = circle(p2,stoneSize)
    	stone3 = circle(p3,stoneSize)
    	stone4 = circle(p4,stoneSize)

    	stone5 = circle(p5,stoneSize)
    	stone6 = circle(p6,stoneSize)
    	stone7 = circle(p7,stoneSize)
    	stone8 = circle(p8,stoneSize)
    	stone9 = circle(p9,stoneSize)

    	stone10 = circle(p10,stoneSize)
    	stone11 = circle(p11,stoneSize)
    	stone12 = circle(p12,stoneSize)
    	stone13 = circle(p13,stoneSize)
    	stone14 = circle(p14,stoneSize)
    }

    %scout
    window winPileTwo = {
      type: DONALD
      box: [{10, 10}, {480, 480}]
      pict: "pileTwo"
      border: 1
      bdcolor: "white"
      bgcolor: "lightblue"
      xmin: -100
      ymin: -100
      ymax: 100
      xmax: 100
    };

    %donald

    within pictPileTwo {
    	p0 = {0, 80}
    	p4 = {0,0}
    	p3 = {-40, 0}
    	p2 = {20, 40}
    	p5 = {40,0}
    	p6 = {-60,-40}
    	p1 = {-20,40}
    	p7 = {-20, -40}
    	p8 = {20,-40}
    	p9 = {60,-40}
    	p10 = {-80, -80}
    	p11 = {-40, -80}
    	p12 = {0, -80}
    	p13 = {40, -80}
    	p14 = {80, -80}
    }

    %donald
    viewport pileThree
    openshape pictPileThree
    within pictPileThree {
    	point p0,p1,p2,p3,p4
    	point p5,p6,p7,p8,p9
    	point p10,p11,p12,p13,p14,p15
    	circle stone0,stone1,stone2,stone3,stone4
    	circle stone5,stone6,stone7,stone8,stone9
    	circle stone10,stone11,stone12,stone13,stone14,stone15

    	int stoneSize
    	stoneSize = 10

    	stone0 = circle(p0,stoneSize)
    	stone1 = circle(p1,stoneSize)
    	stone2 = circle(p2,stoneSize)
    	stone3 = circle(p3,stoneSize)
    	stone4 = circle(p4,stoneSize)

    	stone5 = circle(p5,stoneSize)
    	stone6 = circle(p6,stoneSize)
    	stone7 = circle(p7,stoneSize)
    	stone8 = circle(p8,stoneSize)
    	stone9 = circle(p9,stoneSize)

    	stone10 = circle(p10,stoneSize)
    	stone11 = circle(p11,stoneSize)
    	stone12 = circle(p12,stoneSize)
    	stone13 = circle(p13,stoneSize)
    	stone14 = circle(p14,stoneSize)
    }

    %scout
    window winPileThree = {
      type: DONALD
      box: [{10, 10}, {480, 480}]
      pict: "pileThree"
      border: 1
      bdcolor: "white"
      bgcolor: "lightblue"
      xmin: -100
      ymin: -100
      ymax: 100
      xmax: 100
    };

    %donald

    within pictPileThree {
    	p0 = {0, 80}
    	p4 = {0,0}
    	p3 = {-40, 0}
    	p2 = {20, 40}
    	p5 = {40,0}
    	p6 = {-60,-40}
    	p1 = {-20,40}
    	p7 = {-20, -40}
    	p8 = {20,-40}
    	p9 = {60,-40}
    	p10 = {-80, -80}
    	p11 = {-40, -80}
    	p12 = {0, -80}
    	p13 = {40, -80}
    	p14 = {80, -80}
    }

    %scout
    integer winPileSize = 110;

    point winPileOneNW = {40,10};
    window winPileOne = {
      type: DONALD
      box: [winPileOneNW, winPileOneNW+{winPileSize, winPileSize}]
      pict: "pileOne"
      border: 1
      bdcolor: "white"
      bgcolor: "lightblue"
      xmin: -100
      ymin: -100
      ymax: 100
      xmax: 100
    };

    point winPileTwoNW = {195,10};
    window winPileTwo = {
      type: DONALD
      box: [winPileTwoNW, winPileTwoNW+{winPileSize, winPileSize}]
      pict: "pileTwo"
      border: 1
      bdcolor: "white"
      bgcolor: "lightblue"
      xmin: -100
      ymin: -100
      ymax: 100
      xmax: 100
    };

    point winPileThreeNW = {355,10};
    window winPileThree = {
      type: DONALD
      box: [winPileThreeNW, winPileThreeNW+{winPileSize, winPileSize}]
      pict: "pileThree"
      border: 1
      bdcolor: "white"
      bgcolor: "lightblue"
      xmin: -100
      ymin: -100
      ymax: 100
      xmax: 100
    };

    %scout
    screen = ;

    %eden

    colOne0 is (pileSizeOne>0) ? "red" : "lightblue";
    colOne1 is (pileSizeOne>1) ? "red" : "lightblue";
    colOne2 is (pileSizeOne>2) ? "red" : "lightblue";
    colOne3 is (pileSizeOne>3) ? "red" : "lightblue";
    colOne4 is (pileSizeOne>4) ? "red" : "lightblue";
    colOne5 is (pileSizeOne>5) ? "red" : "lightblue";
    colOne6 is (pileSizeOne>6) ? "red" : "lightblue";
    colOne7 is (pileSizeOne>7) ? "red" : "lightblue";
    colOne8 is (pileSizeOne>8) ? "red" : "lightblue";
    colOne9 is (pileSizeOne>9) ? "red" : "lightblue";
    colOne10 is (pileSizeOne>10) ? "red" : "lightblue";
    colOne11 is (pileSizeOne>11) ? "red" : "lightblue";
    colOne12 is (pileSizeOne>12) ? "red" : "lightblue";
    colOne13 is (pileSizeOne>13) ? "red" : "lightblue";
    colOne14 is (pileSizeOne>14) ? "red" : "lightblue";

    A_pictPileOne_stone0 is "outlinecolor=" // colOne0 // ",fill=solid,color=" // colOne0;
    A_pictPileOne_stone1 is "outlinecolor=" // colOne1 // ",fill=solid,color=" // colOne1;
    A_pictPileOne_stone2 is "outlinecolor=" // colOne2 // ",fill=solid,color=" // colOne2;
    A_pictPileOne_stone3 is "outlinecolor=" // colOne3 // ",fill=solid,color=" // colOne3;
    A_pictPileOne_stone4 is "outlinecolor=" // colOne4 // ",fill=solid,color=" // colOne4;
    A_pictPileOne_stone5 is "outlinecolor=" // colOne5 // ",fill=solid,color=" // colOne5;
    A_pictPileOne_stone6 is "outlinecolor=" // colOne6 // ",fill=solid,color=" // colOne6;
    A_pictPileOne_stone7 is "outlinecolor=" // colOne7 // ",fill=solid,color=" // colOne7;
    A_pictPileOne_stone8 is "outlinecolor=" // colOne8 // ",fill=solid,color=" // colOne8;
    A_pictPileOne_stone9 is "outlinecolor=" // colOne9 // ",fill=solid,color=" // colOne9;
    A_pictPileOne_stone10 is "outlinecolor=" // colOne10 // ",fill=solid,color=" // colOne10;
    A_pictPileOne_stone11 is "outlinecolor=" // colOne11 // ",fill=solid,color=" // colOne11;
    A_pictPileOne_stone12 is "outlinecolor=" // colOne12 // ",fill=solid,color=" // colOne12;
    A_pictPileOne_stone13 is "outlinecolor=" // colOne13 // ",fill=solid,color=" // colOne13;
    A_pictPileOne_stone14 is "outlinecolor=" // colOne14 // ",fill=solid,color=" // colOne14;

    colTwo0 is (pileSizeTwo>0) ? "red" : "lightblue";
    colTwo1 is (pileSizeTwo>1) ? "red" : "lightblue";
    colTwo2 is (pileSizeTwo>2) ? "red" : "lightblue";
    colTwo3 is (pileSizeTwo>3) ? "red" : "lightblue";
    colTwo4 is (pileSizeTwo>4) ? "red" : "lightblue";
    colTwo5 is (pileSizeTwo>5) ? "red" : "lightblue";
    colTwo6 is (pileSizeTwo>6) ? "red" : "lightblue";
    colTwo7 is (pileSizeTwo>7) ? "red" : "lightblue";
    colTwo8 is (pileSizeTwo>8) ? "red" : "lightblue";
    colTwo9 is (pileSizeTwo>9) ? "red" : "lightblue";
    colTwo10 is (pileSizeTwo>10) ? "red" : "lightblue";
    colTwo11 is (pileSizeTwo>11) ? "red" : "lightblue";
    colTwo12 is (pileSizeTwo>12) ? "red" : "lightblue";
    colTwo13 is (pileSizeTwo>13) ? "red" : "lightblue";
    colTwo14 is (pileSizeTwo>14) ? "red" : "lightblue";

    A_pictPileTwo_stone0 is "outlinecolor=" // colTwo0 // ",fill=solid,color=" // colTwo0;
    A_pictPileTwo_stone1 is "outlinecolor=" // colTwo1 // ",fill=solid,color=" // colTwo1;
    A_pictPileTwo_stone2 is "outlinecolor=" // colTwo2 // ",fill=solid,color=" // colTwo2;
    A_pictPileTwo_stone3 is "outlinecolor=" // colTwo3 // ",fill=solid,color=" // colTwo3;
    A_pictPileTwo_stone4 is "outlinecolor=" // colTwo4 // ",fill=solid,color=" // colTwo4;
    A_pictPileTwo_stone5 is "outlinecolor=" // colTwo5 // ",fill=solid,color=" // colTwo5;
    A_pictPileTwo_stone6 is "outlinecolor=" // colTwo6 // ",fill=solid,color=" // colTwo6;
    A_pictPileTwo_stone7 is "outlinecolor=" // colTwo7 // ",fill=solid,color=" // colTwo7;
    A_pictPileTwo_stone8 is "outlinecolor=" // colTwo8 // ",fill=solid,color=" // colTwo8;
    A_pictPileTwo_stone9 is "outlinecolor=" // colTwo9 // ",fill=solid,color=" // colTwo9;
    A_pictPileTwo_stone10 is "outlinecolor=" // colTwo10 // ",fill=solid,color=" // colTwo10;
    A_pictPileTwo_stone11 is "outlinecolor=" // colTwo11 // ",fill=solid,color=" // colTwo11;
    A_pictPileTwo_stone12 is "outlinecolor=" // colTwo12 // ",fill=solid,color=" // colTwo12;
    A_pictPileTwo_stone13 is "outlinecolor=" // colTwo13 // ",fill=solid,color=" // colTwo13;
    A_pictPileTwo_stone14 is "outlinecolor=" // colTwo14 // ",fill=solid,color=" // colTwo14;

    colThree0 is (pileSizeThree>0) ? "red" : "lightblue";
    colThree1 is (pileSizeThree>1) ? "red" : "lightblue";
    colThree2 is (pileSizeThree>2) ? "red" : "lightblue";
    colThree3 is (pileSizeThree>3) ? "red" : "lightblue";
    colThree4 is (pileSizeThree>4) ? "red" : "lightblue";
    colThree5 is (pileSizeThree>5) ? "red" : "lightblue";
    colThree6 is (pileSizeThree>6) ? "red" : "lightblue";
    colThree7 is (pileSizeThree>7) ? "red" : "lightblue";
    colThree8 is (pileSizeThree>8) ? "red" : "lightblue";
    colThree9 is (pileSizeThree>9) ? "red" : "lightblue";
    colThree10 is (pileSizeThree>10) ? "red" : "lightblue";
    colThree11 is (pileSizeThree>11) ? "red" : "lightblue";
    colThree12 is (pileSizeThree>12) ? "red" : "lightblue";
    colThree13 is (pileSizeThree>13) ? "red" : "lightblue";
    colThree14 is (pileSizeThree>14) ? "red" : "lightblue";

    A_pictPileThree_stone0 is "outlinecolor=" // colThree0 // ",fill=solid,color=" // colThree0;
    A_pictPileThree_stone1 is "outlinecolor=" // colThree1 // ",fill=solid,color=" // colThree1;
    A_pictPileThree_stone2 is "outlinecolor=" // colThree2 // ",fill=solid,color=" // colThree2;
    A_pictPileThree_stone3 is "outlinecolor=" // colThree3 // ",fill=solid,color=" // colThree3;
    A_pictPileThree_stone4 is "outlinecolor=" // colThree4 // ",fill=solid,color=" // colThree4;
    A_pictPileThree_stone5 is "outlinecolor=" // colThree5 // ",fill=solid,color=" // colThree5;
    A_pictPileThree_stone6 is "outlinecolor=" // colThree6 // ",fill=solid,color=" // colThree6;
    A_pictPileThree_stone7 is "outlinecolor=" // colThree7 // ",fill=solid,color=" // colThree7;
    A_pictPileThree_stone8 is "outlinecolor=" // colThree8 // ",fill=solid,color=" // colThree8;
    A_pictPileThree_stone9 is "outlinecolor=" // colThree9 // ",fill=solid,color=" // colThree9;
    A_pictPileThree_stone10 is "outlinecolor=" // colThree10 // ",fill=solid,color=" // colThree10;
    A_pictPileThree_stone11 is "outlinecolor=" // colThree11 // ",fill=solid,color=" // colThree11;
    A_pictPileThree_stone12 is "outlinecolor=" // colThree12 // ",fill=solid,color=" // colThree12;
    A_pictPileThree_stone13 is "outlinecolor=" // colThree13 // ",fill=solid,color=" // colThree13;
    A_pictPileThree_stone14 is "outlinecolor=" // colThree14 // ",fill=solid,color=" // colThree14;

    %scout

    string fgcol1, fgcol2, fgcol3;

    fgcol1 = "black";
    fgcol2 = "black";
    fgcol3 = "black";

    pileButtonOne = {
    	type: TEXT
    	string: "Take from pile 1"
    	frame: ([{20,130}, 1, 16])
    	alignment: CENTRE
    	border: 1
    	bgcolor: "White"
    	fgcolor: fgcol1
    	relief: "raised"
    	sensitive: ON
    };

    pileButtonTwo = {
    	type: TEXT
    	string: "Take from pile 2"
    	frame: ([{180,130}, 1, 16])
    	alignment: CENTRE
    	border: 1
    	bgcolor: "White"
    	fgcolor: fgcol2
    	relief: "raised"
    	sensitive: ON
    };

    pileButtonThree = {
    	type: TEXT
    	string: "Take from pile 3"
    	frame: ([{340,130}, 1, 16])
    	alignment: CENTRE
    	border: 1
    	bgcolor: "White"
    	fgcolor: fgcol3
    	relief: "raised"
    	sensitive: ON
    };

    resetButton = {
    	type: TEXT
    	string: "Start New Game"
    	frame: ([{315,225}, 1, 18])
    	alignment: CENTRE
    	border: 1
    	bgcolor: "White"
    	relief: "raised"
    	sensitive: ON
    };

    screen = < pileButtonOne / pileButtonTwo / pileButtonThree / resetButton / winPileOne / winPileTwo / winPileThree >;

    %eden

    /*The response to a player removing a token from pile number 1*/

    proc takePile1 : pileButtonOne_mouse_1 {
    	if (pileButtonOne_mouse_1[2] == 4){
    		if (pileSizeOne>0) pileSizeOne--;
    	}
    }

    /*The response to a player removing a token from pile number 2*/

    proc takePile2 : pileButtonTwo_mouse_1 {
    	if (pileButtonTwo_mouse_1[2] == 4){
    		if (pileSizeTwo>0) pileSizeTwo--;
    	}
    }

    /*The response to a player removing a token from pile number 3*/

    proc takePile3 : pileButtonThree_mouse_1 {
    	if (pileButtonThree_mouse_1[2] == 4){
    		if (pileSizeThree>0) pileSizeThree--;
    	}
    }

    /*The response to a player resetting all piles of tokens*/

    proc resetGame : resetButton_mouse_1 {
    	if (resetButton_mouse_1[2] == 4) {
    		pileSizeOne = rnd(14)+1;
    		pileSizeTwo = rnd(14)+1;
    		pileSizeThree = rnd(14)+1;
    	}
    }