public bool Invoke(XmlBoard b) { List<Territory> landlessTerritories = new List<Territory>(); // make a list per territory with the hexcount // (number of hexes having that territory) foreach (Territory t in b.Territories) { bool hasLand = false; foreach (Hex h in b.Hexes) { ITerritoryHex terrHex = h as ITerritoryHex; if (terrHex != null) { if (terrHex.TerritoryID.Equals(t.ID)) { hasLand=true; break; } } } // If no land found for the territory, add to landless territory list if (!hasLand) { landlessTerritories.Add(t); } } // When we found any territories that do not have any land associated, // the rule is broken. // If so, generate a verbose error message. if (landlessTerritories.Count > 0) { string _Message = String.Format("{0} territory(ies) do not have any land hexes associated: ", landlessTerritories.Count.ToString()); if (landlessTerritories.Count > 1) { for (int t = 0; t < landlessTerritories.Count; t++) { if (t != landlessTerritories.Count - 1) { _Message += String.Format("{0}, ", landlessTerritories[t].Name); } else { _Message += String.Format("and {0}.", landlessTerritories[t].Name); } } } //only one landless territory else { _Message += String.Format("{0}.", landlessTerritories[0].Name); } return false; } return true; }
public bool Invoke(XmlBoard b) { switch (b.Name) { case "Standard Settlers": return false; case "Greater Catan": return false; default: return true; } }
public bool Invoke(XmlBoard b) { if ((from t in b.Territories where t.IsMainland select t).Count() > 1) return false; else return true; }
public bool Invoke(XmlBoard b) { badHexCount = 0; // Check each seahex with a port if the port is attached to // a landhex foreach (SeaHex h in (from hh in b.Hexes.OfType<SeaHex>() where ((SeaHex)hh).XmlPort != null select hh)) { Hex neighbour = null; // if we have an uneven row, we must add an offset int offset = h.Location.H % 2 == 0 ? 0 : -1; switch (h.XmlPort.PortPosition) { case ERotationPosition.Deg0: neighbour = b.Hexes[h.Location.W + offset, h.Location.H + 1]; break; case ERotationPosition.Deg60: neighbour = b.Hexes[h.Location.W + offset + 1, h.Location.H + 1]; break; case ERotationPosition.Deg120: neighbour = b.Hexes[h.Location.W + 1, h.Location.H]; break; case ERotationPosition.Deg180: neighbour = b.Hexes[h.Location.W + offset + 1, h.Location.H - 1]; break; case ERotationPosition.Deg240: neighbour = b.Hexes[h.Location.W + offset, h.Location.H + 1]; break; case ERotationPosition.Deg300: neighbour = b.Hexes[h.Location.W - 1, h.Location.H]; break; } // when neighbour is null here, it means we tried to get an hex outside // the bounds of the array. In turn this means the port is aimed towards // the edge, which is a faulted state. if (neighbour == null) { badHexCount++; } else { ITerritoryHex terrHex = neighbour as ITerritoryHex; if (terrHex==null) { badHexCount++; } } } if (badHexCount > 0) return false; else return true; }
public bool Invoke(XmlBoard b) { /* _DiscoverHexesCount = (from h in b.Hexes where h is DiscoveryHex select h).Count(); if (_DiscoverHexesCount > b.RandomChits.CountAll) return false; else return true; */ return true; }
public bool Invoke(XmlBoard b) { if (b.UseTradeRoutes) { if (b.Territories.Count < 2) { _Message = String.Format("When having trade routes enabled, the board need at least 2 territories defined. Now you have {0} defined", b.Territories.Count); return false; } } return true; }
public bool Invoke(XmlBoard b) { if (b.Name != null) { if (b.Name.Length > 0) { return true; } else { return false; } } else { return false; } }
public bool Invoke(XmlBoard b) { foreach (Territory t in b.Territories) { if (String.IsNullOrEmpty(t.Name)) _InvalidTerritories.Add(t); } if (_InvalidTerritories.Count > 0) { _Problem = String.Format("{0} territories do not have a name!", _InvalidTerritories.Count); return false; } else { return true; } }
public bool Invoke(XmlBoard b) { //check top + bottom hexes for (int i = 0; i < b.Width; i++) { if (!(b.Hexes[i, 0] is SeaHex && b.Hexes[i,b.Height-1] is SeaHex)) { return false; } } //check left + right hexes for (int i = 1; i < b.Height; i++) { if (!(b.Hexes[0,i] is SeaHex && b.Hexes[b.Width-1,i] is SeaHex)) { return false; } } return true; }
public bool Invoke(XmlBoard b) { //create a ist of territory IDs IEnumerable<int> territoryIDs= from t in b.Territories select t.ID; foreach (Hex hex in from h in b.Hexes where h is ITerritoryHex select h) if (!territoryIDs.Contains(((ITerritoryHex)hex).TerritoryID)) hexesWithoutTerritory.Add(hex.Location); if (hexesWithoutTerritory.Count > 0) { _Problem = String.Format("{0} hexes without a territory", hexesWithoutTerritory.Count); return false; } return true; }
/// <summary> /// Whether or not player can build a town /// A town may be built when: /// -player has at least one stock town /// -a spot is available to put the town on /// </summary> /// <param name="game"></param> /// <param name="board"></param> /// <returns></returns> public bool CanBuildTown(XmlGame game, XmlBoard board) { if (StockTowns == 0) return false; // We should have at least one spot to build on if (GetTownBuildPlaces(game, board).Count == 0) return false; return true; }
public bool CanBuildShip(XmlGame game, XmlBoard board) { if (StockShips == 0) return false; if (GetShipBuildPlaces(game, board).Count == 0) return false; return true; }
/// <summary> /// Whether or not the player can build a road /// A road maybe build when: /// -A stock road is present /// -A spot is available to place a road /// </summary> /// <param name="game"></param> /// <param name="board"></param> /// <returns></returns> public bool CanBuildRoad(XmlGame game, XmlBoard board) { if (StockRoads == 0) return false; if (GetRoadBuildPlaces(game, board).Count == 0) return false; return true; }
public List<HexPoint> GetTownBuildPlaces(XmlGame game, XmlBoard board) { List<HexPoint> result = new List<HexPoint>(); // List of all ships+roads of player List<HexSide> sides = GetRoadsShips(); List<HexPoint> allPoints = new List<HexPoint>(); List<HexPoint> allTownsCities = game.AllTownsCities(); //create a list of all possible points a town can be placed on foreach (HexSide side in sides) allPoints.AddRange(side.GetNeighbourPoints());// HexPoint.BuildPointsFromSide(side)); // filter list on unique points // .Distinct doesnt wotk.... horror. See online. List<HexPoint> allUniquePoints = new List<HexPoint>(); foreach (HexPoint p in allPoints) { if (!allUniquePoints.Contains(p)) allUniquePoints.Add(p); } foreach (HexPoint point in allUniquePoints) { List<HexPoint> pointsToCheck = new List<HexPoint>(); pointsToCheck.Add(point); pointsToCheck.AddRange(point.GetNeighbours()); // if the intersection produces more then one, a neighbour is present // where a city/town is built on, so we must omit this point if (pointsToCheck.Intersect<HexPoint>(allTownsCities).Count() == 0 && // We cannot build in the sea, we need at least a nonseahex !((board.Hexes[point.Hex1] is SeaHex) && (board.Hexes[point.Hex2] is SeaHex) && (board.Hexes[point.Hex3] is SeaHex))) result.Add(point); } return result; }
public List<HexSide> GetShipBuildPlaces(XmlGame game, XmlBoard board) { // Keep track of which sides have been added on the list List<HexSide> result = new List<HexSide>(); //create a list of all possible (nonunique) sides a ship may be built List<HexSide> allSides = new List<HexSide>(); // add sides starting from town/city foreach (HexPoint point in game.PlayerOnTurn.Towns.Union(game.PlayerOnTurn.Cities)) allSides.AddRange(point.GetNeighbourSides); //add neighbouring sides from ships foreach (HexSide side in game.PlayerOnTurn.Ships) allSides.AddRange(side.GetNeighbours()); // remove all used sides by ships & roads from the list //allSides.Except(game.AllRoadsShips()); List<HexSide> emptySpots = new List<HexSide>(); // used spot from any player List<HexSide> forbiddenSides = game.AllRoadsShips(); // pirate places forbiddenSides.AddRange(game.Pirate.GetPoints()); foreach (HexSide s in allSides) { if (!forbiddenSides.Contains(s)) emptySpots.Add(s); } foreach (HexSide side in emptySpots) { // we need at least one seahex if (board.Hexes[side.Hex1] is SeaHex || board.Hexes[side.Hex2] is SeaHex) result.Add(side); } return result; }
/// <summary> /// Returns a list of places where player may build a road /// </summary> /// <param name="game"></param> /// <param name="board"></param> /// <returns></returns> public List<HexSide> GetRoadBuildPlaces(XmlGame game, XmlBoard board) { // Keep track of which sides have been added on the list to create a visual for List<HexSide> _AddedSides = new List<HexSide>(); // list of all roads+ships on the board List<HexSide> _AllTravellers = game.AllRoadsShips(); // each town has three starting points to build roads from, add them to the list foreach (HexPoint point in game.PlayerOnTurn.GetTownsCities()) _AddedSides.AddRange(point.GetNeighbourSides); // each side has two neighboring sides, add them too foreach (HexSide side in game.PlayerOnTurn.Roads) _AddedSides.AddRange(side.GetNeighbours()); // Make items in list unique, remove sides with two seahexes IEnumerable<HexSide> uniqueSides = from s in _AddedSides.Distinct() where // exclude sides with two seahexes !(board.Hexes[s.Hex1] is SeaHex && board.Hexes[s.Hex2] is SeaHex) && // exclude sides already owned by any player !(_AllTravellers.Contains(s)) select s; // convert to a list List<HexSide> result = new List<HexSide>(); foreach (HexSide side in uniqueSides) result.Add(side); return result; }
public bool Invoke(XmlBoard b) { throw new NotImplementedException(); }
private void nbNewBoard_BoardPicked(XmlBoard board) { mapEditorViewPort.Board = new BoardVisual(board); _CurrentTerritory = board.Territories[0]; SetOverlay(nbNewBoard); }
public XmlBoard Copy() { XmlBoard result = new XmlBoard(_Hexes); result.AllowedCards = _AllowedCards; result.AssignPortsBeforePlacement = _AssignPortsBeforePlacement; result.BankResources = _BankResources; result.BoardType = _BoardType; result.BonusNewIsland = _BonusNewIsland; result.Creator = _Creator; result.DevCards = _DevCards; result.IsSeafarers = _IsSeafarers; result.MaxPlayers = _MaxPlayers; result.MinPlayers = _MinPlayers; result.Name = _Name; result.RequiresInitialShips= _RequiresInitialShips; result.StockCities = _StockCities; result.StockRoads = _StockRoads; result.StockShips = _StockShips; result.StockTowns = _StockTowns; result.Territories = new ObservableCollection<Territory>(); if (_Territories != null) { foreach (Territory t in _Territories) result._Territories.Add(t.Copy()); } result._UseTradeRoutes = _UseTradeRoutes; result._VpToWin = _VpToWin; result.Width = _Width; result.Height = _Height; return result; }
public bool Invoke(XmlBoard b) { var x = (from h in b.Hexes where h.GetType() == typeof(NoneHex) select h).Count(); return x == 0; }
public void SetLadder(XmlBoard board) { MaximumCardsInHandWhenSeven = board.MaximumCardsInHandWhenSeven; MinPlayers = board.MinPlayers; MaxPlayers = board.MaxPlayers; }
/// <summary> /// Returns a list of ships allowed to move /// </summary> /// <param name="game"></param> /// <param name="board"></param> /// <returns></returns> public List<HexSide> GetMoveableShips(XmlGame game, XmlBoard board) { List<HexSide> result = new List<HexSide>(); // only create a list if we have any ships to move if (_Ships.Count > 0) { // Create a list of ships built this turn IEnumerable<HexSide> buildShips = from BuildShipAction ta in game.GameLog.OfType<BuildShipAction>() where ta.TurnID == game.CurrentTurn select ta.Intersection; // Get the moved ship if the player has done so MoveShipAction movedShip = game.GameLog.OfType<MoveShipAction>() .Where(msa => msa.TurnID == game.CurrentTurn) .SingleOrDefault(); // Create a list of allowed ships // Add all ships to the resultlist which passed the test foreach (HexSide ship in _Ships) { // allowed ships are: // // -ships not having a ship or town on other point/point neighbours // -are not part of a traderoute // Check against traderoutes whether or not ship is moveable // first see if traderouts are relevant if (game.Board.UseTradeRoutes) { // check if we have traderoutes at all if (_TradeRoutes.Count > 0) { bool isPartOfRoute = false; // TODO: optimize by first creating a list of hexsides part of players' traderoutes foreach (TradeRoute tradeRoute in _TradeRoutes) { if (tradeRoute.Contains(new RouteNode(ship))) { isPartOfRoute = true; break; } } // continue with next ship when a route uses it if (isPartOfRoute) continue; } } // If the ship is moved this turn, player is not allowed to move it again if (movedShip != null) { if (ship.Equals(movedShip)) continue; } // If the ship is built this turn, don't allow moving the ship if (buildShips.Contains(ship)) continue; // Check if a combination of point + hexside neighbours have // either a town or at least one ship // Get the points List<HexPoint> points = ship.GetNeighbourPoints(); // Make a list of neighbours of either point var sides1 = from HexSide s in points[0].GetNeighbourSides where !s.Equals(ship) select s; var sides2 = from HexSide s in points[1].GetNeighbourSides where !s.Equals(ship) select s; if ((_Ships.Contains(sides1.ElementAt(0)) || _Ships.Contains(sides1.ElementAt(1)) || _Towns.Contains(points[0])) && (_Ships.Contains(sides2.ElementAt(0)) || _Ships.Contains(sides2.ElementAt(1)) || _Towns.Contains(points[1]))) { // A ship has a town or 1-2 ships at both sides, ignore ship continue; } // if a ship has no spot to move to, it isn't moveable either if (GetShipBuildPlaces(game, board, ship).Count == 0) continue; // we passed the test, we have a moveable ship result.Add(ship); } } return result; }
private bool IsAllSea(HexPoint point, XmlBoard board) { return false; /* if (board.Hexes[point.Hex1] is SeaHex && board.Hexes[point.Hex2] is SeaHex && board.Hexes[point.Hex3] is SeaHex) return true; else return false; */ }
public BoardVisual(XmlBoard board) : this() { Board = board; }
public bool Invoke(XmlBoard b) { _DevCount = b.DevCards.CountAll; if (_DevCount < 25) return false; return true; }
public bool Invoke(XmlBoard b) { if (b.MinPlayers > b.MaxPlayers) return false; return true; }