Example #1
0
        /// <summary>
        /// Calculates a score for the given input data. The higher the score, the more
        /// likely that the input image represents the value of <c>Symbol</c>.
        /// </summary>
        public int Score(WrappedBitmap inputData)
        {
            if (inputData == null)
            {
                throw new ArgumentNullException(nameof(inputData));
            }

            return(_scorer.Score(inputData));
        }
        public Edge Claim(GameState gameState)
        {
            var map    = gameState.Map;
            var punter = gameState.CurrentPunter;

            var connectedComponents = graphVisitor.GetConnectedComponents(map);
            var punters             = connectedComponents.GetPunters;
            var scoreByPunter       = punters
                                      .ToDictionary(x => x,
                                                    x => scorer.Score(new GameState {
                Map = map, CurrentPunter = new Punter {
                    Id = x
                }
            }));

            var reachableNodeIds = GetReachableNodesFromMines(map, punter);

            var bestIncreasingPathEdge = map
                                         .Edges
                                         .Where(x => x.Punter == null)
                                         .Where(x => reachableNodeIds.Contains(x.Source.Id) ||
                                                reachableNodeIds.Contains(x.Target.Id) ||
                                                x.Source.IsMine ||
                                                x.Target.IsMine)
                                         .OrderByDescending(x => GetWeight(x, punter, connectedComponents))
                                         .ThenByDescending(x => CountFreeNeighborEdges(gameState, x))
                                         .FirstOrDefault();

            if (bestIncreasingPathEdge != null)
            {
                return(bestIncreasingPathEdge);
            }

            var bestPunter = new Punter
            {
                Id = scoreByPunter.OrderByDescending(x => x.Value).First().Key
            };

            if (bestPunter.Id != punter.Id)
            {
                return(map
                       .Edges
                       .Where(x => x.Punter == null)
                       .OrderByDescending(x => !connectedComponents.IsInSameComponent(x.Source.Id, x.Target.Id, punter.Id))
                       .ThenByDescending(x => HasNeighborPunterEdge(map, x, bestPunter))
                       .ThenBy(x => Guid.NewGuid())
                       .FirstOrDefault(x => x.Punter == null));
            }

            return(map
                   .Edges
                   .Where(x => x.Punter == null)
                   .OrderByDescending(x => CountFreeNeighborEdges(gameState, x))
                   .ThenBy(x => Guid.NewGuid())
                   .FirstOrDefault(x => x.Punter == null));
        }
