// Compares to previous tile instead of a second ship private void SetTileStateWithOneShip(BooleanDCNode tile, LabelledDCNode ship, BooleanDCNode node, string name) { int shipLength = Settings.boardWidth + 1 - ship.GetTable().GetData().Length / (Settings.dimension * Settings.boardWidth); int xCoord = name[0] - 'A'; int yCoord = name[1] - '0'; Point tilePlace = new Point(xCoord, yCoord); List <Point> shipPoints; bool labelIsTrue; string shipName; ulong count = 0; for (ulong i = 0; i < 2; i++) { labelIsTrue = node.GetStateLabel(i) == "True"; for (ulong j = 0; j < ship.GetNumberOfStates(); j++) { shipName = ship.GetStateLabel(j); shipPoints = ReturnCoordinates(shipLength, shipName); if (labelIsTrue || shipPoints.Contains(tilePlace)) { tile.GetTable().SetDataItem(count++, 0); tile.GetTable().SetDataItem(count++, 1); } else { tile.GetTable().SetDataItem(count++, 1); tile.GetTable().SetDataItem(count++, 0); } } } }
// Compares to two ships private void SetTileStateWithTwoShips(BooleanDCNode tile, LabelledDCNode secondShip, LabelledDCNode firstShip, string name) { int firstShipLength = Settings.boardWidth + 1 - firstShip.GetTable().GetData().Length / (Settings.dimension * Settings.boardWidth); int secondShipLength = Settings.boardWidth + 1 - secondShip.GetTable().GetData().Length / (Settings.dimension * Settings.boardWidth); int xCoord = name[0] - 'A'; int yCoord = name[1] - '0'; List <Point> firstPoints; List <Point> secondPoints; Point tilePlace = new Point(xCoord, yCoord); ulong count = 0; string firstName, secondName; for (int i = 0; i < (int)firstShip.GetNumberOfStates(); i++) { firstName = firstShip.GetStateLabel((ulong)i); // Gets coordinates for first ship firstPoints = ReturnCoordinates(firstShipLength, firstName); for (int j = 0; j < (int)secondShip.GetNumberOfStates(); j++) { secondName = secondShip.GetStateLabel((ulong)j); // Gets coordinates for second ship secondPoints = ReturnCoordinates(secondShipLength, secondName); if (secondPoints.Contains(tilePlace) || firstPoints.Contains(tilePlace)) { tile.GetTable().SetDataItem(count++, 0); tile.GetTable().SetDataItem(count++, 1); } else { tile.GetTable().SetDataItem(count++, 1); tile.GetTable().SetDataItem(count++, 0); } } } }
private void SetStatesForOverlaps(BooleanDCNode overlap, LabelledDCNode secondShip, LabelledDCNode firstShip) { int firstShipLength = Settings.boardWidth + 1 - firstShip.GetTable().GetData().Length / (Settings.dimension * Settings.boardWidth); int secondShipLength = Settings.boardWidth + 1 - secondShip.GetTable().GetData().Length / (Settings.dimension * Settings.boardWidth); List <Point> firstPoints; List <Point> secondPoints; ulong count = 0; string firstName, secondName; // Iterates through entire tables on constraint's parents for (int i = 0; i < (int)firstShip.GetNumberOfStates(); i++) { firstName = firstShip.GetStateLabel((ulong)i); // Gets coordinates for first ship firstPoints = ReturnCoordinates(firstShipLength, firstName); for (int j = 0; j < (int)secondShip.GetNumberOfStates(); j++) { secondName = secondShip.GetStateLabel((ulong)j); // Gets coordinates for second ship secondPoints = ReturnCoordinates(secondShipLength, secondName); // Checks if any ship coordinates overlap if (CheckForOverlap(firstPoints, secondPoints)) { overlap.GetTable().SetDataItem(count++, 0); overlap.GetTable().SetDataItem(count++, 1); } else { overlap.GetTable().SetDataItem(count++, 1); overlap.GetTable().SetDataItem(count++, 0); } } } }