Created
April 4, 2016 19:13
-
-
Save myokoym/e8f6abc2b6831254a4390c70e1b74029 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Board | |
def initialize | |
@board = [ | |
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, | |
0x40, 0x22, 0x23, 0x24, 0x25, 0x28, 0x25, 0x24, 0x23, 0x22, 0x40, | |
0x40, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x40, | |
0x40, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x40, | |
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, | |
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, | |
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, | |
0x40, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x40, | |
0x40, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x40, | |
0x40, 0x12, 0x13, 0x14, 0x15, 0x18, 0x15, 0x14, 0x13, 0x12, 0x40, | |
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, | |
] | |
end | |
def point(x, y) | |
@board[point_to_index(x, y)] | |
end | |
def move(x1, y1, x2, y2) | |
from = @board[point_to_index(x1, y1)] | |
raise if from == 0x00 | |
raise if from == 0x40 | |
tmp = @board[point_to_index(x2, y2)] | |
@board[point_to_index(x2, y2)] = @board[point_to_index(x1, y1)] | |
@board[point_to_index(x1, y1)] = tmp | |
end | |
def to_csa | |
csa = "" | |
1.upto(9) do |y| | |
csa << "P#{y}" | |
9.downto(1) do |x| | |
cell = point(x, y) | |
hand = cell & 0xf0 | |
case hand | |
when 0x10 | |
csa << "+" | |
when 0x20 | |
csa << "-" | |
end | |
type = cell & 0x0f | |
case type | |
when 0x00 | |
csa << " * " | |
when 0x01 | |
csa << "FU" | |
when 0x02 | |
csa << "KY" | |
when 0x03 | |
csa << "KE" | |
when 0x04 | |
csa << "GI" | |
when 0x05 | |
csa << "KI" | |
when 0x06 | |
csa << "KA" | |
when 0x07 | |
csa << "HI" | |
when 0x08 | |
csa << "OU" | |
end | |
end | |
csa << "\n" | |
end | |
csa | |
end | |
private | |
def point_to_index(x, y) | |
y * 11 + (10 - x) | |
end | |
end | |
board = Board.new | |
board.move(5, 9, 5, 8) | |
puts board.to_csa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment