func isValid960Position(_ firstRank: String) -> Bool {
  var rooksPlaced = 0
  var bishopColor = -1

  for (i, piece) in firstRank.enumerated() {
    switch piece {
    case "" where rooksPlaced!= 1:
      return false
    case "":
      rooksPlaced += 1
    case "" where bishopColor == -1:
      bishopColor = i & 1
    case "" where bishopColor == i & 1:
      return false
    case _:
      continue
    }
  }

  return true
}

struct Chess960Counts {
  var king = 0, queen = 0, rook = 0, bishop = 0, knight = 0

  subscript(_ piece: String) -> Int {
    get {
      switch piece {
      case "": return king
      case "": return queen
      case "": return rook
      case "": return bishop
      case "": return knight
      case _:   fatalError()
      }
    }

    set {
      switch piece {
      case "": king = newValue
      case "": queen = newValue
      case "": rook = newValue
      case "": bishop = newValue
      case "": knight = newValue
      case _:   fatalError()
      }
    }
  }
}

func get960Position() -> String {
  var counts = Chess960Counts()
  var bishopColor = -1