//##################################################################################### protected void AttachEvent(IBoardView view) { if (view != null) { view.WhenLeftDown += this.OnLeftDown; view.WhenLeftUp += this.OnLeftUp; view.WhenRightDown += this.OnRightDown; view.WhenRightUp += this.OnRightUp; view.WhenCursorMove += this.OnCursorMove; view.WhenKeyDown += this.OnKeyDown; view.WhenMouseWheelScroll += this.OnMouseWheelScroll; view.WhenInputText += this.OnInputText; view.WhenRequestUserColor += this.OnRequestUserColor; view.WhenLongLeftClick += this.OnLongLeftClick; view.WhenInputMail += this.OnInputMail; view.WhenInputCopApplicationForm += this.OnInputCopApplicationForm; view.WhenDevelopTech += this.OnDevelopTech; view.WhenDiscardTech += this.OnDiscardTech; view.WhenProduceProduct += this.OnProduceProduct; view.WhenDiscardProduct += this.OnDiscardProduct; view.WhenRequestTechProgram += this.OnRequestTechProgram; view.WhenSellTech += this.OnSellTech; view.WhenBuyTech += this.OnBuyTech; view.WhenSellProduct += this.OnSellProduct; view.WhenBuyProduct += this.OnBuyProduct; } }
protected override void MouseUp(IBoardView board, Coord coord) { var player = PlayerAgent; var existing = BoardView.Get(coord); if (existing == null) { player.PushRequest(new MovePiece(PlayerAgent.Model, Agent.Model, coord), Response); return; } if (ReferenceEquals(existing, this)) { return; } // TODO: allow for mounting if (existing.SameOwner(this)) { ReturnToStart(); return; } player.PushRequest(new Battle(PlayerAgent.Model, Agent.Model, existing.Agent.Model), Response); }
private ConstrainResult ApplyConstraint(ConstraintListWrapper constraint) { BoardState state = boardManager.CurrentLayer; IBoardView boardView = constraint.CreateBoardView(state); long oldCost = boardView.ConstraintState.Cost; Debug.Assert(oldCost >= 0); constraint.Constraint.CalculateEstimatedCost(boardView); long newCost = boardView.ConstraintState.Cost; Debug.Assert(newCost <= oldCost); if (newCost <= ENUMERATION_THRESHOLD || oldCost == newCost) { // We've judged that it is cheap enough to brute force hit this, or we don't have any other option return(constraint.Constraint.ConstrainBoard(boardView)); } else { constraint.IsDirty = true; dirtyConstraints.Enqueue(newCost, constraint); return(ConstrainResult.Success); } }
private void Start() { _model = new BoardModel(); _model.Setup(BOARD_SIZE, MINES); _view = GetComponent <BoardView>(); Initialize(); }
private ConstrainResult Emit(IBoardView boardView, ConstraintState state) { ColorSet[] colors = new ColorSet[boardView.Count]; for (int boardIndex = 0; boardIndex < boardView.Count; boardIndex++) { colors[boardIndex] = ColorSet.CreateSingle(ColorSpace.Empty); for (int constraintIndex = 0; constraintIndex < state.minValues.Length; constraintIndex++) { int min = state.minValues[constraintIndex]; int max = state.maxValues[constraintIndex]; if (boardIndex >= min && boardIndex <= max) { Constraint constraint = constraintSet[constraintIndex]; // Check for a guaranteed region long offset = (max - min + 1) - constraint.number; if (boardIndex >= min + offset && boardIndex <= max - offset) { // If this is a guaranteed region, then we know it can't be any other possible color, colors[boardIndex] = ColorSet.CreateSingle(constraint.color); break; } colors[boardIndex] = colors[boardIndex].AddColor(constraint.color); } } } return(boardView.IntersectAll(colors)); }
// Create the view public BoardViewFactory() { var prefab = Resources.Load <GameObject>("Prefabs/Board"); var instance = UnityEngine.Object.Instantiate(prefab); View = instance.GetComponent <BoardView>(); }
public GameStatusObserverDecorator(IGameStatusObserver gameStatusObserver, IBoardView boardView, IGuiManager guiManager) { GameStatusObserver = gameStatusObserver.CheckNull(); BoardView = boardView.CheckNull(); GuiManager = guiManager.CheckNull(); }
public bool Reset(IBoardView boardView) { Debug.Assert(NextNode != null); int start = Math.Max(min, PrevNode.MinEnd); return(MoveWorker(start, boardView)); }
private void UpdateViewToMatchModel(IBoardModel model, IBoardView view) { for (int row = 0; row < this.boardModel.BoardSize; row++) { for (int column = 0; column < this.boardModel.BoardSize; column++) { this.boardView.UpdateCellState(column, row, this.boardModel.Board[column, row]); } } }
public GamePresenter(IBoardView boardView, IGameMaster gameMaster, IBoardModel boardModel, IBoardViewModel boardViewModel) { BoardView = boardView.CheckNull(); GameMaster = gameMaster.CheckNull(); BoardModel = boardModel.CheckNull(); BoardViewModel = boardViewModel.CheckNull(); }
public FormsBoardLabeler(IBoardView i_BoardView) { r_BoardView = i_BoardView; r_BoardView.SetEventListener(this); InitializeComponent(); initializeBoardComponent(); m_LetterLabels = new CreateLetterLabels(this).createLabels(); m_NumberLabels = new CreateNumberLabels(this).createLabels(); new CreateMiddleLabel(this).createLabels(); }
/// <summary> /// Construct a board presenter that will manage the given board view /// </summary> /// <param name="view">The board view</param> public BoardPresenter(IBoardView view) { this.view = view; this.board = new Checkerboard(); this.boardRules = new CheckersRules(); this.turn = blackPlayerInfo; boardRules.ResetBoard(board); view.SetBoardState(board.Copy()); }
public (IBoardModel, IBoardView) GetBoard(Renderer blocksPrefab, Theme blocks, float blockScale, Transform blocksParent, int numLines, int numColumns) { // Create Builder BoardModel.Builder modelBuilder = new BoardModel.Builder(); BoardView.Builder viewBuilder = new BoardView.Builder(); IBoardModel boardModel = modelBuilder.Build(numLines, numColumns); IBoardView boardView = viewBuilder.Build(boardModel, blocksPrefab, blocks, blockScale, blocksParent); return(boardModel, boardView); }
public bool Verify(IBoardView boardView) { for (int i = Start; i < End; i++) { bool valid = boardView[i].HasColor(ColorSpace.Empty); if (!valid) { return(false); } } return(true); }
private void CalculateMinMaxRanges(IBoardView boardView) { ConstraintState state = boardView.ConstraintState; AdjustInitialMins(state); AdjustInitialMaxs(state); CalculateMin(boardView, state); CalculateMax(boardView, state); // TODO: roll these into CalculateMin/Max AdjustInitialMins(state); AdjustInitialMaxs(state); }
private bool AreCompatible(IBoardView boardColors, IReadOnlyList <uint> segmentColors) { Debug.Assert(boardColors.Count == segmentColors.Count); for (int i = 0; i < segmentColors.Count; i++) { if (!boardColors[i].HasColor(segmentColors[i])) { return(false); } } return(true); }
public TalismanBoardController(ITalismanBoard board, IBoardView view) : base(board, view) { for (int i = 0; i < Board.SectionsCount; i++) { TalismanBoardSection section = Board[i]; for (int j = 0; j < section.CellsCount; j++) { foreach (ITalismanAction action in section[i].Actions) { action.OnApplied += () => ActionEnded?.Invoke(); } } } }
public bool VerifyNextMoved(IBoardView boardView) { int newEnd = NextNode.Start; int newLength = newEnd - Start; int minLength = IsRequired ? 1 : 0; if (newLength < minLength) { return(false); } End = newEnd; return(Verify(boardView)); }
private void DrawHoldPiece(IBoardModel boardModel, IBoardView boardView, ITetrominoModel tetromino) { for (int line = 0; line < boardModel.NumLines; line++) { for (int column = 0; column < boardModel.NumColumns; column++) { int blockType = tetromino.BlocksPreview[line, column]; boardModel.Blocks[line, column] = blockType; } } // Update view after showing tetromino boardView.UpdateView(boardModel, _blocks); }
// Controller depends on interfaces for the model and view public BoardController(IBoardModel model, IBoardView view) { this.model = model; this.view = view; // Listen to input from the view view.OnClicked += HandleClicked; // Listen to changes in the model model.OnBlocksChanged += HandleBlocksChanged; // Set the view's initial state by syncing with the model SyncBlocks(); }
public bool Reset(IBoardView boardView) { Start = PrevNode != null ? PrevNode.End : 0; if (NextNode == null) { return(Verify(boardView)); } else { End = MinEnd; } return(NextNode.Reset(boardView)); }
public BoardController(IBoardView view, Board model, System.Func <IPieceView> createNewPieceFunc) { this.view = view; this.model = model; // Initialization view.Size = model.BoardLength; foreach (Piece piece in model.Pieces) { IPieceView newPieceView = createNewPieceFunc.Invoke(); newPieceView.Board = view; pieces.Add(new PieceController(piece, newPieceView)); } }
void CreateBoard(GameObject[,] slotContent) { BoardModelFactory modelFactory = new BoardModelFactory(); boardModel = modelFactory.Create(new SlotModelFactory(), rows, columns); BoardViewFactory viewFactory = new BoardViewFactory(); boardView = viewFactory.Create(new SlotViewFactory(), rows, columns, transform); BoardControllerFactory controllerFactory = new BoardControllerFactory(); boardController = controllerFactory.Create(new SlotControllerFactory(), boardModel, boardView); boardModel.SetSlotsContent(slotContent); }
private ConstrainResult VerifyValid(IBoardView boardView) { int constraintIndex = 0; int colorCount = 0; for (int i = 0; i < boardView.Count; i++) { ColorSet color = boardView[i]; if (!color.IsSingle()) { return(ConstrainResult.Success); } uint currentColor = color.GetSingleColor(); if (currentColor == 0) { if (colorCount != 0) { return(ConstrainResult.NoSolution); } } else { if (constraintIndex >= constraintSet.Count) { return(ConstrainResult.NoSolution); } if (currentColor == constraintSet[constraintIndex].color) { colorCount++; if (colorCount == constraintSet[constraintIndex].number) { constraintIndex++; colorCount = 0; } } else { return(ConstrainResult.NoSolution); } } } return(ConstrainResult.Success); }
private void SetAllConstraintsDirty() { BoardState boardState = boardManager.CurrentLayer; foreach (var constr in rowConstraintList) { IBoardView boardView = constr.CreateBoardView(boardState); constr.Constraint.CalculateEstimatedCost(boardView); Enqueue(constr); } foreach (var constr in colConstraintList) { IBoardView boardView = constr.CreateBoardView(boardState); constr.Constraint.CalculateEstimatedCost(boardView); Enqueue(constr); } }
public ConstrainResult ConstrainBoard(IBoardView boardView) { ConstraintSegment.CreateChain(constraintSet, out ConstraintSegment segmentBegin, out ConstraintSegment segmentEnd); // Start final colors as completely empty: no colors possible at all ColorSet[] finalColors = new ColorSet[boardView.Count]; do { IReadOnlyList <uint> segmentColors = GetColorsFromSegments(segmentBegin); if (AreCompatible(boardView, segmentColors)) { Merge(segmentColors, finalColors); } } while (segmentEnd.Bump(boardView.Count)); // TODO: this will place this constraint on the dirty list again, which is slightly redundant... var result = boardView.IntersectAll(finalColors); return(result); }
private void CalculateMax(IBoardView boardView, ConstraintState state) { for (int constrIndex = state.minValues.Length - 1; constrIndex >= 0; constrIndex--) { Constraint constraint = constraintSet[constrIndex]; int min = state.minValues[constrIndex]; int startPoint = state.maxValues[constrIndex]; for (int boardIndex = startPoint; boardIndex >= min; boardIndex--) { if (!boardView[boardIndex].HasColor(constraint.color)) { startPoint = boardIndex - 1; } else if (startPoint - boardIndex + 1 >= constraint.number) { break; } } state.maxValues[constrIndex] = startPoint; } }
private void CalculateMin(IBoardView boardView, ConstraintState state) { for (int constrIndex = 0; constrIndex < state.minValues.Length; constrIndex++) { Constraint constraint = constraintSet[constrIndex]; int max = state.maxValues[constrIndex]; int startPoint = state.minValues[constrIndex]; for (int boardIndex = startPoint; boardIndex <= max; boardIndex++) { if (!boardView[boardIndex].HasColor(constraint.color)) { startPoint = boardIndex + 1; } else if (boardIndex - startPoint + 1 >= constraint.number) { break; } } state.minValues[constrIndex] = startPoint; } }
private bool MoveWorker(int minStartVal, IBoardView boardView) { Start = minStartVal; while (End <= max) { if (Verify(boardView)) { if (PrevNode.VerifyNextMoved(boardView)) { if (NextNode.Reset(boardView)) { return(true); } } } Start++; } return(false); }
public ConstrainResult ConstrainBoard(IBoardView boardView) { // Make sure what we have even makes sense var result = VerifyValid(boardView); if (result == ConstrainResult.NoSolution) { return(ConstrainResult.NoSolution); } AssignmentGenerator generator = new AssignmentGenerator(boardView, constraintSet); // Start it as completely empty ColorSet[] colorSets = new ColorSet[boardView.Count]; while (generator.MoveNext()) { var assignment = generator.GetAssignment(); Merge(assignment, colorSets); } return(boardView.IntersectAll(colorSets)); }
public IBoardController Create(ISlotControllerFactory slotFactory, IBoardModel model, IBoardView view) { int rows = model.Rows; int columns = model.Columns; ISlotController[,] slots = new ISlotController[rows, columns]; for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { slots[r, c] = slotFactory.Create(model.Slots[r, c], view.Slots[r, c]); } } return(new BoardController(slots, model, view)); }
public BoardController(IBoardView i_View) { r_BoardView = i_View; r_BoardView.SetEventListener(this); initializeCurrentPlayer(); }
public void AddView(IBoardView v) { views.Add(new WeakReference(v)); }