// 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); } } } }
private void SetAllStatesForShips(LabelledDCNode ship, int length) { double possiblePosForRow = Settings.boardWidth - length + 1; // Finds all possible positions on the board for the ship double numberOfStates = Settings.boardWidth * possiblePosForRow * Settings.dimension; ulong count = 0; ship.SetNumberOfStates((ulong)numberOfStates); // Sets state labels and creates table for all states of the ship // Runs through the two orientations; horizontal and vertical for (int orientation = 0; orientation < Settings.dimension; orientation++) { for (int i = 0; i < (orientation == 0 ? Settings.boardWidth : possiblePosForRow); i++) { for (int j = 0; j < (orientation == 1 ? Settings.boardWidth : possiblePosForRow); j++) { ship.SetStateLabel(count, (orientation == 1 ? "H" : "V") + $"_{i}{j}"); ship.GetTable().SetDataItem(count++, 1 / numberOfStates); } } } }
// 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); } } } }