unicode棋子创造了一个奇怪的间距并且弄乱了棋盘的大小。有什么我可以用Ruby来解决这个问题吗?
class GameBoard
attr_accessor :white_king, :white_queen, :white_rook, :white_bishop, :white_knight, :white_pawn, :black_king, :black_queen, :black_rook, :black_knight, :black_bishop, :black_pawn, :board
def initialize
@white_king = "♔"
@white_queen = "♕"
@white_rook = "♖"
@white_bishop = "♗"
@white_knight = "♘"
@white_pawn = "♙"
@black_king = "♚"
@black_queen = "♛"
@black_rook = "♜"
@black_bishop = "♝"
@black_knight = "♞"
@black_pawn = "♟"
@board = Array.new(8) { Array.new(8," ") }
end
def display
@board.each { |i|
print "\n"
@a = "+----+----+----+----+----+----+----+----+"
puts @a
i.each {|n|
print "| #{n} "
}
print "|"}
print "\n"
print @a
end
def knight
@board[0][0] = @black_knight
display
end
end
J = GameBoard.new
J.knight
这是输出,骑士似乎占据了一个半空间。也许是一种改变红宝石空间大小的方法?
+----+----+----+----+----+----+----+----+
| ♞ | | | | | | | |
+----+----+----+----+----+----+----+----+
| | | | | | | | |
+----+----+----+----+----+----+----+----+
| | | | | | | | |
+----+----+----+----+----+----+----+----+
| | | | | | | | |
+----+----+----+----+----+----+----+----+
| | | | | | | | |
+----+----+----+----+----+----+----+----+
| | | | | | | | |
+----+----+----+----+----+----+----+----+
| | | | | | | | |
+----+----+----+----+----+----+----+----+
| | | | | | | | |
+----+----+----+----+----+----+----+----+
答案 0 :(得分:1)
Unicode也可以使用不同大小的空格。
@board = Array.new(8) { Array.new(8," ") }
在声明数组中的第二个参数时,使用这些空格而不是普通空格,使其与Unicode棋子的大小相同。
U+0020 SPACE foo bar Depends on font, typically 1/4 em, often adjusted
U+00A0 NO-BREAK SPACE foo bar As a space, but often not adjusted
U+1680 OGHAM SPACE MARK foo bar Unspecified; usually not really a space but a dash
U+180E MONGOLIAN VOWEL SEPARATOR foobar No width
U+2000 EN QUAD foo bar 1 en (= 1/2 em)
U+2001 EM QUAD foo bar 1 em (nominally, the height of the font)
U+2002 EN SPACE foo bar 1 en (= 1/2 em)
U+2003 EM SPACE foo bar 1 em
U+2004 THREE-PER-EM SPACE foo bar 1/3 em
U+2005 FOUR-PER-EM SPACE foo bar 1/4 em
U+2006 SIX-PER-EM SPACE foo bar 1/6 em
U+2007 FIGURE SPACE foo bar “Tabular width”, the width of digits
U+2008 PUNCTUATION SPACE foo bar The width of a period “.”
U+2009 THIN SPACE foo bar 1/5 em (or sometimes 1/6 em)
U+200A HAIR SPACE foo bar Narrower than THIN SPACE
U+200B ZERO WIDTH SPACE foobar Nominally no width, but may expand
U+202F NARROW NO-BREAK SPACE foo bar Narrower than NO-BREAK SPACE (or SPACE)
U+205F MEDIUM MATHEMATICAL SPACE foo bar 4/18 em
U+3000 IDEOGRAPHIC SPACE foo bar The width of ideographic (CJK) characters.
U+FEFF ZERO WIDTH NO-BREAK SPACE foobar No width (the character is invisible)