fixed gen_jumped methods and wrote/tempalted gen_baord_moves

This commit is contained in:
Dan Ballard 2011-09-05 09:44:19 -07:00
parent f61b9ee0a7
commit 8c0cfc5037
1 changed files with 34 additions and 4 deletions

View File

@ -13,6 +13,7 @@ BOARD_SIZE = 8
class Board class Board
def initialize() def initialize()
@board = Array.new(BOARD_SIZE) {|i| Array.new(BOARD_SIZE, BOARD_EMPTY)} @board = Array.new(BOARD_SIZE) {|i| Array.new(BOARD_SIZE, BOARD_EMPTY)}
@stats = {TEAM_1 => {}, TEAM_2 => {}}
end end
def setup() def setup()
@ -29,6 +30,8 @@ class Board
@board[i][j] = peice @board[i][j] = peice
} }
} }
@stats[TEAM_1]['count'] = 12
@stats[TEAM_2]['count'] = 12
end end
def set(x, y, thing) def set(x, y, thing)
@ -99,7 +102,7 @@ class Board
jumps = [] jumps = []
for xm in x_mod for xm in x_mod
new_x = x + xm new_x = x + xm
for y in ymod for ym in y_mod
new_y = y + ym new_y = y + ym
if valid_coords(new_x, new_y) and piece?(new_x, new_y) and team != team(new_x, new_y) 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 final_x = new_x + xm
@ -112,14 +115,18 @@ class Board
end end
if jumps == [] if jumps == []
return [path] if path == []
return []
else
return [path]
end
else else
return jumps return jumps
end end
end end
def piece?(x, y) def piece?(x, y)
return !emtpy(x, y) return !empty?(x, y)
end end
def team(x, y) def team(x, y)
@ -141,7 +148,7 @@ class Board
return (@board[y][x] == TEAM_1_KING or @board[y][x] == TEAM_2_KING) return (@board[y][x] == TEAM_1_KING or @board[y][x] == TEAM_2_KING)
end end
def valid_moves(x, y, team) def piece_valid_moves(x, y, team)
moves = [] moves = []
if piece_team(@board[y][x]) == team if piece_team(@board[y][x]) == team
direction = [1] direction = [1]
@ -167,6 +174,29 @@ class Board
return b return b
end 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 end
b = Board.new() b = Board.new()