public override List <Move> Moves(Chessboard board, Cell position) { var moves = new List <Move>(); int fwd = team == Team.white ? 1 : -1; var nP = position.NewWithOffset(-1, fwd); if (board.GetCellState(nP, team) == CellState.enemy) { moves.Add(new Move { piece = this, from = position, to = nP }); } nP = position.NewWithOffset(1, fwd); if (board.GetCellState(nP, team) == CellState.enemy) { moves.Add(new Move { piece = this, from = position, to = nP }); } nP = position.NewWithOffset(0, fwd); if (board.GetCellState(nP, team) == CellState.empty) { moves.Add(new Move { piece = this, from = position, to = nP }); } if (position.Y == 1 || position.Y == Chessboard.dim - 2) { nP = position.NewWithOffset(0, fwd * 2); if (board.GetCellState(nP, team) == CellState.empty && board.GetCellState(position.NewWithOffset(0, fwd), team) == CellState.empty) { moves.Add(new Move { piece = this, from = position, to = nP }); } } return(moves); }
protected List <Cell> menaceStraight(Chessboard board, Cell point, Cell direction) { var menacing = new List <Cell>(); var nP = point.NewWithOffset(direction.X, direction.Y); var cs = board.GetCellState(nP, team); while (cs != CellState.invalidPos) { menacing.Add(nP); if (cs == CellState.enemy || cs == CellState.ally) { break; } nP = nP.NewWithOffset(1, 1); cs = board.GetCellState(nP, team); } return(menacing); }
public override List <Cell> CouldMenace(Chessboard board, Cell point) { var menacing = new List <Cell>(); int fwd = team == Team.white ? 1 : -1; var nP = point.NewWithOffset(-1, fwd); if (board.GetCellState(nP, team) != CellState.invalidPos) { menacing.Add(nP); } nP = point.NewWithOffset(1, fwd); if (board.GetCellState(nP, team) != CellState.invalidPos) { menacing.Add(nP); } return(menacing); }
protected List <Move> moveStraight(Chessboard board, Cell position, Cell direction) { var moves = new List <Move>(); var nP = position.NewWithOffset(direction.X, direction.Y); var cs = board.GetCellState(nP, team); while (cs != CellState.invalidPos && cs != CellState.ally) { moves.Add(new Move { piece = this, from = position, to = nP }); if (cs == CellState.enemy) { break; } nP = nP.NewWithOffset(direction.X, direction.Y); cs = board.GetCellState(nP, team); } return(moves); }
public override List <Move> Moves(Chessboard board, Cell position) { var moves = new List <Move>(); var neighbors = board.GetNeighborCells(position); foreach (var cell in neighbors) { var cs = board.GetCellState(cell, team); if (cs != CellState.invalidPos && cs != CellState.ally) // FIXME: redundant check because GetNeighborCells does not return invalid cells { moves.Add(new Move { piece = this, from = position, to = cell }); } } return(moves); }
public override List <Cell> CouldMenace(Chessboard board, Cell point) { var menacing = new List <Cell>(); var nP = point.NewWithOffset(-2, -1); var cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos) { menacing.Add(nP); } nP = point.NewWithOffset(-1, -2); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos) { menacing.Add(nP); } nP = point.NewWithOffset(+2, -1); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos) { menacing.Add(nP); } nP = point.NewWithOffset(-1, +2); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos) { menacing.Add(nP); } nP = point.NewWithOffset(+1, -2); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos) { menacing.Add(nP); } nP = point.NewWithOffset(-2, +1); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos) { menacing.Add(nP); } nP = point.NewWithOffset(+1, +2); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos) { menacing.Add(nP); } nP = point.NewWithOffset(+2, +1); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos) { menacing.Add(nP); } return(menacing); }
public override List <Move> Moves(Chessboard board, Cell position) { var moves = new List <Move>(); var nP = position.NewWithOffset(-2, -1); var cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos && cs != CellState.ally) { moves.Add(new Move { piece = this, from = position, to = nP }); } nP = position.NewWithOffset(-1, -2); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos && cs != CellState.ally) { moves.Add(new Move { piece = this, from = position, to = nP }); } nP = position.NewWithOffset(+2, -1); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos && cs != CellState.ally) { moves.Add(new Move { piece = this, from = position, to = nP }); } nP = position.NewWithOffset(-1, +2); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos && cs != CellState.ally) { moves.Add(new Move { piece = this, from = position, to = nP }); } nP = position.NewWithOffset(+1, -2); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos && cs != CellState.ally) { moves.Add(new Move { piece = this, from = position, to = nP }); } nP = position.NewWithOffset(-2, +1); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos && cs != CellState.ally) { moves.Add(new Move { piece = this, from = position, to = nP }); } nP = position.NewWithOffset(+1, +2); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos && cs != CellState.ally) { moves.Add(new Move { piece = this, from = position, to = nP }); } nP = position.NewWithOffset(+2, +1); cs = board.GetCellState(nP, team); if (cs != CellState.invalidPos && cs != CellState.ally) { moves.Add(new Move { piece = this, from = position, to = nP }); } return(moves); }