# My First Engine
module Chess::Engine; end
module Chess::Engine::FirstEngine
UNIT_SCORES = {
Chess::Piece::PAWN => 1,
Chess::Piece::BISHOP => 3,
Chess::Piece::KNIGHT => 3,
Chess::Piece::ROOK => 5,
Chess::Piece::QUEEN => 8,
Chess::Piece::KING => 0
}
MOVES_PER_UNIT = 5
def position colour
my_pieces = pieces_owned_by colour
score = 0
# add the score of each unit we actually own here
score += MOVES_PER_UNIT * my_pieces.map {|p| UNIT_SCORES[p.type]}.inject {|x,y| x+y}
# now add points for each square our units can move to
score += my_pieces.map {|p| p.possible_targets.length}.inject {|x,y| x+y}
# TODO: add points for pieces defending each other?
score
end
end