コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="maxSearchDepth"></param>
        /// <param name="calculator"></param>
        /// <param name="placementStrategy">If specified, AB will place pieces, otherwise runs in NoPiecePlacing fidelity</param>
        public AlphaBetaMoveMaker(int maxSearchDepth, IUtilityCalculator calculator, IPlacementStrategy placementStrategy = null)
        {
            _thisThreadPool = _pool.Value;
            _maxSearchDepth = maxSearchDepth;
            _calculator     = calculator;

            if (placementStrategy != null)
            {
                _placementMaker = new PlacementMaker(placementStrategy);
            }
        }
コード例 #2
0
        private void TestStrategy(IPlacementStrategy strategy, int expectPiecesPlaced)
        {
            var pieces = new PieceCollection();

            pieces.Populate(SimulationHelpers.GetRandomPieces(1));
            int placed = 0;

            var board = new BoardState();

            for (var i = 0; i < pieces.Count; i++)
            {
                if (strategy.TryPlacePiece(board, PieceDefinition.AllPieceDefinitions[pieces[i]], in pieces, i + 1, out var bitmap, out var x, out var y))
                {
                    placed++;
                    board.Place(bitmap, x, y);
                }
コード例 #3
0
        static void TestPlacementOnly()
        {
            var stopwatch = Stopwatch.StartNew();

            var strategies = new IPlacementStrategy[]
            {
                //FirstPossiblePlacementStrategy.Instance,
                //SimpleClosestToWallAndCornerStrategy.Instance,
                //ClosestToCornerLeastHolesTieBreakerPlacementStrategy.Instance,
                //NextToPieceEdgeLeastHolesTieBreakerPlacementStrategy.Instance,
                //TightPlacementStrategy.InstanceDoubler,
                //TightPlacementStrategy.InstanceIncrement,
                ExhaustiveMostFuturePlacementsPlacementStrategy.Instance1_1,
                ExhaustiveMostFuturePlacementsPlacementStrategy.Instance1_6,
                new BestEvaluatorStrategy(TuneablePattern2x2BoardEvaluator.HandTuned),
                new BestEvaluatorStrategy(TuneablePattern2x2BoardEvaluator.Tuning1),
            };

            //foreach (var strategy in strategies)
            Parallel.ForEach(strategies, (strategy) =>
            {
                //var rand = new Random(0);
                int totalPlaced = 0;

                for (var i = 0; i < 100; i++)
                {
                    var pieces = new PieceCollection();
                    pieces.Populate(SimulationHelpers.GetRandomPieces(i));
                    int index  = 0;
                    int placed = 0;

                    var board = new BoardState();

                    while (true)
                    {
                        var piece = pieces[index];
                        pieces.RemoveAt(index);
                        index = index % pieces.Count;

                        if (strategy.TryPlacePiece(board, PieceDefinition.AllPieceDefinitions[piece], in pieces, index, out var bitmap, out var x, out var y))
                        {
                            placed++;
                            board.Place(bitmap, x, y);

                            //Advance to a random one in the next 6 pieces (TODO: Would be good to bias this towards 1-3 as these are more likely)
                            //index = (index + rand.Next(0, 6)) % pieces.Count;
                        }
コード例 #4
0
ファイル: Placer.cs プロジェクト: nmjmdr/consolebattleships
 public Placer(Grid grid, IPlacementStrategy placementStrategy)
 {
     strategy = placementStrategy;
 }
コード例 #5
0
 public PlacementMaker(IPlacementStrategy strategy)
 {
     _strategy = strategy;
 }
コード例 #6
0
 // mainly to test
 public Board(Grid grid, IPlacementStrategy strategy)
 {
     this.grid = grid;
     this.placementStrategy = strategy;
     this.placer            = new Placer(grid, this.placementStrategy);
 }
コード例 #7
0
 public Board()
 {
     this.grid = new Grid(GridSize);
     this.placementStrategy = new RandomPlacementStrategy(this.grid);
     this.placer            = new Placer(grid, this.placementStrategy);
 }