public override List <Tuple <uint, uint> > getPossibleMoves(Board.QueryFunc QF) { List <Tuple <uint, uint> > tmpList = new List <Tuple <uint, uint> >(); List <Tuple <int, int> > jmpList = new List <Tuple <int, int> >(); //Contains all possible jump locations jmpList.Add(new Tuple <int, int>(1, 2)); jmpList.Add(new Tuple <int, int>(1, -2)); jmpList.Add(new Tuple <int, int>(2, 1)); jmpList.Add(new Tuple <int, int>(2, -1)); jmpList.Add(new Tuple <int, int>(-1, 2)); jmpList.Add(new Tuple <int, int>(-1, -2)); jmpList.Add(new Tuple <int, int>(-2, 1)); jmpList.Add(new Tuple <int, int>(-2, -1)); // Loops over jump locations foreach (Tuple <int, int> item in jmpList) { int x = item.Item1; int y = item.Item2; if (withinBoard((int)getX() + x, (int)getY() + y)) { Square S = QF((uint)(getX() + x), (uint)(getY() + y)); Piece P = S.getPiece(); if (P != null) { if (!isSameColour(P)) { tmpList.Add(new Tuple <uint, uint>((uint)(getX() + x), (uint)(getY() + y))); } } } } return(tmpList); }
public override List <Tuple <uint, uint> > getPossibleMoves(Board.QueryFunc QF) { List <Tuple <uint, uint> > moves = new List <Tuple <uint, uint> >(); // Check down moves int x = (int)getX(); int y = (int)getY(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { int nx = x + i; int ny = y + j; if (withinBoard(nx, ny)) { Square s = QF((uint)nx, (uint)ny); if ((getColour() == "white" && s.getBlackCover() == 0) || (getColour() == "black" && s.getWhiteCover() == 0)) { Piece p = s.getPiece(); if (p == null) { moves.Add(new Tuple <uint, uint>((uint)nx, (uint)ny)); } else { if (p.getColour() != getColour()) { moves.Add(new Tuple <uint, uint>((uint)nx, (uint)ny)); } } } } } } // Done, all moves found return(moves); }
public bool makeMove(string col, uint x1, uint y1, uint x2, uint y2) { Piece p = getPieceAt(x1, y1); Square s1 = getSquareAt(x1, y1); Square s2 = getSquareAt(x2, y2); // Check if squares are ok. if (s1 == null || s2 == null) { return(false); } // Check if piece is ok. if (p == null) { return(false); } if (p.getColour() != col) { return(false); } if (!p.movePossible(x2, y2, getSquareAt)) { return(false); } // Move is legal // If there is a piece at x2,y2 then remove its cover. Piece p2 = s2.getPiece(); if (p2 != null) { foreach (Tuple <uint, uint> t in p2.getPossibleMoves(getSquareAt)) { // If moving piece is white, remove black cover, and vc.v. if (col == COLOUR_WHITE) { getSquareAt(t.Item1, t.Item2).removeBlackCover(); } else { getSquareAt(t.Item1, t.Item2).removeWhiteCover(); } } } // Remove from old position s1.removePiece(); foreach (Tuple <uint, uint> t in p.getPossibleMoves(getSquareAt)) { // If moving piece is white, remove white cover, and vc.v. if (col == COLOUR_WHITE) { getSquareAt(t.Item1, t.Item2).removeWhiteCover(); } else { getSquareAt(t.Item1, t.Item2).removeBlackCover(); } } // Add to new position getSquareAt(x2, y2).setPiece(p); p.move(x2, y2); foreach (Tuple <uint, uint> t in p.getPossibleMoves(getSquareAt)) { // If moving piece is white, add white cover, and vc.v. if (col == COLOUR_WHITE) { getSquareAt(t.Item1, t.Item2).addWhiteCover(); } else { getSquareAt(t.Item1, t.Item2).addBlackCover(); } } return(true); }
public override List <Tuple <uint, uint> > getPossibleMoves(Board.QueryFunc QF) { List <Tuple <uint, uint> > tmpList = new List <Tuple <uint, uint> >(); short yMod; if (this.colour == "white") { yMod = 1; } else { yMod = -1; } // Take left if (withinBoard((int)getX() - 1, (int)getY() + yMod)) { Square S = QF((uint)(getX() - 1), (uint)(getY() + yMod)); Piece P = S.getPiece(); if (P != null) { if (!isSameColour(P)) { tmpList.Add(new Tuple <uint, uint>((uint)(getX() - 1), (uint)(getY() + yMod))); } } } //Take right if (withinBoard((int)getX() + 1, (int)getY() + yMod)) { Square S = QF((uint)(getX() + 1), (uint)(getY() + yMod)); Piece P = S.getPiece(); if (P != null) { if (!isSameColour(P)) { tmpList.Add(new Tuple <uint, uint>((uint)(getX() + 1), (uint)(getY() + yMod))); } } } //Move 1 if (withinBoard((int)getX(), (int)getY() + yMod)) { Square S = QF(getX(), (uint)(getY() + yMod)); Piece P = S.getPiece(); if (P == null) { tmpList.Add(new Tuple <uint, uint>(getX(), (uint)(getY() + yMod))); } } //Move 2 (Only first move) if (!movedFromInit()) { if (withinBoard((int)getX(), (int)getY() + 2 * yMod)) { Square S = QF(getX(), (uint)(getY() + 2 * yMod)); Piece P = S.getPiece(); if (P == null) { tmpList.Add(new Tuple <uint, uint>(getX(), (uint)(getY() + 2 * yMod))); } } } return(tmpList); }