Example #3
0
        public void Defers_Scoring_To_Scorer()
        {
            const int     mockedScore = 555;
            WrappedBitmap wb          = new WrappedBitmap(new Bitmap(1, 1));

            _scorer.Score(null).ReturnsForAnyArgs(mockedScore);

            var score = _recogniser.Score(wb);

            _scorer.Received(1).Score(wb);
            Assert.AreEqual(mockedScore, score);
        }
        public Edge Claim(GameState gameState)
        {
            var map    = gameState.Map;
            var punter = gameState.CurrentPunter;

            var strictComponents = graphVisitor.GetConnectedComponents(map);

            var punters       = strictComponents.GetPunters;
            var scoreByPunter = punters
                                .ToDictionary(x => x,
                                              x => scorer.Score(new GameState {
                Map = map, CurrentPunter = new Punter {
                    Id = x
                }
            }));

            var reachableNodeIds = GetReachableNodesFromMines(map, punter);

            var rushingEdges = map
                               .Edges
                               .Where(x => x.Source.IsMine || x.Target.IsMine)
                               .Where(x => x.Punter == null)
                               .ToArray();

            maxScore = rushingEdges.Length > 0 ? rushingEdges.Max(x => GetWeight(x, punter, strictComponents)) : 1;

            var bestRushingPathEdge = rushingEdges
                                      .OrderByDescending(x => CapturedMinesCount(gameState, x))
                                      .ThenByDescending(x => GetWeight(x, punter, strictComponents))
                                      .ThenBy(x => CountMyNeighborEdges(gameState, x))
                                      .ThenBy(x => GetShortestDistanceToMineInOtherComponent(x, strictComponents, punter))
                                      .ThenByDescending(x => CountFreeNeighborEdges(gameState, x))
                                      .FirstOrDefault();

            if (bestRushingPathEdge != null)
            {
                return(bestRushingPathEdge);
            }

            var bridgeEdges = graphVisitor
                              .GetBridgesInAvailableEdges(map, punter)
                              .Where(x => x.Punter == null)
                              .ToArray();

            var goodBridges = bridgeEdges
                              .Select(x => new { edge = x, weight = GetWeightForBridge(map, x, punter, reachableNodeIds) })
                              .Where(x => x.weight > 0)
                              .ToArray();

            bridgeMaxScore = goodBridges.Length > 0 ? goodBridges.Max(x => x.weight) : 1;
            maxScore       = goodBridges.Length > 0 ? goodBridges.Max(x => GetWeight(x.edge, punter, strictComponents)) : 1;

            var bestBridge = goodBridges
                             .Select(x => x.edge)
                             .OrderByDescending(x => GetWeightForBridge(map, x, punter, reachableNodeIds))
                             .ThenByDescending(x => GetWeight(x, punter, strictComponents))
                             .ThenBy(x => GetShortestDistanceToMineInOtherComponent(x, strictComponents, punter))
                             .ThenByDescending(x => CountFreeNeighborEdges(gameState, x))
                             .FirstOrDefault();

            if (bestBridge != null)
            {
                return(bestBridge);
            }

            var increasingEdges = map
                                  .Edges
                                  .Where(x => x.Punter == null)
                                  .Where(x => reachableNodeIds.Contains(x.Source.Id) ||
                                         reachableNodeIds.Contains(x.Target.Id) ||
                                         x.Source.IsMine ||
                                         x.Target.IsMine)
                                  .ToArray();

            maxScore = increasingEdges.Length > 0
                ? increasingEdges.Max(x => GetWeight(x, punter, strictComponents))
                : 1;

            var bestIncreasingPathEdge = increasingEdges
                                         .OrderByDescending(x => GetWeight(x, punter, strictComponents))
                                         .ThenBy(x => GetShortestDistanceToMineInOtherComponent(x, strictComponents, punter))
                                         .ThenByDescending(x => CountFreeNeighborEdges(gameState, x))
                                         .FirstOrDefault();

            if (bestIncreasingPathEdge != null)
            {
                return(bestIncreasingPathEdge);
            }

            var bestPunter = new Punter
            {
                Id = scoreByPunter.OrderByDescending(x => x.Value).First().Key
            };

            if (bestPunter.Id != punter.Id)
            {
                var enemyBridges = graphVisitor.GetBridgesInAvailableEdges(map, bestPunter)
                                   .Where(x => x.Punter == null)
                                   .ToArray();

                if (enemyBridges.Any())
                {
                    return(enemyBridges
                           .OrderByDescending(
                               x => !strictComponents.IsInSameComponent(x.Source.Id, x.Target.Id, punter.Id))
                           .ThenByDescending(x => HasNeighborPunterEdge(map, x, bestPunter))
                           .ThenBy(x => Guid.NewGuid())
                           .FirstOrDefault(x => x.Punter == null));
                }

                return(map
                       .Edges
                       .Where(x => x.Punter == null)
                       .OrderByDescending(x => !strictComponents.IsInSameComponent(x.Source.Id, x.Target.Id, punter.Id))
                       .ThenByDescending(x => HasNeighborPunterEdge(map, x, bestPunter))
                       .ThenBy(x => Guid.NewGuid())
                       .FirstOrDefault(x => x.Punter == null));
            }

            if (bridgeEdges.Any())
            {
                return(bridgeEdges
                       .Where(x => x.Punter == null)
                       .OrderBy(x => GetShortestDistanceToMineInOtherComponent(x, strictComponents, punter))
                       .ThenByDescending(x => CountFreeNeighborEdges(gameState, x))
                       .ThenBy(x => Guid.NewGuid())
                       .FirstOrDefault(x => x.Punter == null));
            }

            return(map
                   .Edges
                   .Where(x => x.Punter == null)
                   .OrderBy(x => GetShortestDistanceToMineInOtherComponent(x, strictComponents, punter))
                   .ThenByDescending(x => CountFreeNeighborEdges(gameState, x))
                   .ThenBy(x => Guid.NewGuid())
                   .FirstOrDefault(x => x.Punter == null));
        }
Example #5
0
        public static void TheRoundIsScored(IScorer scorer, IList <Player> players, int roundNumber, out Round round)
        {
            var scores = scorer.Score(players);

            round = new Round(roundNumber, scores);
        }
Example #6
0
 /// <summary>
 /// Evaluate player hands and scorer each player from weakest to strongest hand.
 /// </summary>
 public IList <Score> ScorePlayers(IList <Player> players)
 {
     return(_scorer.Score(players));
 }