Example #1
0
        public override bool run()
        {
            // Arrange
            var b = new Board(false);

            b.clear();
            b.set("black king h8");
            var ML = new Agents.ML("placeholder", new Random());

            ML.b   = b;
            ML.rng = new Random();
            // moving to the right = win
            ML.mind.rules.Add(new Agents.Rule(new Agents.PieceStatement(true, Pieces.King, Coord.fromString("b1")), 1, 0, 0));
            // moving up-right = loss
            ML.mind.rules.Add(new Agents.Rule(new Agents.PieceStatement(true, Pieces.King, Coord.fromString("b2")), 0, 1, 0));
            // moving down = tie
            ML.mind.rules.Add(new Agents.Rule(new Agents.PieceStatement(true, Pieces.King, Coord.fromString("a2")), 0, 0, 1));

            // Act
            ML.playerColor = Color.Black;
            var m1 = ML.chooseMove(b.availableMoves(Color.Black));

            b.clear();
            b.set("white king a1");

            ML.playerColor = Color.White;
            var m2 = ML.chooseMove(b.availableMoves(Color.White));

            // Assert
            return(m1.Item2.row == Coord.fromString("g8").row&& m1.Item2.col == Coord.fromString("g8").col&&
                   m2.Item2.row == Coord.fromString("b1").row&& m2.Item2.col == Coord.fromString("b1").col);
        }
Example #2
0
        public override bool run()
        {
            // Arrange
            var b = new Board(false);

            b.clear();
            b.set("black king e4");
            var ML = new Agents.ML("placeholder", new Random());

            ML.b           = b;
            ML.playerColor = Color.Black;
            var p = new Agents.PieceStatement(true, Pieces.King, Coord.fromString("e5").flip());
            var r = new Agents.Rule(p, 0, 0);

            ML.mind.rules.Add(r);
            bool foundMove = false;

            while (!foundMove)
            {
                var m = ML.chooseMove(b.availableMoves(Color.Black));
                if (m.Item2.row == Coord.fromString("e5").row&&
                    m.Item2.col == Coord.fromString("e5").col)
                {
                    foundMove = true;
                }
                //b.display();
                //Console.ReadKey();
            }
            b.clear();
            b.set("black king e5");
            b.state = GameState.BlackVictory;
            ML.finish();
            b.state = GameState.Active;
            b.clear();
            b.set("black king e4");
            // Act
            int count  = 0;
            int target = 10;

            for (int x = 0; x < target; x++)
            {
                var m = ML.chooseMove(b.availableMoves(Color.Black));
                if (m.Item2.row == Coord.fromString("e5").row&&
                    m.Item2.col == Coord.fromString("e5").col)
                {
                    count++;
                }
            }

            // Assert
            return(count == target);
        }