public MyList <Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; MyList <Position> l = new MyList <Position>(); switch (figure.GetFigureType()) { case FigureTypes.King: { if (pos.GetX() > 1) { l.Add(new Position(pos.GetX() - 1, pos.GetY())); } if (pos.GetX() < 8) { l.Add(new Position(pos.GetX() + 1, pos.GetY())); } break; } default: // Bishop, Queen & etc. { // + for (int i = pos.GetX() + 1; i <= 8; i++) { l.Add(new Position(i, pos.GetY())); if (cf.GetFigureAt(new Position(i, pos.GetY())) != null) { break; } } // -- for (int i = pos.GetX() - 1; i > 0; i--) { l.Add(new Position(i, pos.GetY())); if (cf.GetFigureAt(new Position(i, pos.GetY())) != null) { break; } } break; } } return(l); }
public MyList<Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; MyList<Position> l = new MyList<Position>(); switch (figure.GetFigureType()) { case FigureTypes.King: { if (pos.GetX() >1) l.Add(new Position(pos.GetX()-1, pos.GetY())); if (pos.GetX() < 8) l.Add(new Position(pos.GetX()+1, pos.GetY())); break; } default: // Bishop, Queen & etc. { // + for (int i = pos.GetX() + 1; i <= 8; i++) { l.Add(new Position(i, pos.GetY())); if (cf.GetFigureAt(new Position(i, pos.GetY())) != null) break; } // -- for (int i = pos.GetX() - 1; i > 0; i--) { l.Add(new Position( i, pos.GetY())); if (cf.GetFigureAt(new Position( i, pos.GetY())) != null) break; } break; } } return l; }
public MyList <Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position, tmppos; MyList <Position> l = new MyList <Position>(); switch (figure.GetFigureType()) { case FigureTypes.Pawn: { if (figure.Side == Side.Black) { pos = figure.Reverse(pos); } if (pos.GetY() < 8) { if (pos.GetX() < 8) { tmppos = new Position(pos.GetX() + 1, pos.GetY() + 1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } if (pos.GetX() > 1) { tmppos = new Position(pos.GetX() - 1, pos.GetY() + 1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } } break; } case FigureTypes.King: { int x, y; x = pos.GetX(); y = pos.GetY(); if (x < 8) { if (y < 8) { l.Add(new Position(x + 1, y + 1)); } if (y > 1) { l.Add(new Position(x + 1, y - 1)); } } if (x > 1) { if (y < 8) { l.Add(new Position(x - 1, y + 1)); } if (y > 1) { l.Add(new Position(x - 1, y - 1)); } } break; } default: { for (int i = pos.GetX() + 1, j = pos.GetY() + 1; i <= 8 && j <= 8; i++, j++) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) { break; } } for (int i = pos.GetX() - 1, j = pos.GetY() - 1; i >= 1 && j >= 1; i--, j--) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) { break; } } for (int i = pos.GetX() + 1, j = pos.GetY() - 1; i <= 8 && j >= 1; i++, j--) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) { break; } } for (int i = pos.GetX() - 1, j = pos.GetY() + 1; i >= 1 && j <= 8; i--, j++) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) { break; } } break; } } return(l); }
public MyList<Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; Position tmppos; MyList<Position> l = new MyList<Position>(); switch (figure.GetFigureType()) { case FigureTypes.Pawn: { if (figure.Side == Side.Black) pos = figure.Reverse(pos); if (pos.GetY() == 2) { Position middlepos = new Position(pos.GetX(), pos.GetY()+1); middlepos = figure.Side == Side.White ? middlepos : figure.Reverse(middlepos); if (cf.GetFigureAt(middlepos) == null) { tmppos = new Position(pos.GetX(), pos.GetY() + 2); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } } int y = pos.GetY(); if (y+1 <9) { tmppos = new Position(pos.GetX(), y+1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos) ); } break; } case FigureTypes.King: { if (pos.GetY() >1) l.Add(new Position(pos.GetX(), pos.GetY()-1)); if (pos.GetY() < 8) l.Add(new Position(pos.GetX(), pos.GetY()+1)); break; } default: // Bishop, Queen & etc. { // + for (int i = pos.GetY() + 1; i <= 8; i++) { l.Add(new Position(pos.GetX(), i)); if (cf.GetFigureAt(new Position(pos.GetX(), i)) != null) break; } //-- for (int i = pos.GetY() - 1; i > 0; i--) { l.Add(new Position(pos.GetX(), i)); if (cf.GetFigureAt(new Position(pos.GetX(), i)) != null) break; } break; } } return l; }
public MyList<Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position, tmppos; MyList<Position> l = new MyList<Position>(); switch (figure.GetFigureType()) { case FigureTypes.Pawn: { if (figure.Side == Side.Black) pos = figure.Reverse(pos); if (pos.GetY() < 8) { if (pos.GetX() < 8) { tmppos = new Position(pos.GetX()+1, pos.GetY()+1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } if (pos.GetX() > 1) { tmppos = new Position(pos.GetX()- 1, pos.GetY() + 1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } } break; } case FigureTypes.King: { int x,y; x = pos.GetX(); y = pos.GetY(); if (x<8) { if (y<8) l.Add(new Position(x+1,y+1)); if (y>1) l.Add(new Position(x+1,y-1)); } if (x>1) { if (y<8) l.Add(new Position(x-1,y+1)); if (y>1) l.Add(new Position(x-1, y-1)); } break; } default: { for (int i = pos.GetX()+1, j = pos.GetY()+1; i <= 8 && j <= 8; i++, j++) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) break; } for (int i = pos.GetX() - 1, j = pos.GetY() - 1; i >=1 && j >=1 ; i--, j--) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) break; } for (int i = pos.GetX() + 1, j = pos.GetY() - 1; i <= 8 && j >= 1; i++, j--) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) break; } for (int i = pos.GetX() -1, j = pos.GetY() + 1; i >= 1 && j <= 8; i--, j++) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) break; } break; } } return l; }
public MyList <Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; Position tmppos; MyList <Position> l = new MyList <Position>(); switch (figure.GetFigureType()) { case FigureTypes.Pawn: { if (figure.Side == Side.Black) { pos = figure.Reverse(pos); } if (pos.GetY() == 2) { Position middlepos = new Position(pos.GetX(), pos.GetY() + 1); middlepos = figure.Side == Side.White ? middlepos : figure.Reverse(middlepos); if (cf.GetFigureAt(middlepos) == null) { tmppos = new Position(pos.GetX(), pos.GetY() + 2); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } } int y = pos.GetY(); if (y + 1 < 9) { tmppos = new Position(pos.GetX(), y + 1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } break; } case FigureTypes.King: { if (pos.GetY() > 1) { l.Add(new Position(pos.GetX(), pos.GetY() - 1)); } if (pos.GetY() < 8) { l.Add(new Position(pos.GetX(), pos.GetY() + 1)); } break; } default: // Bishop, Queen & etc. { // + for (int i = pos.GetY() + 1; i <= 8; i++) { l.Add(new Position(pos.GetX(), i)); if (cf.GetFigureAt(new Position(pos.GetX(), i)) != null) { break; } } //-- for (int i = pos.GetY() - 1; i > 0; i--) { l.Add(new Position(pos.GetX(), i)); if (cf.GetFigureAt(new Position(pos.GetX(), i)) != null) { break; } } break; } } return(l); }