Example #1
0
        // 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);
                    }
                }
            }
        }
Example #2
0
 private void MakeStatesHelper(BooleanDCNode node, int i, string name)
 {
     node.SetNumberOfStates(2);
     node.SetStateLabel(0, "False");
     node.SetStateLabel(1, "True");
     node.AddParent(shipList[i]);
     node.SetName(name);
 }
Example #3
0
        private void MakeStatesForOverlap(List <LabelledDCNode> shipList)
        {
            BooleanDCNode overlap;

            for (int i = 0; i < shipList.Count; i++)
            {
                for (int j = i + 1; j < shipList.Count; j++)
                {
                    overlap = new BooleanDCNode(battleship);
                    MakeStatesHelper(overlap, i, $"Overlap{i}_{j}");
                    overlap.AddParent(shipList[j]);
                    SetStatesForOverlaps(overlap, shipList[i], shipList[j]);
                    overlap.SelectState(0);
                }
            }
        }
Example #4
0
        private void MakeTileStates(string name)
        {
            List <BooleanDCNode> tileList = new List <BooleanDCNode>();
            BooleanDCNode        tile     = new BooleanDCNode(battleship);
            int templistIndex             = 0;
            int constraintNumber          = 1;

            // Sets states for the two first tiles
            MakeStatesHelper(tile, 0, $"{name}{constraintNumber++}");
            tile.AddParent(shipList[1]);
            SetTileStateWithTwoShips(tile, shipList[0], shipList[1], name);
            tileList.Add(tile);
            // Sets states for the rest of the tiles
            for (int i = 2; i < shipList.Count; i++)
            {
                tile = new BooleanDCNode(battleship);
                MakeStatesHelper(tile, i, $"{name}{constraintNumber++}");
                tile.AddParent(tileList[templistIndex]);
                SetTileStateWithOneShip(tile, shipList[i], tileList[templistIndex++], name);
                tileList.Add(tile);
            }
            tilesList.Add(tileList);
        }
Example #5
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);
                    }
                }
            }
        }
Example #6
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);
                    }
                }
            }
        }