populate board, add axis

This commit is contained in:
Dan Ballard 2011-08-26 14:55:45 -07:00
parent 8e505715b2
commit 6f69940642
1 changed files with 30 additions and 4 deletions

View File

@ -1,13 +1,40 @@
#!/usr/bin/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 class Board
def initialize() def initialize()
@board = Array.new(8) {|i| Array.new(8, '_')} @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 end
def to_s() def to_s()
str = '' str = ' '
0.step(BOARD_SIZE) {|i|
str += ' ' + i.to_s + ' '
}
str += "\n"
i = 0;
@board.each {|row| @board.each {|row|
str += ('A'.ord + i).chr + ' '
i += 1
row.each {|cell| row.each {|cell|
str += cell str += cell
} }
@ -16,7 +43,6 @@ class Board
return str return str
end end
end end
b = Board.new() b = Board.new()