private GridExplorer CreateExplorer() { var explorer = new GridExplorer { AutoResetOnAreaChange = false, TileKnownRadius = Settings.TileKnownRadius, TileSeenRadius = Settings.TileSeenRadius }; explorer.Start(); return(explorer); }
public ComplexExplorer() { Settings = ProvideSettings(); Settings.LogProperties(); if (Settings.BasicExploration) { _explorer = CreateExplorer(); } else { _explorers = new Dictionary <WorldPosition, GridExplorer>(); InitNewLevel(); } }
/// <summary> /// Asks player for move. /// </summary> /// <param name="tile">Tile to be placed.</param> /// <param name="tilePlacement">Tile placement part of the move.</param> /// <param name="followerPlacement">Follower placement part of the move.</param> public void GetMove(TileScheme tile, out PlayerRequest tilePlacement, out PlayerRequest followerPlacement) { var grid = _Executor.CurrentGameState.Grid; List <Tuple <Coords, TileOrientation> > tilePlacementPossibilities = new List <Tuple <Coords, TileOrientation> >(); foreach (var baseCoords in grid.Keys) { // Check all possible placements = places neighbouring already placed tiles foreach (var neighOr in new TileOrienationEnumerator()) { var coords = baseCoords.GetNeighbouringCoords(neighOr); // If tile is already placed, skip if (grid.ContainsKey(coords)) { continue; } // Check all orientations of the tile foreach (var orientation in new TileOrienationEnumerator()) { // If cannot be placed, skip try { GridExplorer.CheckTilePlacement(grid, tile, coords, orientation, false); tilePlacementPossibilities.Add(new Tuple <Coords, TileOrientation>(coords, orientation)); } catch (GameException) { } } } } // Select one possibility var selected = tilePlacementPossibilities[_Random.Next(tilePlacementPossibilities.Count)]; tilePlacement = new PlayerRequest() { Type = PlayerRequestType.TILE_PLACEMENT, Color = Color, Coords = selected.Item1, Orientation = selected.Item2, Scheme = tile }; // Make fake executor GameExecutor executor = new GameExecutor(); executor.CurrentGameState = _Executor.CurrentGameState.Copy(); executor.ChangeTileSetType(TileSetType.PASSIVE); executor.PlaceTile(Color, tile, selected.Item1, selected.Item2); var newState = executor.CurrentGameState; followerPlacement = new PlayerRequest() { Type = PlayerRequestType.NO_FOLLOWER_PLACEMENT, Color = Color }; // Compute best move for followers int bestFollowerMoveValue = -1; // If can place if (newState.PlacedFollowers.Where(p => p.Color == Color).Count() < newState.Params.FollowerAmount) { for (int i = 0; i < tile.RegionCount; i++) { if (!GridExplorer.IsRegionOccupied(newState.Grid, selected.Item1, i)) { int newScore = GridExplorer.GetPointsForFollower(newState.Grid, selected.Item1, i, false); if (newScore > bestFollowerMoveValue) { bestFollowerMoveValue = newScore; followerPlacement.Type = PlayerRequestType.FOLLOWER_PLACEMENT; followerPlacement.Coords = selected.Item1; followerPlacement.RegionId = i; } } } } // For all own placed folowers foreach (var fp in newState.PlacedFollowers.Where(p => p.Color == Color)) { int newScore = -1; switch (newState.Grid[fp.TileCoords].Scheme.GetRegionType(fp.RegionId)) { case RegionType.MOUNTAIN: if (GridExplorer.IsRegionClosed(newState.Grid, fp.TileCoords, fp.RegionId)) { newScore = 2; // If placing is for at least 2, it is good! (else get out of here) } else if (GridExplorer.GetPointsForFollower(newState.Grid, fp.TileCoords, fp.RegionId, false) < 2) { newScore = 1; // If there are too few points, get out of here } else { newScore = -1; // Else you can wait with this follower } break; case RegionType.SEA: case RegionType.GRASSLAND: if (GridExplorer.IsRegionClosed(newState.Grid, fp.TileCoords, fp.RegionId)) { newScore = 3; // If placing is for at least 3, it is good! (else get out of here) } else if (GridExplorer.GetPointsForFollower(newState.Grid, fp.TileCoords, fp.RegionId, false) < 2) { newScore = 1; // If there are too few points, get out of here } else { newScore = -1; } break; } if (newScore > bestFollowerMoveValue) { bestFollowerMoveValue = newScore; followerPlacement.Type = PlayerRequestType.FOLLOWER_REMOVEMENT; followerPlacement.Coords = fp.TileCoords; } } }