/// <summary> /// Попробовать привязаться к конкретной ситуации /// </summary> /// <param name="situationPrototype">Ситуация, к которой мы хотим привязаться (которую мы проверяем)</param> /// <param name="situationExample">Текущий фрейм-экземпляр</param> /// <returns>true - если привязалась. false - в противном случае.</returns> private bool checkSituation(Frame situationPrototype, FrameExample situationExample, int recursionLevel=0) { log("Проверяем ситуацию: " + situationPrototype.FrameName, recursionLevel); bool result = true; if (passedSituationsIds.Contains(situationPrototype.FrameId)) result = true; else { if (failedSituationsIds.Contains(situationPrototype.FrameId)) result = false; else { checkedFramesIDs.Add(situationPrototype.FrameId); List<Slot> boundedSlots = new List<Slot>(); //привязавшиеся слоты Dictionary<string, object> slotValues = new Dictionary<string, object>(); //значения привязавшихся слотов foreach (Slot slot in situationPrototype.FrameSlots) { if (slot.SlotMarker != null && !situationExample.ContainsSlot(slot.SlotName)) { object slotValue; // if (situationExample.ContainsSlot(slot.SlotName)) // slotValue = situationExample.Value(slot.SlotName); // else if (!situationExample.ContainsSlot(slot.SlotName)) { slotValue = boundSlot(slot, situationPrototype, situationExample); if (slotValue == null) { result = false; break; } else { boundedSlots.Add(slot); slotValues.Add(slot.SlotNameTrimmed, slotValue); } } } } if (result) { log("+ Ситуация " + situationPrototype.FrameName + " прошла проверку (исключая родителей).", recursionLevel); passedSituationsIds.Add(situationPrototype.FrameId); foreach (Slot boundedSlot in boundedSlots) { if (!situationExample.ContainsSlot(boundedSlot.SlotName)) { situationExample.AddSlot(boundedSlot); situationExample.SetValue(boundedSlot.SlotName, slotValues[boundedSlot.SlotNameTrimmed]); } } if (situationPrototype.GetParentFrame() != null) { log("Привязка родителей ситуации " + situationPrototype.FrameName + "...", recursionLevel); result = checkSituation(situationPrototype.GetParentFrame(), situationExample, recursionLevel+1); } } else { failedSituationsIds.Add(situationPrototype.FrameId); log("- Ситуация " + situationPrototype.FrameName + " не привязалась.", recursionLevel); } if (result) { log("Ситуация " + situationPrototype.FrameName + " Привязалась полностью.", recursionLevel); //TODO: //тут еще как-то, думаю, будут использоваться задания отсутствия //плюс, возможно, нужно будет добпвлять не только привязавшиеся слоты, но и вообще все. } } } return result; }
public object doMLVForPoint(GameCell gameCell) { log(); object result="Клетка пуста."; if (gameCell.FrameExample != null && gameCell.FrameExample.BaseFrame != null && gameCell.FrameExample.BaseFrame.FrameId != -1) { situations = gatherSituationsList(); situationExample = new FrameExample(); Slot slotAgent = new Slot(); slotAgent.SlotName = "agent"; slotAgent.SlotType = SlotType.Frame; slotAgent.SlotInheritance = SlotInherit.Override; slotAgent.IsSystem = false; situationExample.AddSlot(slotAgent); situationExample.SetValue("agent", gameCell.FrameExample); Frame situationToCheck = this.getNextFrameToCheck(); while (!situationExample.ContainsSlot("action") && situationToCheck != null) //пока не определили целевой слот "действие" { checkedFramesIDs.Add(situationToCheck.FrameId); if (checkSituation(situationToCheck, situationExample)) { Slot actionSlot = situationToCheck.GetSlotByName("action"); situationExample.AddSlot(actionSlot); situationExample.SetValue(actionSlot.SlotName, actionSlot.SlotDefault); } situationToCheck = this.getNextFrameToCheck(); } result = null; if (situationExample.ContainsSlot("action")) result = situationExample.Value("action"); } return result; }
/// <summary> /// Задает размер поля (в ячейках) по вертикали и горизонтали. !ВАЖНО: игровое поле создается заново! Все данные о ячейках стираются! /// </summary> /// <param name="rowCount">Число ячеек по вертикали (число рядов)</param> /// <param name="columnCount">Число ячеек по горизонтали (число столбцов)</param> public void setSize(int rowCount, int columnCount) { if (rowCount < 1 || columnCount < 1) throw new ArgumentException("Row and column counts have to be more than zero! size: (rc:"+rowCount.ToString()+" cc:"+columnCount.ToString()+")"); cells = new List<List<GameCell>>(rowCount); //int xCoord = 0, yCoord = 0; this.SuspendLayout(); this.Controls.Clear(); for (int i = 0; i < RowCount; ++i) { //xCoord = 0; List<GameCell> row = new List<GameCell>(columnCount); for (int j = 0; j < ColumnCount; ++j) { Frame framePrototype = new Frame(); framePrototype.FrameId = -1; Slot slotImage = new Slot(); slotImage.SlotName = "image"; slotImage.SlotInheritance = SlotInherit.Override; slotImage.SlotType = SlotType.String; slotImage.SlotDefault = "Images\\unknown.png"; slotImage.SlotId = 0; slotImage.ParentId = framePrototype.FrameId; Slot slotRow = new Slot(); slotRow.SlotName = "Row"; slotRow.SlotType = SlotType.Integer; slotRow.SlotInheritance = SlotInherit.Override; slotRow.SlotId = 1; slotRow.ParentId = framePrototype.FrameId; Slot slotColumn = new Slot(); slotColumn.SlotName = "Column"; slotColumn.SlotType = SlotType.Integer; slotColumn.SlotInheritance = SlotInherit.Override; slotColumn.SlotId = 1; slotColumn.ParentId = framePrototype.FrameId; framePrototype.FrameSlots.Add(slotImage); framePrototype.FrameSlots.Add(slotRow); framePrototype.FrameSlots.Add(slotColumn); FrameExample frameExample = new FrameExample(framePrototype); frameExample.SetValue("image", "Images\\grass.jpg"); frameExample.SetValue("Row", i); frameExample.SetValue("Column", j); GameCell cell = new GameCell(this, i, j, cellSize, frameExample); cell.GameCellClicked += new GameCellClickedEventHandler(cell_GameCellClicked); row.Add(cell); //cell.Location = new Point(xCoord, yCoord); this.Controls.Add(cell); //xCoord += cellSize+cellOffset; } cells.Add(row); //yCoord += cellSize+cellOffset; } this.rowCount = rowCount; this.columnCount = columnCount; this.ResumeLayout(); this.layoutCells(); }