-class PieceKA < Piece
- def initialize(*arg)
- @normal_moves = []
- @promoted_moves = [[0, +1], [+1, 0], [-1, 0], [0, -1]]
- @name = "KA"
- @promoted_name = "UM"
- super
- end
- def far_movable_grids
- grids = Array::new
- ## up right
- cand_x = @x - 1
- cand_y = @y - 1
- while (jump_to?(cand_x, cand_y))
- grids.push([cand_x, cand_y])
- break if (! put_to?(cand_x, cand_y))
- cand_x = cand_x - 1
- cand_y = cand_y - 1
- end
- ## down right
- cand_x = @x - 1
- cand_y = @y + 1
- while (jump_to?(cand_x, cand_y))
- grids.push([cand_x, cand_y])
- break if (! put_to?(cand_x, cand_y))
- cand_x = cand_x - 1
- cand_y = cand_y + 1
- end
- ## up left
- cand_x = @x + 1
- cand_y = @y - 1
- while (jump_to?(cand_x, cand_y))
- grids.push([cand_x, cand_y])
- break if (! put_to?(cand_x, cand_y))
- cand_x = cand_x + 1
- cand_y = cand_y - 1
- end
- ## down left
- cand_x = @x + 1
- cand_y = @y + 1
- while (jump_to?(cand_x, cand_y))
- grids.push([cand_x, cand_y])
- break if (! put_to?(cand_x, cand_y))
- cand_x = cand_x + 1
- cand_y = cand_y + 1
- end
- return grids
- end
-end
-class PieceHI < Piece
- def initialize(*arg)
- @normal_moves = []
- @promoted_moves = [[+1, +1], [-1, +1], [+1, -1], [-1, -1]]
- @name = "HI"
- @promoted_name = "RY"
- super
- end
- def far_movable_grids
- grids = Array::new
- ## up
- cand_x = @x
- cand_y = @y - 1
- while (jump_to?(cand_x, cand_y))
- grids.push([cand_x, cand_y])
- break if (! put_to?(cand_x, cand_y))
- cand_y = cand_y - 1
- end
- ## down
- cand_x = @x
- cand_y = @y + 1
- while (jump_to?(cand_x, cand_y))
- grids.push([cand_x, cand_y])
- break if (! put_to?(cand_x, cand_y))
- cand_y = cand_y + 1
- end
- ## right
- cand_x = @x - 1
- cand_y = @y
- while (jump_to?(cand_x, cand_y))
- grids.push([cand_x, cand_y])
- break if (! put_to?(cand_x, cand_y))
- cand_x = cand_x - 1
- end
- ## down
- cand_x = @x + 1
- cand_y = @y
- while (jump_to?(cand_x, cand_y))
- grids.push([cand_x, cand_y])
- break if (! put_to?(cand_x, cand_y))
- cand_x = cand_x + 1
- end
- return grids
- end
-end
-class PieceOU < Piece
- def initialize(*arg)
- @normal_moves = [[0, +1], [+1, +1], [-1, +1], [+1, +0], [-1, +0], [0, -1], [+1, -1], [-1, -1]]
- @promoted_moves = []
- @name = "OU"
- @promoted_name = nil
- super
- end
-end
-
-class Board
- def initialize
- @sente_hands = Array::new
- @gote_hands = Array::new
- @history = Hash::new
- @sente_history = Hash::new
- @gote_history = Hash::new
- @array = [[], [], [], [], [], [], [], [], [], []]
- end
- attr_accessor :array, :sente_hands, :gote_hands, :history, :sente_history, :gote_history
-
- def initial
- PieceKY::new(self, 1, 1, false)
- PieceKE::new(self, 2, 1, false)
- PieceGI::new(self, 3, 1, false)
- PieceKI::new(self, 4, 1, false)
- PieceOU::new(self, 5, 1, false)
- PieceKI::new(self, 6, 1, false)
- PieceGI::new(self, 7, 1, false)
- PieceKE::new(self, 8, 1, false)
- PieceKY::new(self, 9, 1, false)
- PieceKA::new(self, 2, 2, false)
- PieceHI::new(self, 8, 2, false)
- PieceFU::new(self, 1, 3, false)
- PieceFU::new(self, 2, 3, false)
- PieceFU::new(self, 3, 3, false)
- PieceFU::new(self, 4, 3, false)
- PieceFU::new(self, 5, 3, false)
- PieceFU::new(self, 6, 3, false)
- PieceFU::new(self, 7, 3, false)
- PieceFU::new(self, 8, 3, false)
- PieceFU::new(self, 9, 3, false)
-
- PieceKY::new(self, 1, 9, true)
- PieceKE::new(self, 2, 9, true)
- PieceGI::new(self, 3, 9, true)
- PieceKI::new(self, 4, 9, true)
- PieceOU::new(self, 5, 9, true)
- PieceKI::new(self, 6, 9, true)
- PieceGI::new(self, 7, 9, true)
- PieceKE::new(self, 8, 9, true)
- PieceKY::new(self, 9, 9, true)
- PieceKA::new(self, 8, 8, true)
- PieceHI::new(self, 2, 8, true)
- PieceFU::new(self, 1, 7, true)
- PieceFU::new(self, 2, 7, true)
- PieceFU::new(self, 3, 7, true)
- PieceFU::new(self, 4, 7, true)
- PieceFU::new(self, 5, 7, true)
- PieceFU::new(self, 6, 7, true)
- PieceFU::new(self, 7, 7, true)
- PieceFU::new(self, 8, 7, true)
- PieceFU::new(self, 9, 7, true)
- end
-
- def have_piece?(hands, name)
- piece = hands.find { |i|
- i.name == name
- }
- return piece
- end
-
- def move_to(x0, y0, x1, y1, name, sente)
- if (sente)
- hands = @sente_hands
- else
- hands = @gote_hands
- end