Skip to content

Instantly share code, notes, and snippets.

@miketheman
Created April 10, 2013 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketheman/5353364 to your computer and use it in GitHub Desktop.
Save miketheman/5353364 to your computer and use it in GitHub Desktop.
WFTDA Rules calculation for jammers time to serve, according to Rule 7.3 http://wftda.com/rules/20130101/section/7.3
#!/usr/bin/env ruby
# seconds of penalty assignment
# you may pass these in on the commandline so:
# => ./jammers.rb 120 60
jammerA = ARGV[0] ? ARGV[0].to_i : 60
jammerB = ARGV[1] ? ARGV[1].to_i : 60
t = rand(0..jammerA) # => random number between 0 and the maximum time for jammerA
# calculate remaining time
jAremain = jammerA - t
jBremain = jammerB # => assign full value, no time has been served
if jAremain < jBremain == true
rule = "7.3, 7.3.10.1"
jAfinal = 0 # => reduce this jammer's time to 0
jBfinal = jBremain - jAremain # => reduce the time remaining by time served by other jammer
elsif jAremain >= jBremain == true
rule = "7.3.10"
jAfinal = jAremain - 60
jBfinal = 0
else
puts "unhandled calculation, should never see this message"
end
def resultmsg(result)
case result
when 0
"Jammer may be released"
else
"Jammer must serve #{result} seconds"
end
end
puts "We started with Jammer A serving #{jammerA} seconds, and has served #{t} seconds."
puts "Then Jammer B arrives with #{jammerB} seconds to serve."
puts "Let's see what our Jammers should do:"
puts "- Jammer A: #{resultmsg(jAfinal)}"
puts "- Jammer B: #{resultmsg(jBfinal)}"
puts "rule referenced: #{rule}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment