private CheckerMove[] SearchMoveAround(byte x, byte y, CellState[][] field, Team team) { var possibleMoves = new List <CheckerMove>(); foreach (var i in _dx) { foreach (var j in _dy) { if (CanMove(x, y, i, j, field, team)) { var step = 1; do { possibleMoves.Add(new CheckerMove { FromPoint = new CellPoint(x, y), ToPoint = new CellPoint((byte)(x + step * i), (byte)(y + step * j)) }); step++; } while (IsQueen(field[y][x]) && CellPoint.IsValidCellPoint(x + step * i, y + step * j) && IsEmptyCell(field[y + step * j][x + step * i])); } } } return(possibleMoves.ToArray()); }
public void SearchAttackMoves(byte x, byte y, CellState[][] field, Team team, CheckerMoveTreeNode parent) { parent.ChildMoves = new List <CheckerMoveTreeNode>(); foreach (var i in _dx) { foreach (var j in _dy) { var c = 1; if (IsQueen(field[y][x])) { while (CellPoint.IsValidCellPoint(x + c * i, y + c * j) && IsEmptyCell(field[y + c * j][x + c * i])) { c++; } } if (CheckAttackMove(x, y, i, j, c, field, team)) { var step = 1; do { var node = new CheckerMoveTreeNode { Move = new CheckerMove { FromPoint = new CellPoint(x, y), ToPoint = new CellPoint((byte)(x + (c + step) * i), (byte)(y + (c + step) * j)) } }; SearchAttackMoves( node.Move.ToPoint.X, node.Move.ToPoint.Y, RefreshedField(field, x, y, i, j, c, step), team, node); parent.ChildMoves.Add(node); step++; } while (IsQueen(field[y][x]) && CellPoint.IsValidCellPoint(x + (c + 1 * step) * i, y + (c + 1 * step) * j) && IsEmptyCell(field[y + (c + 1 * step) * j][x + (c + 1 * step) * i])); } } } }
private static bool CanMove(byte x, byte y, int dirrectionX, int dirrectionY, CellState[][] field, Team team) { var targetX = x + dirrectionX; var targetY = y + dirrectionY; if (!CellPoint.IsValidCellPoint(targetX, targetY) || !IsEmptyCell(field[targetY][targetX])) { return(false); } if (IsQueen(field[y][x])) { return(true); } return(team == Team.White && targetY < y || team == Team.Black && targetY > y); }
private bool CheckAttackMove(byte x, byte y, int dirrectionX, int dirrectionY, int cofficient, CellState[][] field, Team team) { int victomCellX = x + cofficient * dirrectionX; int victomCellY = y + cofficient * dirrectionY; int nextCellX = victomCellX + 1 * dirrectionX; int nextCellY = victomCellY + 1 * dirrectionY; if (CellPoint.IsValidCellPoint(victomCellX, victomCellY) && CellPoint.IsValidCellPoint(nextCellX, nextCellY)) { if (IsEnemyChecker(field[victomCellY][victomCellX], team) && IsEmptyCell(field[nextCellY][nextCellX])) { return(true); } } return(false); }