public override IEnumerable <BoardGames.Action <Vector2i> > GetActions(BoardGames.Piece <Vector2i> piece) { //Get all possible spaces to move to and filter out the illegal ones. foreach (Vector2i v in possibleMoves) { Action_Move move = new Action_Move(piece.CurrentPos.Value + v, (Piece)piece); if (IsInBounds(move.EndPos) && !visitedSpaces[move.EndPos.x, move.EndPos.y]) { yield return(move); } } }
public Board(int width, int height) { //Create the board. visitedSpaces = new bool[width, height]; for (int y = 0; y < Height; ++y) { for (int x = 0; x < Width; ++x) { visitedSpaces[x, y] = false; } } //Create the pieces. piece1 = new Piece(new Vector2i((Width - 1) / 2, 0), BoardGames.Players.One, this); piece2 = new Piece(new Vector2i(Width / 2, Height - 1), BoardGames.Players.Two, this); //Set up the pieces. foreach (var piece in GetPieces()) { visitedSpaces[piece.CurrentPos.Value.x, piece.CurrentPos.Value.y] = true; piece.CurrentPos.OnChanged += (_piece, oldPos, newPos) => { visitedSpaces[newPos.x, newPos.y] = true; if (OnTileVisitedChanged != null) { OnTileVisitedChanged(this, newPos, true); } }; } //When a move is undone, undo the change to the "visitedSpaces" array. OnUndoAction += (thisBoard, action) => { Action_Move move = (Action_Move)action; visitedSpaces[move.EndPos.x, move.EndPos.y] = false; if (OnTileVisitedChanged != null) { OnTileVisitedChanged(this, move.EndPos, false); } }; piece1.CurrentPos.OnChanged += Callback_PieceMoved; piece2.CurrentPos.OnChanged += Callback_PieceMoved; }