Sha256: b60e09204361040f906d98f66686239ebd38cdd442bec1fe348d62ac8b0178e3
Contents?: true
Size: 978 Bytes
Versions: 220
Compression:
Stored size: 978 Bytes
Contents
object Queens { def boardString(white: Option[Position], black: Option[Position]): String = { def rowString(row: Int): String = (0 until 8).flatMap(col => tileString(row, col)).mkString def tileString(row: Int, col: Int): String = tileChar(Position(row, col)).toString + tileSep(col) def tileChar(pos: Position): Char = Some(pos) match { case `white` => 'W' case `black` => 'B' case _ => '_' } def tileSep(col: Int) = if (col == 7) '\n' else ' ' (0 until 8).flatMap(row => rowString(row)).mkString } def canAttack(white: Position, black: Position): Boolean = { val canAttackHoriz = white.x == black.x val canAttackVert = white.y == black.y val deltaRow = Math.abs(white.x - black.x) val deltaCol = Math.abs(white.y - black.y) val canAttackDiag = deltaRow == deltaCol canAttackHoriz || canAttackVert || canAttackDiag } } case class Position(x: Int, y: Int)
Version data entries
220 entries across 220 versions & 1 rubygems