public override IEnumerable <IMove> ValidMovesFor(MapCellLocation location, HeroState owner, HeroState target, MapState map) { var(dr, dc) = MapCellLocation.Diff(target.Location, location); (int r, int c) = target.Location; dr = Math.Sign(dr); dc = Math.Sign(dc); // can we push the target 1 space away? if (map.CanMoveTo(target, (r + dr, c + dc), out MapCellState cell)) { yield return(new MoveHeroTo(target, 1, cell, map, true)); } }
public override IEnumerable <IMove> ValidMovesFor(MapCellLocation location, HeroState owner, HeroState target, MapState map) { // can the target move to the cell we're on? if (map.CanMoveTo(target, location, out MapCellState currentCell)) { yield break; } // if the target can move to my position, I need to be able to move // in the same direction to the next cell var(dr, dc) = MapCellLocation.Diff(location, target.Location); (int r, int c) = location; if (map.CanMoveTo(owner, (r + dr, c + dc), out MapCellState desiredCell)) { var moveTargetBack = new MoveHeroTo(target, 1, currentCell, map); var moveMeBack = new MoveHeroTo(owner, 1, desiredCell, map); yield return(new AggregateMove(moveMeBack, moveTargetBack)); } }
public override IEnumerable <IMove> ValidMovesFor(MapCellLocation location, HeroState owner, HeroState target, MapState map) { var(dr, dc) = MapCellLocation.Diff(target.Location, location); (int r, int c) = target.Location; dr = Math.Sign(dr); dc = Math.Sign(dc); // can we push the target 2 spaces away? var distance = 2; if (!map.CanMoveTo(target, (r + dr + dr, c + dc + dc), out MapCellState cell)) { // no? Can we push them one square away? distance = 1; if (!map.CanMoveTo(target, (r + dr, c + dc), out cell)) { yield break; } } // we can push the target 2/1 squares away yield return(new MoveHeroTo(target, distance, cell, map, true)); }