50 lines
778 B
Ruby
50 lines
778 B
Ruby
#!/usr/bin/ruby
|
|
|
|
TEAM_1_MAN = ' w '
|
|
TEAM_1_KING = ' W '
|
|
TEAM_2_MAN = ' b '
|
|
TEAM_2_KING = ' B '
|
|
BOARD_EMPTY = ' _ '
|
|
BOARD_SIZE = 8
|
|
|
|
class Board
|
|
def initialize()
|
|
@board = Array.new(BOARD_SIZE) {|i| Array.new(BOARD_SIZE, BOARD_EMPTY)}
|
|
0.step(BOARD_SIZE) {|i|
|
|
peice = (i < 3 ? TEAM_1_MAN : TEAM_2_MAN)
|
|
if [0,2,5,7].include? i
|
|
start = 1
|
|
elsif [1,6].include? i
|
|
start = 0
|
|
else
|
|
next
|
|
end
|
|
start.step(BOARD_SIZE,2) {|j|
|
|
@board[i][j] = peice
|
|
}
|
|
}
|
|
end
|
|
|
|
def to_s()
|
|
str = ' '
|
|
0.step(BOARD_SIZE) {|i|
|
|
str += ' ' + i.to_s + ' '
|
|
}
|
|
str += "\n"
|
|
i = 0;
|
|
@board.each {|row|
|
|
str += ('A'.ord + i).chr + ' '
|
|
i += 1
|
|
row.each {|cell|
|
|
str += cell
|
|
}
|
|
str += "\n"
|
|
}
|
|
return str
|
|
end
|
|
|
|
end
|
|
|
|
b = Board.new()
|
|
puts b.to_s
|