public static string AsText(this MoveOrAtack mA) { switch (mA) { case MoveOrAtack.Move: return("Move"); case MoveOrAtack.Atack: return("Black"); } // Catch any other enum value return(mA.ToString()); }
public override Tuple <int, int>[] PossibleMoves(MoveOrAtack moveOrAtack, int fromRow, int fromCol) { // Console.WriteLine("fromRow: {0}, fromCol: {1}", fromRow, fromCol); List <Tuple <int, int> > list = new List <Tuple <int, int> >(); int toRow, toCol; ////////////// // Like a King // Upper left, Upper, Upper right, Right, Lower right, Lower, Lower left, Left. int[] toRowAr = new int[8] { -1, -1, -1, 0, +1, +1, +1, 0 }; int[] toColAr = new int[8] { -1, 0, +1, +1, +1, +0, -1, -1 }; for (int i = 0; i < toRowAr.Length; i++) { toRow = fromRow + toRowAr[i]; toCol = fromCol + toColAr[i]; if (BoundsCheck(toRow) && BoundsCheck(toCol)) { if (b[toRow, toCol] != null && b[toRow, toCol].GetColor() == color) { } else if (b[toRow, toCol] != null && b[toRow, toCol].GetColor() == otherColor) { list.Add(new Tuple <int, int>(toRow, toCol)); } else if (b[toRow, toCol] == null) { list.Add(new Tuple <int, int>(toRow, toCol)); } } } return(list.ToArray()); }
public override Tuple <int, int>[] PossibleMoves(MoveOrAtack moveOrAtack, int fromRow, int fromCol) { // Console.WriteLine("fromRow: {0}, fromCol: {1}", fromRow, fromCol); List <Tuple <int, int> > list = new List <Tuple <int, int> >(); int toRow, toCol; // Vertical toCol = fromCol; for (toRow = fromRow - 1; toRow > toRow - 8; toRow--) { if (BoundsCheck(toRow)) { if (b[toRow, toCol] != null && b[toRow, toCol].GetColor() == color) { break; } if (b[toRow, toCol] != null && b[toRow, toCol].GetColor() == otherColor) { list.Add(new Tuple <int, int>(toRow, toCol)); break; } if (b[toRow, toCol] == null) { list.Add(new Tuple <int, int>(toRow, toCol)); } } else { break; } } toCol = fromCol; for (toRow = fromRow + 1; toRow < toRow + 8; toRow++) { if (BoundsCheck(toRow)) { if (b[toRow, toCol] != null && b[toRow, toCol].GetColor() == color) { break; } if (b[toRow, toCol] != null && b[toRow, toCol].GetColor() == otherColor) { list.Add(new Tuple <int, int>(toRow, toCol)); break; } if (b[toRow, toCol] == null) { list.Add(new Tuple <int, int>(toRow, toCol)); } } else { break; } } // Horizontal toRow = fromRow; for (toCol = fromCol - 1; toCol > toCol - 8; toCol--) { if (BoundsCheck(toCol)) { if (b[toRow, toCol] != null && b[toRow, toCol].GetColor() == color) { break; } if (b[toRow, toCol] != null && b[toRow, toCol].GetColor() == otherColor) { list.Add(new Tuple <int, int>(toRow, toCol)); break; } if (b[toRow, toCol] == null) { list.Add(new Tuple <int, int>(toRow, toCol)); } } else { break; } } toRow = fromRow; for (toCol = fromCol + 1; toCol < toCol + 8; toCol++) { if (BoundsCheck(toCol)) { if (b[toRow, toCol] != null && b[toRow, toCol].GetColor() == color) { break; } if (b[toRow, toCol] != null && b[toRow, toCol].GetColor() == otherColor) { list.Add(new Tuple <int, int>(toRow, toCol)); break; } if (b[toRow, toCol] == null) { list.Add(new Tuple <int, int>(toRow, toCol)); } } else { break; } } return(list.ToArray()); }
public override Tuple <int, int>[] PossibleMoves(MoveOrAtack moveOrAtack, int fromRow, int fromCol) { // Console.WriteLine("fromRow: {0}, fromCol: {1}", fromRow, fromCol); List <Tuple <int, int> > list = new List <Tuple <int, int> >(); // Direction int dir = color == Color.White ? 1 : -1; // Default direction is White. int toRow, toCol; // Next forward position opening. // If there is no peace in the path. if (moveOrAtack == MoveOrAtack.Move) { toRow = fromRow - 2 * dir; toCol = fromCol; if (!hasMoved && b[fromRow - 1 * dir, fromCol] == null && b[toRow, toCol] == null) { list.Add(new Tuple <int, int>(toRow, toCol)); } // Nest forward position normal. toRow = fromRow - 1 * dir; toCol = fromCol; if (BoundsCheck(toRow) && b[toRow, toCol] == null) { list.Add(new Tuple <int, int>(toRow, toCol)); } // Eat to the right and eat to the left. toRow = fromRow - 1 * dir; toCol = fromCol - 1; if (BoundsCheck(toRow) && BoundsCheck(toCol) && b[toRow, toCol] != null && b[toRow, toCol].GetColor() == otherColor) { list.Add(new Tuple <int, int>(toRow, toCol)); } toRow = fromRow - 1 * dir; toCol = fromCol + 1; if (BoundsCheck(toRow) && BoundsCheck(toCol) && b[toRow, toCol] != null && b[toRow, toCol].GetColor() == otherColor) { list.Add(new Tuple <int, int>(toRow, toCol)); } } else if (moveOrAtack == MoveOrAtack.Atack) { // Eat to the right and eat to the left. toRow = fromRow - 1 * dir; toCol = fromCol - 1; if (BoundsCheck(toRow) && BoundsCheck(toCol) && (b[toRow, toCol] == null || (b[toRow, toCol] != null && (b[toRow, toCol].GetColor() == color || b[toRow, toCol].GetColor() != color)))) // Someting not correct here. { list.Add(new Tuple <int, int>(toRow, toCol)); } toRow = fromRow - 1 * dir; toCol = fromCol + 1; if (BoundsCheck(toRow) && BoundsCheck(toCol) && (b[toRow, toCol] == null || (b[toRow, toCol] != null && (b[toRow, toCol].GetColor() == color || b[toRow, toCol].GetColor() != color)))) // Someting not correct here. { list.Add(new Tuple <int, int>(toRow, toCol)); } } return(list.ToArray()); }
public abstract Tuple <int, int>[] PossibleMoves(MoveOrAtack moveOrAtack, int fromRow, int fromCol);