fixed gen_jumped methods and wrote/tempalted gen_baord_moves
This commit is contained in:
parent
f61b9ee0a7
commit
8c0cfc5037
38
checkers.rb
38
checkers.rb
|
@ -13,6 +13,7 @@ BOARD_SIZE = 8
|
|||
class Board
|
||||
def initialize()
|
||||
@board = Array.new(BOARD_SIZE) {|i| Array.new(BOARD_SIZE, BOARD_EMPTY)}
|
||||
@stats = {TEAM_1 => {}, TEAM_2 => {}}
|
||||
end
|
||||
|
||||
def setup()
|
||||
|
@ -29,6 +30,8 @@ class Board
|
|||
@board[i][j] = peice
|
||||
}
|
||||
}
|
||||
@stats[TEAM_1]['count'] = 12
|
||||
@stats[TEAM_2]['count'] = 12
|
||||
end
|
||||
|
||||
def set(x, y, thing)
|
||||
|
@ -99,7 +102,7 @@ class Board
|
|||
jumps = []
|
||||
for xm in x_mod
|
||||
new_x = x + xm
|
||||
for y in ymod
|
||||
for ym in y_mod
|
||||
new_y = y + ym
|
||||
if valid_coords(new_x, new_y) and piece?(new_x, new_y) and team != team(new_x, new_y)
|
||||
final_x = new_x + xm
|
||||
|
@ -112,14 +115,18 @@ class Board
|
|||
end
|
||||
|
||||
if jumps == []
|
||||
return [path]
|
||||
if path == []
|
||||
return []
|
||||
else
|
||||
return [path]
|
||||
end
|
||||
else
|
||||
return jumps
|
||||
end
|
||||
end
|
||||
|
||||
def piece?(x, y)
|
||||
return !emtpy(x, y)
|
||||
return !empty?(x, y)
|
||||
end
|
||||
|
||||
def team(x, y)
|
||||
|
@ -141,7 +148,7 @@ class Board
|
|||
return (@board[y][x] == TEAM_1_KING or @board[y][x] == TEAM_2_KING)
|
||||
end
|
||||
|
||||
def valid_moves(x, y, team)
|
||||
def piece_valid_moves(x, y, team)
|
||||
moves = []
|
||||
if piece_team(@board[y][x]) == team
|
||||
direction = [1]
|
||||
|
@ -167,6 +174,29 @@ class Board
|
|||
return b
|
||||
end
|
||||
|
||||
#def do_move(x, y, move, team)
|
||||
# move.each
|
||||
|
||||
def gen_next_move_boards()
|
||||
boards = []
|
||||
for x in 0..(BOARD_SIZE-1)
|
||||
for y in 0..(BOARD_SIZE-1)
|
||||
if piece?(x, y)
|
||||
moves = piece_valid_moves(x, y, team(x, y))
|
||||
moves.each { |move|
|
||||
board = dup()
|
||||
board.do_move(x, y, move, team(x, y))
|
||||
boards.push(board)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
return boards
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
b = Board.new()
|
||||
|
|
Loading…
Reference in New Issue