private bool MoveIsLegal(bool black, int x, int y, Direction direction) { var dir = DirectionHelper.DirectionToPoint(direction); var targetX = x; var targetY = y; ApplyMovement(dir, ref targetX, ref targetY); if (!OnBoard(targetX, targetY)) { return(false); } if (_game.GetTileAt(targetX, targetY) == Tile.None || IsFriendColor(black, targetX, targetY)) { return(false); } do { ApplyMovement(dir, ref targetX, ref targetY); if (!OnBoard(targetX, targetY) || _game.GetTileAt(targetX, targetY) == Tile.None) { return(false); } if (IsEnemyColor(black, targetX, targetY)) { continue; } if (IsFriendColor(black, targetX, targetY)) { return(true); } } while (true); }
private void FlipAt(bool black, Direction direction, int x, int y) { var dir = DirectionHelper.DirectionToPoint(direction); var targetX = x; var targetY = y; var changes = new List <Point>(); do { ApplyMovement(dir, ref targetX, ref targetY); if (!OnBoard(targetX, targetY) || _game.GetTileAt(targetX, targetY) == Tile.None) { return; } if (IsFriendColor(black, targetX, targetY)) { if (changes.Count > 0) { break; } return; } if (IsEnemyColor(black, targetX, targetY)) { changes.Add(new Point(targetX, targetY)); } } while (true); foreach (var point in changes) { _game.SetTileAt(point.X, point.Y, black ? Tile.Black : Tile.White); } }
private bool HasNeighbours(int x, int y) => Enum.GetValues( typeof(Direction)) .Cast <Direction>() .Any(direction => IsSet(x, y, DirectionHelper.DirectionToPoint(direction)) );