#!/usr/bin/ruby require "taskrandmove.rb" class ElAIManager def initialize() end def run_next_task() elected_task = nil ballot = {} # Create a ballot (hash) of tasks sorted by their votes (desire * weight). candidate = TaskRandMove.new ballot[candidate] = candidate.desire * 1 # Vote for TaskRandMove with a weight of 0.1 sorted_ballot = ballot.keys.sort {|a,b| ballot[a] < ballot[b]} # Pick the action with the greatest vote, and store that in elected_task elected_task = sorted_ballot[0] # Let the newly elected task serve a term in office if (elected_task != nil) elected_task.execute() else print "Elected a dead candidate!" #TODO: Print out more debug info end end end if __FILE__ == $0 require "../utils/assert.rb" print "unit test succeeded\n" end